spec/cronline_spec.rb in rufus-scheduler-3.1.8 vs spec/cronline_spec.rb in rufus-scheduler-3.1.9
- old
+ new
@@ -44,10 +44,13 @@
end
def ns(cronline, now)
Rufus::Scheduler::CronLine.new(cronline).next_second(now)
end
+ def ps(cronline, now)
+ Rufus::Scheduler::CronLine.new(cronline).prev_second(now)
+ end
def match(line, time)
expect(cl(line).matches?(time)).to eq(true)
end
def no_match(line, time)
@@ -470,10 +473,30 @@
expect(ns(cronline,now)).to eq(sec)
end
end
end
+ describe '#prev_second' do
+
+ it 'returns the time to the closest previous second' do
+
+ t = local(1970, 1, 1, 1, 1, 42)
+
+ expect(ps('35,44 * * * * *', t)).to eq(7)
+ end
+
+ context 'when time sec is lower then all cron seconds (gh-177)' do
+
+ it 'returns the time to the last second a minute before' do
+
+ t = local(1970, 1, 1, 1, 1, 42)
+
+ expect(ps('43,44 * * * * *', t)).to eq(58)
+ end
+ end
+ end
+
describe '#previous_time' do
it 'returns the previous time the cron should have triggered' do
expect(
@@ -485,9 +508,30 @@
expect(
pt('0 0 2 1 *', lo(1970, 1, 1))).to eq(lo(1969, 1, 2, 0, 00))
expect(
pt('* * * * * sun', lo(1970, 1, 1))).to eq(lo(1969, 12, 28, 23, 59, 59))
+ end
+
+ it 'jumps to the previous minute if necessary (gh-177)' do
+
+ t = local(1970, 12, 31, 1, 1, 0) # vanilla
+ expect(pt('43,44 * * * * *', t)).to eq(lo(1970, 12, 31, 1, 0, 44))
+
+ t = local(1970, 12, 31, 1, 1, 30) # 30 < 43 <---- here!
+ expect(pt('43,44 * * * * *', t)).to eq(lo(1970, 12, 31, 1, 0, 44))
+
+ t = local(1970, 12, 31, 1, 1, 43) # 43 <= 43 < 44
+ expect(pt('43,44 * * * * *', t)).to eq(lo(1970, 12, 31, 1, 0, 44))
+
+ t = local(1970, 12, 31, 1, 1, 44) # 44 <= 44
+ expect(pt('43,44 * * * * *', t)).to eq(lo(1970, 12, 31, 1, 1, 43))
+
+ t = local(1970, 12, 31, 1, 1, 59) # 44 < 59
+ expect(pt('43,44 * * * * *', t)).to eq(lo(1970, 12, 31, 1, 1, 44))
+
+ t = local(1970, 12, 31, 1, 1, 30) # a bigger jump
+ expect(pt('43,44 10 * * * *', t)).to eq(lo(1970, 12, 31, 0, 10, 44))
end
# New York EST: UTC-5
# summer (dst) EDT: UTC-4