cron 3.5.1-beta.1 → 4.1.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,8 +1,33 @@
1
- ## [3.5.1-beta.1](https://github.com/kelektiv/node-cron/compare/v3.5.0...v3.5.1-beta.1) (2025-02-18)
1
+ ## [4.1.0](https://github.com/kelektiv/node-cron/compare/v4.0.0...v4.1.0) (2025-02-24)
2
2
 
3
- ### 🐛 Bug Fixes
3
+ ### ✨ Features
4
4
 
5
- * attempt to fix [#805](https://github.com/kelektiv/node-cron/issues/805) ([187dbe5](https://github.com/kelektiv/node-cron/commit/187dbe57ada28217b810b231bf57afdfe3a3b394))
5
+ * add isCronTimeValid function to validate cron expressions ([#959](https://github.com/kelektiv/node-cron/issues/959)) ([cbd8106](https://github.com/kelektiv/node-cron/commit/cbd81063229036859fbb6969d4f628a0e7945e57))
6
+
7
+ ### ♻️ Chores
8
+
9
+ * **action:** update actions/setup-node action to v4.2.0 ([#950](https://github.com/kelektiv/node-cron/issues/950)) ([3a4a701](https://github.com/kelektiv/node-cron/commit/3a4a7015b59c56434b462754728e4ed6483202ef))
10
+ * **action:** update github/codeql-action action to v3.28.9 ([#946](https://github.com/kelektiv/node-cron/issues/946)) ([84ebb32](https://github.com/kelektiv/node-cron/commit/84ebb32e0db478e48e82203099ec0e301021cfc3))
11
+ * **action:** update marocchino/sticky-pull-request-comment action to v2.9.1 ([#947](https://github.com/kelektiv/node-cron/issues/947)) ([7cdcbc2](https://github.com/kelektiv/node-cron/commit/7cdcbc21676fa48f78d58146590e9f59796b56b9))
12
+ * **action:** update step-security/harden-runner action to v2.11.0 ([#948](https://github.com/kelektiv/node-cron/issues/948)) ([b7f9c79](https://github.com/kelektiv/node-cron/commit/b7f9c794f95a95d19a4bfa11d2778dc6a0a21666))
13
+ * **deps:** lock file maintenance ([fa08aa3](https://github.com/kelektiv/node-cron/commit/fa08aa3e0edacdc324381cff33160d49b6db6af0))
14
+ * **deps:** lock file maintenance ([#944](https://github.com/kelektiv/node-cron/issues/944)) ([374ac42](https://github.com/kelektiv/node-cron/commit/374ac429d4ff6f19440d4c18d6e366a69cfea233))
15
+ * **deps:** update dependency [@types](https://github.com/types)/node to v22.13.4 ([#952](https://github.com/kelektiv/node-cron/issues/952)) ([05f1702](https://github.com/kelektiv/node-cron/commit/05f17020fe33ded1839c43132caa0b3dc2770f6e))
16
+ * **deps:** update dependency lint-staged to v15.4.3 ([#953](https://github.com/kelektiv/node-cron/issues/953)) ([b99fc3b](https://github.com/kelektiv/node-cron/commit/b99fc3b82c613b3686930f2055a2b8e10134238b))
17
+ * **deps:** update dependency typescript to v5.7.3 ([#949](https://github.com/kelektiv/node-cron/issues/949)) ([5313b71](https://github.com/kelektiv/node-cron/commit/5313b71e20bcd7a417fce03966cfa5c78062b05a))
18
+ * **deps:** update linters ([#954](https://github.com/kelektiv/node-cron/issues/954)) ([9159759](https://github.com/kelektiv/node-cron/commit/91597592d05770b7e31bbd93eb0b4160da175154))
19
+ * **deps:** update semantic-release related packages ([#951](https://github.com/kelektiv/node-cron/issues/951)) ([92d7ac3](https://github.com/kelektiv/node-cron/commit/92d7ac3f8fa6fcbf37ead72abc3f798fdc05370a))
20
+ * remove bower.json, which is unused ([#955](https://github.com/kelektiv/node-cron/issues/955)) ([8e509f3](https://github.com/kelektiv/node-cron/commit/8e509f3ad7dcd5d250e75a41417830b9b01c2bdb))
21
+
22
+ ## [4.0.0](https://github.com/kelektiv/node-cron/compare/v3.5.0...v4.0.0) (2025-02-19)
23
+
24
+ ### ⚠ Breaking changes
25
+
26
+ * drop support for Node v16 and rename job.running to job.isActive (#957)
27
+
28
+ ### 📦 Code Refactoring
29
+
30
+ * drop support for Node v16 and rename job.running to job.isActive ([#957](https://github.com/kelektiv/node-cron/issues/957)) ([605e94e](https://github.com/kelektiv/node-cron/commit/605e94ef3b6469caf2e8526d0935014eea8804c8)), closes [#902](https://github.com/kelektiv/node-cron/issues/902) [#905](https://github.com/kelektiv/node-cron/issues/905)
6
31
 
7
32
  ### ♻️ Chores
8
33
 
@@ -14,7 +39,6 @@
14
39
  * **deps:** lock file maintenance ([c3af5fc](https://github.com/kelektiv/node-cron/commit/c3af5fc439b822683377abea4a7e957ee7743c5c))
15
40
  * **deps:** lock file maintenance ([d689a1c](https://github.com/kelektiv/node-cron/commit/d689a1c489f9576de49da8ee8489cbaf700be3c3))
16
41
  * **renovate:** improve schedules & automerging to reduce noise ([#942](https://github.com/kelektiv/node-cron/issues/942)) ([c253032](https://github.com/kelektiv/node-cron/commit/c253032d520edd09f29e111fa181f4977a7f9d53))
17
- * **runtime:** dirty Node 16 drop, don't cherry-pick ([d6815f3](https://github.com/kelektiv/node-cron/commit/d6815f3ff94799f8157b8ee8daae1897d3fa0cf2))
18
42
 
19
43
  ## [3.5.0](https://github.com/kelektiv/node-cron/compare/v3.4.0...v3.5.0) (2025-01-10)
20
44
 
@@ -55,12 +79,6 @@
55
79
 
56
80
  * fix infinite loop on expressions resolving only inside a DST forward jump ([#938](https://github.com/kelektiv/node-cron/issues/938)) ([efb8df5](https://github.com/kelektiv/node-cron/commit/efb8df53405b4ce2ea2e70be9e4d90c124616a51)), closes [/github.com/kelektiv/node-cron/pull/667/files#diff-c14c2dca8456f15417b39cfbd9758009f8eb4f3a190a415768d6e4ae6ae9dceeL473-L477](https://github.com/kelektiv//github.com/kelektiv/node-cron/pull/667/files/issues/diff-c14c2dca8456f15417b39cfbd9758009f8eb4f3a190a415768d6e4ae6ae9dceeL473-L477) [#919](https://github.com/kelektiv/node-cron/issues/919) [#919](https://github.com/kelektiv/node-cron/issues/919)
57
81
 
58
- ## [3.3.2-beta.1](https://github.com/kelektiv/node-cron/compare/v3.3.1...v3.3.2-beta.1) (2024-12-27)
59
-
60
- ### 🐛 Bug Fixes
61
-
62
- * attempt to fix [#805](https://github.com/kelektiv/node-cron/issues/805) ([187dbe5](https://github.com/kelektiv/node-cron/commit/187dbe57ada28217b810b231bf57afdfe3a3b394))
63
-
64
82
  ### ⚙️ Continuous Integrations
65
83
 
66
84
  * **action:** update marocchino/sticky-pull-request-comment action to v2.9.0 ([#930](https://github.com/kelektiv/node-cron/issues/930)) ([1e7bce9](https://github.com/kelektiv/node-cron/commit/1e7bce9d12a774104f39c1d75b37bdb134e4b270))
@@ -68,10 +86,7 @@
68
86
 
69
87
  ### ♻️ Chores
70
88
 
71
- <<<<<<< HEAD
72
- =======
73
89
  * **deps:** lock file maintenance ([70c3339](https://github.com/kelektiv/node-cron/commit/70c333955612d39b692ab9535b36fe33423eb593))
74
- >>>>>>> main
75
90
  * **deps:** lock file maintenance ([afad454](https://github.com/kelektiv/node-cron/commit/afad454e5e4f52e3da54965a0e10540e035c4f58))
76
91
  * **deps:** lock file maintenance ([b1dbf69](https://github.com/kelektiv/node-cron/commit/b1dbf69104a58022a638d5b68b59f85089fae7c6))
77
92
  * **deps:** pin dependencies ([#915](https://github.com/kelektiv/node-cron/issues/915)) ([dfcbd3c](https://github.com/kelektiv/node-cron/commit/dfcbd3cf7d901415bda5b4929566bd4ad527af62))
package/README.md CHANGED
@@ -6,11 +6,6 @@
6
6
  Perfect for tasks like data backups, notifications, and many more!
7
7
  </p>
8
8
 
9
- > **⚠️ WARNING**
10
- >
11
- > This is a WIP released as beta for testing purposes.
12
- > For more information, please refer to [issue #805](https://github.com/kelektiv/node-cron/issues/805).
13
-
14
9
  # Cron for Node.js
15
10
 
16
11
  [![Version](https://img.shields.io/npm/v/cron?label=version&logo=npm)](https://www.npmjs.com/package/cron)
@@ -39,27 +34,42 @@ npm install cron
39
34
 
40
35
  1. [Features](#-features)
41
36
  2. [Installation](#-installation)
42
- 3. [Migrating from v2 to v3](#-migrating-from-v2-to-v3)
37
+ 3. [Migrating](#-migrating)
43
38
  4. [Basic Usage](#-basic-usage)
44
- 5. [Cron Patterns](#cron-patterns)
45
- - [Cron Syntax Overview](#cron-patterns)
39
+ 5. [Cron Patterns](#-cron-patterns)
40
+ - [Cron Syntax Overview](#-cron-patterns)
46
41
  - [Supported Ranges](#supported-ranges)
47
- 6. [Gotchas](#gotchas)
48
- 7. [API](#api)
42
+ 6. [API](#-api)
49
43
  - [Standalone Functions](#standalone-functions)
50
44
  - [CronJob Class](#cronjob-class)
51
45
  - [CronTime Class](#crontime-class)
46
+ 7. [Gotchas](#-gotchas)
52
47
  8. [Community](#-community)
53
48
  - [Join the Community](#-community)
54
49
  9. [Contributing](#-contributing)
55
50
  - [General Contribution](#-contributing)
56
51
  - [Submitting Bugs/Issues](#-submitting-bugsissues)
57
52
  10. [Acknowledgements](#-acknowledgements)
58
- 11. [License](#license)
53
+ 11. [License](#-license)
54
+
55
+ ## ⬆ Migrating
56
+
57
+ v4 dropped Node v16 and renamed the `job.running` property:
58
+
59
+ <details>
60
+ <summary>Migrating from v3 to v4</summary>
61
+
62
+ ### Dropped Node version
63
+
64
+ Node v16 is no longer supported. Upgrade your Node installation to Node v18 or above
59
65
 
60
- ## 🔄 Migrating from v2 to v3
66
+ ### Property renamed and now read-only
61
67
 
62
- With the introduction of TypeScript in version 3 and alignment with UNIX cron patterns, a few changes have been made:
68
+ You can no longer set the `running` property (now `isActive`). It is read-only. To start or stop a cron job, use `job.start()` and `job.stop()`.
69
+
70
+ </details>
71
+
72
+ v3 introduced TypeScript and tighter Unix cron pattern alignment:
63
73
 
64
74
  <details>
65
75
  <summary>Migrating from v2 to v3</summary>
@@ -117,7 +127,7 @@ const job = CronJob.from({
117
127
 
118
128
  For more advanced examples, check the [examples directory](https://github.com/kelektiv/node-cron/tree/main/examples).
119
129
 
120
- ## Cron Patterns
130
+ ## ⏰ Cron Patterns
121
131
 
122
132
  Cron patterns are the backbone of this library. Familiarize yourself with the syntax:
123
133
 
@@ -147,13 +157,7 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
147
157
  > 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.
148
158
  > Examples: "mon,wed,fri", "jan-mar".
149
159
 
150
- ## Gotchas
151
-
152
- - Both JS `Date` and Luxon `DateTime` objects don't guarantee millisecond precision due to computation delays. This module excludes millisecond precision for standard cron syntax but allows execution date specification through JS `Date` or Luxon `DateTime` objects. However, specifying a precise future execution time, such as adding a millisecond to the current time, may not always work due to these computation delays. It's observed that delays less than 4-5 ms might lead to inconsistencies. While we could limit all date granularity to seconds, we've chosen to allow greater precision but advise users of potential issues.
153
-
154
- - Using arrow functions for `onTick` binds them to the parent's `this` context. As a result, they won't have access to the cronjob's `this` context. You can read a little more in issue [#47 (comment)](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775).
155
-
156
- ## API
160
+ ## 📖 API
157
161
 
158
162
  ### Standalone Functions
159
163
 
@@ -175,6 +179,18 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
175
179
  console.log(`The job would run in ${timeout}ms`);
176
180
  ```
177
181
 
182
+ - `validateCronExpression`: Validates if a given cron expression is valid (returns an object with `valid` and `error` properties).
183
+
184
+ ```javascript
185
+ import * as cron from 'cron';
186
+
187
+ const validation = cron.validateCronExpression('0 0 * * *');
188
+ console.log(`Is the cron expression valid? ${validation.valid}`);
189
+ if (!validation.valid) {
190
+ console.error(`Validation error: ${validation.error}`);
191
+ }
192
+ ```
193
+
178
194
  ### CronJob Class
179
195
 
180
196
  #### Constructor
@@ -225,6 +241,8 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
225
241
 
226
242
  #### Properties
227
243
 
244
+ - `isActive`: [READ-ONLY] Indicates if a job is active (checking to see if the callback needs to be called).
245
+
228
246
  - `isCallbackRunning`: [READ-ONLY] Indicates if a callback is currently executing.
229
247
 
230
248
  ```javascript
@@ -236,8 +254,8 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
236
254
 
237
255
  console.log(job.isCallbackRunning); // false
238
256
  job.start();
239
- console.log(job.running); // true (schedule is active)
240
- console.log(job.isCallbackRunning); // false (no callback executing)
257
+ console.log(job.isActive); // true
258
+ console.log(job.isCallbackRunning); // false
241
259
  ```
242
260
 
243
261
  ### CronTime Class
@@ -252,6 +270,12 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
252
270
 
253
271
  - `utcOffset`: [OPTIONAL] - Analogous to `utcOffset` from `CronJob` parameters.
254
272
 
273
+ ## 💢 Gotchas
274
+
275
+ - Both JS `Date` and Luxon `DateTime` objects don't guarantee millisecond precision due to computation delays. This module excludes millisecond precision for standard cron syntax but allows execution date specification through JS `Date` or Luxon `DateTime` objects. However, specifying a precise future execution time, such as adding a millisecond to the current time, may not always work due to these computation delays. It's observed that delays less than 4-5 ms might lead to inconsistencies. While we could limit all date granularity to seconds, we've chosen to allow greater precision but advise users of potential issues.
276
+
277
+ - Using arrow functions for `onTick` binds them to the parent's `this` context. As a result, they won't have access to the cronjob's `this` context. You can read a little more in issue [#47 (comment)](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775).
278
+
255
279
  ## 🤝 Community
256
280
 
257
281
  Join the [Discord server](https://discord.gg/yyKns29zch)! Here you can discuss issues and get help in a more casual forum than GitHub.
@@ -270,6 +294,6 @@ This is a community effort project. In the truest sense, this project started as
270
294
 
271
295
  Special thanks to [Hiroki Horiuchi](https://github.com/horiuchi), [Lundarl Gholoi](https://github.com/winup) and [koooge](https://github.com/koooge) for their work on the [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) typings before they were imported in v2.4.0.
272
296
 
273
- ## License
297
+ ## ⚖ License
274
298
 
275
299
  MIT
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { DateTime } from 'luxon';
2
+ import { CronTime } from './time';
2
3
  export { CronJob } from './job';
3
4
  export { CronTime } from './time';
4
5
  export { CronCallback, CronCommand, CronContext, CronJobParams, CronOnCompleteCallback, CronOnCompleteCommand, Ranges, TimeUnit } from './types/cron.types';
5
6
  export declare const sendAt: (cronTime: string | Date | DateTime) => DateTime;
6
7
  export declare const timeout: (cronTime: string | Date | DateTime) => number;
8
+ export declare const validateCronExpression: typeof CronTime.validateCronExpression;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.timeout = exports.sendAt = exports.CronTime = exports.CronJob = void 0;
3
+ exports.validateCronExpression = exports.timeout = exports.sendAt = exports.CronTime = exports.CronJob = void 0;
4
4
  const time_1 = require("./time");
5
5
  var job_1 = require("./job");
6
6
  Object.defineProperty(exports, "CronJob", { enumerable: true, get: function () { return job_1.CronJob; } });
@@ -10,4 +10,5 @@ const sendAt = (cronTime) => new time_1.CronTime(cronTime).sendAt();
10
10
  exports.sendAt = sendAt;
11
11
  const timeout = (cronTime) => new time_1.CronTime(cronTime).getTimeout();
12
12
  exports.timeout = timeout;
13
+ exports.validateCronExpression = time_1.CronTime.validateCronExpression;
13
14
  //# sourceMappingURL=index.js.map
package/dist/job.d.ts CHANGED
@@ -2,7 +2,6 @@ import { CronTime } from './time';
2
2
  import { CronCallback, CronContext, CronJobParams, CronOnCompleteCallback, CronOnCompleteCommand, WithOnComplete } from './types/cron.types';
3
3
  export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C = null> {
4
4
  cronTime: CronTime;
5
- running: boolean;
6
5
  unrefTimeout: boolean;
7
6
  lastExecution: Date | null;
8
7
  runOnce: boolean;
@@ -10,9 +9,11 @@ export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C =
10
9
  onComplete?: WithOnComplete<OC> extends true ? CronOnCompleteCallback : undefined;
11
10
  waitForCompletion: boolean;
12
11
  errorHandler?: CronJobParams<OC, C>['errorHandler'];
12
+ private _isActive;
13
13
  private _isCallbackRunning;
14
14
  private _timeout?;
15
15
  private _callbacks;
16
+ get isActive(): boolean;
16
17
  get isCallbackRunning(): boolean;
17
18
  constructor(cronTime: CronJobParams<OC, C>['cronTime'], onTick: CronJobParams<OC, C>['onTick'], onComplete?: CronJobParams<OC, C>['onComplete'], start?: CronJobParams<OC, C>['start'], timeZone?: CronJobParams<OC, C>['timeZone'], context?: CronJobParams<OC, C>['context'], runOnInit?: CronJobParams<OC, C>['runOnInit'], utcOffset?: null, unrefTimeout?: CronJobParams<OC, C>['unrefTimeout'], waitForCompletion?: CronJobParams<OC, C>['waitForCompletion'], errorHandler?: CronJobParams<OC, C>['errorHandler']);
18
19
  constructor(cronTime: CronJobParams<OC, C>['cronTime'], onTick: CronJobParams<OC, C>['onTick'], onComplete?: CronJobParams<OC, C>['onComplete'], start?: CronJobParams<OC, C>['start'], timeZone?: null, context?: CronJobParams<OC, C>['context'], runOnInit?: CronJobParams<OC, C>['runOnInit'], utcOffset?: CronJobParams<OC, C>['utcOffset'], unrefTimeout?: CronJobParams<OC, C>['unrefTimeout'], waitForCompletion?: CronJobParams<OC, C>['waitForCompletion'], errorHandler?: CronJobParams<OC, C>['errorHandler']);
package/dist/job.js CHANGED
@@ -14,15 +14,18 @@ const child_process_1 = require("child_process");
14
14
  const errors_1 = require("./errors");
15
15
  const time_1 = require("./time");
16
16
  class CronJob {
17
+ get isActive() {
18
+ return this._isActive;
19
+ }
17
20
  get isCallbackRunning() {
18
21
  return this._isCallbackRunning;
19
22
  }
20
23
  constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion, errorHandler) {
21
- this.running = false;
22
24
  this.unrefTimeout = false;
23
25
  this.lastExecution = null;
24
26
  this.runOnce = false;
25
27
  this.waitForCompletion = false;
28
+ this._isActive = false;
26
29
  this._isCallbackRunning = false;
27
30
  this._callbacks = [];
28
31
  this.context = (context !== null && context !== void 0 ? context : this);
@@ -95,7 +98,7 @@ class CronJob {
95
98
  if (!(time instanceof time_1.CronTime)) {
96
99
  throw new errors_1.CronError('time must be an instance of CronTime.');
97
100
  }
98
- const wasRunning = this.running;
101
+ const wasRunning = this._isActive;
99
102
  this.stop();
100
103
  this.cronTime = time;
101
104
  if (time.realDate)
@@ -133,7 +136,7 @@ class CronJob {
133
136
  return this.cronTime.sendAt(i !== null && i !== void 0 ? i : 0);
134
137
  }
135
138
  start() {
136
- if (this.running)
139
+ if (this._isActive)
137
140
  return;
138
141
  const MAXDELAY = 2147483647;
139
142
  let timeout = this.cronTime.getTimeout();
@@ -168,14 +171,14 @@ class CronJob {
168
171
  }
169
172
  else {
170
173
  this.lastExecution = new Date();
171
- this.running = false;
174
+ this._isActive = false;
172
175
  if (!this.runOnce)
173
176
  this.start();
174
177
  void this.fireOnTick();
175
178
  }
176
179
  };
177
180
  if (timeout >= 0) {
178
- this.running = true;
181
+ this._isActive = true;
179
182
  if (timeout > MAXDELAY) {
180
183
  remaining = timeout - MAXDELAY;
181
184
  timeout = MAXDELAY;
@@ -183,20 +186,7 @@ class CronJob {
183
186
  setCronTimeout(timeout);
184
187
  }
185
188
  else {
186
- if (timeout <= 1000) {
187
- console.warn(`[CRON DEBUG] Executing job with a delay: ${timeout}ms`);
188
- this.lastExecution = new Date();
189
- this.running = false;
190
- if (!this.runOnce)
191
- this.start();
192
- void this.fireOnTick();
193
- }
194
- else {
195
- console.error(`[CRON DEBUG] Stopping job due to delay being higher than 1s: ${timeout}ms`);
196
- this.stop();
197
- }
198
- console.debug(`[CRON DEBUG] Current date: ${new Date().toISOString()}`);
199
- console.debug(`[CRON DEBUG] Source: ${String(this.cronTime.source)}`);
189
+ this.stop();
200
190
  }
201
191
  }
202
192
  lastDate() {
@@ -224,7 +214,7 @@ class CronJob {
224
214
  stop() {
225
215
  if (this._timeout)
226
216
  clearTimeout(this._timeout);
227
- this.running = false;
217
+ this._isActive = false;
228
218
  if (!this.waitForCompletion) {
229
219
  void this._executeOnComplete();
230
220
  return;
package/dist/time.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DateTime, Zone } from 'luxon';
2
+ import { CronError } from './errors';
2
3
  import { CronJobParams } from './types/cron.types';
3
4
  export declare class CronTime {
4
5
  source: string | DateTime;
@@ -13,6 +14,10 @@ export declare class CronTime {
13
14
  private dayOfWeek;
14
15
  constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
15
16
  constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
17
+ static validateCronExpression(cronExpression: string): {
18
+ valid: boolean;
19
+ error?: CronError;
20
+ };
16
21
  private _getWeekDay;
17
22
  sendAt(): DateTime;
18
23
  sendAt(i: number): DateTime[];
package/dist/time.js CHANGED
@@ -36,6 +36,20 @@ class CronTime {
36
36
  this._parse(this.source);
37
37
  }
38
38
  }
39
+ static validateCronExpression(cronExpression) {
40
+ try {
41
+ new CronTime(cronExpression);
42
+ return {
43
+ valid: true
44
+ };
45
+ }
46
+ catch (error) {
47
+ return {
48
+ valid: false,
49
+ error
50
+ };
51
+ }
52
+ }
39
53
  _getWeekDay(date) {
40
54
  return date.weekday === 7 ? 0 : date.weekday;
41
55
  }
@@ -77,7 +91,7 @@ class CronTime {
77
91
  }
78
92
  }
79
93
  getTimeout() {
80
- return this.sendAt().toMillis() - luxon_1.DateTime.local().toMillis();
94
+ return Math.max(-1, this.sendAt().toMillis() - luxon_1.DateTime.local().toMillis());
81
95
  }
82
96
  toString() {
83
97
  return this.toJSON().join(' ');
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.5.1-beta.1",
4
+ "version": "4.1.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"
@@ -28,8 +28,8 @@
28
28
  "luxon": "~3.5.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@commitlint/cli": "19.6.1",
32
- "@eslint/js": "9.17.0",
31
+ "@commitlint/cli": "19.7.1",
32
+ "@eslint/js": "9.20.0",
33
33
  "@fast-check/jest": "2.0.3",
34
34
  "@insurgent/commitlint-config": "20.0.0",
35
35
  "@insurgent/conventional-changelog-preset": "10.0.0",
@@ -40,21 +40,21 @@
40
40
  "@semantic-release/npm": "12.0.1",
41
41
  "@semantic-release/release-notes-generator": "14.0.3",
42
42
  "@types/jest": "29.5.14",
43
- "@types/node": "22.10.5",
43
+ "@types/node": "22.13.4",
44
44
  "@types/sinon": "17.0.3",
45
45
  "chai": "5.1.2",
46
46
  "eslint": "8.57.1",
47
47
  "eslint-config-prettier": "9.1.0",
48
48
  "eslint-plugin-jest": "27.9.0",
49
- "eslint-plugin-prettier": "5.2.1",
49
+ "eslint-plugin-prettier": "5.2.3",
50
50
  "husky": "9.1.7",
51
51
  "jest": "29.7.0",
52
- "lint-staged": "15.3.0",
53
- "prettier": "3.4.2",
54
- "semantic-release": "24.2.1",
52
+ "lint-staged": "15.4.3",
53
+ "prettier": "3.5.1",
54
+ "semantic-release": "24.2.3",
55
55
  "sinon": "19.0.2",
56
56
  "ts-jest": "29.2.5",
57
- "typescript": "5.7.2",
57
+ "typescript": "5.7.3",
58
58
  "typescript-eslint": "7.18.0"
59
59
  },
60
60
  "keywords": [
@@ -85,6 +85,9 @@
85
85
  "Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)",
86
86
  "Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"
87
87
  ],
88
+ "engines": {
89
+ "node": ">=18.x"
90
+ },
88
91
  "files": [
89
92
  "dist/**/*.js",
90
93
  "dist/**/*.d.ts",