ruby-duration icon indicating copy to clipboard operation
ruby-duration copied to clipboard

Adding duration to time

Open sandstrom opened this issue 9 years ago • 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:

  • https://www.mutuallyhuman.com/blog/2011/01/25/class-coercion-in-ruby/
  • http://c2.com/cgi/wiki?RubyCoerce

# 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!

sandstrom avatar May 30 '16 17:05 sandstrom