cron 2.2.0 → 2.3.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 CHANGED
File without changes
package/.eslintrc CHANGED
File without changes
File without changes
File without changes
File without changes
package/.prettierrc CHANGED
File without changes
package/CHANGELOG.md CHANGED
File without changes
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
- # Looking for maintainers/contributors
2
-
3
- This project is looking for help! If you're interested in helping with the project please reach out to me [ncb000gt](https://twitter.com/ncb000gt) and let me know. I'd love for it to continue on, but it needs a lot of attention.
1
+ ## Looking for maintainers/contributors
4
2
 
3
+ This project is looking for help! If you're interested in helping with the project please reach out to me (ncb000gt) on [Twitter](https://twitter.com/ncb000gt) and let me know. I'd love for it to continue on, but it needs a lot of attention. You can also join the [Discord server](https://discord.gg/yyKns29zch) to learn more about what needs to be done.
5
4
 
6
5
  # node-cron
7
6
 
@@ -13,178 +12,115 @@ This project is looking for help! If you're interested in helping with the proje
13
12
  [![Known Vulnerabilities](https://snyk.io/test/github/kelektiv/node-cron/badge.svg)](https://snyk.io/test/github/kelektiv/node-cron)
14
13
  [![Minified size](https://badgen.net/bundlephobia/min/cron)](https://badgen.net/bundlephobia/min/cron)
15
14
  [![Minzipped size](https://badgen.net/bundlephobia/minzip/cron)](https://badgen.net/bundlephobia/minzip/cron)
16
- [![monthly downloads](https://badgen.net/npm/dm/cron?icon=npm)](https://badgen.net/npm/dm/cron)
17
-
18
- Cron is a tool that allows you to execute _something_ on a schedule. This is
19
- typically done using the cron syntax. We allow you to execute a function
20
- whenever your scheduled job triggers. We also allow you to execute a job
21
- external to the javascript process using `child_process`. Additionally, this
22
- library goes beyond the basic cron syntax and allows you to
23
- supply a Date object. This will be used as the trigger for your callback. Cron
24
- syntax is still an acceptable CronTime format. Although the Cron patterns
25
- supported here extend on the standard Unix format to support seconds digits,
26
- leaving it off will default to 0 and match the Unix behavior.
27
-
28
- # Installation
15
+ [![monthly downloads](https://badgen.net/npm/dm/cron?icon=npm)](https://badgen.net/npm/dm/cron)
29
16
 
30
- npm install cron
17
+ Cron is a tool that allows you to execute _something_ on a schedule. This is typically done using the cron syntax. We allow you to execute a function whenever your scheduled job triggers. We also allow you to execute a job external to the javascript process using `child_process`. Additionally, this library goes beyond the basic cron syntax and allows you to supply a Date object. This will be used as the trigger for your callback. Cron syntax is still an acceptable CronTime format. Although the Cron patterns supported here extend on the standard Unix format to support seconds digits, leaving it off will default to 0 and match the Unix behavior.
31
18
 
32
- # If You Are Submitting Bugs/Issues
19
+ ## Installation
33
20
 
34
- Because we can't magically know what you are doing to expose an issue, it is
35
- best if you provide a snippet of code. This snippet need not include your secret
36
- sauce, but it must replicate the issue you are describing. The issues that get
37
- closed without resolution tend to be the ones without code examples. Thanks.
21
+ ```
22
+ npm install cron
23
+ ```
38
24
 
39
- # Versions and Backwards compatibility breaks:
25
+ ## Versions and Backwards compatibility breaks:
40
26
 
41
- As goes with semver, breaking backwards compatibility should be explicit in the
42
- versioning of your library. As such, we'll upgrade the version of this module
43
- in accordance with breaking changes (I'm not always great about doing it this
44
- way so if you notice that there are breaking changes that haven't been bumped
45
- appropriately please let me know).
27
+ As goes with semver, breaking backwards compatibility should be explicit in the versioning of your library. As such, we'll upgrade the version of this module in accordance with breaking changes (I'm not always great about doing it this way so if you notice that there are breaking changes that haven't been bumped appropriately please let me know).
46
28
 
47
- # Usage (basic cron usage):
29
+ ## Usage (basic cron usage):
48
30
 
49
31
  ```javascript
50
32
  var CronJob = require('cron').CronJob;
51
33
  var job = new CronJob(
52
- '* * * * * *',
53
- function() {
54
- console.log('You will see this message every second');
55
- },
56
- null,
57
- true,
58
- 'America/Los_Angeles'
34
+ '* * * * * *',
35
+ function() {
36
+ console.log('You will see this message every second');
37
+ },
38
+ null,
39
+ true,
40
+ 'America/Los_Angeles'
59
41
  );
60
42
  // Use this if the 4th param is default value(false)
61
43
  // job.start()
62
- ```
44
+ ```
63
45
 
64
- Note - You don't need to explicitly start a job in order to make it run since the 4th parameter is set to `true`. However, by default you need to call `job.start()` to start the cron job, which gives a little more control over running your jobs.
46
+ Note - You don't need to explicitly start a job in order to make it run since the 4th parameter is set to `true`. However, by default you need to call `job.start()` to start the cron job, which gives a little more control over running your jobs.
65
47
 
66
- There are more examples available in this repository at:
67
- [/examples](https://github.com/kelektiv/node-cron/tree/master/examples)
48
+ There are more examples available in this repository at: [/examples](https://github.com/kelektiv/node-cron/tree/master/examples)
68
49
 
69
- # Available Cron patterns:
50
+ ## Available Cron patterns:
70
51
 
71
- Asterisk. E.g. *
72
- Ranges. E.g. 1-3,5
73
- Steps. E.g. */2
52
+ ```
53
+ Asterisks e.g. *
54
+ Ranges e.g. 1-3,5
55
+ Steps e.g. */2
56
+ ```
74
57
 
75
- [Read up on cron patterns here](http://crontab.org). Note the examples in the
76
- link have five fields, and 1 minute as the finest granularity, but this library
77
- has six fields, with 1 second as the finest granularity.
58
+ [Read up on cron patterns here](http://crontab.org). Note the examples in the link have five fields, and 1 minute as the finest granularity, but this library has six fields, with 1 second as the finest granularity.
78
59
 
79
- There are tools that help when constructing your cronjobs. You might find
80
- something like https://crontab.guru/ or https://cronjob.xyz/ helpful. But,
81
- note that these don't necessarily accept the exact same syntax as this
82
- library, for instance, it doesn't accept the `seconds` field, so keep that in
83
- mind.
60
+ There are tools that help when constructing your cronjobs. You might find something like https://crontab.guru/ or https://cronjob.xyz/ helpful. But, note that these don't necessarily accept the exact same syntax as this library, for instance, it doesn't accept the `seconds` field, so keep that in mind.
84
61
 
85
- # Cron Ranges
62
+ ### Cron Ranges
86
63
 
87
- When specifying your cron values you'll need to make sure that your values fall
88
- within the ranges. For instance, some cron's use a 0-7 range for the day of
89
- week where both 0 and 7 represent Sunday. We do not. And that is an optimisation.
64
+ When specifying your cron values you'll need to make sure that your values fall within the ranges. For instance, some cron's use a 0-7 range for the day of week where both 0 and 7 represent Sunday. We do not. And that is an optimisation.
90
65
 
91
66
  - Seconds: 0-59
92
67
  - Minutes: 0-59
93
68
  - Hours: 0-23
94
69
  - Day of Month: 1-31
95
70
  - Months: 0-11 (Jan-Dec)
96
- - Day of Week: 0-6 (Sun-Sat)
97
-
98
- # Gotchas
99
-
100
- - Millisecond level granularity in JS or moment date objects.
101
- Because computers take time to do things, there may be some delay in execution.
102
- This should be on the order of milliseconds. This module doesn't allow MS level
103
- granularity for the regular cron syntax, but _does_ allow you to specify a real
104
- date of execution in either a javascript date object or a moment object.
105
- When this happens you may find that you aren't able to execute a job that
106
- _should_ run in the future like with `new Date().setMilliseconds(new Date().getMilliseconds() + 1)`. This is due to those cycles of execution
107
- above. This wont be the same for everyone because of compute speed. When I
108
- tried it locally I saw that somewhere around the 4-5 ms mark was where I got
109
- consistent ticks using real dates, but anything less than that would result
110
- in an exception. This could be really confusing. We could restrict the
111
- granularity for all dates to seconds, but felt that it wasn't a huge problem
112
- so long as you were made aware. If this becomes more of an issue, We can
113
- revisit it.
114
- - Arrow Functions for `onTick`
115
- Arrow functions get their `this` context from their parent scope. Thus, if you use them, you will not get
116
- the `this` context of the cronjob. You can read a little more in this ticket [GH-40](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775)
117
-
118
- # API
119
-
120
- Parameter Based
71
+ - Day of Week: 0-6 (Sun-Sat)
72
+
73
+ ## Gotchas
74
+
75
+ - Millisecond level granularity in JS `Date` or Luxon `DateTime` objects: Because computers take time to do things, there may be some delay in execution. This should be on the order of milliseconds. This module doesn't allow MS level granularity for the regular cron syntax, but _does_ allow you to specify a real date of execution in either a javascript `Date` object or a Luxon `DateTime` object. When this happens you may find that you aren't able to execute a job that _should_ run in the future like with `new Date().setMilliseconds(new Date().getMilliseconds() + 1)`. This is due to those cycles of execution above. This wont be the same for everyone because of compute speed. When I tried it locally I saw that somewhere around the 4-5 ms mark was where I got consistent ticks using real dates, but anything less than that would result in an exception. This could be really confusing. We could restrict the granularity for all dates to seconds, but felt that it wasn't a huge problem so long as you were made aware. If this becomes more of an issue, We can revisit it.
76
+ - Arrow Functions for `onTick`: Arrow functions get their `this` context from their parent scope. Thus, if you use them, you will not get the `this` context of the cronjob. You can read a little more in issue [GH-47](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775)
77
+
78
+ ## API
79
+
80
+ Parameter Based
121
81
 
122
82
  - `job` - shortcut to `new cron.CronJob()`.
123
83
  - `time` - shortcut to `new cron.CronTime()`.
124
84
  - `sendAt` - tells you when a `CronTime` will be run.
125
85
  - `timeout` - tells you when the next timeout is.
126
86
  - `CronJob`
127
- - `constructor(cronTime, onTick, onComplete, start, timezone, context, runOnInit, utcOffset, unrefTimeout)` - Of note, the first parameter here can be a JSON object that
128
- has the below names and associated types (see examples above).
129
- - `cronTime` - [REQUIRED] - The time to fire off your job. This can be in
130
- the form of cron syntax or a JS
131
- [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
132
- - `onTick` - [REQUIRED] - The function to fire at the specified time. If an
133
- `onComplete` callback was provided, `onTick` will receive it as an argument.
134
- `onTick` may call `onComplete` when it has finished its work.
135
- - `onComplete` - [OPTIONAL] - A function that will fire when the job is
136
- stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
137
- - `start` - [OPTIONAL] - Specifies whether to start the job just before
138
- exiting the constructor. By default this is set to false. If left at default
139
- you will need to call `job.start()` in order to start the job (assuming
140
- `job` is the variable you set the cronjob to). This does not immediately
141
- fire your `onTick` function, it just gives you more control over the
142
- behavior of your jobs.
143
- - `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This
144
- will modify the actual time relative to your timezone. If the timezone is
145
- invalid, an error is thrown. You can check all timezones available at
146
- [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use
147
- both `timeZone` and `utcOffset` together or weird things may happen.
148
- - `context` - [OPTIONAL] - The context within which to execute the onTick
149
- method. This defaults to the cronjob itself allowing you to call
150
- `this.stop()`. However, if you change this you'll have access to the
151
- functions and values within your context object.
152
- - `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick`
153
- function as soon as the requisite initialization has happened. This option
154
- is set to `false` by default for backwards compatibility.
155
- - `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your
156
- timezone rather than using the `timeZone` param. Probably don't use both
157
- `timeZone` and `utcOffset` together or weird things may happen.
158
- - `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop
159
- running and want to stop the node process when that finishes regardless of
160
- the state of your cronjob, you can do so making use of this parameter. This
161
- is off by default and cron will run as if it needs to control the event
162
- loop. For more information take a look at
163
- [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref)
164
- from the NodeJS docs.
165
- - `start` - Runs your job.
166
- - `stop` - Stops your job.
167
- - `setTime` - Stops and changes the time for the `CronJob`. Param must be a `CronTime`.
168
- - `lastDate` - Tells you the last execution date.
169
- - `nextDates` - Provides an array of the next set of dates that will trigger an `onTick`.
170
- - `fireOnTick` - Allows you to override the `onTick` calling behavior. This
171
- matters so only do this if you have a really good reason to do so.
172
- - `addCallback` - Allows you to add `onTick` callbacks.
87
+ - `constructor(cronTime, onTick, onComplete, start, timezone, context, runOnInit, utcOffset, unrefTimeout)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
88
+ - `cronTime` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
89
+ - `onTick` - [REQUIRED] - The function to fire at the specified time. If an `onComplete` callback was provided, `onTick` will receive it as an argument. `onTick` may call `onComplete` when it has finished its work.
90
+ - `onComplete` - [OPTIONAL] - A function that will fire when the job is stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
91
+ - `start` - [OPTIONAL] - Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call `job.start()` in order to start the job (assuming `job` is the variable you set the cronjob to). This does not immediately fire your `onTick` function, it just gives you more control over the behavior of your jobs.
92
+ - `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. You can check all timezones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
93
+ - `context` - [OPTIONAL] - The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call `this.stop()`. However, if you change this you'll have access to the functions and values within your context object.
94
+ - `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick` function as soon as the requisite initialization has happened. This option is set to `false` by default for backwards compatibility.
95
+ - `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your timezone rather than using the `timeZone` param. This should be an integer amount representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours) Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
96
+ - `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.
97
+ - `start` - Runs your job.
98
+ - `stop` - Stops your job.
99
+ - `setTime` - Stops and changes the time for the `CronJob`. Param must be a `CronTime`.
100
+ - `lastDate` - Tells you the last execution date.
101
+ - `nextDates` - Provides an array of the next set of dates that will trigger an `onTick`.
102
+ - `fireOnTick` - Allows you to override the `onTick` calling behavior. This matters so only do this if you have a really good reason to do so.
103
+ - `addCallback` - Allows you to add `onTick` callbacks.
173
104
  - `CronTime`
174
- - `constructor(time)`
175
- - `time` - [REQUIRED] - The time to fire off your job. This can be in the
176
- form of cron syntax or a JS
177
- [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date)
178
- object.
105
+ - `constructor(time)`
106
+ - `time` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
107
+
108
+ ## Community
109
+
110
+ Join the [Discord server](https://discord.gg/yyKns29zch)! Here you can discuss issues and get help in a more casual forum than GitHub.
111
+
112
+ ## Contributing
113
+
114
+ ### Submitting Bugs/Issues
115
+
116
+ Before submitting a bug, please search the existing issues, [Discord](https://discord.gg/yyKns29zch) conversations, and the web to see if someone else has run into the same issue before.
117
+
118
+ Because we can't magically know what you are doing to expose an issue, it is best if you provide a snippet of code. This snippet need not include your secret sauce, but it must replicate the issue you are describing. The issues that get closed without resolution tend to be the ones without code examples. Thanks.
179
119
 
180
- # Contributions
120
+ ### Acknowledgements
181
121
 
182
- This is a community effort project. In the truest sense, this project started as
183
- an open source project from [cron.js](http://github.com/padolsey/cron.js) and
184
- grew into something else. Other people have contributed code, time, and
185
- oversight to the project. At this point there are too many to name here so I'll
186
- just say thanks.
122
+ This is a community effort project. In the truest sense, this project started as an open source project from [cron.js](http://github.com/padolsey/cron.js) and grew into something else. Other people have contributed code, time, and oversight to the project. At this point there are too many to name here so I'll just say thanks.
187
123
 
188
- # License
124
+ ## License
189
125
 
190
- MIT
126
+ MIT
package/bower.json CHANGED
File without changes
File without changes
File without changes
package/examples/basic.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,16 @@
1
+ const CronJob = require('../lib/cron.js').CronJob;
2
+
3
+ console.log('first');
4
+ const job = new CronJob(
5
+ '0 0 9 4 * *',
6
+ function() {
7
+ console.log('message');
8
+ },
9
+ null,
10
+ true,
11
+ null,
12
+ null,
13
+ null,
14
+ -360, // UTC-6, represented in minutes
15
+ );
16
+ console.log('second');
package/lib/cron.js CHANGED
File without changes
package/lib/job.js CHANGED
File without changes
package/lib/time.js CHANGED
@@ -219,6 +219,10 @@ function CronTime(luxon) {
219
219
  });
220
220
  },
221
221
 
222
+ getNextDateFrom: function (start, zone) {
223
+ return this._getNextDateFrom(start, zone);
224
+ },
225
+
222
226
  /**
223
227
  * Get next date matching the specified cron time.
224
228
  *
@@ -268,9 +272,8 @@ function CronTime(luxon) {
268
272
  throw new Error(
269
273
  `Something went wrong. It took over five seconds to find the next execution time for the cron job.
270
274
  Please refer to the canonical issue (https://github.com/kelektiv/node-cron/issues/467) and provide the following string if you would like to help debug:
271
- Time Zone: ${zone || '""'} - Cron String: ${this} - UTC offset: ${date.format(
272
- 'Z'
273
- )} - current Date: ${luxon.DateTime.local().toString()}`
275
+ Time Zone: ${zone || '""'} - Cron String: ${this} - UTC offset: ${date.offset}
276
+ - current Date: ${luxon.DateTime.local().toString()}`
274
277
  );
275
278
  }
276
279
 
@@ -280,6 +283,12 @@ function CronTime(luxon) {
280
283
  ) {
281
284
  date = date.plus({ months: 1 });
282
285
  date = date.set({ day: 1, hour: 0, minute: 0, second: 0 });
286
+
287
+ if (this._forwardDSTJump(0, 0, date)) {
288
+ const [done, newDate] = this._findPreviousDSTJump(date);
289
+ date = newDate;
290
+ if (done) break;
291
+ }
283
292
  continue;
284
293
  }
285
294
 
@@ -293,6 +302,12 @@ function CronTime(luxon) {
293
302
  ) {
294
303
  date = date.plus({ days: 1 });
295
304
  date = date.set({ hour: 0, minute: 0, second: 0 });
305
+
306
+ if (this._forwardDSTJump(0, 0, date)) {
307
+ const [done, newDate] = this._findPreviousDSTJump(date);
308
+ date = newDate;
309
+ if (done) break;
310
+ }
296
311
  continue;
297
312
  }
298
313
 
@@ -306,14 +321,34 @@ function CronTime(luxon) {
306
321
  ) {
307
322
  date = date.plus({ days: 1 });
308
323
  date = date.set({ hour: 0, minute: 0, second: 0 });
324
+ if (this._forwardDSTJump(0, 0, date)) {
325
+ const [done, newDate] = this._findPreviousDSTJump(date);
326
+ date = newDate;
327
+ if (done) break;
328
+ }
309
329
  continue;
310
330
  }
311
331
 
312
332
  if (!(date.hour in this.hour) && Object.keys(this.hour).length !== 24) {
313
- date = date.set({
314
- hour: date.hour === 23 && diff > 86400000 ? 0 : date.hour + 1
315
- });
333
+ const expectedHour =
334
+ date.hour === 23 && diff > 86400000 ? 0 : date.hour + 1;
335
+ const expectedMinute = date.minute; // expect no change.
336
+
337
+ date = date.set({ hour: expectedHour });
316
338
  date = date.set({ minute: 0, second: 0 });
339
+
340
+ // When this is the case, Asking luxon to go forward by 1 hour actually made us go forward by more hours...
341
+ // This indicates that somewhere between these two time points, a forward DST adjustment has happened.
342
+ // When this happens, the job should be scheduled to execute as though the time has come when the jump is made.
343
+ // Therefore, the job should be scheduled on the first tick after the forward jump.
344
+ if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
345
+ const [done, newDate] = this._findPreviousDSTJump(date);
346
+ date = newDate;
347
+ if (done) break;
348
+ }
349
+ // backwards jumps do not seem to have any problems (i.e. double activations),
350
+ // so they need not be handled in a similar way.
351
+
317
352
  continue;
318
353
  }
319
354
 
@@ -321,10 +356,21 @@ function CronTime(luxon) {
321
356
  !(date.minute in this.minute) &&
322
357
  Object.keys(this.minute).length !== 60
323
358
  ) {
324
- date = date.set({
325
- minute: date.minute === 59 && diff > 3600000 ? 0 : date.minute + 1
326
- });
359
+ const expectedMinute =
360
+ date.minute === 59 && diff > 3600000 ? 0 : date.minute + 1;
361
+ const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
362
+
363
+ date = date.set({ minute: expectedMinute });
327
364
  date = date.set({ second: 0 });
365
+
366
+ // Same case as with hours: DST forward jump.
367
+ // This must be accounted for if a minute increment pushed us to a jumping point.
368
+ if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
369
+ const [done, newDate] = this._findPreviousDSTJump(date);
370
+ date = newDate;
371
+ if (done) break;
372
+ }
373
+
328
374
  continue;
329
375
  }
330
376
 
@@ -332,14 +378,37 @@ function CronTime(luxon) {
332
378
  !(date.second in this.second) &&
333
379
  Object.keys(this.second).length !== 60
334
380
  ) {
335
- date = date.set({
336
- second: date.second === 59 && diff > 60000 ? 0 : date.second + 1
337
- });
381
+ const expectedSecond =
382
+ date.second === 59 && diff > 60000 ? 0 : date.second + 1;
383
+ const expectedMinute = date.minute + (expectedSecond === 60);
384
+ const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
385
+
386
+ date = date.set({ second: expectedSecond });
387
+
388
+ // Seconds can cause it too, imagine 21:59:59 -> 23:00:00.
389
+ if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
390
+ const [done, newDate] = this._findPreviousDSTJump(date);
391
+ date = newDate;
392
+ if (done) break;
393
+ }
394
+
338
395
  continue;
339
396
  }
340
397
 
341
398
  if (date.toMillis() === firstDate) {
342
- date = date.set({ second: date.second + 1 });
399
+ const expectedSecond = date.second + 1;
400
+ const expectedMinute = date.minute + (expectedSecond === 60);
401
+ const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
402
+
403
+ date = date.set({ second: expectedSecond });
404
+
405
+ // Same as always.
406
+ if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
407
+ const [done, newDate] = this._findPreviousDSTJump(date);
408
+ date = newDate;
409
+ if (done) break;
410
+ }
411
+
343
412
  continue;
344
413
  }
345
414
 
@@ -349,6 +418,241 @@ function CronTime(luxon) {
349
418
  return date;
350
419
  },
351
420
 
421
+ /**
422
+ * Search backwards in time 1 minute at a time, to detect a DST forward jump.
423
+ * When the jump is found, the range of the jump is investigated to check for acceptable cron times.
424
+ *
425
+ * A pair is returned, whose first is a boolean representing if an acceptable time was found inside the jump,
426
+ * and whose second is a DateTime representing the first millisecond after the jump.
427
+ *
428
+ * The input date is expected to be decently close to a DST jump.
429
+ * Up to a day in the past is checked before an error is thrown.
430
+ * @param date
431
+ * @return [boolean, DateTime]
432
+ */
433
+ _findPreviousDSTJump: function (date) {
434
+ /** @type number */
435
+ let expectedMinute, expectedHour, actualMinute, actualHour;
436
+ /** @type DateTime */
437
+ let maybeJumpingPoint = date;
438
+
439
+ // representing one day of backwards checking. If this is hit, the input must be wrong.
440
+ const iterationLimit = 60 * 24;
441
+ let iteration = 0;
442
+ do {
443
+ if (++iteration > iterationLimit) {
444
+ throw new Error(
445
+ `ERROR: This DST checking related function assumes the input DateTime (${date.toISO()}) is within 24 hours of a DST jump.`
446
+ );
447
+ }
448
+
449
+ expectedMinute = maybeJumpingPoint.minute - 1;
450
+ expectedHour = maybeJumpingPoint.hour;
451
+
452
+ if (expectedMinute < 0) {
453
+ expectedMinute += 60;
454
+ expectedHour = (expectedHour + 24 - 1) % 24; // Subtract 1 hour, but we must account for the -1 case.
455
+ }
456
+
457
+ maybeJumpingPoint = maybeJumpingPoint.minus({ minute: 1 });
458
+
459
+ actualMinute = maybeJumpingPoint.minute;
460
+ actualHour = maybeJumpingPoint.hour;
461
+ } while (expectedMinute === actualMinute && expectedHour === actualHour);
462
+
463
+ // Setting the seconds and milliseconds to zero is necessary for two reasons:
464
+ // Firstly, the range checking function needs the earliest moment after the jump.
465
+ // Secondly, this DateTime may be used for scheduling jobs, if there existed a job in the skipped range.
466
+ const afterJumpingPoint = maybeJumpingPoint
467
+ .plus({ minute: 1 }) // back to the first minute _after_ the jump
468
+ .set({ seconds: 0, millisecond: 0 });
469
+
470
+ // Get the lower bound of the range to check as well. This only has to be accurate down to minutes.
471
+ const beforeJumpingPoint = afterJumpingPoint.minus({ second: 1 });
472
+
473
+ if (
474
+ date.month in this.month &&
475
+ date.day in this.dayOfMonth &&
476
+ date.getWeekDay() in this.dayOfWeek
477
+ ) {
478
+ return [
479
+ this._checkTimeInSkippedRange(beforeJumpingPoint, afterJumpingPoint),
480
+ afterJumpingPoint
481
+ ];
482
+ }
483
+
484
+ // no valid time in the range for sure, units that didn't change from the skip mismatch.
485
+ return [false, afterJumpingPoint];
486
+ },
487
+
488
+ /**
489
+ * Given 2 DateTimes, which represent 1 second before and immediately after a DST forward jump,
490
+ * checks if a time in the skipped range would have been a valid CronJob time.
491
+ *
492
+ * Could technically work with just one of these values, extracting the other by adding or subtracting seconds.
493
+ * However, this couples the input DateTime to actually being tied to a DST jump,
494
+ * which would make the function harder to test.
495
+ * This way the logic just tests a range of minutes and hours, regardless if there are skipped time points underneath.
496
+ *
497
+ * Assumes the DST jump started no earlier than 0:00 and jumped forward by at least 1 minute, to at most 23:59.
498
+ * i.e. The day is assumed constant, but the jump is not assumed to be an hour long.
499
+ * Empirically, it is almost always one hour, but very, very rarely 30 minutes.
500
+ *
501
+ * Assumes dayOfWeek, dayOfMonth and month match all match, so only the hours, minutes and seconds are to be checked.
502
+ * @param {DateTime} beforeJumpingPoint
503
+ * @param {DateTime} afterJumpingPoint
504
+ * @returns {boolean}
505
+ */
506
+ _checkTimeInSkippedRange: function (beforeJumpingPoint, afterJumpingPoint) {
507
+ // start by getting the first minute & hour inside the skipped range.
508
+ const startingMinute = (beforeJumpingPoint.minute + 1) % 60;
509
+ const startingHour =
510
+ (beforeJumpingPoint.hour + (startingMinute === 0)) % 24;
511
+
512
+ const hourRangeSize = afterJumpingPoint.hour - startingHour + 1;
513
+ const isHourJump = startingMinute === 0 && afterJumpingPoint.minute === 0;
514
+
515
+ // There exist DST jumps other than 1 hour long, and the function is built to deal with it.
516
+ // It may be overkill to assume some cases, but it shouldn't cost much at runtime.
517
+ // https://en.wikipedia.org/wiki/Daylight_saving_time_by_country
518
+ if (hourRangeSize === 2 && isHourJump) {
519
+ // Exact 1 hour jump, most common real-world case.
520
+ // There is no need to check minutes and seconds, as any value would suffice.
521
+ return startingHour in this.hour;
522
+ } else if (hourRangeSize === 1) {
523
+ // less than 1 hour jump, rare but does exist.
524
+ return (
525
+ startingHour in this.hour &&
526
+ this._checkTimeInSkippedRangeSingleHour(
527
+ startingMinute,
528
+ afterJumpingPoint.minute
529
+ )
530
+ );
531
+ } else {
532
+ // non-round or multi-hour jump. (does not exist in the real world at the time of writing)
533
+ return this._checkTimeInSkippedRangeMultiHour(
534
+ startingHour,
535
+ startingMinute,
536
+ afterJumpingPoint.hour,
537
+ afterJumpingPoint.minute
538
+ );
539
+ }
540
+ },
541
+
542
+ /**
543
+ * Component of checking if a CronJob time existed in a DateTime range skipped by DST.
544
+ * This subroutine makes a further assumption that the skipped range is fully contained in one hour,
545
+ * and that all other larger units are valid for the job.
546
+ *
547
+ * for example a jump from 02:00:00 to 02:30:00, but not from 02:00:00 to 03:00:00.
548
+ * @see _checkTimeInSkippedRange
549
+ *
550
+ * This is done by checking if any minute in startMinute - endMinute is valid, excluding endMinute.
551
+ * For endMinute, there is only a match if the 0th second is a valid time.
552
+ */
553
+ _checkTimeInSkippedRangeSingleHour: function (startMinute, endMinute) {
554
+ for (let minute = startMinute; minute < endMinute; ++minute) {
555
+ if (minute in this.minute) return true;
556
+ }
557
+
558
+ // Unless the very last second of the jump matched, there is no match.
559
+ return endMinute in this.minute && 0 in this.second;
560
+ },
561
+
562
+ /**
563
+ * Component of checking if a CronJob time existed in a DateTime range skipped by DST.
564
+ * This subroutine assumes the jump touches at least 2 hours, but the jump does not necessarily fully contain these hours.
565
+ *
566
+ * @see _checkTimeInSkippedRange
567
+ *
568
+ * This is done by defining the minutes to check for the first and last hour,
569
+ * and checking all 60 minutes for any hours in between them.
570
+ *
571
+ * If any hour x minute combination is a valid time, true is returned.
572
+ * The endMinute x endHour combination is only checked with the 0th second, since the rest would be out of the range.
573
+ *
574
+ * @param startHour {number}
575
+ * @param startMinute {number}
576
+ * @param endHour {number}
577
+ * @param endMinute {number}
578
+ */
579
+ _checkTimeInSkippedRangeMultiHour: function (
580
+ startHour,
581
+ startMinute,
582
+ endHour,
583
+ endMinute
584
+ ) {
585
+ if (startHour >= endHour) {
586
+ throw new Error(
587
+ `ERROR: This DST checking related function assumes the forward jump starting hour (${startHour}) is less than the end hour (${endHour})`
588
+ );
589
+ }
590
+
591
+ /** @type number[] */
592
+ const firstHourMinuteRange = Array.from(
593
+ { length: 60 - startMinute },
594
+ (_, k) => startMinute + k
595
+ );
596
+ /** @type {number[]} The final minute is not contained on purpose. Every minute in this range represents one for which any second is valid. */
597
+ const lastHourMinuteRange = Array.from(
598
+ { length: endMinute },
599
+ (_, k) => k
600
+ );
601
+ /** @type number[] */
602
+ const middleHourMinuteRange = Array.from({ length: 60 }, (_, k) => k);
603
+
604
+ /** @type (number) => number[] */
605
+ const selectRange = forHour => {
606
+ if (forHour === startHour) {
607
+ return firstHourMinuteRange;
608
+ } else if (forHour === endHour) {
609
+ return lastHourMinuteRange;
610
+ } else {
611
+ return middleHourMinuteRange;
612
+ }
613
+ };
614
+
615
+ // Include the endHour: Selecting the right range still ensures no values outside the skip are checked.
616
+ for (let hour = startHour; hour <= endHour; ++hour) {
617
+ if (!(hour in this.hour)) continue;
618
+
619
+ // The hour matches, so if the minute is in the range, we have a match!
620
+ const usingRange = selectRange(hour);
621
+
622
+ for (const minute of usingRange) {
623
+ // All minutes in any of the selected ranges represent minutes which are fully contained in the jump,
624
+ // So we need not check the seconds. If the minute is in there, it is a match.
625
+ if (minute in this.minute) return true;
626
+ }
627
+ }
628
+
629
+ // The endMinute of the endHour was not checked in the loop, because only the 0th second of it is in the range.
630
+ // Arriving here means no match was found yet, but this final check may turn up as a match.
631
+ return (
632
+ endHour in this.hour && endMinute in this.minute && 0 in this.second
633
+ );
634
+ },
635
+ /**
636
+ * Given expected and actual hours and minutes, report if a DST forward jump occurred.
637
+ *
638
+ * This is the case when the expected is smaller than the acutal.
639
+ *
640
+ * It is not sufficient to check only hours, because some parts of the world apply DST by shifting in minutes.
641
+ * Better to account for it by checking minutes too, before an Australian of Lord Howe Island call us.
642
+ * @param expectedHour
643
+ * @param expectedMinute
644
+ * @param {DateTime} actualDate
645
+ */
646
+ _forwardDSTJump: function (expectedHour, expectedMinute, actualDate) {
647
+ const actualHour = actualDate.hour;
648
+ const actualMinute = actualDate.minute;
649
+
650
+ const hoursJumped = expectedHour % 24 < actualHour;
651
+ const minutesJumped = expectedMinute % 60 < actualMinute;
652
+
653
+ return hoursJumped || minutesJumped;
654
+ },
655
+
352
656
  /**
353
657
  * wildcard, or all params in array (for to string)
354
658
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cron",
3
3
  "description": "Cron jobs for your node",
4
- "version": "2.2.0",
4
+ "version": "2.3.0",
5
5
  "author": "Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/kelektiv/node-cron/issues"
File without changes
@@ -292,7 +292,21 @@ describe('crontime', () => {
292
292
  );
293
293
  });
294
294
 
295
- it('should generete the right next days when cron is set to every minute', () => {
295
+ it('should expose _getNextDateFrom as a public function', () => {
296
+ const cronTime = new cron.CronTime('0 */10 * * * *');
297
+ cronTime._getNextDateFrom = jest.fn();
298
+
299
+ const testDate = new Date('2018-08-10T02:19:59.999Z');
300
+ const testTimezone = 'Asia/Amman';
301
+ cronTime.getNextDateFrom(testDate, testTimezone);
302
+
303
+ expect(cronTime._getNextDateFrom).toHaveBeenCalledWith(
304
+ testDate,
305
+ testTimezone
306
+ );
307
+ });
308
+
309
+ it('should generate the right next days when cron is set to every minute', () => {
296
310
  const cronTime = new cron.CronTime('* * * * *');
297
311
  const min = 60000;
298
312
  let previousDate = new Date(Date.UTC(2018, 5, 3, 0, 0));
@@ -303,7 +317,7 @@ describe('crontime', () => {
303
317
  }
304
318
  });
305
319
 
306
- it('should generete the right next days when cron is set to every 15 min', () => {
320
+ it('should generate the right next days when cron is set to every 15 min', () => {
307
321
  const cronTime = new cron.CronTime('*/15 * * * *');
308
322
  const min = 60000 * 15;
309
323
  let previousDate = new Date(Date.UTC(2016, 6, 3, 0, 0));
@@ -346,7 +360,164 @@ describe('crontime', () => {
346
360
  currentDate = nextDate;
347
361
  }
348
362
  });
349
- it('should generate the right N next days for * * * * *', () => {
363
+ it('Should schedule jobs inside time zone changes that shifts time forward to the end of the shift, for weekly jobs', () => {
364
+ let currentDate = luxon.DateTime.fromISO('2018-03-29T23:15', {
365
+ zone: 'Asia/Amman'
366
+ });
367
+ const cronTime = new cron.CronTime('30 0 * * 5'); // the next 0:30 is March 30th, but it will jump from 0:00 to 1:00.
368
+ let nextDate = cronTime._getNextDateFrom(currentDate, 'Asia/Amman');
369
+ expect(nextDate - currentDate).toEqual(1000 * 60 * 45); // 45 minutes is 30T00:00, which jumps to 1:00 which is past the trigger of 0:30.
370
+ // the next one should just be at 0:30 again. i.e. a week minus 30 minutes.
371
+ currentDate = nextDate;
372
+ nextDate = cronTime._getNextDateFrom(currentDate);
373
+ expect(nextDate - currentDate).toEqual(3600000 * 24 * 7 - 60000 * 30);
374
+ // the next one is again at 0:30, but now we're 'back to normal' with weekly offsets.
375
+ currentDate = nextDate;
376
+ nextDate = cronTime._getNextDateFrom(currentDate);
377
+ expect(nextDate - currentDate).toEqual(1000 * 3600 * 24 * 7);
378
+ });
379
+ it('Should schedule jobs inside time zone changes that shifts the time forward to the end of the shift, for daily jobs', () => {
380
+ let currentDate = luxon.DateTime.fromISO('2018-03-29T23:45', {
381
+ zone: 'Asia/Amman'
382
+ });
383
+ const cronTime = new cron.CronTime('30 0 * * *'); // the next 0:30 is March 30th, but it will jump from 0:00 to 1:00.
384
+ let nextDate = cronTime._getNextDateFrom(currentDate, 'Asia/Amman');
385
+ expect(nextDate - currentDate).toEqual(1000 * 60 * 15); // 15 minutes is 30T00:00, which jumps to 1:00 which is past the trigger of 0:30.
386
+ // the next one is tomorrow at 0:30, so 23h30m.
387
+ currentDate = nextDate;
388
+ nextDate = cronTime._getNextDateFrom(currentDate);
389
+ expect(nextDate - currentDate).toEqual(1000 * 3600 * 24 - 1000 * 60 * 30);
390
+ // back to normal.
391
+ currentDate = nextDate;
392
+ nextDate = cronTime._getNextDateFrom(currentDate);
393
+ expect(nextDate - currentDate).toEqual(1000 * 3600 * 24);
394
+ });
395
+ it('Should schedule jobs inside time zone changes that shifts the time forward to the end of the shift, for hourly jobs', () => {
396
+ let currentDate = luxon.DateTime.fromISO('2018-03-29T23:45', {
397
+ zone: 'Asia/Amman'
398
+ });
399
+ const cronTime = new cron.CronTime('30 * * * *'); // the next 0:30 is March 30th, but it will jump from 0:00 to 1:00.
400
+ let nextDate = cronTime._getNextDateFrom(currentDate, 'Asia/Amman');
401
+ expect(nextDate - currentDate).toEqual(1000 * 60 * 15); // 15 minutes is 30T00:00, which jumps to 1:00 which is past the trigger of 0:30.
402
+ // the next one is at 1:30, so 30m.
403
+ currentDate = nextDate;
404
+ nextDate = cronTime._getNextDateFrom(currentDate);
405
+ expect(nextDate - currentDate).toEqual(1000 * 60 * 30);
406
+ // back to normal.
407
+ currentDate = nextDate;
408
+ nextDate = cronTime._getNextDateFrom(currentDate);
409
+ expect(nextDate - currentDate).toEqual(1000 * 3600);
410
+ });
411
+ it('Should schedule jobs inside time zone changes that shifts the time forward to the end of the shift, for minutely jobs', () => {
412
+ let currentDate = luxon.DateTime.fromISO('2018-03-29T23:59', {
413
+ zone: 'Asia/Amman'
414
+ });
415
+ const cronTime = new cron.CronTime('* * * * *'); // the next minute is 0:00 is March 30th, but it will jump from 0:00 to 1:00.
416
+ let nextDate = cronTime._getNextDateFrom(currentDate, 'Asia/Amman');
417
+ expect(nextDate - currentDate).toEqual(1000 * 60);
418
+ // the next one is at 1:01:00, this should still be 60 seconds in the future.
419
+ currentDate = nextDate;
420
+ nextDate = cronTime._getNextDateFrom(currentDate);
421
+ expect(nextDate - currentDate).toEqual(1000 * 60);
422
+ });
423
+ // Do not think a similar test for secondly job is necessary, the minutely one already ensured no double hits in the overlap zone.
424
+ it('Should throw when dates that are not within 24 hours of DST jumps are checked for past DST jumps', () => {
425
+ const cronTime = new cron.CronTime('* * * * *');
426
+ const tryFindPastDST = isoTime => () => {
427
+ const maybeBadDate = luxon.DateTime.fromISO(isoTime, {
428
+ zone: 'Asia/Amman'
429
+ });
430
+ expect(maybeBadDate.invalid).toEqual(null);
431
+ cronTime._findPreviousDSTJump(maybeBadDate);
432
+ };
433
+
434
+ // This timezone jumps from 0:00 to 1:00 on March 30th, so the cutoff is March 31st 1:00:00
435
+ expect(tryFindPastDST('2018-03-31T00:59:00')).not.toThrow();
436
+ expect(tryFindPastDST('2018-03-31T01:00:00')).toThrow();
437
+ });
438
+ // The following few DST related tests do not need specific dates that are actually DST,
439
+ // the functions they are calling assume the given parameters encapsulate a DST jump,
440
+ // and use the raw hour and minute data to check it from there.
441
+ it('Should correctly scan time periods as if they are DST jumps, half hour jumps', () => {
442
+ let endDate = luxon.DateTime.fromISO('2023-01-01T16:00:00.000', {
443
+ zone: 'Europe/Amsterdam'
444
+ });
445
+ let startDate = endDate.minus({ minute: 30, second: 1 });
446
+ const cronTime = new cron.CronTime('5 16 * * *'); // at 16:05:00.
447
+ let jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
448
+ expect(jobInRange).toEqual(false);
449
+
450
+ endDate = endDate.plus({ minute: 30 }); // 16:30:00
451
+ startDate = endDate.minus({ minute: 30, second: 1 }); // 15:59:59
452
+ jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
453
+ expect(jobInRange).toEqual(true);
454
+ });
455
+ it('Should not include seconds in the minute after the DST jump as part of the jump scan', () => {
456
+ const endDate = luxon.DateTime.fromISO('2023-01-01T16:00:00.000', {
457
+ zone: 'Europe/Amsterdam'
458
+ });
459
+ // 1 hour jump case
460
+ let startDate = endDate.minus({ hour: 1, second: 1 });
461
+ const cronTime = new cron.CronTime('1 5 16 * * *'); // at 16:00:01.
462
+ let jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
463
+ expect(jobInRange).toEqual(false);
464
+ // 'quirky' jump case
465
+ startDate = endDate.minus({ hour: 1, minute: 45, second: 1 });
466
+ jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
467
+ expect(jobInRange).toEqual(false);
468
+ });
469
+ it('Should correctly scan time periods as if they are DST jumps, full hour jumps', () => {
470
+ let endDate = luxon.DateTime.fromISO('2023-01-01T16:00:00.000', {
471
+ zone: 'Europe/Amsterdam'
472
+ });
473
+ let startDate = endDate.minus({ hour: 1, second: 1 });
474
+ const cronTime = new cron.CronTime('5 16 * * *'); // at 16:05:00.
475
+ let jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
476
+ expect(jobInRange).toEqual(false);
477
+
478
+ endDate = endDate.plus({ hour: 1 }); // 17:00:00
479
+ startDate = endDate.minus({ hour: 1, second: 1 }); // 15:59:59
480
+ jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
481
+ expect(jobInRange).toEqual(true);
482
+ });
483
+ // A 'quirky' DST jump is one that should not break the implementation, but does not exist in real life (yet)
484
+ it('Should correctly scan time periods as if they are DST jumps, quirky jumps (1)', () => {
485
+ // Testing a jump that is less than an hour long, but wraps around an hour.
486
+ let endDate = luxon.DateTime.fromISO('2023-01-01T16:15:00.000', {
487
+ zone: 'Europe/Amsterdam'
488
+ });
489
+ let startDate = endDate.minus({ minute: 45, second: 1 }); // 15:29:59
490
+ const cronTime = new cron.CronTime('30 16 * * *'); // at 16:30:00.
491
+ let jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
492
+ expect(jobInRange).toEqual(false);
493
+
494
+ endDate = endDate.plus({ minute: 30 }); // 16:45:00
495
+ startDate = endDate.minus({ minute: 50, second: 1 }); // 15:54:59
496
+ jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
497
+ expect(jobInRange).toEqual(true);
498
+ });
499
+ it('Should correctly scan time periods as if they are DST jumps, quirky jumps (2)', () => {
500
+ // Testing a jump that is over an hour long.
501
+ let endDate = luxon.DateTime.fromISO('2023-01-01T16:15:00.000', {
502
+ zone: 'Europe/Amsterdam'
503
+ });
504
+ let startDate = endDate.minus({ hour: 3, minute: 45, second: 1 }); // 12:29:59
505
+ const cronTime = new cron.CronTime('30 16 * * *'); // at 16:30:00.
506
+ let jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
507
+ expect(jobInRange).toEqual(false);
508
+
509
+ endDate = endDate.plus({ minute: 30 }); // 16:45:00
510
+ startDate = endDate.minus({ hour: 3, minute: 45, second: 1 }); // 12:59:59
511
+ jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
512
+ expect(jobInRange).toEqual(true);
513
+ });
514
+ it('Enforces the hour difference assumption for handling multi-hour DST jumps', () => {
515
+ const cronTime = new cron.CronTime('30 16 * * *');
516
+ expect(() => {
517
+ cronTime._checkTimeInSkippedRangeMultiHour(15, 0, 15, 30);
518
+ }).toThrow();
519
+ });
520
+ it('should generate the right N next days for * * * * *', () => {
350
521
  const cronTime = new cron.CronTime('* * * * *');
351
522
  let currentDate = luxon.DateTime.local().set({ second: 0, millisecond: 0 });
352
523
  for (let i = 0; i < 100; i++) {
@@ -394,7 +565,7 @@ describe('crontime', () => {
394
565
  currentDate = nextDate;
395
566
  }
396
567
  });
397
- it('should generete the right next day when cron is set to every 15 min in Feb', () => {
568
+ it('should generate the right next day when cron is set to every 15 min in Feb', () => {
398
569
  const cronTime = new cron.CronTime('*/15 * * FEB *');
399
570
  const previousDate = new Date(Date.UTC(2018, 3, 0, 0, 0));
400
571
  const nextDate = cronTime._getNextDateFrom(previousDate, 'UTC');