Skip to content
This repository
Browse code

TimeWithZone #in_time_zone returns +self+ if zone argument is the sam…

…e as #time_zone

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8853 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 8ad5a29cef38cd95aac6553357fc32a6e9e7b411 1 parent 8831180
Geoff Buesing authored February 10, 2008
2  activesupport/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* TimeWithZone #in_time_zone returns +self+ if zone argument is the same as #time_zone [Geoff Buesing]
  4
+
3 5
 * Adding TimeWithZone #to_a, #to_f, #to_i, #httpdate, #rfc2822 [Geoff Buesing]
4 6
 
5 7
 * Pruning unneeded TimeWithZone#change_time_zone_to_current [Geoff Buesing]
1  activesupport/lib/active_support/time_with_zone.rb
@@ -29,6 +29,7 @@ def period
29 29
 
30 30
     # Returns the simultaneous time in the specified zone
31 31
     def in_time_zone(new_zone)
  32
+      return self if time_zone == new_zone
32 33
       utc.in_time_zone(new_zone)
33 34
     end
34 35
   
4  activesupport/test/core_ext/time_with_zone_test.rb
@@ -25,6 +25,10 @@ def test_time_zone
25 25
     def test_in_time_zone
26 26
       assert_equal ActiveSupport::TimeWithZone.new(@utc, TimeZone['Alaska']), @twz.in_time_zone('Alaska')
27 27
     end
  28
+    
  29
+    def test_in_time_zone_with_new_zone_equal_to_old_zone_does_not_create_new_object
  30
+      assert_equal @twz.object_id, @twz.in_time_zone(TimeZone['Eastern Time (US & Canada)']).object_id
  31
+    end
28 32
   
29 33
     def test_in_current_time_zone
30 34
       Time.use_zone 'Alaska' do

0 notes on commit 8ad5a29

Please sign in to comment.
Something went wrong with that request. Please try again.