josedonizetti / ruby-duration

Immutable type that represents some amount of time with accuracy in seconds.
http://bit.ly/ruby-duration
MIT License
124 stars 23 forks source link

Adding duration to time #32

Open sandstrom opened 8 years ago

sandstrom commented 8 years ago

Would be great if one could add a duration to time, yielding a new time instance.

Time.now + Duration.new(:days => 1) #=> time_at_one_day_from_now

Ruby's coerce should also be helpful here, so that the ordering doesn't matter:


# Similarly, I would expect
Duration.new(:days => 2) + Time.now === Time.now.advance(:days => 2)

# Currently this is instead:
Duration.new(:days => 2) + Time.now # => seconds since 1970 + 2 days (as `Duration`)

# While this is one possible interpretation It's fairy non-sensical, 
# i.e. it's not very useful, while a result that returned a new time instance 
# would make durations much more useable!