cron 1.7.1 → 1.8.2

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/.eslintrc CHANGED
@@ -1,34 +1,28 @@
1
1
  {
2
- "extends": [
3
- "standard",
4
- "prettier",
5
- "prettier/standard"
6
- ],
7
- "parserOptions": {
8
- "ecmaVersion": "2017",
9
- "sourceType": "module"
10
- },
11
- "globals": {
12
- "define": true,
13
- "after": true,
14
- "afterEach": true,
15
- "before": true,
16
- "beforeEach": true,
17
- "describe": true,
18
- "expect": true,
19
- "it": true
20
- },
21
- "env": {
22
- "browser": true,
23
- "node": true
24
- },
25
- "plugins": [
26
- "prettier",
27
- "standard"
28
- ],
29
- "rules": {
30
- "space-before-function-paren": 0,
31
- "new-cap": 0,
32
- "prettier/prettier": 2
33
- }
2
+ "extends": ["standard", "prettier", "prettier/standard"],
3
+ "parserOptions": {
4
+ "ecmaVersion": "2017",
5
+ "sourceType": "module"
6
+ },
7
+ "globals": {
8
+ "define": true,
9
+ "after": true,
10
+ "afterEach": true,
11
+ "before": true,
12
+ "beforeEach": true,
13
+ "describe": true,
14
+ "expect": true,
15
+ "it": true
16
+ },
17
+ "env": {
18
+ "browser": true,
19
+ "node": true,
20
+ "jest/globals": true
21
+ },
22
+ "plugins": ["prettier", "standard", "jest"],
23
+ "rules": {
24
+ "space-before-function-paren": 0,
25
+ "new-cap": 0,
26
+ "prettier/prettier": 2
27
+ }
34
28
  }
package/.travis.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  language: node_js
2
2
  node_js:
3
- - '4'
4
3
  - '6'
5
4
  - '8'
6
5
  - '10'
6
+ - '12'
7
7
  notifications:
8
8
  email:
9
9
  on_success: never
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [v1.8.1] - 2020-01-19
2
+ - Revert TS definition defaulting to DefinitelyTyped definitions.
3
+
4
+ ## [v1.8.0] - 2020-01-19
5
+ - GH-454 - Range upper limit should default to highest value when step is provided by Noah May <noahmouse2011@gmail.com> in d36dc9581f9f68580a2016b368f8002a9f1e357d
6
+
1
7
  ## [v1.7.1] - 2019-04-26
2
8
  - GH-416 - Fix issue where next execution time is incorrect in some cases in Naoya Inada <naoina@kuune.org> in c08522ff80b3987843e9930c307b76d5fe38b5dc
3
9
 
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  node-cron
2
2
  =
3
3
 
