aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/time_with_zone_test.rb
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxed.co>2016-08-03 14:45:09 +0100
committerAndrew White <andrew.white@unboxed.co>2016-08-03 14:45:09 +0100
commit0e762ecdc3026d0c2191e42fbca8021da9ec34cc (patch)
treeffe76cc5fe509b0f03ffab33db1dfa377fee0116 /activesupport/test/core_ext/time_with_zone_test.rb
parentfac9938b917f3417a19775d1c6905123fc402256 (diff)
downloadrails-0e762ecdc3026d0c2191e42fbca8021da9ec34cc.tar.gz
rails-0e762ecdc3026d0c2191e42fbca8021da9ec34cc.tar.bz2
rails-0e762ecdc3026d0c2191e42fbca8021da9ec34cc.zip
Add :weeks to the list of variable duration parts
Since 434df00 week durations are no longer converted to days. This means we need to add :weeks to the parts that ActiveSupport::TimeWithZone will consider being of variable duration to take account of DST transitions. Fixes #26039.
Diffstat (limited to 'activesupport/test/core_ext/time_with_zone_test.rb')
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index d90714acdb..c873b28211 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -834,6 +834,38 @@ class TimeWithZoneTest < ActiveSupport::TestCase
assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:hours => -24).inspect
end
+ def test_advance_1_week_across_spring_dst_transition
+ twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,1,10,30))
+ assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.advance(:weeks => 1).inspect
+ assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.weeks_since(1).inspect
+ assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.since(1.week).inspect
+ assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", (twz + 1.week).inspect
+ end
+
+ def test_advance_1_week_across_spring_dst_transition_backwards
+ twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,8,10,30))
+ assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:weeks => -1).inspect
+ assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.weeks_ago(1).inspect
+ assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1.week).inspect
+ assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1.week).inspect
+ end
+
+ def test_advance_1_week_across_fall_dst_transition
+ twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,28,10,30))
+ assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.advance(:weeks => 1).inspect
+ assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.weeks_since(1).inspect
+ assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.since(1.week).inspect
+ assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", (twz + 1.week).inspect
+ end
+
+ def test_advance_1_week_across_fall_dst_transition_backwards
+ twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,11,4,10,30))
+ assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:weeks => -1).inspect
+ assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.weeks_ago(1).inspect
+ assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1.week).inspect
+ assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1.week).inspect
+ end
+
def test_advance_1_month_across_spring_dst_transition
twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,1,10,30))
assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.advance(:months => 1).inspect