diff options
author | gbuesing <gbuesing@gmail.com> | 2008-04-12 19:35:47 -0500 |
---|---|---|
committer | gbuesing <gbuesing@gmail.com> | 2008-04-12 19:35:47 -0500 |
commit | 9620372a6dc7eeebdb04f1fdb7f150d29e60fc00 (patch) | |
tree | 602897010f85ae36f4849bd6ba0c0c9010986191 /activesupport/lib/active_support | |
parent | f285b6119b9ca7f598e31c0c8518dce3e1b13386 (diff) | |
download | rails-9620372a6dc7eeebdb04f1fdb7f150d29e60fc00.tar.gz rails-9620372a6dc7eeebdb04f1fdb7f150d29e60fc00.tar.bz2 rails-9620372a6dc7eeebdb04f1fdb7f150d29e60fc00.zip |
Time#since behaves correctly when passed a Duration. Closes #11527 [kemiller]
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 0bc83af709..ffbdf37789 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -88,18 +88,21 @@ module ActiveSupport #:nodoc: end # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension - # Do not use this method in combination with x.months, use months_ago instead! def ago(seconds) self.since(-seconds) end # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around - # the Numeric extension. Do not use this method in combination with x.months, use months_since instead! + # the Numeric extension. def since(seconds) - initial_dst = self.dst? ? 1 : 0 f = seconds.since(self) - final_dst = f.dst? ? 1 : 0 - (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f + if ActiveSupport::Duration === seconds + f + else + initial_dst = self.dst? ? 1 : 0 + final_dst = f.dst? ? 1 : 0 + (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f + end rescue self.to_datetime.since(seconds) end |