spec/cronline_spec.rb in rufus-scheduler-3.1.7 vs spec/cronline_spec.rb in rufus-scheduler-3.1.8
- old
+ new
@@ -5,11 +5,22 @@
# Sat Mar 21 12:55:27 JST 2009
#
require 'spec_helper'
+class Time
+ def to_compact_s
+
+ off = self.utc_offset / 3600
+ off = off >= 0 ? "+#{off}" : off.to_s
+
+ self.strftime('%H%M') + off + self.dup.utc.strftime('(%H%M)')
+ end
+end
+
+
describe Rufus::Scheduler::CronLine do
def cl(cronline_string)
Rufus::Scheduler::CronLine.new(cronline_string)
end
@@ -390,11 +401,14 @@
expect(
ntz(
'30 1 31 10 * America/New_York',
ltz('America/New_York', 2004, 10, 1)
)
- ).to eq(ltz('America/New_York', 2004, 10, 31, 1, 30, 0))
+ ).to eq(
+ ltz('America/New_York', 0, 30, 1, 31, 10, 2004, nil, nil, true, nil)
+ # EDT summer time UTC-4
+ )
end
end
# gh-127
#
@@ -493,11 +507,14 @@
expect(
ptz(
'30 1 31 10 * America/New_York',
ltz('America/New_York', 2004, 10, 31, 14, 30, 0)
)
- ).to eq(ltz('America/New_York', 2004, 10, 31, 1, 30, 0))
+ ).to eq(
+ ltz('America/New_York', 0, 30, 1, 31, 10, 2004, nil, nil, false, nil)
+ # EST time UTC-5
+ )
end
end
# gh-127
#
@@ -861,23 +878,21 @@
line = cl('* * * * * America/Los_Angeles')
t = Time.local(2015, 3, 8, 1, 57)
points =
- [ 0, 1, 2, 3 ].collect do
+ 4.times.collect do
t = line.next_time(t)
- t.strftime('%H:%M:%Sl') + ' ' + t.dup.utc.strftime('%H:%M:%Su')
+ t.to_compact_s
end
- expect(points).to eq(
- [
- '01:58:00l 09:58:00u',
- '01:59:00l 09:59:00u',
- '03:00:00l 10:00:00u',
- '03:01:00l 10:01:00u'
- ]
- )
+ expect(points).to eq([
+ '0158-8(0958)',
+ '0159-8(0959)',
+ '0300-7(1000)',
+ '0301-7(1001)'
+ ])
end
end
it 'correctly decrements through a DST transition' do
@@ -893,22 +908,161 @@
line = cl('* * * * * America/Los_Angeles')
t = Time.local(2015, 3, 8, 3, 2)
points =
- [ 0, 1, 2, 3 ].collect do
+ 4.times.collect do
t = line.previous_time(t)
- t.strftime('%H:%M:%Sl') + ' ' + t.dup.utc.strftime('%H:%M:%Su')
+ t.to_compact_s
end
- expect(points).to eq(
- [
- '03:01:00l 10:01:00u',
- '03:00:00l 10:00:00u',
- '01:59:00l 09:59:00u',
- '01:58:00l 09:58:00u'
- ]
- )
+ expect(points).to eq([
+ '0301-7(1001)',
+ '0300-7(1000)',
+ '0159-8(0959)',
+ '0158-8(0958)'
+ ])
+ end
+ end
+
+ it 'correctly increments when entering DST' do
+
+ in_zone 'America/Los_Angeles' do
+
+ line = cl('*/10 * * * * America/Los_Angeles')
+
+ t = Time.local(2015, 3, 8, 1, 40)
+ t1 = t.dup
+
+ points = []
+ while t1 - t < 1 * 3600
+ t1 = line.next_time(t1)
+ points << t1.to_compact_s
+ end
+
+ expect(points).to eq(%w[
+ 0150-8(0950)
+ 0300-7(1000)
+ 0310-7(1010)
+ 0320-7(1020)
+ 0330-7(1030)
+ 0340-7(1040)
+ ])
+ end
+ end
+ end
+
+ context 'fall time' do
+
+ it 'correctly increments through a DST transition' do
+
+ expect(
+ nt('* * * * * America/Los_Angeles', Time.utc(2015, 11, 1, 9, 59))
+ ).to eq(Time.utc(2015, 11, 1, 10, 00))
+ end
+
+ it 'correctly increments every minute through a DST transition' do
+
+ in_zone 'America/Los_Angeles' do
+
+ line = cl('* * * * * America/Los_Angeles')
+
+ #t = Time.local(2015, 11, 1, 1, 57)
+ #
+ # --> 2015-11-01 01:57:00 -0800 (already PST)
+
+ t = Time.local(0, 57, 1, 1, 11, 2015, nil, nil, true, nil)
+ #
+ # --> 2015-11-01 01:57:00 -0700 (still PDT)
+
+ points =
+ 4.times.collect do
+ t = line.next_time(t)
+ t.to_compact_s
+ end
+
+ expect(points).to eq([
+ '0158-7(0858)',
+ '0159-7(0859)',
+ '0100-8(0900)',
+ '0101-8(0901)'
+ ])
+ end
+ end
+
+ it 'correctly decrements through a DST transition' do
+
+ expect(
+ pt('* * * * * America/Los_Angeles', Time.utc(2015, 11, 1, 10, 00))
+ ).to eq(Time.utc(2015, 11, 1, 9, 59))
+ end
+
+ it 'correctly decrements every minute through a DST transition' do
+
+ in_zone 'America/Los_Angeles' do
+
+ line = cl('* * * * * America/Los_Angeles')
+
+ t = Time.local(0, 2, 1, 1, 11, 2015, nil, nil, true, nil)
+ #
+ # try to force PST
+
+ # TODO: at some point, try to find out if the latest jRuby still
+ # exhibits that behaviour, report to them if necessary
+
+ points =
+ (0..3).collect do
+ t = line.previous_time(t)
+ t.to_compact_s
+ end
+
+ if t.zone == 'PST'
+ expect(points).to eq([
+ '0101-8(0901)',
+ '0100-8(0900)',
+ '0159-7(0859)',
+ '0158-7(0858)'
+ ])
+ else
+ expect(points).to eq([
+ '0101-7(0801)',
+ '0100-7(0800)',
+ '0059-7(0759)',
+ '0058-7(0758)'
+ ])
+ end
+ end
+ end
+
+ it 'correctly increments when leaving DST' do
+
+ in_zone 'America/Los_Angeles' do
+
+ line = cl('*/10 * * * * America/Los_Angeles')
+
+ t = Time.local(2015, 11, 1, 0, 40)
+ t1 = t.dup
+
+ points = []
+ while t1 - t < 2 * 3600
+ t1 = line.next_time(t1)
+ points << t1.to_compact_s
+ end
+
+ expect(points).to eq([
+ '0050-7(0750)', # | PDT
+ '0100-7(0800)', # |
+ '0110-7(0810)', # V
+ '0120-7(0820)',
+ '0130-7(0830)',
+ '0140-7(0840)',
+ '0150-7(0850)',
+ '0100-8(0900)', # + PST
+ '0110-8(0910)', # |
+ '0120-8(0920)', # V
+ '0130-8(0930)',
+ '0140-8(0940)'
+ ])
end
end
end
end