cron 2.4.1 → 3.0.0-beta.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/CHANGELOG.md +28 -0
- package/README.md +29 -7
- package/lib/time.js +41 -28
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [3.0.0-beta.2](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2023-08-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🐛 Bug Fixes
|
|
5
|
+
|
|
6
|
+
* replace loop timeout by max match date ([#686](https://github.com/kelektiv/node-cron/issues/686)) ([c685c63](https://github.com/kelektiv/node-cron/commit/c685c63a6d7fa86d6c8afca29b536b9da24e824b))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 🚨 Tests
|
|
10
|
+
|
|
11
|
+
* update new test for cron standard alignments ([ea56fc1](https://github.com/kelektiv/node-cron/commit/ea56fc1c32905d711b160823fc09f39169dd3efd))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### ⚙️ Continuous Integrations
|
|
15
|
+
|
|
16
|
+
* **renovate:** configure renovate ([#683](https://github.com/kelektiv/node-cron/issues/683)) ([9dbe962](https://github.com/kelektiv/node-cron/commit/9dbe962fad1c8b1b020441bce84ab91b1a7b4415))
|
|
17
|
+
|
|
18
|
+
## [3.0.0-beta.1](https://github.com/kelektiv/node-cron/compare/v2.3.1...v3.0.0-beta.1) (2023-07-23)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### ⚠ Breaking changes
|
|
22
|
+
|
|
23
|
+
* UNIX standard alignments (#667)
|
|
24
|
+
|
|
25
|
+
### ✨ Features
|
|
26
|
+
|
|
27
|
+
* UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([96ef954](https://github.com/kelektiv/node-cron/commit/96ef954998f9c109cc2a969296568b1b56bbbd79))
|
|
28
|
+
|
|
1
29
|
## [2.4.1](https://github.com/kelektiv/node-cron/compare/v2.4.0...v2.4.1) (2023-08-14)
|
|
2
30
|
|
|
3
31
|
|
package/README.md
CHANGED
|
@@ -27,6 +27,21 @@ Cron is a tool that allows you to execute _something_ on a schedule. This is typ
|
|
|
27
27
|
npm install cron
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Migrating from v2 to v3
|
|
31
|
+
|
|
32
|
+
In version 3 of this library, we aligned our format for the cron patterns with the UNIX format. See below for the changes you need to make when upgrading:
|
|
33
|
+
|
|
34
|
+
<details>
|
|
35
|
+
<summary>Migrating from v2 to v3</summary>
|
|
36
|
+
|
|
37
|
+
### Month & day-of-week indexing changes
|
|
38
|
+
|
|
39
|
+
**Month indexing went from `0-11` to `1-12`. So you need to increment all numeric months by 1.**
|
|
40
|
+
|
|
41
|
+
For day-of-week indexing, we only added support for `7` as Sunday, so you don't need to change anything !
|
|
42
|
+
|
|
43
|
+
</details>
|
|
44
|
+
|
|
30
45
|
## Versions and Backwards compatibility breaks
|
|
31
46
|
|
|
32
47
|
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 (We're 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 us know).
|
|
@@ -65,14 +80,21 @@ There are tools that help when constructing your cronjobs. You might find someth
|
|
|
65
80
|
|
|
66
81
|
### Cron Ranges
|
|
67
82
|
|
|
68
|
-
|
|
83
|
+
This library follows the [UNIX Cron format](https://man7.org/linux/man-pages/man5/crontab.5.html), with an added field at the beginning for second granularity.
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
field allowed values
|
|
87
|
+
----- --------------
|
|
88
|
+
second 0-59
|
|
89
|
+
minute 0-59
|
|
90
|
+
hour 0-23
|
|
91
|
+
day of month 1-31
|
|
92
|
+
month 1-12 (or names, see below)
|
|
93
|
+
day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
94
|
+
```
|
|
69
95
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- Hours: 0-23
|
|
73
|
-
- Day of Month: 1-31
|
|
74
|
-
- Months: 0-11 (Jan-Dec) <-- currently different from Unix `cron`!
|
|
75
|
-
- Day of Week: 0-6 (Sun-Sat)
|
|
96
|
+
> Names can also be used for the 'month' and 'day of week' fields. Use the first three letters of the particular day or month (case does not matter). Ranges and lists of names are allowed.
|
|
97
|
+
> Examples: "mon,wed,fri", "jan-mar".
|
|
76
98
|
|
|
77
99
|
## Gotchas
|
|
78
100
|
|
package/lib/time.js
CHANGED
|
@@ -3,8 +3,8 @@ const CONSTRAINTS = [
|
|
|
3
3
|
[0, 59],
|
|
4
4
|
[0, 23],
|
|
5
5
|
[1, 31],
|
|
6
|
-
[
|
|
7
|
-
[0,
|
|
6
|
+
[1, 12],
|
|
7
|
+
[0, 7]
|
|
8
8
|
];
|
|
9
9
|
const MONTH_CONSTRAINTS = [
|
|
10
10
|
31,
|
|
@@ -22,18 +22,18 @@ const MONTH_CONSTRAINTS = [
|
|
|
22
22
|
];
|
|
23
23
|
const PARSE_DEFAULTS = ['0', '*', '*', '*', '*', '*'];
|
|
24
24
|
const ALIASES = {
|
|
25
|
-
jan:
|
|
26
|
-
feb:
|
|
27
|
-
mar:
|
|
28
|
-
apr:
|
|
29
|
-
may:
|
|
30
|
-
jun:
|
|
31
|
-
jul:
|
|
32
|
-
aug:
|
|
33
|
-
sep:
|
|
34
|
-
oct:
|
|
35
|
-
nov:
|
|
36
|
-
dec:
|
|
25
|
+
jan: 1,
|
|
26
|
+
feb: 2,
|
|
27
|
+
mar: 3,
|
|
28
|
+
apr: 4,
|
|
29
|
+
may: 5,
|
|
30
|
+
jun: 6,
|
|
31
|
+
jul: 7,
|
|
32
|
+
aug: 8,
|
|
33
|
+
sep: 9,
|
|
34
|
+
oct: 10,
|
|
35
|
+
nov: 11,
|
|
36
|
+
dec: 12,
|
|
37
37
|
sun: 0,
|
|
38
38
|
mon: 1,
|
|
39
39
|
tue: 2,
|
|
@@ -42,17 +42,18 @@ const ALIASES = {
|
|
|
42
42
|
fri: 5,
|
|
43
43
|
sat: 6
|
|
44
44
|
};
|
|
45
|
-
const
|
|
46
|
-
'second',
|
|
47
|
-
'minute',
|
|
48
|
-
'hour',
|
|
49
|
-
'dayOfMonth',
|
|
50
|
-
'month',
|
|
51
|
-
'dayOfWeek'
|
|
52
|
-
|
|
45
|
+
const TIME_UNITS_MAP = {
|
|
46
|
+
SECOND: 'second',
|
|
47
|
+
MINUTE: 'minute',
|
|
48
|
+
HOUR: 'hour',
|
|
49
|
+
DAY_OF_MONTH: 'dayOfMonth',
|
|
50
|
+
MONTH: 'month',
|
|
51
|
+
DAY_OF_WEEK: 'dayOfWeek'
|
|
52
|
+
};
|
|
53
|
+
const TIME_UNITS = Object.values(TIME_UNITS_MAP);
|
|
53
54
|
const TIME_UNITS_LEN = TIME_UNITS.length;
|
|
54
55
|
const PRESETS = {
|
|
55
|
-
'@yearly': '0 0 0 1
|
|
56
|
+
'@yearly': '0 0 0 1 1 *',
|
|
56
57
|
'@monthly': '0 0 0 1 * *',
|
|
57
58
|
'@weekly': '0 0 0 * * 0',
|
|
58
59
|
'@daily': '0 0 0 * * *',
|
|
@@ -112,7 +113,7 @@ function CronTime(luxon) {
|
|
|
112
113
|
let lastWrongMonth = NaN;
|
|
113
114
|
for (let i = 0; i < months.length; i++) {
|
|
114
115
|
const m = months[i];
|
|
115
|
-
const con = MONTH_CONSTRAINTS[parseInt(m, 10)];
|
|
116
|
+
const con = MONTH_CONSTRAINTS[parseInt(m, 10) - 1];
|
|
116
117
|
|
|
117
118
|
for (let j = 0; j < dom.length; j++) {
|
|
118
119
|
const day = dom[j];
|
|
@@ -130,7 +131,7 @@ function CronTime(luxon) {
|
|
|
130
131
|
|
|
131
132
|
// infinite loop detected (dayOfMonth is not found in all months)
|
|
132
133
|
if (!ok) {
|
|
133
|
-
const notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10)];
|
|
134
|
+
const notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10) - 1];
|
|
134
135
|
for (let k = 0; k < dom.length; k++) {
|
|
135
136
|
const notOkDay = dom[k];
|
|
136
137
|
if (notOkDay > notOkCon) {
|
|
@@ -282,7 +283,7 @@ function CronTime(luxon) {
|
|
|
282
283
|
}
|
|
283
284
|
|
|
284
285
|
if (
|
|
285
|
-
!(date.month
|
|
286
|
+
!(date.month in this.month) &&
|
|
286
287
|
Object.keys(this.month).length !== 12
|
|
287
288
|
) {
|
|
288
289
|
date = date.plus({ months: 1 });
|
|
@@ -475,7 +476,7 @@ function CronTime(luxon) {
|
|
|
475
476
|
const beforeJumpingPoint = afterJumpingPoint.minus({ second: 1 });
|
|
476
477
|
|
|
477
478
|
if (
|
|
478
|
-
date.month in this.month &&
|
|
479
|
+
date.month + 1 in this.month &&
|
|
479
480
|
date.day in this.dayOfMonth &&
|
|
480
481
|
date.getWeekDay() in this.dayOfWeek
|
|
481
482
|
) {
|
|
@@ -675,8 +676,13 @@ function CronTime(luxon) {
|
|
|
675
676
|
|
|
676
677
|
_hasAll: function (type) {
|
|
677
678
|
const constraints = CONSTRAINTS[TIME_UNITS.indexOf(type)];
|
|
679
|
+
const low = constraints[0];
|
|
680
|
+
const high =
|
|
681
|
+
type === TIME_UNITS_MAP.DAY_OF_WEEK
|
|
682
|
+
? constraints[1] - 1
|
|
683
|
+
: constraints[1];
|
|
678
684
|
|
|
679
|
-
for (let i =
|
|
685
|
+
for (let i = low, n = high; i < n; i++) {
|
|
680
686
|
if (!(i in this[type])) {
|
|
681
687
|
return false;
|
|
682
688
|
}
|
|
@@ -807,6 +813,13 @@ function CronTime(luxon) {
|
|
|
807
813
|
typeObj[pointer] = true; // mutates the field objects values inside CronTime
|
|
808
814
|
pointer += step;
|
|
809
815
|
} while (pointer <= upper);
|
|
816
|
+
|
|
817
|
+
// merge day 7 into day 0 (both Sunday), and remove day 7
|
|
818
|
+
// since we work with day-of-week 0-6 under the hood
|
|
819
|
+
if (type === 'dayOfWeek') {
|
|
820
|
+
if (!typeObj[0] && !!typeObj[7]) typeObj[0] = typeObj[7];
|
|
821
|
+
delete typeObj[7];
|
|
822
|
+
}
|
|
810
823
|
});
|
|
811
824
|
} else {
|
|
812
825
|
throw new Error(`Field (${type}) cannot be parsed`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cron",
|
|
3
3
|
"description": "Cron jobs for your node",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0-beta.2",
|
|
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"
|