From 550e571d0af076d918459c432bbd850245cf0702 Mon Sep 17 00:00:00 2001 From: John Mettraux Date: Thu, 25 Mar 2021 15:54:28 +0900 Subject: [PATCH] Ensure leaving ZH DST is OK, gh-53 --- CHANGELOG.md | 2 ++ lib/fugit/cron.rb | 3 ++- spec/cron_spec.rb | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 628b2dd..863ca86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ## fugit 1.4.4 not yet released +* Ensure leaving ZH DST is OK, gh-53 + ## fugit 1.4.3 released 2021-03-23 diff --git a/lib/fugit/cron.rb b/lib/fugit/cron.rb index a149c9f..2dac6ee 100644 --- a/lib/fugit/cron.rb +++ b/lib/fugit/cron.rb @@ -92,7 +92,8 @@ def inc_month def inc_day inc((24 - @t.hour) * 3600 - @t.min * 60 - @t.sec) - inc( - @t.hour * 3600) if @t.hour != 0 # compensate for entering DST + #inc( - @t.hour * 3600) if @t.hour != 0 # compensate for entering DST + inc( - @t.hour * 3600) if @t.hour > 0 && @t.hour < 7 end def inc_hour inc((60 - @t.min) * 60 - @t.sec) diff --git a/spec/cron_spec.rb b/spec/cron_spec.rb index c567e22..b3083c5 100644 --- a/spec/cron_spec.rb +++ b/spec/cron_spec.rb @@ -311,6 +311,30 @@ end end + it 'correctly increments out of DST (gh-53 e)' do + + in_zone 'Europe/Zurich' do + + #c = Fugit::Nat.parse('every monday at midnight') + c = Fugit::Cron.parse('0 0 * * 2') + t = EtOrbi::EoTime.parse('2021-10-18 12:00:00') + + points = + 4.times.collect do + t = c.next_time(t) + tu = t.dup.utc + "#{t.strftime('%F_%H:%M_%Z')}__#{tu.strftime('%F_%H:%M_%Z')}" + end + + expect(points.join("\n")).to eq(%w[ + 2021-10-19_00:00_CEST__2021-10-18_22:00_UTC + 2021-10-26_00:00_CEST__2021-10-25_22:00_UTC + 2021-11-02_00:00_CET__2021-11-01_23:00_UTC + 2021-11-09_00:00_CET__2021-11-08_23:00_UTC + ].join("\n")) + end + end + it 'correctly increments out of DST' do in_zone 'America/Los_Angeles' do