- Notifications
You must be signed in to change notification settings - Fork23
Immutable type that represents some amount of time with accuracy in seconds.
License
josedonizetti/ruby-duration
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Duration is an immutable type that represents some amount of time with accuracy in seconds.
A lot of the code and inspirations is borrowed fromdurationlib, which is amutable Duration type with lot more features.
If you use ruby-duration and want to take over the project, let me know.
- Representation of time in weeks, days, hours, minutes and seconds.
- Construtor can receive the amount of time in seconds or a Hash with unit and amount of time.
- Format method to display the time with i18n support.
- Mongoid serialization support. Use
require 'duration/mongoid'. - Tested on mri 1.9.3 and jruby. Kudos to rvm!
Duration.new(100) => #<Duration: minutes=1, seconds=40, total=100>Duration.new(:hours => 5, :minutes => 70) => #<Duration: hours=6, minutes=10, total=22200>Duration.new(:weeks => 3, :days => 1).format("%w %~w and %d %~d") => "3 weeks and 1 day"Duration.new(:weeks => 1, :days => 20).format("%w %~w and %d %~d") => "3 weeks and 6 days"Duration.new(:weeks => 1, :days => 20).iso8601 => "P3W6DT0H0M0S"Duration.new("P6DT5S") => #<Duration: days=6, seconds=5, total=518405>The current version of this gem supports Mongoid >=3.0.0.For lower Mongoid versions try:
require 'duration/mongoid' class MyModel include Mongoid::Document field :duration, type => Duration endThe current version of this gem runs only on Ruby Versions >= 1.9.3.If you are running a older version of Ruby try:
- tagv2.1.4
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it. This is important so I don't break it in afuture version unintentionally.
- Commit, do not mess with rakefile, version, or history.(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
- Send me a pull request. Bonus points for topic branches.
Copyright (c) 2010 Jose Peleteiro
Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:
The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
About
Immutable type that represents some amount of time with accuracy in seconds.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.