cron 3.0.0-beta.8 β†’ 3.0.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/CHANGELOG.md CHANGED
@@ -1,104 +1,84 @@
1
- ## [3.0.0-beta.8](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2023-09-26)
2
-
3
-
4
- ### ✨ Features
5
-
6
- * expose useful types ([6a1816d](https://github.com/kelektiv/node-cron/commit/6a1816dcefdfa456f1dc8ac744a32e8d879194a6))
7
-
8
- ## [3.0.0-beta.7](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2023-09-26)
9
-
10
-
11
- ### πŸ“š Documentation
12
-
13
- * **readme:** remove outdated informations ([#695](https://github.com/kelektiv/node-cron/issues/695)) ([51d2bab](https://github.com/kelektiv/node-cron/commit/51d2bab4f1e6a0419f6592efbfdf72f17fa2fb07))
14
-
15
- ## [3.0.0-beta.6](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2023-09-26)
1
+ ## [3.0.0](https://github.com/kelektiv/node-cron/compare/v2.4.4...v3.0.0) (2023-09-30)
16
2
 
17
3
 
18
4
  ### ⚠ Breaking changes
19
5
 
6
+ * `utcOffset` parameter no longer accepts a string
7
+ * `utcOffset` values between -60 and 60 are no longer
8
+ treated as hours
9
+ * providing both `timeZone` and `utcOffset` parameters
10
+ now throws an error
20
11
  * removed `cron.job()` method in favor of `new CronJob(...args)` /
21
12
  `CronJob.from(argsObject)`
22
13
  * removed `cron.time()` method in favor of `new CronTime()`
23
14
  * `CronJob`: constructor no longer accepts an object as its first and
24
15
  only params. Use `CronJob.from(argsObject)` instead.
25
16
  * `CronJob`: callbacks are now called in the order they were registered
17
+ * return empty array from nextDates when called without argument (#519)
18
+ * UNIX standard alignments (#667)
26
19
 
27
- ### πŸ“¦ Code Refactoring
28
-
29
- * migrate to TypeScript ([#694](https://github.com/kelektiv/node-cron/issues/694)) ([97a65e1](https://github.com/kelektiv/node-cron/commit/97a65e109d473cb037e2fb4690c18ac897d5316a))
30
-
31
- ## [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)
32
-
33
-
34
- ### πŸ› Bug Fixes
35
-
36
- * added fractional offset support ([#685](https://github.com/kelektiv/node-cron/issues/685)) ([ce78478](https://github.com/kelektiv/node-cron/commit/ce784784575b65bd75b8b1a4adda3d8fd42fe1c0))
20
+ ### ✨ Features
37
21
 
38
- ## [2.4.4](https://github.com/kelektiv/node-cron/compare/v2.4.3...v2.4.4) (2023-09-25)
22
+ * expose useful types ([737b344](https://github.com/kelektiv/node-cron/commit/737b34482c47033f9affab4426a3201681f42e97))
23
+ * rework utcOffset parameter ([#699](https://github.com/kelektiv/node-cron/issues/699)) ([671e933](https://github.com/kelektiv/node-cron/commit/671e933d9107b1e4e1166ab681f9e14a8a3a7c16))
24
+ * UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([ff615f1](https://github.com/kelektiv/node-cron/commit/ff615f1592287262b7ebc95312cdac0f9c59d272))
39
25
 
40
26
 
41
27
  ### πŸ› Bug Fixes
42
28
 
43
- * added fractional offset support ([#685](https://github.com/kelektiv/node-cron/issues/685)) ([ce78478](https://github.com/kelektiv/node-cron/commit/ce784784575b65bd75b8b1a4adda3d8fd42fe1c0))
44
-
45
- ## [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)
29
+ * return empty array from nextDates when called without argument ([#519](https://github.com/kelektiv/node-cron/issues/519)) ([c2891ba](https://github.com/kelektiv/node-cron/commit/c2891bacbc0d88616b69449fc6237f716dfe4faf))
46
30
 
47
31
 
48
- * **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)
49
- * 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))
50
-
51
-
52
- ### 🚨 Tests
53
-
54
- * add TS types check ([#690](https://github.com/kelektiv/node-cron/issues/690)) ([f046016](https://github.com/kelektiv/node-cron/commit/f046016dc64438c4a12a4615a919b046d3a846de))
32
+ ### πŸ“¦ Code Refactoring
55
33
 
56
- ## [2.4.3](https://github.com/kelektiv/node-cron/compare/v2.4.2...v2.4.3) (2023-08-26)
34
+ * migrate to TypeScript ([#694](https://github.com/kelektiv/node-cron/issues/694)) ([2d77894](https://github.com/kelektiv/node-cron/commit/2d778942c523f8480051216b4ced46c1d2651153))
57
35
 
58
36
 
59
- ### πŸ› Bug Fixes
37
+ ### πŸ“š Documentation
60
38
 
61
- * 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))
39
+ * **readme:** remove outdated informations ([#695](https://github.com/kelektiv/node-cron/issues/695)) ([b5ceaf1](https://github.com/kelektiv/node-cron/commit/b5ceaf16913f78ca8d4037594a86df61f116d08e))
62
40
 
63
41
 
64
42
  ### 🚨 Tests
65
43
 
66
- * add TS types check ([#690](https://github.com/kelektiv/node-cron/issues/690)) ([f046016](https://github.com/kelektiv/node-cron/commit/f046016dc64438c4a12a4615a919b046d3a846de))
44
+ * update new test for cron standard alignments ([4a406c1](https://github.com/kelektiv/node-cron/commit/4a406c1f7e7b77ec9c7433c61a4929a341bfe300))
67
45
 
68
- ## [2.4.2](https://github.com/kelektiv/node-cron/compare/v2.4.1...v2.4.2) (2023-08-26)
69
46
 
47
+ ### ♻️ Chores
70
48
 
71
- ### πŸ› Bug Fixes
49
+ * improve GitHub community standards ([#698](https://github.com/kelektiv/node-cron/issues/698)) ([6bdef77](https://github.com/kelektiv/node-cron/commit/6bdef779b813ee84c03b7c708176410aa24a8cfe))
50
+ * update contributors list ([dab3d69](https://github.com/kelektiv/node-cron/commit/dab3d6929ca47e22388a96eb92d43258b39b093a))
72
51
 
73
- * **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)
74
52
 
75
- ## [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)
53
+ ### πŸ’Ž Styles
76
54
 
55
+ * fix linting issues ([47e665f](https://github.com/kelektiv/node-cron/commit/47e665fb176addd0eb258d5aaff85c77e7f4b17f))
77
56
 
78
- ### ⚠ Breaking changes
57
+ ## [2.4.4](https://github.com/kelektiv/node-cron/compare/v2.4.3...v2.4.4) (2023-09-25)
79
58
 
80
- * return empty array from nextDates when called without argument (#519)
81
59
 
82
60
  ### πŸ› Bug Fixes
83
61
 
84
- * return empty array from nextDates when called without argument ([#519](https://github.com/kelektiv/node-cron/issues/519)) ([e65c3dc](https://github.com/kelektiv/node-cron/commit/e65c3dc6c334b8d4df0da317b75494d78cd5d52b))
62
+ * added fractional offset support ([#685](https://github.com/kelektiv/node-cron/issues/685)) ([ce78478](https://github.com/kelektiv/node-cron/commit/ce784784575b65bd75b8b1a4adda3d8fd42fe1c0))
85
63
 
86
- ## [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)
64
+ ## [2.4.3](https://github.com/kelektiv/node-cron/compare/v2.4.2...v2.4.3) (2023-08-26)
87
65
 
88
66
 
89
67
  ### πŸ› Bug Fixes
90
68
 
91
- * 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))
69
+ * 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))
92
70
 
93
71
 
94
72
  ### 🚨 Tests
95
73
 
96
- * update new test for cron standard alignments ([ea56fc1](https://github.com/kelektiv/node-cron/commit/ea56fc1c32905d711b160823fc09f39169dd3efd))
74
+ * add TS types check ([#690](https://github.com/kelektiv/node-cron/issues/690)) ([f046016](https://github.com/kelektiv/node-cron/commit/f046016dc64438c4a12a4615a919b046d3a846de))
97
75
 
76
+ ## [2.4.2](https://github.com/kelektiv/node-cron/compare/v2.4.1...v2.4.2) (2023-08-26)
98
77
 
99
- ### βš™οΈ Continuous Integrations
100
78
 
101
- * **renovate:** configure renovate ([#683](https://github.com/kelektiv/node-cron/issues/683)) ([9dbe962](https://github.com/kelektiv/node-cron/commit/9dbe962fad1c8b1b020441bce84ab91b1a7b4415))
79
+ ### πŸ› Bug Fixes
80
+
81
+ * **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)
102
82
 
103
83
  ## [2.4.1](https://github.com/kelektiv/node-cron/compare/v2.4.0...v2.4.1) (2023-08-14)
104
84
 
@@ -147,17 +127,6 @@ only params. Use `CronJob.from(argsObject)` instead.
147
127
  * update default branch name ([#678](https://github.com/kelektiv/node-cron/issues/678)) ([7471e95](https://github.com/kelektiv/node-cron/commit/7471e95cb7433b4f29cfa68da0a652ec8cf630b6))
148
128
  * wrap setTime tests in describe and move down ([31989e0](https://github.com/kelektiv/node-cron/commit/31989e06f939bf1e9dbc6c0b6fc62c0a7144b9eb))
149
129
 
150
- ## [3.0.0-beta.1](https://github.com/kelektiv/node-cron/compare/v2.3.1...v3.0.0-beta.1) (2023-07-23)
151
-
152
-
153
- ### ⚠ Breaking changes
154
-
155
- * UNIX standard alignments (#667)
156
-
157
- ### ✨ Features
158
-
159
- * UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([96ef954](https://github.com/kelektiv/node-cron/commit/96ef954998f9c109cc2a969296568b1b56bbbd79))
160
-
161
130
  ## [v2.3.1](https://github.com/kelektiv/node-cron/compare/v2.3.0...v2.3.1) (2023-05-25)
162
131
 
163
132
  ### Added
package/README.md CHANGED
@@ -120,10 +120,10 @@ Parameter Based
120
120
  - `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.
121
121
  - `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.
122
122
  - `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.
123
- - `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.
123
+ - `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`. **Note**: Cannot be used together with `utcOffset`.
124
124
  - `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.
125
125
  - `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.
126
- - `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.
126
+ - `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). **Note**: Cannot be used together with `timeZone`.
127
127
  - `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.
128
128
  - `from` (static) - Create a new CronJob object providing arguments as an object. See argument names and descriptions above.
129
129
  - `start` - Runs your job.
@@ -146,17 +146,13 @@ Join the [Discord server](https://discord.gg/yyKns29zch)! Here you can discuss i
146
146
 
147
147
  ## Contributing
148
148
 
149
- ### Looking for maintainers/contributors
150
-
151
- 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). We'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.
149
+ This project is looking for help! If you're interested in helping with the project, please take a look at our [contributing documentation](https://github.com/kelektiv/node-cron/blob/main/CONTRIBUTING.md).
152
150
 
153
151
  ### Submitting Bugs/Issues
154
152
 
155
- 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.
156
-
157
- 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.
153
+ Please have a look at our [contributing documentation](https://github.com/kelektiv/node-cron/blob/main/CONTRIBUTING.md), it contains all the information you need to know before submitting an issue.
158
154
 
159
- ### Acknowledgements
155
+ ## Acknowledgements
160
156
 
161
157
  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 we'll just say thanks.
162
158
 
@@ -0,0 +1,3 @@
1
+ export declare class ExclusiveParametersError extends Error {
2
+ constructor(param1: string, param2: string);
3
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExclusiveParametersError = void 0;
4
+ class ExclusiveParametersError extends Error {
5
+ constructor(param1, param2) {
6
+ super(`You can't specify both ${param1} and ${param2}`);
7
+ }
8
+ }
9
+ exports.ExclusiveParametersError = ExclusiveParametersError;
10
+ //# sourceMappingURL=errors.js.map
package/dist/job.d.ts CHANGED
@@ -10,7 +10,8 @@ export declare class CronJob {
10
10
  onComplete?: (...args: any) => void;
11
11
  private _timeout?;
12
12
  private _callbacks;
13
- constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: CronJobParams['timeZone'], context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: CronJobParams['utcOffset'], unrefTimeout?: CronJobParams['unrefTimeout']);
13
+ constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: CronJobParams['timeZone'], context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: null, unrefTimeout?: CronJobParams['unrefTimeout']);
14
+ constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: null, context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: CronJobParams['utcOffset'], unrefTimeout?: CronJobParams['unrefTimeout']);
14
15
  static from(params: CronJobParams): CronJob;
15
16
  private _fnWrap;
16
17
  addCallback(callback: (...args: any) => void): void;
package/dist/job.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CronJob = void 0;
4
4
  const child_process_1 = require("child_process");
5
+ const errors_1 = require("./errors");
5
6
  const time_1 = require("./time");
6
7
  class CronJob {
7
8
  constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout) {
@@ -11,7 +12,18 @@ class CronJob {
11
12
  this.runOnce = false;
12
13
  this._callbacks = [];
13
14
  this.context = context || this;
14
- this.cronTime = new time_1.CronTime(cronTime, timeZone, utcOffset);
15
+ if (timeZone != null && utcOffset != null) {
16
+ throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
17
+ }
18
+ if (timeZone != null) {
19
+ this.cronTime = new time_1.CronTime(cronTime, timeZone, null);
20
+ }
21
+ else if (utcOffset != null) {
22
+ this.cronTime = new time_1.CronTime(cronTime, null, utcOffset);
23
+ }
24
+ else {
25
+ this.cronTime = new time_1.CronTime(cronTime, timeZone, utcOffset);
26
+ }
15
27
  if (unrefTimeout != null) {
16
28
  this.unrefTimeout = unrefTimeout;
17
29
  }
@@ -30,7 +42,18 @@ class CronJob {
30
42
  this.start();
31
43
  }
32
44
  static from(params) {
33
- return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
45
+ if (params.timeZone != null && params.utcOffset != null) {
46
+ throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
47
+ }
48
+ if (params.timeZone != null) {
49
+ return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
50
+ }
51
+ else if (params.utcOffset != null) {
52
+ return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
53
+ }
54
+ else {
55
+ return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
56
+ }
34
57
  }
35
58
  _fnWrap(cmd) {
36
59
  var _a, _b;
package/dist/time.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { DateTime, Zone } from 'luxon';
2
+ import { CronJobParams } from './types/cron.types';
2
3
  export declare class CronTime {
3
4
  source: string | DateTime;
4
- zone?: string;
5
- utcOffset?: number | string;
5
+ timeZone?: string;
6
+ utcOffset?: number;
6
7
  realDate: boolean;
7
8
  private second;
8
9
  private minute;
@@ -10,7 +11,8 @@ export declare class CronTime {
10
11
  private dayOfMonth;
11
12
  private month;
12
13
  private dayOfWeek;
13
- constructor(source: string | Date | DateTime, zone?: string | null, utcOffset?: string | number | null);
14
+ constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
15
+ constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
14
16
  private _getWeekDay;
15
17
  private _verifyParse;
16
18
  sendAt(): DateTime;
@@ -18,7 +20,7 @@ export declare class CronTime {
18
20
  getTimeout(): number;
19
21
  toString(): string;
20
22
  toJSON(): string[];
21
- getNextDateFrom(start: Date | DateTime, zone?: string | Zone): DateTime;
23
+ getNextDateFrom(start: Date | DateTime, timeZone?: string | Zone): DateTime;
22
24
  private _findPreviousDSTJump;
23
25
  private _checkTimeInSkippedRange;
24
26
  private _checkTimeInSkippedRangeSingleHour;
package/dist/time.js CHANGED
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CronTime = void 0;
4
4
  const luxon_1 = require("luxon");
5
5
  const constants_1 = require("./constants");
6
+ const errors_1 = require("./errors");
6
7
  const utils_1 = require("./utils");
7
8
  class CronTime {
8
- constructor(source, zone, utcOffset) {
9
+ constructor(source, timeZone, utcOffset) {
9
10
  this.realDate = false;
10
11
  this.second = {};
11
12
  this.minute = {};
@@ -13,12 +14,15 @@ class CronTime {
13
14
  this.dayOfMonth = {};
14
15
  this.month = {};
15
16
  this.dayOfWeek = {};
16
- if (zone) {
17
- const dt = luxon_1.DateTime.fromObject({}, { zone });
17
+ if (timeZone != null && utcOffset != null) {
18
+ throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
19
+ }
20
+ if (timeZone) {
21
+ const dt = luxon_1.DateTime.fromObject({}, { zone: timeZone });
18
22
  if (!dt.isValid) {
19
23
  throw new Error('Invalid timezone.');
20
24
  }
21
- this.zone = zone;
25
+ this.timeZone = timeZone;
22
26
  }
23
27
  if (utcOffset != null) {
24
28
  this.utcOffset = utcOffset;
@@ -69,26 +73,16 @@ class CronTime {
69
73
  let date = this.realDate && this.source instanceof luxon_1.DateTime
70
74
  ? this.source
71
75
  : luxon_1.DateTime.local();
72
- if (this.zone) {
73
- date = date.setZone(this.zone);
74
- }
75
- if (this.utcOffset != null) {
76
- const offsetHours = parseInt(this.utcOffset >= 60 || this.utcOffset <= -60
77
- ?
78
- this.utcOffset / 60
79
- : this.utcOffset);
80
- const offsetMins = this.utcOffset >= 60 || this.utcOffset <= -60
81
- ?
82
- Math.abs(this.utcOffset - offsetHours * 60)
83
- : 0;
84
- const offsetMinsStr = offsetMins >= 10 ? offsetMins : `0${offsetMins}`;
85
- let utcZone = 'UTC';
86
- if (parseInt(this.utcOffset) < 0) {
87
- utcZone += `${offsetHours === 0 ? '-0' : offsetHours}:${offsetMinsStr}`;
88
- }
89
- else {
90
- utcZone += `+${offsetHours}:${offsetMinsStr}`;
91
- }
76
+ if (this.timeZone) {
77
+ date = date.setZone(this.timeZone);
78
+ }
79
+ if (this.utcOffset !== undefined) {
80
+ const sign = this.utcOffset < 0 ? '-' : '+';
81
+ const offsetHours = Math.trunc(this.utcOffset / 60);
82
+ const offsetHoursStr = String(Math.abs(offsetHours)).padStart(2, '0');
83
+ const offsetMins = Math.abs(this.utcOffset - offsetHours * 60);
84
+ const offsetMinsStr = String(offsetMins).padStart(2, '0');
85
+ const utcZone = `UTC${sign}${offsetHoursStr}:${offsetMinsStr}`;
92
86
  date = date.setZone(utcZone);
93
87
  if (!date.isValid) {
94
88
  throw new Error('ERROR: You specified an invalid UTC offset.');
@@ -123,15 +117,15 @@ class CronTime {
123
117
  return this._wcOrAll(unit);
124
118
  });
125
119
  }
126
- getNextDateFrom(start, zone) {
120
+ getNextDateFrom(start, timeZone) {
127
121
  var _a;
128
122
  if (start instanceof Date) {
129
123
  start = luxon_1.DateTime.fromJSDate(start);
130
124
  }
131
125
  let date = start;
132
126
  const firstDate = start.toMillis();
133
- if (zone) {
134
- date = date.setZone(zone);
127
+ if (timeZone) {
128
+ date = date.setZone(timeZone);
135
129
  }
136
130
  if (!this.realDate) {
137
131
  if (date.millisecond > 0) {
@@ -147,7 +141,7 @@ class CronTime {
147
141
  if (date > maxMatch) {
148
142
  throw new Error(`Something went wrong. No execution date was found in the next 8 years.
149
143
  Please provide the following string if you would like to help debug:
150
- Time Zone: ${(_a = zone === null || zone === void 0 ? void 0 : zone.toString()) !== null && _a !== void 0 ? _a : '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
144
+ Time Zone: ${(_a = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toString()) !== null && _a !== void 0 ? _a : '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
151
145
  }
152
146
  if (!(date.month in this.month) &&
153
147
  Object.keys(this.month).length !== 12) {
@@ -4,17 +4,22 @@ import { DateTime } from 'luxon';
4
4
  import { CONSTRAINTS, TIME_UNITS_MAP } from '../constants';
5
5
  import { CronJob } from '../job';
6
6
  import { IntRange } from './utils';
7
- export interface CronJobParams {
7
+ interface BaseCronJobParams {
8
8
  cronTime: string | Date | DateTime;
9
9
  onTick: CronCommand;
10
10
  onComplete?: CronCommand | null;
11
11
  start?: boolean | null;
12
- timeZone?: string | null;
13
12
  context?: unknown | null;
14
13
  runOnInit?: boolean | null;
15
- utcOffset?: string | number | null;
16
14
  unrefTimeout?: boolean | null;
17
15
  }
16
+ export type CronJobParams = BaseCronJobParams & ({
17
+ timeZone?: string | null;
18
+ utcOffset?: never;
19
+ } | {
20
+ timeZone?: never;
21
+ utcOffset?: number | null;
22
+ });
18
23
  export type CronCommand = ((this: CronJob | any) => void) | string | {
19
24
  command: string;
20
25
  args?: readonly string[] | null;
@@ -36,3 +41,4 @@ export type HourRange = IntRange<(typeof CONSTRAINTS)['hour'][0], (typeof CONSTR
36
41
  export type DayOfMonthRange = IntRange<(typeof CONSTRAINTS)['dayOfMonth'][0], (typeof CONSTRAINTS)['dayOfMonth'][1]>;
37
42
  export type MonthRange = IntRange<(typeof CONSTRAINTS)['month'][0], (typeof CONSTRAINTS)['month'][1]>;
38
43
  export type DayOfWeekRange = IntRange<(typeof CONSTRAINTS)['dayOfWeek'][0], (typeof CONSTRAINTS)['dayOfWeek'][1]>;
44
+ export {};
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.8",
4
+ "version": "3.0.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"
@@ -65,6 +65,7 @@
65
65
  "license": "MIT",
66
66
  "contributors": [
67
67
  "Brandon der BlΓ€tter <https://interlucid.com/contact/> (https://github.com/intcreator)",
68
+ "Pierre Cavin <me@sherlox.io> (https://github.com/sheerlox)",
68
69
  "Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)",
69
70
  "James Padolsey <> (https://github.com/jamespadolsey)",
70
71
  "Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)",