cron 3.0.0-beta.3 → 3.0.0-beta.5
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 +55 -11
- package/README.md +2 -2
- package/lib/time.js +21 -12
- package/package.json +6 -3
- package/types/index.test-d.ts +85 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
## [3.0.0-beta.5](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2023-09-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🐛 Bug Fixes
|
|
5
|
+
|
|
6
|
+
* added fractional offset support ([#685](https://github.com/kelektiv/node-cron/issues/685)) ([ce78478](https://github.com/kelektiv/node-cron/commit/ce784784575b65bd75b8b1a4adda3d8fd42fe1c0))
|
|
7
|
+
|
|
8
|
+
## [2.4.4](https://github.com/kelektiv/node-cron/compare/v2.4.3...v2.4.4) (2023-09-25)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### 🐛 Bug Fixes
|
|
12
|
+
|
|
13
|
+
* added fractional offset support ([#685](https://github.com/kelektiv/node-cron/issues/685)) ([ce78478](https://github.com/kelektiv/node-cron/commit/ce784784575b65bd75b8b1a4adda3d8fd42fe1c0))
|
|
14
|
+
|
|
15
|
+
## [3.0.0-beta.4](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2023-09-10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
* **deps:** update dependency luxon to v3.3.0 & add [@types](https://github.com/types)/luxon ([#689](https://github.com/kelektiv/node-cron/issues/689)) ([c95a449](https://github.com/kelektiv/node-cron/commit/c95a449121e440b82d391fc11f8dc148748f93ec)), closes [#688](https://github.com/kelektiv/node-cron/issues/688)
|
|
19
|
+
* fix range parsing when upper limit = 0 ([#687](https://github.com/kelektiv/node-cron/issues/687)) ([d96746f](https://github.com/kelektiv/node-cron/commit/d96746f7b8f357e565d1fad48c9f70d3d646da64))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### 🚨 Tests
|
|
23
|
+
|
|
24
|
+
* add TS types check ([#690](https://github.com/kelektiv/node-cron/issues/690)) ([f046016](https://github.com/kelektiv/node-cron/commit/f046016dc64438c4a12a4615a919b046d3a846de))
|
|
25
|
+
|
|
26
|
+
## [2.4.3](https://github.com/kelektiv/node-cron/compare/v2.4.2...v2.4.3) (2023-08-26)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### 🐛 Bug Fixes
|
|
30
|
+
|
|
31
|
+
* fix range parsing when upper limit = 0 ([#687](https://github.com/kelektiv/node-cron/issues/687)) ([d96746f](https://github.com/kelektiv/node-cron/commit/d96746f7b8f357e565d1fad48c9f70d3d646da64))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### 🚨 Tests
|
|
35
|
+
|
|
36
|
+
* add TS types check ([#690](https://github.com/kelektiv/node-cron/issues/690)) ([f046016](https://github.com/kelektiv/node-cron/commit/f046016dc64438c4a12a4615a919b046d3a846de))
|
|
37
|
+
|
|
38
|
+
## [2.4.2](https://github.com/kelektiv/node-cron/compare/v2.4.1...v2.4.2) (2023-08-26)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### 🐛 Bug Fixes
|
|
42
|
+
|
|
43
|
+
* **deps:** update dependency luxon to v3.3.0 & add [@types](https://github.com/types)/luxon ([#689](https://github.com/kelektiv/node-cron/issues/689)) ([c95a449](https://github.com/kelektiv/node-cron/commit/c95a449121e440b82d391fc11f8dc148748f93ec)), closes [#688](https://github.com/kelektiv/node-cron/issues/688)
|
|
44
|
+
|
|
1
45
|
## [3.0.0-beta.3](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2023-08-15)
|
|
2
46
|
|
|
3
47
|
|
|
@@ -26,17 +70,6 @@
|
|
|
26
70
|
|
|
27
71
|
* **renovate:** configure renovate ([#683](https://github.com/kelektiv/node-cron/issues/683)) ([9dbe962](https://github.com/kelektiv/node-cron/commit/9dbe962fad1c8b1b020441bce84ab91b1a7b4415))
|
|
28
72
|
|
|
29
|
-
## [3.0.0-beta.1](https://github.com/kelektiv/node-cron/compare/v2.3.1...v3.0.0-beta.1) (2023-07-23)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### ⚠ Breaking changes
|
|
33
|
-
|
|
34
|
-
* UNIX standard alignments (#667)
|
|
35
|
-
|
|
36
|
-
### ✨ Features
|
|
37
|
-
|
|
38
|
-
* UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([96ef954](https://github.com/kelektiv/node-cron/commit/96ef954998f9c109cc2a969296568b1b56bbbd79))
|
|
39
|
-
|
|
40
73
|
## [2.4.1](https://github.com/kelektiv/node-cron/compare/v2.4.0...v2.4.1) (2023-08-14)
|
|
41
74
|
|
|
42
75
|
|
|
@@ -84,6 +117,17 @@
|
|
|
84
117
|
* update default branch name ([#678](https://github.com/kelektiv/node-cron/issues/678)) ([7471e95](https://github.com/kelektiv/node-cron/commit/7471e95cb7433b4f29cfa68da0a652ec8cf630b6))
|
|
85
118
|
* wrap setTime tests in describe and move down ([31989e0](https://github.com/kelektiv/node-cron/commit/31989e06f939bf1e9dbc6c0b6fc62c0a7144b9eb))
|
|
86
119
|
|
|
120
|
+
## [3.0.0-beta.1](https://github.com/kelektiv/node-cron/compare/v2.3.1...v3.0.0-beta.1) (2023-07-23)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
### ⚠ Breaking changes
|
|
124
|
+
|
|
125
|
+
* UNIX standard alignments (#667)
|
|
126
|
+
|
|
127
|
+
### ✨ Features
|
|
128
|
+
|
|
129
|
+
* UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([96ef954](https://github.com/kelektiv/node-cron/commit/96ef954998f9c109cc2a969296568b1b56bbbd79))
|
|
130
|
+
|
|
87
131
|
## [v2.3.1](https://github.com/kelektiv/node-cron/compare/v2.3.0...v2.3.1) (2023-05-25)
|
|
88
132
|
|
|
89
133
|
### Added
|
package/README.md
CHANGED
|
@@ -116,10 +116,10 @@ Parameter Based
|
|
|
116
116
|
- `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.
|
|
117
117
|
- `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.
|
|
118
118
|
- `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.
|
|
119
|
-
- `timeZone` - [OPTIONAL] - Specify the time zone for the execution. This will modify the actual time relative to your time zone. If the time zone is invalid, an error is thrown. By default (if this is omitted) the local time zone will be used. You can check
|
|
119
|
+
- `timeZone` - [OPTIONAL] - Specify the time zone for the execution. This will modify the actual time relative to your time zone. If the time zone is invalid, an error is thrown. By default (if this is omitted) the local time zone will be used. You can check the various time zones format accepted in the [Luxon documentation](https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone). Note: This parameter supports minutes offsets, e.g. `UTC+5:30`. **Warning**: Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
|
|
120
120
|
- `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.
|
|
121
121
|
- `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.
|
|
122
|
-
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your time zone rather than using the `timeZone` param. This should be an integer
|
|
122
|
+
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your time zone rather than using the `timeZone` param. This should be an integer representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours). **Warning**: Minutes offsets < 60 and >-60 will be treated as an offset in hours. This means a minute offset of `30` means an offset of +30 hours. Use the `timeZone` param in this case. This behavior [is planned to be removed in V3](https://github.com/kelektiv/node-cron/pull/685#issuecomment-1676417917). **Warning**: Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
|
|
123
123
|
- `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.
|
|
124
124
|
- `start` - Runs your job.
|
|
125
125
|
- `stop` - Stops your job.
|
package/lib/time.js
CHANGED
|
@@ -153,17 +153,26 @@ function CronTime(luxon) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
if (typeof this.utcOffset !== 'undefined') {
|
|
156
|
-
|
|
156
|
+
const offsetHours = parseInt(
|
|
157
157
|
this.utcOffset >= 60 || this.utcOffset <= -60
|
|
158
158
|
? this.utcOffset / 60
|
|
159
|
-
: this.utcOffset
|
|
160
|
-
|
|
159
|
+
: this.utcOffset
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const offsetMins =
|
|
163
|
+
this.utcOffset >= 60 || this.utcOffset <= -60
|
|
164
|
+
? Math.abs(this.utcOffset - offsetHours * 60)
|
|
165
|
+
: 0;
|
|
166
|
+
const offsetMinsStr = offsetMins >= 10 ? offsetMins : '0' + offsetMins;
|
|
161
167
|
|
|
162
168
|
let utcZone = 'UTC';
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
|
|
170
|
+
if (parseInt(this.utcOffset) < 0) {
|
|
171
|
+
utcZone += `${
|
|
172
|
+
offsetHours === 0 ? '-0' : offsetHours
|
|
173
|
+
}:${offsetMinsStr}`;
|
|
174
|
+
} else {
|
|
175
|
+
utcZone += `+${offsetHours}:${offsetMinsStr}`;
|
|
167
176
|
}
|
|
168
177
|
|
|
169
178
|
date = date.setZone(utcZone);
|
|
@@ -774,7 +783,7 @@ function CronTime(luxon) {
|
|
|
774
783
|
if (allRanges[i].match(RE_RANGE)) {
|
|
775
784
|
allRanges[i].replace(RE_RANGE, ($0, lower, upper, step) => {
|
|
776
785
|
lower = parseInt(lower, 10);
|
|
777
|
-
upper = parseInt(upper, 10)
|
|
786
|
+
upper = upper !== undefined ? parseInt(upper, 10) : undefined;
|
|
778
787
|
|
|
779
788
|
const wasStepDefined = !isNaN(parseInt(step, 10));
|
|
780
789
|
if (step === '0') {
|
|
@@ -782,14 +791,14 @@ function CronTime(luxon) {
|
|
|
782
791
|
}
|
|
783
792
|
step = parseInt(step, 10) || 1;
|
|
784
793
|
|
|
785
|
-
if (upper && lower > upper) {
|
|
794
|
+
if (upper !== undefined && lower > upper) {
|
|
786
795
|
throw new Error(`Field (${type}) has an invalid range`);
|
|
787
796
|
}
|
|
788
797
|
|
|
789
798
|
const outOfRangeError =
|
|
790
799
|
lower < low ||
|
|
791
|
-
(upper && upper > high) ||
|
|
792
|
-
(
|
|
800
|
+
(upper !== undefined && upper > high) ||
|
|
801
|
+
(upper === undefined && lower > high);
|
|
793
802
|
|
|
794
803
|
if (outOfRangeError) {
|
|
795
804
|
throw new Error(`Field value (${value}) is out of range`);
|
|
@@ -799,7 +808,7 @@ function CronTime(luxon) {
|
|
|
799
808
|
lower = Math.min(Math.max(low, ~~Math.abs(lower)), high);
|
|
800
809
|
|
|
801
810
|
// Positive integer lower than constraints[1]
|
|
802
|
-
if (upper) {
|
|
811
|
+
if (upper !== undefined) {
|
|
803
812
|
upper = Math.min(high, ~~Math.abs(upper));
|
|
804
813
|
} else {
|
|
805
814
|
// If step is provided, the default upper range is the highest value
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cron",
|
|
3
3
|
"description": "Cron jobs for your node",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.5",
|
|
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"
|
|
@@ -15,12 +15,14 @@
|
|
|
15
15
|
"lint": "eslint {lib,tests}/*.js",
|
|
16
16
|
"test": "jest --coverage",
|
|
17
17
|
"test:watch": "jest --watch --coverage",
|
|
18
|
+
"test:types": "tsd",
|
|
18
19
|
"prepare": "husky install",
|
|
19
20
|
"release": "semantic-release"
|
|
20
21
|
},
|
|
21
22
|
"types": "types/index.d.ts",
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"luxon": "
|
|
24
|
+
"@types/luxon": "~3.3.0",
|
|
25
|
+
"luxon": "~3.3.0"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@commitlint/cli": "~17.6.6",
|
|
@@ -45,7 +47,8 @@
|
|
|
45
47
|
"jest": "~29.5.x",
|
|
46
48
|
"prettier": "~2.8.x",
|
|
47
49
|
"semantic-release": "~21.0.x",
|
|
48
|
-
"sinon": "^15.0.x"
|
|
50
|
+
"sinon": "^15.0.x",
|
|
51
|
+
"tsd": "^0.28.1"
|
|
49
52
|
},
|
|
50
53
|
"keywords": [
|
|
51
54
|
"cron",
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as luxon from 'luxon';
|
|
2
|
+
import { expectType } from 'tsd';
|
|
3
|
+
import * as cron from '..';
|
|
4
|
+
|
|
5
|
+
const CronJob = cron.CronJob;
|
|
6
|
+
const CronTime = cron.CronTime;
|
|
7
|
+
|
|
8
|
+
const DateTime = luxon.DateTime;
|
|
9
|
+
|
|
10
|
+
const timeZone = 'America/Los_Angeles';
|
|
11
|
+
|
|
12
|
+
// basic cron usage
|
|
13
|
+
const job = new CronJob(
|
|
14
|
+
'* * * * * *',
|
|
15
|
+
() => {},
|
|
16
|
+
null,
|
|
17
|
+
true
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// using factory function with parameters object
|
|
21
|
+
expectType<cron.CronJob>(cron.job({
|
|
22
|
+
cronTime: '00 30 11 * * 1-5',
|
|
23
|
+
onTick: () => {},
|
|
24
|
+
start: false,
|
|
25
|
+
timeZone: 'America/Los_Angeles'
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
// with timezone
|
|
29
|
+
new CronJob(
|
|
30
|
+
'* * * * * *',
|
|
31
|
+
() => {},
|
|
32
|
+
null,
|
|
33
|
+
true,
|
|
34
|
+
timeZone
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// with onComplete
|
|
38
|
+
new CronJob(
|
|
39
|
+
'00 30 11 * * 1-5',
|
|
40
|
+
() => {},
|
|
41
|
+
() => {},
|
|
42
|
+
true,
|
|
43
|
+
timeZone
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// with Date
|
|
47
|
+
new CronJob(
|
|
48
|
+
new Date(),
|
|
49
|
+
() => {},
|
|
50
|
+
null,
|
|
51
|
+
true,
|
|
52
|
+
timeZone
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// with Luxon DateTime
|
|
56
|
+
new CronJob(
|
|
57
|
+
DateTime.local(),
|
|
58
|
+
() => {},
|
|
59
|
+
null,
|
|
60
|
+
true,
|
|
61
|
+
timeZone
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// with system commands
|
|
65
|
+
new CronJob(
|
|
66
|
+
'00 30 11 * * 1-5',
|
|
67
|
+
'ls',
|
|
68
|
+
{ command: 'ls', args: ['./'] },
|
|
69
|
+
true,
|
|
70
|
+
timeZone
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// check function return types
|
|
74
|
+
expectType<Date>(job.lastDate());
|
|
75
|
+
expectType<luxon.DateTime>(job.nextDates());
|
|
76
|
+
expectType<luxon.DateTime | luxon.DateTime[]>(job.nextDates(1));
|
|
77
|
+
expectType<boolean | undefined>(job.running);
|
|
78
|
+
job.setTime(new CronTime('00 30 11 * * 1-2'));
|
|
79
|
+
job.start();
|
|
80
|
+
job.stop();
|
|
81
|
+
|
|
82
|
+
// check cronTime format
|
|
83
|
+
new CronTime('* * * * * *');
|
|
84
|
+
new CronTime(new Date());
|
|
85
|
+
new CronTime(DateTime.local());
|