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