Permalink
Browse files

Maintain the current timezone in wrap_with_time_zone

Extend the solution from the fix for #12163 to the general case where
`Time` methods are wrapped with a time zone.

Fixes #12596.
  • Loading branch information...
1 parent f484df7 commit 63f8fabe4939ad59d597dfea441002ef5b16d2f4 @pixeltrix pixeltrix committed Jan 31, 2014
@@ -1,3 +1,12 @@
+* Maintain the current timezone when calling `wrap_with_time_zone`
+
+ Extend the solution from the fix for #12163 to the general case where `Time`
+ methods are wrapped with a time zone.
+
+ Fixes #12596.
+
+ *Andrew White*
+
* Remove behavior that automatically remove the Date/Time stubs, added by `travel`
and `travel_to` methods, after each test case.
@@ -292,12 +292,6 @@ def advance(options)
end
end
- def change(options)
- new_time = time.change(options)
- periods = time_zone.periods_for_local(new_time)
- self.class.new(nil, time_zone, new_time, periods.include?(period) ? period : nil)
- end
-
%w(year mon month day mday wday yday hour min sec usec nsec to_date).each do |method_name|
class_eval <<-EOV, __FILE__, __LINE__ + 1
def #{method_name} # def month
@@ -396,7 +390,8 @@ def duration_of_variable_length?(obj)
def wrap_with_time_zone(time)
if time.acts_like?(:time)
- self.class.new(nil, time_zone, time)
+ periods = time_zone.periods_for_local(time)
+ self.class.new(nil, time_zone, time, periods.include?(period) ? period : nil)
elsif time.is_a?(Range)
wrap_with_time_zone(time.begin)..wrap_with_time_zone(time.end)
else
@@ -500,6 +500,11 @@ def test_change_at_dst_boundary
assert_equal twz, twz.change(:min => 0)
end
+ def test_round_at_dst_boundary
+ twz = ActiveSupport::TimeWithZone.new(Time.at(1319936400).getutc, ActiveSupport::TimeZone['Madrid'])
+ assert_equal twz, twz.round
+ end
+
def test_advance
assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect
assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.advance(:years => 2).inspect

0 comments on commit 63f8fab

Please sign in to comment.