rufus-scheduler 3.0.8 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,681 +0,0 @@
1
-
2
- #
3
- # Specifying rufus-scheduler
4
- #
5
- # Sat Mar 21 12:55:27 JST 2009
6
- #
7
-
8
- require 'tzinfo'
9
- require 'spec_helper'
10
-
11
-
12
- describe Rufus::Scheduler::CronLine do
13
-
14
- def cl(cronline_string)
15
- Rufus::Scheduler::CronLine.new(cronline_string)
16
- end
17
-
18
- def match(line, time)
19
- expect(cl(line).matches?(time)).to eq(true)
20
- end
21
- def no_match(line, time)
22
- expect(cl(line).matches?(time)).to eq(false)
23
- end
24
- def to_a(line, array)
25
- expect(cl(line).to_array).to eq(array)
26
- end
27
-
28
- describe '.new' do
29
-
30
- it 'interprets cron strings correctly' do
31
-
32
- to_a '* * * * *', [ [0], nil, nil, nil, nil, nil, nil, nil ]
33
- to_a '10-12 * * * *', [ [0], [10, 11, 12], nil, nil, nil, nil, nil, nil ]
34
- to_a '* * * * sun,mon', [ [0], nil, nil, nil, nil, [0, 1], nil, nil ]
35
- to_a '* * * * mon-wed', [ [0], nil, nil, nil, nil, [1, 2, 3], nil, nil ]
36
- to_a '* * * * 7', [ [0], nil, nil, nil, nil, [0], nil, nil ]
37
- to_a '* * * * 0', [ [0], nil, nil, nil, nil, [0], nil, nil ]
38
- to_a '* * * * 0,1', [ [0], nil, nil, nil, nil, [0,1], nil, nil ]
39
- to_a '* * * * 7,1', [ [0], nil, nil, nil, nil, [0,1], nil, nil ]
40
- to_a '* * * * 7,0', [ [0], nil, nil, nil, nil, [0], nil, nil ]
41
- to_a '* * * * sun,2-4', [ [0], nil, nil, nil, nil, [0, 2, 3, 4], nil, nil ]
42
-
43
- to_a '* * * * sun,mon-tue', [ [0], nil, nil, nil, nil, [0, 1, 2], nil, nil ]
44
-
45
- to_a '* * * * * *', [ nil, nil, nil, nil, nil, nil, nil, nil ]
46
- to_a '1 * * * * *', [ [1], nil, nil, nil, nil, nil, nil, nil ]
47
- to_a '7 10-12 * * * *', [ [7], [10, 11, 12], nil, nil, nil, nil, nil, nil ]
48
- to_a '1-5 * * * * *', [ [1,2,3,4,5], nil, nil, nil, nil, nil, nil, nil ]
49
-
50
- to_a '0 0 1 1 *', [ [0], [0], [0], [1], [1], nil, nil, nil ]
51
-
52
- to_a '0 23-24 * * *', [ [0], [0], [23, 0], nil, nil, nil, nil, nil ]
53
- #
54
- # as reported by Aimee Rose in
55
- # https://github.com/jmettraux/rufus-scheduler/issues/56
56
-
57
- to_a '0 23-2 * * *', [ [0], [0], [23, 0, 1, 2], nil, nil, nil, nil, nil ]
58
- end
59
-
60
- it 'rejects invalid weekday expressions' do
61
-
62
- expect { cl '0 17 * * MON_FRI' }.to raise_error
63
- # underline instead of dash
64
-
65
- expect { cl '* * * * 9' }.to raise_error
66
- expect { cl '* * * * 0-12' }.to raise_error
67
- expect { cl '* * * * BLABLA' }.to raise_error
68
- end
69
-
70
- it 'rejects invalid cronlines' do
71
-
72
- expect { cl '* nada * * 9' }.to raise_error(ArgumentError)
73
- end
74
-
75
- it 'interprets cron strings with TZ correctly' do
76
-
77
- to_a('* * * * * EST', [ [0], nil, nil, nil, nil, nil, nil, 'EST' ])
78
- to_a('* * * * * * EST', [ nil, nil, nil, nil, nil, nil, nil, 'EST' ])
79
-
80
- to_a(
81
- '* * * * * * America/Chicago',
82
- [ nil, nil, nil, nil, nil, nil, nil, 'America/Chicago' ])
83
- to_a(
84
- '* * * * * * America/New_York',
85
- [ nil, nil, nil, nil, nil, nil, nil, 'America/New_York' ])
86
-
87
- expect { cl '* * * * * NotATimeZone' }.to raise_error
88
- expect { cl '* * * * * * NotATimeZone' }.to raise_error
89
- end
90
-
91
- it 'interprets cron strings with / (slashes) correctly' do
92
-
93
- to_a(
94
- '0 */2 * * *',
95
- [ [0], [0], (0..11).collect { |e| e * 2 }, nil, nil, nil, nil, nil ])
96
- to_a(
97
- '0 7-23/2 * * *',
98
- [ [0], [0], (7..23).select { |e| e.odd? }, nil, nil, nil, nil, nil ])
99
- to_a(
100
- '*/10 * * * *',
101
- [ [0], [0, 10, 20, 30, 40, 50], nil, nil, nil, nil, nil, nil ])
102
-
103
- # fighting https://github.com/jmettraux/rufus-scheduler/issues/65
104
- #
105
- to_a(
106
- '*/10 * * * * Europe/Berlin',
107
- [ [0], [ 0, 10, 20, 30, 40, 50], nil, nil, nil, nil, nil, 'Europe/Berlin' ])
108
- end
109
-
110
- it 'accepts lonely / (slashes) (like <= 2.0.19 did)' do
111
-
112
- # fighting https://github.com/jmettraux/rufus-scheduler/issues/65
113
-
114
- to_a(
115
- '/10 * * * *',
116
- [ [0], [ 0, 10, 20, 30, 40, 50], nil, nil, nil, nil, nil, nil ])
117
- end
118
-
119
- it 'rejects / for days (every other wednesday)' do
120
-
121
- expect {
122
- Rufus::Scheduler::CronLine.new('* * * * wed/2')
123
- }.to raise_error(ArgumentError)
124
- end
125
-
126
- it 'does not support ranges for monthdays (sun#1-sun#2)' do
127
-
128
- expect {
129
- Rufus::Scheduler::CronLine.new('* * * * sun#1-sun#2')
130
- }.to raise_error(ArgumentError)
131
- end
132
-
133
- it 'accepts items with initial 0' do
134
-
135
- to_a(
136
- '09 * * * *', [ [0], [9], nil, nil, nil, nil, nil, nil ])
137
- to_a(
138
- '09-12 * * * *', [ [0], [9, 10, 11, 12], nil, nil, nil, nil, nil, nil ])
139
- to_a(
140
- '07-08 * * * *', [ [0], [7, 8], nil, nil, nil, nil, nil, nil ])
141
- to_a(
142
- '* */08 * * *', [ [0], nil, [0, 8, 16], nil, nil, nil, nil, nil ])
143
- to_a(
144
- '* */07 * * *', [ [0], nil, [0, 7, 14, 21], nil, nil, nil, nil, nil ])
145
- to_a(
146
- '* 01-09/04 * * *', [ [0], nil, [1, 5, 9], nil, nil, nil, nil, nil ])
147
- to_a(
148
- '* * * * 06', [ [0], nil, nil, nil, nil, [6], nil, nil ])
149
- end
150
-
151
- it 'interprets cron strings with L correctly' do
152
-
153
- to_a(
154
- '* * L * *', [[0], nil, nil, ['L'], nil, nil, nil, nil ])
155
- to_a(
156
- '* * 2-5,L * *', [[0], nil, nil, [2,3,4,5,'L'], nil, nil, nil, nil ])
157
- to_a(
158
- '* * */8,L * *', [[0], nil, nil, [1,9,17,25,'L'], nil, nil, nil, nil ])
159
- end
160
-
161
- it 'does not support ranges for L' do
162
-
163
- expect { cl '* * 15-L * *'}.to raise_error(ArgumentError)
164
- expect { cl '* * L/4 * *'}.to raise_error(ArgumentError)
165
- end
166
-
167
- it 'does not support multiple Ls' do
168
-
169
- expect { cl '* * L,L * *'}.to raise_error(ArgumentError)
170
- end
171
-
172
- it 'raises if L is used for something else than days' do
173
-
174
- expect { cl '* L * * *'}.to raise_error(ArgumentError)
175
- end
176
-
177
- it 'raises for out of range input' do
178
-
179
- expect { cl '60-62 * * * *'}.to raise_error(ArgumentError)
180
- expect { cl '62 * * * *'}.to raise_error(ArgumentError)
181
- expect { cl '60 * * * *'}.to raise_error(ArgumentError)
182
- expect { cl '* 25-26 * * *'}.to raise_error(ArgumentError)
183
- expect { cl '* 25 * * *'}.to raise_error(ArgumentError)
184
- #
185
- # as reported by Aimee Rose in
186
- # https://github.com/jmettraux/rufus-scheduler/pull/58
187
- end
188
- end
189
-
190
- describe '#next_time' do
191
-
192
- def nt(cronline, now)
193
- Rufus::Scheduler::CronLine.new(cronline).next_time(now)
194
- end
195
- def ntz(cronline, now)
196
- tz = cronline.split.last
197
- tu = nt(cronline, now).utc
198
- in_zone(tz) { tu.getlocal }
199
- end
200
-
201
- it 'computes the next occurence correctly' do
202
-
203
- now = Time.at(0).getutc # Thu Jan 01 00:00:00 UTC 1970
204
-
205
- expect(nt('* * * * *', now)).to eq(now + 60)
206
- expect(nt('* * * * sun', now)).to eq(now + 259200)
207
- expect(nt('* * * * * *', now)).to eq(now + 1)
208
- expect(nt('* * 13 * fri', now)).to eq(now + 3715200)
209
-
210
- expect(nt('10 12 13 12 *', now)).to eq(now + 29938200)
211
- # this one is slow (1 year == 3 seconds)
212
- #
213
- # historical note:
214
- # (comment made in 2006 or 2007, the underlying libs got better and
215
- # that slowness is gone)
216
-
217
- expect(nt('0 0 * * thu', now)).to eq(now + 604800)
218
- expect(nt('00 0 * * thu', now)).to eq(now + 604800)
219
-
220
- expect(nt('0 0 * * *', now)).to eq(now + 24 * 3600)
221
- expect(nt('0 24 * * *', now)).to eq(now + 24 * 3600)
222
-
223
- now = local(2008, 12, 31, 23, 59, 59, 0)
224
-
225
- expect(nt('* * * * *', now)).to eq(now + 1)
226
- end
227
-
228
- it 'computes the next occurence correctly in UTC (TZ not specified)' do
229
-
230
- now = utc(1970, 1, 1)
231
-
232
- expect(nt('* * * * *', now)).to eq(utc(1970, 1, 1, 0, 1))
233
- expect(nt('* * * * sun', now)).to eq(utc(1970, 1, 4))
234
- expect(nt('* * * * * *', now)).to eq(utc(1970, 1, 1, 0, 0, 1))
235
- expect(nt('* * 13 * fri', now)).to eq(utc(1970, 2, 13))
236
-
237
- expect(nt('10 12 13 12 *', now)).to eq(utc(1970, 12, 13, 12, 10))
238
- # this one is slow (1 year == 3 seconds)
239
- expect(nt('* * 1 6 *', now)).to eq(utc(1970, 6, 1))
240
-
241
- expect(nt('0 0 * * thu', now)).to eq(utc(1970, 1, 8))
242
- end
243
-
244
- it 'computes the next occurence correctly in local TZ (TZ not specified)' do
245
-
246
- now = local(1970, 1, 1)
247
-
248
- expect(nt('* * * * *', now)).to eq(local(1970, 1, 1, 0, 1))
249
- expect(nt('* * * * sun', now)).to eq(local(1970, 1, 4))
250
- expect(nt('* * * * * *', now)).to eq(local(1970, 1, 1, 0, 0, 1))
251
- expect(nt('* * 13 * fri', now)).to eq(local(1970, 2, 13))
252
-
253
- expect(nt('10 12 13 12 *', now)).to eq(local(1970, 12, 13, 12, 10))
254
- # this one is slow (1 year == 3 seconds)
255
- expect(nt('* * 1 6 *', now)).to eq(local(1970, 6, 1))
256
-
257
- expect(nt('0 0 * * thu', now)).to eq(local(1970, 1, 8))
258
- end
259
-
260
- it 'computes the next occurence correctly in UTC (TZ specified)' do
261
-
262
- zone = 'Europe/Stockholm'
263
- tz = TZInfo::Timezone.get(zone)
264
- now = tz.local_to_utc(local(1970, 1, 1))
265
- # Midnight in zone, UTC
266
-
267
- expect(nt("* * * * * #{zone}", now)).to eq(utc(1969, 12, 31, 23, 1))
268
- expect(nt("* * * * sun #{zone}", now)).to eq(utc(1970, 1, 3, 23))
269
- expect(nt("* * * * * * #{zone}", now)).to eq(utc(1969, 12, 31, 23, 0, 1))
270
- expect(nt("* * 13 * fri #{zone}", now)).to eq(utc(1970, 2, 12, 23))
271
-
272
- expect(nt("10 12 13 12 * #{zone}", now)).to eq(utc(1970, 12, 13, 11, 10))
273
- expect(nt("* * 1 6 * #{zone}", now)).to eq(utc(1970, 5, 31, 23))
274
-
275
- expect(nt("0 0 * * thu #{zone}", now)).to eq(utc(1970, 1, 7, 23))
276
- end
277
-
278
- #it 'computes the next occurence correctly in local TZ (TZ specified)' do
279
- # zone = 'Europe/Stockholm'
280
- # tz = TZInfo::Timezone.get(zone)
281
- # now = tz.local_to_utc(utc(1970, 1, 1)).localtime
282
- # # Midnight in zone, local time
283
- # nt("* * * * * #{zone}", now).should == local(1969, 12, 31, 18, 1)
284
- # nt("* * * * sun #{zone}", now).should == local(1970, 1, 3, 18)
285
- # nt("* * * * * * #{zone}", now).should == local(1969, 12, 31, 18, 0, 1)
286
- # nt("* * 13 * fri #{zone}", now).should == local(1970, 2, 12, 18)
287
- # nt("10 12 13 12 * #{zone}", now).should == local(1970, 12, 13, 6, 10)
288
- # nt("* * 1 6 * #{zone}", now).should == local(1970, 5, 31, 19)
289
- # nt("0 0 * * thu #{zone}", now).should == local(1970, 1, 7, 18)
290
- #end
291
-
292
- it 'computes the next time correctly when there is a sun#2 involved' do
293
-
294
- expect(nt('* * * * sun#1', local(1970, 1, 1))).to eq(local(1970, 1, 4))
295
- expect(nt('* * * * sun#2', local(1970, 1, 1))).to eq(local(1970, 1, 11))
296
-
297
- expect(nt('* * * * sun#2', local(1970, 1, 12))).to eq(local(1970, 2, 8))
298
- end
299
-
300
- it 'computes next time correctly when there is a sun#2,sun#3 involved' do
301
-
302
- expect(
303
- nt('* * * * sun#2,sun#3', local(1970, 1, 1))).to eq(local(1970, 1, 11))
304
- expect(
305
- nt('* * * * sun#2,sun#3', local(1970, 1, 12))).to eq(local(1970, 1, 18))
306
- end
307
-
308
- it 'understands sun#L' do
309
-
310
- expect(nt('* * * * sun#L', local(1970, 1, 1))).to eq(local(1970, 1, 25))
311
- end
312
-
313
- it 'understands sun#-1' do
314
-
315
- expect(nt('* * * * sun#-1', local(1970, 1, 1))).to eq(local(1970, 1, 25))
316
- end
317
-
318
- it 'understands sun#-2' do
319
-
320
- expect(nt('* * * * sun#-2', local(1970, 1, 1))).to eq(local(1970, 1, 18))
321
- end
322
-
323
- it 'computes the next time correctly when "L" (last day of month)' do
324
-
325
- expect(nt('* * L * *', lo(1970, 1, 1))).to eq(lo(1970, 1, 31))
326
- expect(nt('* * L * *', lo(1970, 2, 1))).to eq(lo(1970, 2, 28))
327
- expect(nt('* * L * *', lo(1972, 2, 1))).to eq(lo(1972, 2, 29))
328
- expect(nt('* * L * *', lo(1970, 4, 1))).to eq(lo(1970, 4, 30))
329
- end
330
-
331
- it 'returns a time with subseconds chopped off' do
332
-
333
- expect(
334
- nt('* * * * *', Time.now).usec).to eq(0)
335
- expect(
336
- nt('* * * * *', Time.now).iso8601(10).match(/\.0+[^\d]/)).not_to eq(nil)
337
- end
338
-
339
- # New York EST: UTC-5
340
- # summer (dst) EDT: UTC-4
341
-
342
- # gh-127
343
- #
344
- it 'survives TZInfo::AmbiguousTime' do
345
-
346
- if ruby18? or jruby?
347
- expect(
348
- ntz(
349
- '30 1 31 10 * America/New_York',
350
- ltz('America/New_York', 2004, 10, 1)
351
- ).strftime('%Y-%m-%d %H:%M:%S')
352
- ).to eq('2004-10-31 01:30:00')
353
- else
354
- expect(
355
- ntz(
356
- '30 1 31 10 * America/New_York',
357
- ltz('America/New_York', 2004, 10, 1)
358
- )
359
- ).to eq(ltz('America/New_York', 2004, 10, 31, 1, 30, 0))
360
- end
361
- end
362
-
363
- # gh-127
364
- #
365
- it 'survives TZInfo::PeriodNotFound' do
366
-
367
- expect(
368
- ntz(
369
- '0 2 9 3 * America/New_York',
370
- ltz('America/New_York', 2014, 3, 1)
371
- )
372
- ).to eq(ltz('America/New_York', 2015, 3, 9, 2, 0, 0))
373
- end
374
- end
375
-
376
- describe '#previous_time' do
377
-
378
- def pt(cronline, now)
379
- Rufus::Scheduler::CronLine.new(cronline).previous_time(now)
380
- end
381
- def ptz(cronline, now)
382
- tz = cronline.split.last
383
- tu = pt(cronline, now).utc
384
- in_zone(tz) { tu.getlocal }
385
- end
386
-
387
- it 'returns the previous time the cron should have triggered' do
388
-
389
- expect(
390
- pt('* * * * sun', lo(1970, 1, 1))).to eq(lo(1969, 12, 28, 23, 59, 00))
391
- expect(
392
- pt('* * 13 * *', lo(1970, 1, 1))).to eq(lo(1969, 12, 13, 23, 59, 00))
393
- expect(
394
- pt('0 12 13 * *', lo(1970, 1, 1))).to eq(lo(1969, 12, 13, 12, 00))
395
- expect(
396
- pt('0 0 2 1 *', lo(1970, 1, 1))).to eq(lo(1969, 1, 2, 0, 00))
397
-
398
- expect(
399
- pt('* * * * * sun', lo(1970, 1, 1))).to eq(lo(1969, 12, 28, 23, 59, 59))
400
- end
401
-
402
- # New York EST: UTC-5
403
- # summer (dst) EDT: UTC-4
404
-
405
- # gh-127
406
- #
407
- it 'survives TZInfo::AmbiguousTime' do
408
-
409
- if ruby18? or jruby?
410
- expect(
411
- ptz(
412
- '30 1 31 10 * America/New_York',
413
- ltz('America/New_York', 2004, 10, 31, 14, 30, 0)
414
- ).strftime('%Y-%m-%d %H:%M:%S')
415
- ).to eq('2004-10-31 01:30:00')
416
- else
417
- expect(
418
- ptz(
419
- '30 1 31 10 * America/New_York',
420
- ltz('America/New_York', 2004, 10, 31, 14, 30, 0)
421
- )
422
- ).to eq(ltz('America/New_York', 2004, 10, 31, 1, 30, 0))
423
- end
424
- end
425
-
426
- # gh-127
427
- #
428
- it 'survives TZInfo::PeriodNotFound' do
429
-
430
- expect(
431
- ptz(
432
- '0 2 9 3 * America/New_York',
433
- ltz('America/New_York', 2015, 3, 9, 12, 0, 0)
434
- )
435
- ).to eq(ltz('America/New_York', 2015, 3, 9, 2, 0, 0))
436
- end
437
- end
438
-
439
- describe '#matches?' do
440
-
441
- it 'matches correctly in UTC (TZ not specified)' do
442
-
443
- match '* * * * *', utc(1970, 1, 1, 0, 1)
444
- match '* * * * sun', utc(1970, 1, 4)
445
- match '* * * * * *', utc(1970, 1, 1, 0, 0, 1)
446
- match '* * 13 * fri', utc(1970, 2, 13)
447
-
448
- match '10 12 13 12 *', utc(1970, 12, 13, 12, 10)
449
- match '* * 1 6 *', utc(1970, 6, 1)
450
-
451
- match '0 0 * * thu', utc(1970, 1, 8)
452
-
453
- match '0 0 1 1 *', utc(2012, 1, 1)
454
- no_match '0 0 1 1 *', utc(2012, 1, 1, 1, 0)
455
- end
456
-
457
- it 'matches correctly in local TZ (TZ not specified)' do
458
-
459
- match '* * * * *', local(1970, 1, 1, 0, 1)
460
- match '* * * * sun', local(1970, 1, 4)
461
- match '* * * * * *', local(1970, 1, 1, 0, 0, 1)
462
- match '* * 13 * fri', local(1970, 2, 13)
463
-
464
- match '10 12 13 12 *', local(1970, 12, 13, 12, 10)
465
- match '* * 1 6 *', local(1970, 6, 1)
466
-
467
- match '0 0 * * thu', local(1970, 1, 8)
468
-
469
- match '0 0 1 1 *', local(2012, 1, 1)
470
- no_match '0 0 1 1 *', local(2012, 1, 1, 1, 0)
471
- end
472
-
473
- it 'matches correctly in UTC (TZ specified)' do
474
-
475
- zone = 'Europe/Stockholm'
476
-
477
- match "* * * * * #{zone}", utc(1969, 12, 31, 23, 1)
478
- match "* * * * sun #{zone}", utc(1970, 1, 3, 23)
479
- match "* * * * * * #{zone}", utc(1969, 12, 31, 23, 0, 1)
480
- match "* * 13 * fri #{zone}", utc(1970, 2, 12, 23)
481
-
482
- match "10 12 13 12 * #{zone}", utc(1970, 12, 13, 11, 10)
483
- match "* * 1 6 * #{zone}", utc(1970, 5, 31, 23)
484
-
485
- match "0 0 * * thu #{zone}", utc(1970, 1, 7, 23)
486
- end
487
-
488
- it 'matches correctly when there is a sun#2 involved' do
489
-
490
- match '* * 13 * fri#2', utc(1970, 2, 13)
491
- no_match '* * 13 * fri#2', utc(1970, 2, 20)
492
- end
493
-
494
- it 'matches correctly when there is a L involved' do
495
-
496
- match '* * L * *', utc(1970, 1, 31)
497
- no_match '* * L * *', utc(1970, 1, 30)
498
- end
499
-
500
- it 'matches correctly when there is a sun#2,sun#3 involved' do
501
-
502
- no_match '* * * * sun#2,sun#3', local(1970, 1, 4)
503
- match '* * * * sun#2,sun#3', local(1970, 1, 11)
504
- match '* * * * sun#2,sun#3', local(1970, 1, 18)
505
- no_match '* * * * sun#2,sun#3', local(1970, 1, 25)
506
- end
507
-
508
- it 'matches correctly for seconds' do
509
-
510
- match '* * * * * *', local(1970, 1, 11)
511
- match '* * * * * *', local(1970, 1, 11, 0, 0, 13)
512
- end
513
-
514
- it 'matches correctly for seconds / interval' do
515
-
516
- match '*/2 * * * * *', local(1970, 1, 11)
517
- match '*/5 * * * * *', local(1970, 1, 11)
518
- match '*/5 * * * * *', local(1970, 1, 11, 0, 0, 0)
519
- no_match '*/5 * * * * *', local(1970, 1, 11, 0, 0, 1)
520
- match '*/5 * * * * *', local(1970, 1, 11, 0, 0, 5)
521
- match '*/2 * * * * *', local(1970, 1, 11, 0, 0, 2)
522
- match '*/2 * * * * *', local(1970, 1, 11, 0, 0, 2, 500)
523
- end
524
- end
525
-
526
- describe '#monthdays' do
527
-
528
- it 'returns the appropriate "sun#2"-like string' do
529
-
530
- class Rufus::Scheduler::CronLine
531
- public :monthdays
532
- end
533
-
534
- cl = Rufus::Scheduler::CronLine.new('* * * * *')
535
-
536
- expect(cl.monthdays(local(1970, 1, 1))).to eq(%w[ thu#1 thu#-5 ])
537
- expect(cl.monthdays(local(1970, 1, 7))).to eq(%w[ wed#1 wed#-4 ])
538
- expect(cl.monthdays(local(1970, 1, 14))).to eq(%w[ wed#2 wed#-3 ])
539
-
540
- expect(cl.monthdays(local(2011, 3, 11))).to eq(%w[ fri#2 fri#-3 ])
541
- end
542
- end
543
-
544
- describe '#frequency' do
545
-
546
- it 'returns the shortest delta between two occurrences' do
547
-
548
- expect(Rufus::Scheduler::CronLine.new(
549
- '* * * * *').frequency).to eq(60)
550
- expect(Rufus::Scheduler::CronLine.new(
551
- '* * * * * *').frequency).to eq(1)
552
-
553
- expect(Rufus::Scheduler::CronLine.new(
554
- '5 23 * * *').frequency).to eq(24 * 3600)
555
- expect(Rufus::Scheduler::CronLine.new(
556
- '5 * * * *').frequency).to eq(3600)
557
- expect(Rufus::Scheduler::CronLine.new(
558
- '10,20,30 * * * *').frequency).to eq(600)
559
-
560
- expect(Rufus::Scheduler::CronLine.new(
561
- '10,20,30 * * * * *').frequency).to eq(10)
562
- end
563
- end
564
-
565
- describe '#brute_frequency' do
566
-
567
- it 'returns the shortest delta between two occurrences' do
568
-
569
- expect(Rufus::Scheduler::CronLine.new(
570
- '* * * * *').brute_frequency).to eq(60)
571
- expect(Rufus::Scheduler::CronLine.new(
572
- '* * * * * *').brute_frequency).to eq(1)
573
-
574
- expect(Rufus::Scheduler::CronLine.new(
575
- '5 23 * * *').brute_frequency).to eq(24 * 3600)
576
- expect(Rufus::Scheduler::CronLine.new(
577
- '5 * * * *').brute_frequency).to eq(3600)
578
- expect(Rufus::Scheduler::CronLine.new(
579
- '10,20,30 * * * *').brute_frequency).to eq(600)
580
-
581
- #Rufus::Scheduler::CronLine.new(
582
- # '10,20,30 * * * * *').brute_frequency.should == 10
583
- #
584
- # takes > 20s ...
585
- end
586
- end
587
-
588
- context 'summer time' do
589
-
590
- # let's assume summer time jumps always occur on sundays
591
-
592
- # cf gh-114
593
- #
594
- it 'schedules correctly through a switch into summer time' do
595
-
596
- #j = `zdump -v Europe/Berlin | grep "Sun Mar" | grep 2014`.split("\n")[0]
597
- #j = j.match(/^.+ (Sun Mar .+ UTC) /)[1]
598
- # only works on system that have a zdump...
599
-
600
- in_zone 'Europe/Berlin' do
601
-
602
- # find the summer jump
603
-
604
- j = Time.parse('2014-02-28 12:00')
605
- loop do
606
- jj = j + 24 * 3600
607
- break if jj.isdst
608
- j = jj
609
- end
610
-
611
- # test
612
-
613
- friday = j - 24 * 3600 # one day before
614
-
615
- # verify the playground...
616
- #
617
- expect(friday.isdst).to eq(false)
618
- expect((friday + 24 * 3600 * 3).isdst).to eq(true)
619
-
620
- cl0 = Rufus::Scheduler::CronLine.new('02 00 * * 1,2,3,4,5')
621
- cl1 = Rufus::Scheduler::CronLine.new('45 08 * * 1,2,3,4,5')
622
-
623
- n0 = cl0.next_time(friday)
624
- n1 = cl1.next_time(friday)
625
-
626
- expect(n0.strftime('%H:%M:%S %^a')).to eq('00:02:00 MON')
627
- expect(n1.strftime('%H:%M:%S %^a')).to eq('08:45:00 MON')
628
-
629
- expect(n0.isdst).to eq(true)
630
- expect(n1.isdst).to eq(true)
631
-
632
- expect(
633
- (n0 - 24 * 3600 * 3).strftime('%H:%M:%S %^a')).to eq('23:02:00 THU')
634
- expect(
635
- (n1 - 24 * 3600 * 3).strftime('%H:%M:%S %^a')).to eq('07:45:00 FRI')
636
- end
637
- end
638
-
639
- it 'schedules correctly through a switch out of summer time' do
640
-
641
- in_zone 'Europe/Berlin' do
642
-
643
- # find the winter jump
644
-
645
- j = Time.parse('2014-08-31 12:00')
646
- loop do
647
- jj = j + 24 * 3600
648
- break if jj.isdst == false
649
- j = jj
650
- end
651
-
652
- # test
653
-
654
- friday = j - 24 * 3600 # one day before
655
-
656
- # verify the playground...
657
- #
658
- expect(friday.isdst).to eq(true)
659
- expect((friday + 24 * 3600 * 3).isdst).to eq(false)
660
-
661
- cl0 = Rufus::Scheduler::CronLine.new('02 00 * * 1,2,3,4,5')
662
- cl1 = Rufus::Scheduler::CronLine.new('45 08 * * 1,2,3,4,5')
663
-
664
- n0 = cl0.next_time(friday)
665
- n1 = cl1.next_time(friday)
666
-
667
- expect(n0.strftime('%H:%M:%S %^a')).to eq('00:02:00 MON')
668
- expect(n1.strftime('%H:%M:%S %^a')).to eq('08:45:00 MON')
669
-
670
- expect(n0.isdst).to eq(false)
671
- expect(n1.isdst).to eq(false)
672
-
673
- expect(
674
- (n0 - 24 * 3600 * 3).strftime('%H:%M:%S %^a')).to eq('01:02:00 FRI')
675
- expect(
676
- (n1 - 24 * 3600 * 3).strftime('%H:%M:%S %^a')).to eq('09:45:00 FRI')
677
- end
678
- end
679
- end
680
- end
681
-