diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-01-23 18:49:54 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-01-23 18:49:54 +0000 |
commit | cb8de22dfb7a6dd5cb5bdca0d38ae797925e89d7 (patch) | |
tree | 65c68554635c0a462b3318ccd0534d3d29d83508 /activesupport | |
parent | b2fa70a8e1a7a02873e54bb38abafabdd103476a (diff) | |
download | rails-cb8de22dfb7a6dd5cb5bdca0d38ae797925e89d7.tar.gz rails-cb8de22dfb7a6dd5cb5bdca0d38ae797925e89d7.tar.bz2 rails-cb8de22dfb7a6dd5cb5bdca0d38ae797925e89d7.zip |
Time #in_current_time_zone and #change_time_zone_to_current return self when Time.zone is nil
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8708 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/zones.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 8 |
3 files changed, 8 insertions, 6 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 8e74df3097..633b9cbb89 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Time #in_current_time_zone and #change_time_zone_to_current return self when Time.zone is nil [Geoff Buesing] + * Remove unneeded #to_datetime_default_s alias for DateTime#to_s, given that we inherit a #to_default_s from Date that does exactly the same thing [Geoff Buesing] * Refactor Time and DateTime #to_formatted_s: use ternary instead of nested if/else [Geoff Buesing] diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb index 563d522d9a..390d4128a1 100644 --- a/activesupport/lib/active_support/core_ext/time/zones.rb +++ b/activesupport/lib/active_support/core_ext/time/zones.rb @@ -46,7 +46,7 @@ module ActiveSupport #:nodoc: # Returns the simultaneous time in Time.zone def in_current_time_zone - in_time_zone(::Time.zone) + ::Time.zone ? in_time_zone(::Time.zone) : self end # Replaces the existing zone; leaves time value intact. Examples: @@ -60,7 +60,7 @@ module ActiveSupport #:nodoc: # Replaces the existing zone to Time.zone; leaves time value intact def change_time_zone_to_current - change_time_zone(::Time.zone) + ::Time.zone ? change_time_zone(::Time.zone) : self end end end diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 5b0c0fd569..55f41e0715 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -170,8 +170,8 @@ uses_tzinfo 'TimeWithZoneTest' do assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_current_time_zone.inspect end with_time_zone nil do - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.in_current_time_zone.inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.in_current_time_zone.inspect + assert_equal @t, @t.in_current_time_zone + assert_equal @dt, @dt.in_current_time_zone end end @@ -196,8 +196,8 @@ uses_tzinfo 'TimeWithZoneTest' do assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @dt.change_time_zone_to_current.inspect end with_time_zone nil do - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.change_time_zone_to_current.inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.change_time_zone_to_current.inspect + assert_equal @t, @t.change_time_zone_to_current + assert_equal @dt, @dt.change_time_zone_to_current end end |