josedonizetti/ruby-duration

Adding duration to time

sandstrom opened this issue · 0 comments

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!