4
- [![Build Status](https://travis-ci.org/kelektiv/node-cron.svg?branch=master)](https://travis-ci.org/#!/kelektiv/node-cron)
4
+ [![Build Status](https://travis-ci.org/kelektiv/node-cron.svg?branch=master)](https://travis-ci.org/kelektiv/node-cron)
5
5
  [![Dependency Status](https://david-dm.org/ncb000gt/node-cron.svg)](https://david-dm.org/ncb000gt/node-cron)
6
6
 
7
7
  Cron is a tool that allows you to execute _something_ on a schedule. This is
@@ -45,9 +45,10 @@ Usage (basic cron usage):
45
45
 
46
46
  ```javascript
47
47
  var CronJob = require('cron').CronJob;
48
- new CronJob('* * * * * *', function() {
48
+ var job = new CronJob('* * * * * *', function() {
49
49
  console.log('You will see this message every second');
50
50
  }, null, true, 'America/Los_Angeles');
51
+ job.start();
51
52
  ```
52
53
 
53
54
  Note - You need to explicitly start a job in order to make it run. This gives a
@@ -80,7 +81,7 @@ Cron Ranges
80
81
 
81
82
  When specifying your cron values you'll need to make sure that your values fall
82
83
  within the ranges. For instance, some cron's use a 0-7 range for the day of
83
- week where both 0 and 7 represent Sunday. We do not.
84
+ week where both 0 and 7 represent Sunday. We do not. And that is an optimisation.
84
85
 
85
86
  * Seconds: 0-59
86
87
  * Minutes: 0-59
@@ -165,7 +166,7 @@ Parameter Based
165
166
  from the NodeJS docs.
166
167
  * `start` - Runs your job.
167
168
  * `stop` - Stops your job.
168
- * `setTime` - Change the time for the `CronJob`. Param must be a `CronTime`.
169
+ * `setTime` - Stops and changes the time for the `CronJob`. Param must be a `CronTime`.
169
170
  * `lastDate` - Tells you the last execution date.
170
171
  * `nextDates` - Provides an array of the next set of dates that will trigger an `onTick`.
171
172
  * `fireOnTick` - Allows you to override the `onTick` calling behavior. This
package/examples/basic.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const CronJob = require('../lib/cron.js').CronJob;
2
2
 
3
3
  console.log('Before job instantiation');
4
- const job = new CronJob('* * * * * *', function() {
4
+ const job = new CronJob('* * 7-23 * * *', function() {
5
5
  const d = new Date();
6
6
  console.log('Every second:', d);
7
7
  });
package/lib/cron.js CHANGED
@@ -93,7 +93,7 @@
93
93
 
94
94
  /* if a dayOfMonth is not found in all months, we only need to fix the last
95
95
  wrong month to prevent infinite loop */
96
- var lastWrongMonth = {};
96
+ var lastWrongMonth = NaN;
97
97
  for (var i = 0; i < months.length; i++) {
98
98
  var m = months[i];
99
99
  var con = CronTime.monthConstraints[parseInt(m, 10)];
@@ -221,10 +221,7 @@
221
221
  // it shouldn't take more than 5 seconds to find the next execution time
222
222
  // being very generous with this. Throw error if it takes too long to find the next time to protect from
223
223
  // infinite loop.
224
- var finding = true;
225
- var findingTimeout = setTimeout(function() {
226
- finding = false;
227
- }, 5000);
224
+ var timeout = Date.now() + 5000;
228
225
  // determine next date
229
226
  while (true) {
230
227
  var diff = date - start;
@@ -234,7 +231,7 @@
234
231
  var prevSeconds = date.seconds();
235
232
  var origDate = new Date(date);
236
233
 
237
- if (!finding) {
234
+ if (Date.now() > timeout) {
238
235
  throw new Error(
239
236
  `Something went wrong. cron reached maximum iterations.
240
237
  Please open an issue (https://github.com/kelektiv/node-cron/issues/new) and provide the following string
@@ -304,14 +301,14 @@
304
301
  origDate = moment(date);
305
302
  var curHour = date.hours();
306
303
  date.hours(
307
- date.hours() === 23 && diff > 86400000 ? 0 : date.hours() + 1
304
+ date.hours() === 23 && diff > 86400000 ? 0 : date.hours() + 1
308
305
  );
309
306
  /*
310
- * Moment Date will not allow you to set the time to 2 AM if there is no 2 AM (on the day we change the clock)
311
- * We will therefore jump to 3AM if time stayed at 1AM
312
- */
313
- if(curHour === date.hours()){
314
- date.hours(date.hours() + 2);
307
+ * Moment Date will not allow you to set the time to 2 AM if there is no 2 AM (on the day we change the clock)
308
+ * We will therefore jump to 3AM if time stayed at 1AM
309
+ */
310
+ if (curHour === date.hours()) {
311
+ date.hours(date.hours() + 2);
315
312
  }
316
313
  date.minutes(0);
317
314
  date.seconds(0);
@@ -360,7 +357,6 @@
360
357
  break;
361
358
  }
362
359
 
363
- clearTimeout(findingTimeout);
364
360
  return date;
365
361
  },
366
362
 
@@ -417,6 +413,14 @@
417
413
  var i = 0;
418
414
  var len = timeUnits.length;
419
415
 
416
+ // seconds are optional
417
+ if (split.length < timeUnits.length - 1) {
418
+ throw new Error('Too few fields');
419
+ }
420
+ if (split.length > timeUnits.length) {
421
+ throw new Error('Too many fields');
422
+ }
423
+
420
424
  for (; i < timeUnits.length; i++) {
421
425
  // If the split source string doesn't contain all digits,
422
426
  // assume defaults for first n missing digits.
@@ -433,6 +437,14 @@
433
437
  var low = constraints[0];
434
438
  var high = constraints[1];
435
439
 
440
+ var fields = field.split(',');
441
+ fields.forEach(function(field) {
442
+ var wildcardIndex = field.indexOf('*');
443
+ if (wildcardIndex !== -1 && wildcardIndex !== 0) {
444
+ throw new Error('Field (' + field + ') has an invalid wildcard expression');
445
+ }
446
+ });
447
+
436
448
  // * is a shortcut to [lower-upper] range
437
449
  field = field.replace(/\*/g, low + '-' + high);
438
450
 
@@ -442,12 +454,38 @@
442
454
  for (var i = 0; i < allRanges.length; i++) {
443
455
  if (allRanges[i].match(rangePattern)) {
444
456
  allRanges[i].replace(rangePattern, function($0, lower, upper, step) {
445
- step = parseInt(step) || 1;
457
+ lower = parseInt(lower, 10);
458
+ upper = parseInt(upper, 10) || undefined;
459
+
460
+ const wasStepDefined = !isNaN(parseInt(step, 10));
461
+ if (step === '0') {
462
+ throw new Error('Field (' + field + ') has a step of zero');
463
+ }
464
+ step = parseInt(step, 10) || 1;
465
+
466
+ if (upper && lower > upper) {
467
+ throw new Error('Field (' + field + ') has an invalid range');
468
+ }
469
+
470
+ const outOfRangeError =
471
+ lower < low ||
472
+ (upper && upper > high) ||
473
+ (!upper && lower > high);
474
+
475
+ if (outOfRangeError) {
476
+ throw new Error('Field (' + field + ') value is out of range');
477
+ }
478
+
446
479
  // Positive integer higher than constraints[0]
447
480
  lower = Math.min(Math.max(low, ~~Math.abs(lower)), high);
448
481
 
449
482
  // Positive integer lower than constraints[1]
450
- upper = upper ? Math.min(high, ~~Math.abs(upper)) : lower;
483
+ if (upper) {
484
+ upper = Math.min(high, ~~Math.abs(upper));
485
+ } else {
486
+ // If step is provided, the default upper range is the highest value
487
+ upper = wasStepDefined ? high : lower;
488
+ }
451
489
 
452
490
  // Count from the lower barrier to the upper
453
491
  pointer = lower;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cron",
3
3
  "description": "Cron jobs for your node",
4
- "version": "1.7.1",
4
+ "version": "1.8.2",
5
5
  "author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)",
6
6
  "bugs": {
7
7
  "url": "http://github.com/kelektiv/node-cron/issues"
@@ -12,24 +12,25 @@
12
12
  },
13
13
  "main": "lib/cron",
14
14
  "scripts": {
15
- "test": "make test"
15
+ "test": "jest"
16
16
  },
17
17
  "dependencies": {
18
18
  "moment-timezone": "^0.5.x"
19
19
  },
20
20
  "devDependencies": {
21
- "mocha": "~5.2.x",
22
21
  "chai": "~4.2.x",
23
- "sinon": "~7.2.x",
24
- "eslint": "~5.13.x",
25
- "eslint-config-prettier": "~4.0.x",
26
- "eslint-config-standard": "~12.0.x",
27
- "eslint-plugin-import": "~2.16.x",
28
- "eslint-plugin-node": "~8.0.x",
29
- "eslint-plugin-prettier": "~3.0.x",
30
- "eslint-plugin-promise": "~4.0.x",
22
+ "eslint": "~6.3.x",
23
+ "eslint-config-prettier": "~6.2.x",
24
+ "eslint-config-standard": "~14.1.x",
25
+ "eslint-plugin-import": "~2.18.x",
26
+ "eslint-plugin-jest": "^22.17.0",
27
+ "eslint-plugin-node": "~10.0.x",
28
+ "eslint-plugin-prettier": "~3.1.x",
29
+ "eslint-plugin-promise": "~4.2.x",
31
30
  "eslint-plugin-standard": "~4.0.x",
32
- "prettier": "~1.16.x"
31
+ "jest": "^24.9.0",
32
+ "prettier": "~1.18.x",
33
+ "sinon": "~7.4.x"
33
34
  },
34
35
  "keywords": [
35
36
  "cron",
@@ -54,6 +55,7 @@
54
55
  "Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)",
55
56
  "Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)",
56
57
  "Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)",
57
- "Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)"
58
+ "Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)",
59
+ "Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"
58
60
  ]
59
61
  }