diff options
author | gbuesing <gbuesing@gmail.com> | 2008-04-20 21:57:04 -0500 |
---|---|---|
committer | gbuesing <gbuesing@gmail.com> | 2008-04-20 21:57:04 -0500 |
commit | 32b82e4c6f5523cdf5ee78c3022c50b46e018351 (patch) | |
tree | 1dd9310b862dde2a4788e1d7c7fda99838b7c172 /activesupport/lib/active_support | |
parent | ef8d26653d308354050ed80f61444bec5458ce05 (diff) | |
download | rails-32b82e4c6f5523cdf5ee78c3022c50b46e018351.tar.gz rails-32b82e4c6f5523cdf5ee78c3022c50b46e018351.tar.bz2 rails-32b82e4c6f5523cdf5ee78c3022c50b46e018351.zip |
Duration #since and #ago with no argument (e.g., 5.days.ago) return TimeWithZone when config.time_zone is set. Introducing Time.current, which returns Time.zone.now if config.time_zone is set, otherwise just returns Time.now
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/zones.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/duration.rb | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb index d2b95698e5..3ffc71407c 100644 --- a/activesupport/lib/active_support/core_ext/time/zones.rb +++ b/activesupport/lib/active_support/core_ext/time/zones.rb @@ -35,6 +35,11 @@ module ActiveSupport #:nodoc: ::Time.zone = old_zone end + # Returns Time.zone.now when config.time_zone is set, otherwise just returns Time.now. + def current + ::Time.zone_default ? ::Time.zone.now : ::Time.now + end + private def get_zone(time_zone) return time_zone if time_zone.nil? || time_zone.is_a?(TimeZone) diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index ff51b49dcf..8eae85d38e 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -51,14 +51,14 @@ module ActiveSupport # Calculates a new Time or Date that is as far in the future # as this Duration represents. - def since(time = ::Time.now) + def since(time = ::Time.current) sum(1, time) end alias :from_now :since # Calculates a new Time or Date that is as far in the past # as this Duration represents. - def ago(time = ::Time.now) + def ago(time = ::Time.current) sum(-1, time) end alias :until :ago @@ -73,7 +73,7 @@ module ActiveSupport protected - def sum(sign, time = ::Time.now) #:nodoc: + def sum(sign, time = ::Time.current) #:nodoc: parts.inject(time) do |t,(type,number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds |