From b8b7490f8ae8867f886ccde4406cdc56325b127a Mon Sep 17 00:00:00 2001 From: John Mettraux Date: Wed, 13 Mar 2024 10:31:36 +0900 Subject: [PATCH] Align Cron#previous_time on #next_time spec, gh-95 --- spec/cron_spec.rb | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/spec/cron_spec.rb b/spec/cron_spec.rb index ed2a654..7edbc7a 100644 --- a/spec/cron_spec.rb +++ b/spec/cron_spec.rb @@ -888,31 +888,37 @@ class Fugit::Cron::TimeCursor # at 4:30 am on the 1st and 15th of each month, plus every Friday. [ '21 0 * * 1%2 America/Sao_Paulo', - '2024-03-04 12:21:00', '2024-03-13 12:00' ], + '2024-03-04 04:21:00', '2024-03-13 12:00', 'Europe/Paris' ], [ '21 0 * * 1%2 America/Santarem', - '2024-03-04 12:21:00', '2024-03-13 12:00' ], + '2024-03-04 04:21:00', '2024-03-13 12:00', 'Europe/Paris' ], ] describe '#previous_time' do - PREVIOUS_TIMES.each do |cron, previous_time, now| + PREVIOUS_TIMES.each do |cron, previous_time, now, zone_name| - now = now ? Time.parse(now) : NOW + d = "succeeds #{cron.inspect} #{now} -> #{previous_time.inspect}" + d = d += " in #{zone_name}" if zone_name - it "succeeds #{cron.inspect} #{now} -> #{previous_time.inspect}" do + it(d) do - c = Fugit::Cron.parse(cron) - ept = Time.parse(previous_time) + in_zone(zone_name) do - pt = c.previous_time(now) + now = now ? Time.parse(now) : NOW - expect( - Fugit.time_to_plain_s(pt, false) - ).to eq( - Fugit.time_to_plain_s(ept, false) - ) + c = Fugit::Cron.parse(cron) + ept = Time.parse(previous_time) - expect(c.match?(ept)).to eq(true) # quick check + pt = c.previous_time(now) + + expect( + Fugit.time_to_plain_s(pt, false) + ).to eq( + Fugit.time_to_plain_s(ept, false) + ) + + expect(c.match?(ept)).to eq(true) # quick check + end end end