From: sawadatsuyoshi@... Date: 2016-03-14T19:48:41+00:00 Subject: [ruby-core:74304] [Ruby trunk Feature#12173] `Time#till_now` Issue #12173 has been updated by Tsuyoshi Sawada. This can also be used to wait until a preset time: ~~~RUBY target_time = Time.new(2017, 1, 1, 0, 0, 0) sleep(-target_time.till_now) ~~~ Or perhaps, the opposite (multiplied by `-1`) might be more intuitive: ~~~RUBY class Time def from_now; self - self.class.now end end ~~~ so that we can do: ~~~RUBY target_time = Time.new(2017, 1, 1, 0, 0, 0) sleep(target_time.from_now) ~~~ or t = Time.now # some heavy operation puts "It took #{-t.from_now} secs." ---------------------------------------- Feature #12173: `Time#till_now` https://bugs.ruby-lang.org/issues/12173#change-57422 * Author: Tsuyoshi Sawada * Status: Open * Priority: Normal * Assignee: ---------------------------------------- It is very frequent to have a time instance: ~~~RUBY t = Time.now ~~~ and then after some operations, do: ~~~RUBY Time.now - t ~~~ I propose `Time#till_now`, which is equivalent to: ~~~RUBY class Time def till_now; self.class.now - self end end ~~~ and similar methods can perhaps be defined on `Date` and `DateTime` classes as well. Another candidate for the method name is `until_now`. Then we can do: ~~~RUBY t = Time.now # some heavy operation puts "It took #{t.till_now} secs." -- https://bugs.ruby-lang.org/ Unsubscribe: