cron 2.2.0 → 2.3.1

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/lib/time.js CHANGED
@@ -70,7 +70,7 @@ function CronTime(luxon) {
70
70
  this.source = source;
71
71
 
72
72
  if (zone) {
73
- const dt = luxon.DateTime.fromObject({}, { zone: zone });
73
+ const dt = luxon.DateTime.fromObject({}, { zone });
74
74
  if (dt.invalid) {
75
75
  throw new Error('Invalid timezone.');
76
76
  }
@@ -82,8 +82,8 @@ function CronTime(luxon) {
82
82
  this.utcOffset = utcOffset;
83
83
  }
84
84
 
85
- var that = this;
86
- TIME_UNITS.map(timeUnit => {
85
+ const that = this;
86
+ TIME_UNITS.forEach(timeUnit => {
87
87
  that[timeUnit] = {};
88
88
  });
89
89
 
@@ -103,19 +103,19 @@ function CronTime(luxon) {
103
103
  * Ensure that the syntax parsed correctly and correct the specified values if needed.
104
104
  */
105
105
  _verifyParse: function () {
106
- var months = Object.keys(this.month);
107
- var dom = Object.keys(this.dayOfMonth);
108
- var ok = false;
106
+ const months = Object.keys(this.month);
107
+ const dom = Object.keys(this.dayOfMonth);
108
+ let ok = false;
109
109
 
110
110
  /* if a dayOfMonth is not found in all months, we only need to fix the last
111
111
  wrong month to prevent infinite loop */
112
- var lastWrongMonth = NaN;
113
- for (var i = 0; i < months.length; i++) {
114
- var m = months[i];
115
- var con = MONTH_CONSTRAINTS[parseInt(m, 10)];
112
+ let lastWrongMonth = NaN;
113
+ for (let i = 0; i < months.length; i++) {
114
+ const m = months[i];
115
+ const con = MONTH_CONSTRAINTS[parseInt(m, 10)];
116
116
 
117
- for (var j = 0; j < dom.length; j++) {
118
- var day = dom[j];
117
+ for (let j = 0; j < dom.length; j++) {
118
+ const day = dom[j];
119
119
  if (day <= con) {
120
120
  ok = true;
121
121
  }
@@ -130,12 +130,12 @@ function CronTime(luxon) {
130
130
 
131
131
  // infinite loop detected (dayOfMonth is not found in all months)
132
132
  if (!ok) {
133
- var notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10)];
134
- for (var k = 0; k < dom.length; k++) {
135
- var notOkDay = dom[k];
133
+ const notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10)];
134
+ for (let k = 0; k < dom.length; k++) {
135
+ const notOkDay = dom[k];
136
136
  if (notOkDay > notOkCon) {
137
137
  delete this.dayOfMonth[notOkDay];
138
- var fixedDay = Number(notOkDay) % notOkCon;
138
+ const fixedDay = Number(notOkDay) % notOkCon;
139
139
  this.dayOfMonth[fixedDay] = true;
140
140
  }
141
141
  }
@@ -146,7 +146,7 @@ function CronTime(luxon) {
146
146
  * Calculate the "next" scheduled time
147
147
  */
148
148
  sendAt: function (i) {
149
- var date = this.realDate ? this.source : luxon.DateTime.local();
149
+ let date = this.realDate ? this.source : luxon.DateTime.local();
150
150
  if (this.zone) {
151
151
  date = date.setZone(this.zone);
152
152
  }
@@ -185,7 +185,7 @@ function CronTime(luxon) {
185
185
  return this._getNextDateFrom(date);
186
186
  } else {
187
187
  // return the next schedule times
188
- var dates = [];
188
+ const dates = [];
189
189
  for (; i > 0; i--) {
190
190
  date = this._getNextDateFrom(date);
191
191
  dates.push(date);
@@ -213,12 +213,16 @@ function CronTime(luxon) {
213
213
  * Json representation of the parsed cron syntax.
214
214
  */
215
215
  toJSON: function () {
216
- var self = this;
216
+ const self = this;
217
217
  return TIME_UNITS.map(function (timeName) {
218
218
  return self._wcOrAll(timeName);
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
  *
@@ -240,8 +244,8 @@ function CronTime(luxon) {
240
244
  if (start instanceof Date) {
241
245
  start = luxon.DateTime.fromJSDate(start);
242
246
  }
243
- var date = start;
244
- var firstDate = start.toMillis();
247
+ let date = start;
248
+ const firstDate = start.toMillis();
245
249
  if (zone) {
246
250
  date = date.setZone(zone);
247
251
  }
@@ -258,19 +262,18 @@ function CronTime(luxon) {
258
262
  // it shouldn't take more than 5 seconds to find the next execution time
259
263
  // being very generous with this. Throw error if it takes too long to find the next time to protect from
260
264
  // infinite loop.
261
- var timeout = Date.now() + 5000;
265
+ const timeout = Date.now() + 5000;
262
266
  // determine next date
263
267
  while (true) {
264
- var diff = date - start;
268
+ const diff = date - start;
265
269
 
266
270
  // hard stop if the current date is after the expected execution
267
271
  if (Date.now() > timeout) {
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
  */
@@ -357,8 +661,8 @@ function CronTime(luxon) {
357
661
  return '*';
358
662
  }
359
663
 
360
- var all = [];
361
- for (var time in this[type]) {
664
+ const all = [];
665
+ for (const time in this[type]) {
362
666
  all.push(time);
363
667
  }
364
668
 
@@ -366,9 +670,9 @@ function CronTime(luxon) {
366
670
  },
367
671
 
368
672
  _hasAll: function (type) {
369
- var constraints = CONSTRAINTS[TIME_UNITS.indexOf(type)];
673
+ const constraints = CONSTRAINTS[TIME_UNITS.indexOf(type)];
370
674
 
371
- for (var i = constraints[0], n = constraints[1]; i < n; i++) {
675
+ for (let i = constraints[0], n = constraints[1]; i < n; i++) {
372
676
  if (!(i in this[type])) {
373
677
  return false;
374
678
  }
@@ -403,7 +707,7 @@ function CronTime(luxon) {
403
707
  throw new Error(`Unknown alias: ${alias}`);
404
708
  });
405
709
 
406
- var units = source.trim().split(/\s+/);
710
+ const units = source.trim().split(/\s+/);
407
711
 
408
712
  // seconds are optional
409
713
  if (units.length < TIME_UNITS_LEN - 1) {
@@ -414,12 +718,12 @@ function CronTime(luxon) {
414
718
  throw new Error('Too many fields');
415
719
  }
416
720
 
417
- var unitsLen = units.length;
418
- for (var i = 0; i < TIME_UNITS_LEN; i++) {
721
+ const unitsLen = units.length;
722
+ for (let i = 0; i < TIME_UNITS_LEN; i++) {
419
723
  // If the split source string doesn't contain all digits,
420
724
  // assume defaults for first n missing digits.
421
725
  // This adds support for 5-digit standard cron syntax
422
- var cur = units[i - (TIME_UNITS_LEN - unitsLen)] || PARSE_DEFAULTS[i];
726
+ const cur = units[i - (TIME_UNITS_LEN - unitsLen)] || PARSE_DEFAULTS[i];
423
727
  this._parseField(cur, TIME_UNITS[i], CONSTRAINTS[i]);
424
728
  }
425
729
  },
@@ -435,14 +739,14 @@ function CronTime(luxon) {
435
739
  * - Starting with the lower bounds of the range iterate by step up to the upper bounds and toggle the CronTime field value flag on.
436
740
  */
437
741
  _parseField: function (value, type, constraints) {
438
- var typeObj = this[type];
439
- var pointer;
440
- var low = constraints[0];
441
- var high = constraints[1];
742
+ const typeObj = this[type];
743
+ let pointer;
744
+ const low = constraints[0];
745
+ const high = constraints[1];
442
746
 
443
- var fields = value.split(',');
747
+ const fields = value.split(',');
444
748
  fields.forEach(field => {
445
- var wildcardIndex = field.indexOf('*');
749
+ const wildcardIndex = field.indexOf('*');
446
750
  if (wildcardIndex !== -1 && wildcardIndex !== 0) {
447
751
  throw new Error(
448
752
  `Field (${field}) has an invalid wildcard expression`
@@ -454,9 +758,9 @@ function CronTime(luxon) {
454
758
  value = value.replace(RE_WILDCARDS, `${low}-${high}`);
455
759
 
456
760
  // commas separate information, so split based on those
457
- var allRanges = value.split(',');
761
+ const allRanges = value.split(',');
458
762
 
459
- for (var i = 0; i < allRanges.length; i++) {
763
+ for (let i = 0; i < allRanges.length; i++) {
460
764
  if (allRanges[i].match(RE_RANGE)) {
461
765
  allRanges[i].replace(RE_RANGE, ($0, lower, upper, step) => {
462
766
  lower = parseInt(lower, 10);
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.1",
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"
@@ -13,26 +13,25 @@
13
13
  "main": "lib/cron",
14
14
  "scripts": {
15
15
  "lint": "eslint {lib,tests}/*.js",
16
- "test": "jest --coverage"
16
+ "test": "jest --coverage",
17
+ "test:watch": "jest --watch --coverage"
17
18
  },
18
19
  "dependencies": {
19
20
  "luxon": "^3.2.1"
20
21
  },
21
22
  "devDependencies": {
22
23
  "chai": "~4.2.x",
23
- "eslint": "~6.8.x",
24
- "eslint-config-prettier": "^6.11.x",
25
- "eslint-config-standard": "~14.1.x",
26
- "eslint-module-utils": "~2.6.x",
27
- "eslint-plugin-import": "~2.20.x",
28
- "eslint-plugin-jest": "~23.8.x",
29
- "eslint-plugin-node": "~11.1.x",
30
- "eslint-plugin-prettier": "~3.1.x",
31
- "eslint-plugin-promise": "~4.2.x",
32
- "eslint-plugin-standard": "~4.0.x",
33
- "jest": "~28.0.x",
34
- "prettier": "~2.0.x",
35
- "sinon": "^9.0.x"
24
+ "eslint": "~8.36.x",
25
+ "eslint-config-prettier": "^8.7.x",
26
+ "eslint-config-standard": "~17.0.x",
27
+ "eslint-plugin-import": "~2.27.x",
28
+ "eslint-plugin-jest": "~27.2.x",
29
+ "eslint-plugin-n": "~15.6.x",
30
+ "eslint-plugin-prettier": "~4.2.x",
31
+ "eslint-plugin-promise": "~6.1.x",
32
+ "jest": "~29.5.x",
33
+ "prettier": "~2.8.x",
34
+ "sinon": "^15.0.x"
36
35
  },
37
36
  "keywords": [
38
37
  "cron",
@@ -45,6 +44,7 @@
45
44
  ],
46
45
  "license": "MIT",
47
46
  "contributors": [
47
+ "Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)",
48
48
  "Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)",
49
49
  "James Padolsey <> (https://github.com/jamespadolsey)",
50
50
  "Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)",
@@ -73,5 +73,11 @@
73
73
  "lines": 80
74
74
  }
75
75
  }
76
- }
76
+ },
77
+ "files": [
78
+ "lib",
79
+ "CHANGELOG.md",
80
+ "LICENSE",
81
+ "README.md"
82
+ ]
77
83
  }
package/.editorconfig DELETED
@@ -1,5 +0,0 @@
1
- root = true
2
-
3
- [*.{js}]
4
- indent_style = tab
5
- indent_size = 2
package/.eslintrc DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "extends": ["standard", "prettier", "prettier/standard"],
3
- "parserOptions": {
4
- "ecmaVersion": 2018
5
- },
6
- "globals": {
7
- "define": "readonly"
8
- },
9
- "env": {
10
- "browser": true,
11
- "es6": true,
12
- "node": true,
13
- "jest/globals": true
14
- },
15
- "plugins": ["prettier", "standard", "jest"],
16
- "rules": {
17
- "space-before-function-paren": 0,
18
- "new-cap": 0,
19
- "prettier/prettier": 2,
20
- "jest/no-disabled-tests": 1,
21
- "jest/no-focused-tests": 2,
22
- "jest/no-identical-title": 2,
23
- "jest/prefer-to-have-length": 1,
24
- "jest/valid-expect": 2
25
- }
26
- }