cron 1.8.1 → 2.0.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.
- package/.editorconfig +5 -0
- package/.eslintrc +9 -11
- package/.github/ISSUE_TEMPLATE/bug_issue.yaml +26 -0
- package/.github/ISSUE_TEMPLATE/feature.yaml +31 -0
- package/.github/workflows/nodejs.yml +39 -0
- package/.prettierrc +5 -2
- package/CHANGELOG.md +7 -0
- package/README.md +127 -132
- package/lib/cron.js +16 -700
- package/lib/job.js +214 -0
- package/lib/time.js +513 -0
- package/package.json +75 -59
- package/tests/cron.test.js +180 -86
- package/tests/crontime.test.js +195 -124
- package/.travis.yml +0 -11
package/tests/crontime.test.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
/* eslint-disable no-new */
|
|
2
2
|
const sinon = require('sinon');
|
|
3
|
+
const luxon = require('luxon');
|
|
3
4
|
const cron = require('../lib/cron');
|
|
4
|
-
const moment = require('moment-timezone');
|
|
5
5
|
|
|
6
|
-
describe('crontime',
|
|
7
|
-
it('should test stars (* * * * * *)',
|
|
8
|
-
expect(
|
|
6
|
+
describe('crontime', () => {
|
|
7
|
+
it('should test stars (* * * * * *)', () => {
|
|
8
|
+
expect(() => {
|
|
9
9
|
new cron.CronTime('* * * * * *');
|
|
10
10
|
}).not.toThrow();
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
it('should test digit (0 * * * * *)',
|
|
14
|
-
expect(
|
|
13
|
+
it('should test digit (0 * * * * *)', () => {
|
|
14
|
+
expect(() => {
|
|
15
15
|
new cron.CronTime('0 * * * * *');
|
|
16
16
|
}).not.toThrow();
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
it('should test multi digits (08 * * * * *)',
|
|
20
|
-
expect(
|
|
19
|
+
it('should test multi digits (08 * * * * *)', () => {
|
|
20
|
+
expect(() => {
|
|
21
21
|
new cron.CronTime('08 * * * * *');
|
|
22
22
|
}).not.toThrow();
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
it('should test all digits (08 8 8 8 8 5)',
|
|
26
|
-
expect(
|
|
25
|
+
it('should test all digits (08 8 8 8 8 5)', () => {
|
|
26
|
+
expect(() => {
|
|
27
27
|
new cron.CronTime('08 * * * * *');
|
|
28
28
|
}).not.toThrow();
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
it('should test too many digits (08 8 8 8 8 5)',
|
|
32
|
-
expect(
|
|
31
|
+
it('should test too many digits (08 8 8 8 8 5)', () => {
|
|
32
|
+
expect(() => {
|
|
33
33
|
new cron.CronTime('08 * * * * *');
|
|
34
34
|
}).not.toThrow();
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it('should test standard cron format (* * * * *)',
|
|
38
|
-
expect(
|
|
37
|
+
it('should test standard cron format (* * * * *)', () => {
|
|
38
|
+
expect(() => {
|
|
39
39
|
new cron.CronTime('* * * * *');
|
|
40
40
|
}).not.toThrow();
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it('should test standard cron format (8 8 8 8 5)',
|
|
43
|
+
it('should test standard cron format (8 8 8 8 5)', () => {
|
|
44
44
|
const standard = new cron.CronTime('8 8 8 8 5');
|
|
45
45
|
const extended = new cron.CronTime('0 8 8 8 8 5');
|
|
46
46
|
|
|
@@ -52,115 +52,115 @@ describe('crontime', function() {
|
|
|
52
52
|
expect(standard.second).toEqual(extended.second);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
it('should test hyphen (0-10 * * * * *)',
|
|
56
|
-
expect(
|
|
55
|
+
it('should test hyphen (0-10 * * * * *)', () => {
|
|
56
|
+
expect(() => {
|
|
57
57
|
new cron.CronTime('0-10 * * * * *');
|
|
58
58
|
}).not.toThrow();
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
it('should test multi hyphens (0-10 0-10 * * * *)',
|
|
62
|
-
expect(
|
|
61
|
+
it('should test multi hyphens (0-10 0-10 * * * *)', () => {
|
|
62
|
+
expect(() => {
|
|
63
63
|
new cron.CronTime('0-10 0-10 * * * *');
|
|
64
64
|
}).not.toThrow();
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
it('should test all hyphens (0-10 0-10 1-10 1-10 0-6 0-1)',
|
|
68
|
-
expect(
|
|
67
|
+
it('should test all hyphens (0-10 0-10 1-10 1-10 0-6 0-1)', () => {
|
|
68
|
+
expect(() => {
|
|
69
69
|
new cron.CronTime('0-10 0-10 1-10 1-10 0-6 0-1');
|
|
70
70
|
}).not.toThrow();
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
it('should test comma (0,10 * * * * *)',
|
|
74
|
-
expect(
|
|
73
|
+
it('should test comma (0,10 * * * * *)', () => {
|
|
74
|
+
expect(() => {
|
|
75
75
|
new cron.CronTime('0,10 * * * * *');
|
|
76
76
|
}).not.toThrow();
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
it('should test multi commas (0,10 0,10 * * * *)',
|
|
80
|
-
expect(
|
|
79
|
+
it('should test multi commas (0,10 0,10 * * * *)', () => {
|
|
80
|
+
expect(() => {
|
|
81
81
|
new cron.CronTime('0,10 0,10 * * * *');
|
|
82
82
|
}).not.toThrow();
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it('should test all commas (0,10 0,10 1,10 1,10 0,6 0,1)',
|
|
86
|
-
expect(
|
|
85
|
+
it('should test all commas (0,10 0,10 1,10 1,10 0,6 0,1)', () => {
|
|
86
|
+
expect(() => {
|
|
87
87
|
new cron.CronTime('0,10 0,10 1,10 1,10 0,6 0,1');
|
|
88
88
|
}).not.toThrow();
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
it('should test alias (* * * * jan *)',
|
|
92
|
-
expect(
|
|
91
|
+
it('should test alias (* * * * jan *)', () => {
|
|
92
|
+
expect(() => {
|
|
93
93
|
new cron.CronTime('* * * * jan *');
|
|
94
94
|
}).not.toThrow();
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
-
it('should test multi aliases (* * * * jan,feb *)',
|
|
98
|
-
expect(
|
|
97
|
+
it('should test multi aliases (* * * * jan,feb *)', () => {
|
|
98
|
+
expect(() => {
|
|
99
99
|
new cron.CronTime('* * * * jan,feb *');
|
|
100
100
|
}).not.toThrow();
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
it('should test all aliases (* * * * jan,feb mon,tue)',
|
|
104
|
-
expect(
|
|
103
|
+
it('should test all aliases (* * * * jan,feb mon,tue)', () => {
|
|
104
|
+
expect(() => {
|
|
105
105
|
new cron.CronTime('* * * * jan,feb mon,tue');
|
|
106
106
|
}).not.toThrow();
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
-
it('should test unknown alias (* * * * jar *)',
|
|
110
|
-
expect(
|
|
109
|
+
it('should test unknown alias (* * * * jar *)', () => {
|
|
110
|
+
expect(() => {
|
|
111
111
|
new cron.CronTime('* * * * jar *');
|
|
112
112
|
}).toThrow();
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
it('should test unknown alias - short (* * * * j *)',
|
|
116
|
-
expect(
|
|
115
|
+
it('should test unknown alias - short (* * * * j *)', () => {
|
|
116
|
+
expect(() => {
|
|
117
117
|
new cron.CronTime('* * * * j *');
|
|
118
118
|
}).toThrow();
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
it('should test too few fields',
|
|
122
|
-
expect(
|
|
121
|
+
it('should test too few fields', () => {
|
|
122
|
+
expect(() => {
|
|
123
123
|
new cron.CronTime('* * * *', null, null);
|
|
124
124
|
}).toThrow();
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
it('should test too many fields',
|
|
128
|
-
expect(
|
|
127
|
+
it('should test too many fields', () => {
|
|
128
|
+
expect(() => {
|
|
129
129
|
new cron.CronTime('* * * * * * *', null, null);
|
|
130
130
|
}).toThrow();
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
it('should test out of range values',
|
|
134
|
-
expect(
|
|
133
|
+
it('should test out of range values', () => {
|
|
134
|
+
expect(() => {
|
|
135
135
|
new cron.CronTime('* * * * 1234', null, null);
|
|
136
136
|
}).toThrow();
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
-
it('should test invalid wildcard expression',
|
|
140
|
-
expect(
|
|
139
|
+
it('should test invalid wildcard expression', () => {
|
|
140
|
+
expect(() => {
|
|
141
141
|
new cron.CronTime('* * * * 0*');
|
|
142
142
|
}).toThrow();
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
-
it('should test invalid step',
|
|
146
|
-
expect(
|
|
145
|
+
it('should test invalid step', () => {
|
|
146
|
+
expect(() => {
|
|
147
147
|
new cron.CronTime('* * * 1/0 *');
|
|
148
148
|
}).toThrow();
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
it('should test invalid range',
|
|
152
|
-
expect(
|
|
151
|
+
it('should test invalid range', () => {
|
|
152
|
+
expect(() => {
|
|
153
153
|
new cron.CronTime('* 2-1 * * *');
|
|
154
154
|
}).toThrow();
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
it('should test Date',
|
|
157
|
+
it('should test Date', () => {
|
|
158
158
|
const d = new Date();
|
|
159
159
|
const ct = new cron.CronTime(d);
|
|
160
|
-
expect(ct.source.
|
|
160
|
+
expect(ct.source.toMillis()).toEqual(d.getTime());
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
-
it('should test day roll-over',
|
|
163
|
+
it('should test day roll-over', () => {
|
|
164
164
|
const numHours = 24;
|
|
165
165
|
const ct = new cron.CronTime('0 0 17 * * *');
|
|
166
166
|
|
|
@@ -168,80 +168,131 @@ describe('crontime', function() {
|
|
|
168
168
|
const start = new Date(2012, 3, 16, hr, 30, 30);
|
|
169
169
|
const next = ct._getNextDateFrom(start);
|
|
170
170
|
expect(next - start).toBeLessThan(24 * 60 * 60 * 1000);
|
|
171
|
-
expect(next.
|
|
171
|
+
expect(next.toMillis()).toBeGreaterThan(start.getTime());
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
it('should test illegal repetition syntax',
|
|
176
|
-
expect(
|
|
175
|
+
it('should test illegal repetition syntax', () => {
|
|
176
|
+
expect(() => {
|
|
177
177
|
new cron.CronTime('* * /4 * * *');
|
|
178
178
|
}).toThrow();
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
it('should test next date',
|
|
181
|
+
it('should test next date', () => {
|
|
182
182
|
const ct = new cron.CronTime('0 0 */4 * * *');
|
|
183
183
|
|
|
184
184
|
const nextDate = new Date();
|
|
185
185
|
nextDate.setHours(23);
|
|
186
186
|
const nextdt = ct._getNextDateFrom(nextDate);
|
|
187
187
|
|
|
188
|
-
expect(nextdt.
|
|
189
|
-
expect(nextdt.
|
|
188
|
+
expect(nextdt.toMillis()).toBeGreaterThan(nextDate.getTime());
|
|
189
|
+
expect(nextdt.hour % 4).toEqual(0);
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
-
it('should throw an exception because next date is invalid',
|
|
192
|
+
it('should throw an exception because next date is invalid', () => {
|
|
193
193
|
const ct = new cron.CronTime('0 0 * * * *');
|
|
194
194
|
const nextDate = new Date('My invalid date string');
|
|
195
195
|
try {
|
|
196
|
-
|
|
197
|
-
const nextdt = ct._getNextDateFrom(nextDate);
|
|
196
|
+
ct._getNextDateFrom(nextDate);
|
|
198
197
|
} catch (e) {
|
|
199
198
|
expect(e.message).toEqual('ERROR: You specified an invalid date.');
|
|
200
199
|
}
|
|
201
200
|
});
|
|
202
201
|
|
|
203
|
-
it('should test next real date',
|
|
202
|
+
it('should test next real date', () => {
|
|
204
203
|
const initialDate = new Date();
|
|
204
|
+
initialDate.setDate(initialDate.getDate() + 1); // In other case date will be in the past
|
|
205
205
|
const ct = new cron.CronTime(initialDate);
|
|
206
206
|
|
|
207
207
|
const nextDate = new Date();
|
|
208
208
|
nextDate.setMonth(nextDate.getMonth() + 1);
|
|
209
|
-
expect(nextDate.getTime()).toBeGreaterThan(ct.source.
|
|
209
|
+
expect(nextDate.getTime()).toBeGreaterThan(ct.source.toMillis());
|
|
210
210
|
const nextdt = ct.sendAt(0);
|
|
211
211
|
// there shouldn't be a "next date" when using a real date.
|
|
212
212
|
// execution happens once
|
|
213
213
|
// so the return should be the date passed in unless explicitly reset
|
|
214
|
-
expect(nextdt
|
|
215
|
-
expect(nextdt.
|
|
214
|
+
expect(nextdt < nextDate).toBeTruthy();
|
|
215
|
+
expect(nextdt.toMillis()).toEqual(initialDate.getTime());
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
-
describe('
|
|
219
|
-
it('
|
|
220
|
-
|
|
218
|
+
describe('presets', () => {
|
|
219
|
+
it('should parse @secondly', () => {
|
|
220
|
+
const cronTime = new cron.CronTime('@secondly');
|
|
221
|
+
expect(cronTime.toString()).toEqual('* * * * * *');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should parse @minutely', () => {
|
|
225
|
+
const cronTime = new cron.CronTime('@minutely');
|
|
226
|
+
expect(cronTime.toString()).toEqual('0 * * * * *');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('should parse @hourly', () => {
|
|
230
|
+
const cronTime = new cron.CronTime('@hourly');
|
|
231
|
+
expect(cronTime.toString()).toEqual('0 0 * * * *');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should parse @daily', () => {
|
|
235
|
+
const cronTime = new cron.CronTime('@daily');
|
|
236
|
+
expect(cronTime.toString()).toEqual('0 0 0 * * *');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('should parse @weekly', () => {
|
|
240
|
+
const cronTime = new cron.CronTime('@weekly');
|
|
241
|
+
expect(cronTime.toString()).toEqual('0 0 0 * * 0');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should parse @weekdays', () => {
|
|
245
|
+
const cronTime = new cron.CronTime('@weekdays');
|
|
246
|
+
expect(cronTime.toString()).toEqual('0 0 0 * * 1,2,3,4,5');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('should parse @weekends', () => {
|
|
250
|
+
const cronTime = new cron.CronTime('@weekends');
|
|
251
|
+
expect(cronTime.toString()).toEqual('0 0 0 * * 0,6');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should parse @monthly', () => {
|
|
255
|
+
const cronTime = new cron.CronTime('@monthly');
|
|
256
|
+
expect(cronTime.toString()).toEqual('0 0 0 1 * *');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should parse @yearly', () => {
|
|
260
|
+
const cronTime = new cron.CronTime('@yearly');
|
|
261
|
+
expect(cronTime.toString()).toEqual('0 0 0 1 0 *');
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe('should throw an exception because `L` not supported', () => {
|
|
266
|
+
it('(* * * L * *)', () => {
|
|
267
|
+
expect(() => {
|
|
221
268
|
new cron.CronTime('* * * L * *');
|
|
222
269
|
}).toThrow();
|
|
223
270
|
});
|
|
224
271
|
|
|
225
|
-
it('(* * * * * L)',
|
|
226
|
-
expect(
|
|
272
|
+
it('(* * * * * L)', () => {
|
|
273
|
+
expect(() => {
|
|
227
274
|
new cron.CronTime('* * * * * L');
|
|
228
275
|
}).toThrow();
|
|
229
276
|
});
|
|
230
277
|
});
|
|
231
278
|
|
|
232
|
-
it('should strip off millisecond',
|
|
279
|
+
it('should strip off millisecond', () => {
|
|
233
280
|
const cronTime = new cron.CronTime('0 */10 * * * *');
|
|
234
281
|
const x = cronTime._getNextDateFrom(new Date('2018-08-10T02:20:00.999Z'));
|
|
235
|
-
expect(x.
|
|
282
|
+
expect(x.toMillis()).toEqual(
|
|
283
|
+
new Date('2018-08-10T02:30:00.000Z').getTime()
|
|
284
|
+
);
|
|
236
285
|
});
|
|
237
286
|
|
|
238
|
-
it('should strip off millisecond (2)',
|
|
287
|
+
it('should strip off millisecond (2)', () => {
|
|
239
288
|
const cronTime = new cron.CronTime('0 */10 * * * *');
|
|
240
289
|
const x = cronTime._getNextDateFrom(new Date('2018-08-10T02:19:59.999Z'));
|
|
241
|
-
expect(x.
|
|
290
|
+
expect(x.toMillis()).toEqual(
|
|
291
|
+
new Date('2018-08-10T02:20:00.000Z').getTime()
|
|
292
|
+
);
|
|
242
293
|
});
|
|
243
294
|
|
|
244
|
-
it('should generete the right next days when cron is set to every minute',
|
|
295
|
+
it('should generete the right next days when cron is set to every minute', () => {
|
|
245
296
|
const cronTime = new cron.CronTime('* * * * *');
|
|
246
297
|
const min = 60000;
|
|
247
298
|
let previousDate = new Date(Date.UTC(2018, 5, 3, 0, 0));
|
|
@@ -252,7 +303,7 @@ describe('crontime', function() {
|
|
|
252
303
|
}
|
|
253
304
|
});
|
|
254
305
|
|
|
255
|
-
it('should generete the right next days when cron is set to every 15 min',
|
|
306
|
+
it('should generete the right next days when cron is set to every 15 min', () => {
|
|
256
307
|
const cronTime = new cron.CronTime('*/15 * * * *');
|
|
257
308
|
const min = 60000 * 15;
|
|
258
309
|
let previousDate = new Date(Date.UTC(2016, 6, 3, 0, 0));
|
|
@@ -262,25 +313,32 @@ describe('crontime', function() {
|
|
|
262
313
|
previousDate = nextDate;
|
|
263
314
|
}
|
|
264
315
|
});
|
|
265
|
-
it('should work around time zone changes that shifts time back (1)',
|
|
316
|
+
it('should work around time zone changes that shifts time back (1)', () => {
|
|
266
317
|
const d = new Date('10-7-2018');
|
|
267
318
|
// America/Sao_Paulo has a time zone change around NOV 3 2018.
|
|
268
319
|
const cronTime = new cron.CronTime('0 0 9 4 * *');
|
|
269
320
|
const nextDate = cronTime._getNextDateFrom(d, 'America/Sao_Paulo');
|
|
270
321
|
expect(nextDate.valueOf()).toEqual(
|
|
271
|
-
|
|
322
|
+
luxon.DateTime.fromISO('2018-11-04T09:00:00.000-02:00').valueOf()
|
|
272
323
|
);
|
|
273
324
|
});
|
|
274
|
-
it('should work around time zone changes that shifts time back (2)',
|
|
325
|
+
it('should work around time zone changes that shifts time back (2)', () => {
|
|
275
326
|
// Asia/Amman DST ends in 26 - OCT-2018 (-1 to hours)
|
|
276
|
-
const
|
|
327
|
+
const currentDate = luxon.DateTime.fromISO('2018-10-25T23:00', {
|
|
328
|
+
zone: 'Asia/Amman'
|
|
329
|
+
});
|
|
277
330
|
const cronTime = new cron.CronTime('0 0 * * *');
|
|
278
|
-
const nextDate = cronTime._getNextDateFrom(
|
|
279
|
-
|
|
331
|
+
const nextDate = cronTime._getNextDateFrom(currentDate, 'Asia/Amman');
|
|
332
|
+
const expectedDate = luxon.DateTime.fromISO('2018-10-26T00:00', {
|
|
333
|
+
zone: 'Asia/Amman'
|
|
334
|
+
});
|
|
335
|
+
expect(nextDate - expectedDate).toEqual(0);
|
|
280
336
|
});
|
|
281
|
-
it('should work around time zone changes that shifts time forward',
|
|
337
|
+
it('should work around time zone changes that shifts time forward', () => {
|
|
282
338
|
// Asia/Amman DST starts in 30-March-2018 (+1 to hours)
|
|
283
|
-
let currentDate =
|
|
339
|
+
let currentDate = luxon.DateTime.fromISO('2018-03-29T23:00', {
|
|
340
|
+
zone: 'Asia/Amman'
|
|
341
|
+
});
|
|
284
342
|
const cronTime = new cron.CronTime('* * * * *');
|
|
285
343
|
for (let i = 0; i < 100; i++) {
|
|
286
344
|
const nextDate = cronTime._getNextDateFrom(currentDate, 'Asia/Amman');
|
|
@@ -288,37 +346,31 @@ describe('crontime', function() {
|
|
|
288
346
|
currentDate = nextDate;
|
|
289
347
|
}
|
|
290
348
|
});
|
|
291
|
-
it('should generate the right N next days for * * * * *',
|
|
349
|
+
it('should generate the right N next days for * * * * *', () => {
|
|
292
350
|
const cronTime = new cron.CronTime('* * * * *');
|
|
293
|
-
let currentDate =
|
|
294
|
-
.seconds(0)
|
|
295
|
-
.milliseconds(0);
|
|
351
|
+
let currentDate = luxon.DateTime.local().set({ second: 0, millisecond: 0 });
|
|
296
352
|
for (let i = 0; i < 100; i++) {
|
|
297
353
|
const nextDate = cronTime._getNextDateFrom(currentDate);
|
|
298
354
|
expect(nextDate - currentDate).toEqual(1000 * 60);
|
|
299
355
|
currentDate = nextDate;
|
|
300
356
|
}
|
|
301
357
|
});
|
|
302
|
-
it('should generate the right N next days for 0 0 9 * * *',
|
|
358
|
+
it('should generate the right N next days for 0 0 9 * * *', () => {
|
|
303
359
|
const cronTime = new cron.CronTime('0 0 9 * * *');
|
|
304
|
-
let currentDate =
|
|
305
|
-
.utc
|
|
306
|
-
.
|
|
307
|
-
.milliseconds(0)
|
|
308
|
-
.hours(9)
|
|
309
|
-
.minutes(0);
|
|
360
|
+
let currentDate = luxon.DateTime.local()
|
|
361
|
+
.setZone('utc')
|
|
362
|
+
.set({ hour: 9, minute: 0, second: 0, millisecond: 0 });
|
|
310
363
|
for (let i = 0; i < 100; i++) {
|
|
311
364
|
const nextDate = cronTime._getNextDateFrom(currentDate);
|
|
312
365
|
expect(nextDate - currentDate).toEqual(1000 * 60 * 60 * 24);
|
|
313
366
|
currentDate = nextDate;
|
|
314
367
|
}
|
|
315
368
|
});
|
|
316
|
-
it('should generate the right N next days for 0 0 * * * with a time zone',
|
|
369
|
+
it('should generate the right N next days for 0 0 * * * with a time zone', () => {
|
|
317
370
|
const cronTime = new cron.CronTime('0 * * * *');
|
|
318
|
-
let currentDate =
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
.milliseconds(0);
|
|
371
|
+
let currentDate = luxon.DateTime.fromISO('2018-11-02T23:00', {
|
|
372
|
+
zone: 'America/Sao_Paulo'
|
|
373
|
+
}).set({ second: 0, millisecond: 0 });
|
|
322
374
|
for (let i = 0; i < 25; i++) {
|
|
323
375
|
const nextDate = cronTime._getNextDateFrom(
|
|
324
376
|
currentDate,
|
|
@@ -328,12 +380,11 @@ describe('crontime', function() {
|
|
|
328
380
|
currentDate = nextDate;
|
|
329
381
|
}
|
|
330
382
|
});
|
|
331
|
-
it('should generate the right N next days for */3 * * * * with a time zone',
|
|
383
|
+
it('should generate the right N next days for */3 * * * * with a time zone', () => {
|
|
332
384
|
const cronTime = new cron.CronTime('*/3 * * * *');
|
|
333
|
-
let currentDate =
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
.milliseconds(0);
|
|
385
|
+
let currentDate = luxon.DateTime.fromISO('2018-11-02T23:00', {
|
|
386
|
+
zone: 'America/Sao_Paulo'
|
|
387
|
+
}).set({ second: 0, millisecond: 0 });
|
|
337
388
|
for (let i = 0; i < 25; i++) {
|
|
338
389
|
const nextDate = cronTime._getNextDateFrom(
|
|
339
390
|
currentDate,
|
|
@@ -343,7 +394,7 @@ describe('crontime', function() {
|
|
|
343
394
|
currentDate = nextDate;
|
|
344
395
|
}
|
|
345
396
|
});
|
|
346
|
-
it('should generete the right next day when cron is set to every 15 min in Feb',
|
|
397
|
+
it('should generete the right next day when cron is set to every 15 min in Feb', () => {
|
|
347
398
|
const cronTime = new cron.CronTime('*/15 * * FEB *');
|
|
348
399
|
const previousDate = new Date(Date.UTC(2018, 3, 0, 0, 0));
|
|
349
400
|
const nextDate = cronTime._getNextDateFrom(previousDate, 'UTC');
|
|
@@ -351,23 +402,23 @@ describe('crontime', function() {
|
|
|
351
402
|
new Date(Date.UTC(2019, 1, 1, 0, 0)).valueOf()
|
|
352
403
|
);
|
|
353
404
|
});
|
|
354
|
-
it('should generate the right next day when cron is set to both day of the month and day of the week (1)',
|
|
405
|
+
it('should generate the right next day when cron is set to both day of the month and day of the week (1)', () => {
|
|
355
406
|
const cronTime = new cron.CronTime('0 8 1 * 4');
|
|
356
|
-
const previousDate = new Date(Date.UTC(2019, 3,
|
|
407
|
+
const previousDate = new Date(Date.UTC(2019, 3, 21, 0, 0));
|
|
357
408
|
const nextDate = cronTime._getNextDateFrom(previousDate, 'UTC');
|
|
358
|
-
expect(nextDate.
|
|
359
|
-
new Date(Date.UTC(2019, 3, 25, 8, 0)).
|
|
409
|
+
expect(nextDate.toMillis()).toEqual(
|
|
410
|
+
new Date(Date.UTC(2019, 3, 25, 8, 0)).getTime()
|
|
360
411
|
);
|
|
361
412
|
});
|
|
362
|
-
it('should generate the right next day when cron is set to both day of the month and day of the week (2)',
|
|
413
|
+
it('should generate the right next day when cron is set to both day of the month and day of the week (2)', () => {
|
|
363
414
|
const cronTime = new cron.CronTime('0 8 1 * 4');
|
|
364
415
|
const previousDate = new Date(Date.UTC(2019, 3, 26, 0, 0));
|
|
365
416
|
const nextDate = cronTime._getNextDateFrom(previousDate, 'UTC');
|
|
366
|
-
expect(nextDate.
|
|
367
|
-
new Date(Date.UTC(2019, 4, 1, 8, 0)).
|
|
417
|
+
expect(nextDate.toMillis()).toEqual(
|
|
418
|
+
new Date(Date.UTC(2019, 4, 1, 8, 0)).getTime()
|
|
368
419
|
);
|
|
369
420
|
});
|
|
370
|
-
it('should generate the right next day when cron is set to both day of the month and day of the week (3)',
|
|
421
|
+
it('should generate the right next day when cron is set to both day of the month and day of the week (3)', () => {
|
|
371
422
|
const cronTime = new cron.CronTime('0 8 1 * 4');
|
|
372
423
|
const previousDate = new Date(Date.UTC(2019, 7, 1, 7, 59));
|
|
373
424
|
const nextDate = cronTime._getNextDateFrom(previousDate, 'UTC');
|
|
@@ -376,31 +427,51 @@ describe('crontime', function() {
|
|
|
376
427
|
);
|
|
377
428
|
});
|
|
378
429
|
|
|
379
|
-
it('should accept 0 as a valid UTC offset',
|
|
430
|
+
it('should accept 0 as a valid UTC offset', () => {
|
|
380
431
|
const clock = sinon.useFakeTimers();
|
|
381
432
|
|
|
382
433
|
const cronTime = new cron.CronTime('0 11 * * *', null, 0);
|
|
383
|
-
const expected =
|
|
384
|
-
|
|
385
|
-
.unix();
|
|
386
|
-
const actual = cronTime.sendAt().unix();
|
|
434
|
+
const expected = luxon.DateTime.local().plus({ hours: 11 }).toSeconds();
|
|
435
|
+
const actual = cronTime.sendAt().toSeconds();
|
|
387
436
|
|
|
388
437
|
expect(actual).toEqual(expected);
|
|
389
438
|
|
|
390
439
|
clock.restore();
|
|
391
440
|
});
|
|
392
441
|
|
|
393
|
-
it('should accept -120 as a valid UTC offset',
|
|
442
|
+
it('should accept -120 as a valid UTC offset', () => {
|
|
394
443
|
const clock = sinon.useFakeTimers();
|
|
395
444
|
|
|
396
445
|
const cronTime = new cron.CronTime('0 11 * * *', null, -120);
|
|
397
|
-
const expected =
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
446
|
+
const expected = luxon.DateTime.local().plus({ hours: 13 }).toSeconds();
|
|
447
|
+
const actual = cronTime.sendAt().toSeconds();
|
|
448
|
+
|
|
449
|
+
expect(actual).toEqual(expected);
|
|
450
|
+
|
|
451
|
+
clock.restore();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it('should accept 4 as a valid UTC offset', () => {
|
|
455
|
+
const clock = sinon.useFakeTimers();
|
|
456
|
+
|
|
457
|
+
const cronTime = new cron.CronTime('0 11 * * *', null, 5);
|
|
458
|
+
const expected = luxon.DateTime.local().plus({ hours: 6 }).toSeconds();
|
|
459
|
+
const actual = cronTime.sendAt().toSeconds();
|
|
401
460
|
|
|
402
461
|
expect(actual).toEqual(expected);
|
|
403
462
|
|
|
404
463
|
clock.restore();
|
|
405
464
|
});
|
|
465
|
+
|
|
466
|
+
it('should detect real date in the past', () => {
|
|
467
|
+
const clock = sinon.useFakeTimers();
|
|
468
|
+
|
|
469
|
+
const d = new Date();
|
|
470
|
+
clock.tick(1000);
|
|
471
|
+
const time = new cron.CronTime(d);
|
|
472
|
+
expect(() => {
|
|
473
|
+
time.sendAt();
|
|
474
|
+
}).toThrow();
|
|
475
|
+
clock.restore();
|
|
476
|
+
});
|
|
406
477
|
});
|
package/.travis.yml
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
language: node_js
|
|
2
|
-
node_js:
|
|
3
|
-
- '6'
|
|
4
|
-
- '8'
|
|
5
|
-
- '10'
|
|
6
|
-
- '12'
|
|
7
|
-
notifications:
|
|
8
|
-
email:
|
|
9
|
-
on_success: never
|
|
10
|
-
slack:
|
|
11
|
-
secure: hHI67BDSUiJQeEiJI/+XJzR/oSsjYPoylhqY10WIZWXfs4TIrdLe513Fzt9BnDNtxpHnCqkgqCb1lF8gNkkOhJKezfDwOZK6HKpNp+zfn7WqBxL0VB3rPw3JoOO9JWoELwV2LyUutbw7m4+OMO45eWgQmQM4mddUMHjyV0awa7A=
|