cron 4.0.0 → 4.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,59 @@
1
+ ## [4.1.1](https://github.com/kelektiv/node-cron/compare/v4.1.0...v4.1.1) (2025-03-26)
2
+
3
+ ### 🐛 Bug Fixes
4
+
5
+ * cron should still execute after changing the time back during daylight savings ([#966](https://github.com/kelektiv/node-cron/issues/966)) ([8cf0712](https://github.com/kelektiv/node-cron/commit/8cf07121290beb1b9e1a33bd393503fa031c691a)), closes [#881](https://github.com/kelektiv/node-cron/issues/881) [#881](https://github.com/kelektiv/node-cron/issues/881)
6
+
7
+ ### ♻️ Chores
8
+
9
+ * **action:** update actions/setup-node action to v4.3.0 ([e70709f](https://github.com/kelektiv/node-cron/commit/e70709f3b004f8ccdddbebf308e85aeabf76ffb5))
10
+ * **action:** update actions/upload-artifact action to v4.6.1 ([06ed76c](https://github.com/kelektiv/node-cron/commit/06ed76c0f0947132eb951b13503f7cb0db797880))
11
+ * **action:** update actions/upload-artifact action to v4.6.2 ([69ea222](https://github.com/kelektiv/node-cron/commit/69ea2223febff26b5dd0074bde002f218ba93c4c))
12
+ * **action:** update github/codeql-action action to v3.28.10 ([1d14a08](https://github.com/kelektiv/node-cron/commit/1d14a0896732686dbc1020fb3ba9d0bf890acec4))
13
+ * **action:** update github/codeql-action action to v3.28.11 ([cd28d4f](https://github.com/kelektiv/node-cron/commit/cd28d4ffb7000c35d766b564f33d2988be5b4601))
14
+ * **action:** update github/codeql-action action to v3.28.13 ([154f885](https://github.com/kelektiv/node-cron/commit/154f885d2da0c203395daa746a9fd3c378d35ab8))
15
+ * **action:** update ossf/scorecard-action action to v2.4.1 ([6a4ec39](https://github.com/kelektiv/node-cron/commit/6a4ec391836848fa4fa0949cc03acb0da1d1cf6b))
16
+ * **deps:** lock file maintenance ([6742c01](https://github.com/kelektiv/node-cron/commit/6742c01a10ec1651de29897d826b0fa21e5f44fc))
17
+ * **deps:** lock file maintenance ([a97cdb1](https://github.com/kelektiv/node-cron/commit/a97cdb19b2c179c1e7fcb07c8f5357299e252a13))
18
+ * **deps:** lock file maintenance ([c585973](https://github.com/kelektiv/node-cron/commit/c585973bf822713a8c0c9006074827732130f345))
19
+ * **deps:** lock file maintenance ([e156aa7](https://github.com/kelektiv/node-cron/commit/e156aa768821ca644c61ddd1387764aa817c85ca))
20
+ * **deps:** update dependency [@commitlint](https://github.com/commitlint)/cli to v19.8.0 ([3984884](https://github.com/kelektiv/node-cron/commit/3984884b29315d73c7323f52d238480e31da1ba3))
21
+ * **deps:** update dependency [@eslint](https://github.com/eslint)/js to v9.22.0 ([7415480](https://github.com/kelektiv/node-cron/commit/7415480ccafddad023f62df6cd9ca975930c8315))
22
+ * **deps:** update dependency [@eslint](https://github.com/eslint)/js to v9.23.0 ([00fc7ed](https://github.com/kelektiv/node-cron/commit/00fc7ed1e679f31eeef1a057cbb791bd415c76e7))
23
+ * **deps:** update dependency [@fast-check](https://github.com/fast-check)/jest to v2.1.0 ([a9a8608](https://github.com/kelektiv/node-cron/commit/a9a860807f01fe8526e0d8983b6371ceb27c68dd))
24
+ * **deps:** update dependency [@types](https://github.com/types)/node to v22.13.11 ([38cf6a6](https://github.com/kelektiv/node-cron/commit/38cf6a6ce15d17d888b6103457c4a0c8cb4a1019))
25
+ * **deps:** update dependency [@types](https://github.com/types)/node to v22.13.5 ([a746320](https://github.com/kelektiv/node-cron/commit/a746320f3efe92e47423cf949f42ed1eef945a45))
26
+ * **deps:** update dependency [@types](https://github.com/types)/node to v22.13.9 ([4ac339f](https://github.com/kelektiv/node-cron/commit/4ac339fe4848e20caad97844a283df5a4344bedd))
27
+ * **deps:** update dependency lint-staged to v15.5.0 ([5efb27f](https://github.com/kelektiv/node-cron/commit/5efb27f1e1657fc439781ba3ea1fdb2e571ea03e))
28
+ * **deps:** update dependency prettier to v3.5.3 ([d8f2456](https://github.com/kelektiv/node-cron/commit/d8f245616d1415fa08569ac571af4db77ed7f4ab))
29
+ * **deps:** update dependency sinon to v19.0.4 ([5144f4d](https://github.com/kelektiv/node-cron/commit/5144f4dfd90d0755591200cf957b3aff76f52afb))
30
+ * **deps:** update dependency ts-jest to v29.2.6 ([3625528](https://github.com/kelektiv/node-cron/commit/3625528fbcd2fd0e3da63a03e80271541fe92086))
31
+ * **deps:** update dependency typescript to v5.8.2 ([4ef66e8](https://github.com/kelektiv/node-cron/commit/4ef66e84985b5b2259ae67aded6391f5cbd3a5ec))
32
+ * **deps:** update linters ([ecbe916](https://github.com/kelektiv/node-cron/commit/ecbe916c825663839038e94a23aefe5c91744fe5))
33
+ * **deps:** update node.js to v23.10.0 ([#970](https://github.com/kelektiv/node-cron/issues/970)) ([6775fff](https://github.com/kelektiv/node-cron/commit/6775fff2d06798954d60cc66964e2b671a8be1e7))
34
+ * **deps:** update tests ([5d5e555](https://github.com/kelektiv/node-cron/commit/5d5e55527a5dc108f814f5ab8825e405b91a467d))
35
+
36
+ ## [4.1.0](https://github.com/kelektiv/node-cron/compare/v4.0.0...v4.1.0) (2025-02-24)
37
+
38
+ ### ✨ Features
39
+
40
+ * 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))
41
+
42
+ ### ♻️ Chores
43
+
44
+ * **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))
45
+ * **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))
46
+ * **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))
47
+ * **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))
48
+ * **deps:** lock file maintenance ([fa08aa3](https://github.com/kelektiv/node-cron/commit/fa08aa3e0edacdc324381cff33160d49b6db6af0))
49
+ * **deps:** lock file maintenance ([#944](https://github.com/kelektiv/node-cron/issues/944)) ([374ac42](https://github.com/kelektiv/node-cron/commit/374ac429d4ff6f19440d4c18d6e366a69cfea233))
50
+ * **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))
51
+ * **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))
52
+ * **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))
53
+ * **deps:** update linters ([#954](https://github.com/kelektiv/node-cron/issues/954)) ([9159759](https://github.com/kelektiv/node-cron/commit/91597592d05770b7e31bbd93eb0b4160da175154))
54
+ * **deps:** update semantic-release related packages ([#951](https://github.com/kelektiv/node-cron/issues/951)) ([92d7ac3](https://github.com/kelektiv/node-cron/commit/92d7ac3f8fa6fcbf37ead72abc3f798fdc05370a))
55
+ * remove bower.json, which is unused ([#955](https://github.com/kelektiv/node-cron/issues/955)) ([8e509f3](https://github.com/kelektiv/node-cron/commit/8e509f3ad7dcd5d250e75a41417830b9b01c2bdb))
56
+
1
57
  ## [4.0.0](https://github.com/kelektiv/node-cron/compare/v3.5.0...v4.0.0) (2025-02-19)
2
58
 
3
59
  ### ⚠ Breaking changes
package/README.md CHANGED
@@ -179,6 +179,18 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
179
179
  console.log(`The job would run in ${timeout}ms`);
180
180
  ```
181
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
+
182
194
  ### CronJob Class
183
195
 
184
196
  #### Constructor
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/time.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import { DateTime, Zone } from 'luxon';
2
+ import { CronError } from './errors';
2
3
  import { CronJobParams } from './types/cron.types';
4
+ type CustomZone = Zone & {
5
+ zoneName?: string;
6
+ fixed?: string;
7
+ };
8
+ type CustomDateTime = Omit<DateTime, 'zone'> & {
9
+ zone: CustomZone;
10
+ };
3
11
  export declare class CronTime {
4
12
  source: string | DateTime;
5
13
  timeZone?: string;
@@ -13,20 +21,20 @@ export declare class CronTime {
13
21
  private dayOfWeek;
14
22
  constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
15
23
  constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
24
+ static validateCronExpression(cronExpression: string): {
25
+ valid: boolean;
26
+ error?: CronError;
27
+ };
16
28
  private _getWeekDay;
17
29
  sendAt(): DateTime;
18
30
  sendAt(i: number): DateTime[];
19
31
  getTimeout(): number;
20
32
  toString(): string;
21
33
  toJSON(): string[];
22
- getNextDateFrom(start: Date | DateTime, timeZone?: string | Zone): DateTime<boolean>;
23
- private _findPreviousDSTJump;
24
- private _checkTimeInSkippedRange;
25
- private _checkTimeInSkippedRangeSingleHour;
26
- private _checkTimeInSkippedRangeMultiHour;
27
- private _forwardDSTJump;
34
+ getNextDateFrom(start: Date | CustomDateTime, timeZone?: string | CustomZone): DateTime;
28
35
  private _wcOrAll;
29
36
  private _hasAll;
30
37
  private _parse;
31
38
  private _parseField;
32
39
  }
40
+ export {};
package/dist/time.js CHANGED
@@ -36,13 +36,27 @@ 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
  }
42
56
  sendAt(i) {
43
57
  let date = this.realDate && this.source instanceof luxon_1.DateTime
44
58
  ? this.source
45
- : luxon_1.DateTime.local();
59
+ : luxon_1.DateTime.utc();
46
60
  if (this.timeZone) {
47
61
  date = date.setZone(this.timeZone);
48
62
  }
@@ -65,7 +79,8 @@ class CronTime {
65
79
  return date;
66
80
  }
67
81
  if (i === undefined || isNaN(i) || i < 0) {
68
- return this.getNextDateFrom(date);
82
+ const nextDate = this.getNextDateFrom(date);
83
+ return nextDate;
69
84
  }
70
85
  else {
71
86
  const dates = [];
@@ -77,7 +92,7 @@ class CronTime {
77
92
  }
78
93
  }
79
94
  getTimeout() {
80
- return Math.max(-1, this.sendAt().toMillis() - luxon_1.DateTime.local().toMillis());
95
+ return Math.max(-1, this.sendAt().toMillis() - luxon_1.DateTime.utc().toMillis());
81
96
  }
82
97
  toString() {
83
98
  return this.toJSON().join(' ');
@@ -88,15 +103,20 @@ class CronTime {
88
103
  });
89
104
  }
90
105
  getNextDateFrom(start, timeZone) {
91
- var _a;
106
+ var _a, _b;
92
107
  if (start instanceof Date) {
93
108
  start = luxon_1.DateTime.fromJSDate(start);
94
109
  }
95
- let date = start;
96
- const firstDate = start.toMillis();
97
110
  if (timeZone) {
98
- date = date.setZone(timeZone);
111
+ start = start.setZone(timeZone);
112
+ }
113
+ else {
114
+ timeZone = (_a = start.zone.zoneName) !== null && _a !== void 0 ? _a : start.zone.fixed;
99
115
  }
116
+ let date = luxon_1.DateTime.fromFormat(`${start.year}-${start.month}-${start.day} ${start.hour}:${start.minute}:${start.second}`, 'yyyy-M-d H:m:s', {
117
+ zone: 'UTC'
118
+ });
119
+ const firstDate = date.toMillis();
100
120
  if (!this.realDate) {
101
121
  if (date.millisecond > 0) {
102
122
  date = date.set({ millisecond: 0, second: date.second + 1 });
@@ -107,202 +127,75 @@ class CronTime {
107
127
  }
108
128
  const maxMatch = luxon_1.DateTime.now().plus({ years: 8 });
109
129
  while (true) {
110
- const diff = date.toMillis() - start.toMillis();
111
130
  if (date > maxMatch) {
112
131
  throw new errors_1.CronError(`Something went wrong. No execution date was found in the next 8 years.
113
132
  Please provide the following string if you would like to help debug:
114
- 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()}`);
133
+ Time Zone: ${(_b = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toString()) !== null && _b !== void 0 ? _b : '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
115
134
  }
116
135
  if (!(date.month in this.month) &&
117
136
  Object.keys(this.month).length !== 12) {
118
- date = date.plus({ months: 1 });
137
+ date = date.plus({ month: 1 });
119
138
  date = date.set({ day: 1, hour: 0, minute: 0, second: 0 });
120
- if (this._forwardDSTJump(0, 0, date)) {
121
- const [isDone, newDate] = this._findPreviousDSTJump(date);
122
- date = newDate;
123
- if (isDone)
124
- break;
125
- }
126
139
  continue;
127
140
  }
128
- if (!(date.day in this.dayOfMonth) &&
141
+ if ((!(date.day in this.dayOfMonth) &&
129
142
  Object.keys(this.dayOfMonth).length !== 31 &&
130
143
  !(this._getWeekDay(date) in this.dayOfWeek &&
131
- Object.keys(this.dayOfWeek).length !== 7)) {
144
+ Object.keys(this.dayOfWeek).length !== 7)) ||
145
+ (!(this._getWeekDay(date) in this.dayOfWeek) &&
146
+ Object.keys(this.dayOfWeek).length !== 7 &&
147
+ !(date.day in this.dayOfMonth &&
148
+ Object.keys(this.dayOfMonth).length !== 31))) {
132
149
  date = date.plus({ days: 1 });
133
150
  date = date.set({ hour: 0, minute: 0, second: 0 });
134
- if (this._forwardDSTJump(0, 0, date)) {
135
- const [isDone, newDate] = this._findPreviousDSTJump(date);
136
- date = newDate;
137
- if (isDone)
138
- break;
139
- }
140
- continue;
141
- }
142
- if (!(this._getWeekDay(date) in this.dayOfWeek) &&
143
- Object.keys(this.dayOfWeek).length !== 7 &&
144
- !(date.day in this.dayOfMonth &&
145
- Object.keys(this.dayOfMonth).length !== 31)) {
146
- date = date.plus({ days: 1 });
147
- date = date.set({ hour: 0, minute: 0, second: 0 });
148
- if (this._forwardDSTJump(0, 0, date)) {
149
- const [isDone, newDate] = this._findPreviousDSTJump(date);
150
- date = newDate;
151
- if (isDone)
152
- break;
153
- }
154
151
  continue;
155
152
  }
156
153
  if (!(date.hour in this.hour) && Object.keys(this.hour).length !== 24) {
157
- const expectedHour = date.hour === 23 && diff > 86400000 ? 0 : date.hour + 1;
158
- const expectedMinute = date.minute;
159
- date = date.set({ hour: expectedHour });
154
+ date = date.plus({ hour: 1 });
160
155
  date = date.set({ minute: 0, second: 0 });
161
- if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
162
- const [isDone, newDate] = this._findPreviousDSTJump(date);
163
- date = newDate;
164
- if (isDone)
165
- break;
166
- }
167
156
  continue;
168
157
  }
169
158
  if (!(date.minute in this.minute) &&
170
159
  Object.keys(this.minute).length !== 60) {
171
- const expectedMinute = date.minute === 59 && diff > 3600000 ? 0 : date.minute + 1;
172
- const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
173
- date = date.set({ minute: expectedMinute });
160
+ date = date.plus({ minute: 1 });
174
161
  date = date.set({ second: 0 });
175
- if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
176
- const [isDone, newDate] = this._findPreviousDSTJump(date);
177
- date = newDate;
178
- if (isDone)
179
- break;
180
- }
181
162
  continue;
182
163
  }
183
- if (!(date.second in this.second) &&
184
- Object.keys(this.second).length !== 60) {
185
- const expectedSecond = date.second === 59 && diff > 60000 ? 0 : date.second + 1;
186
- const expectedMinute = date.minute + (expectedSecond === 60 ? 1 : 0);
187
- const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
188
- date = date.set({ second: expectedSecond });
189
- if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
190
- const [isDone, newDate] = this._findPreviousDSTJump(date);
191
- date = newDate;
192
- if (isDone)
193
- break;
194
- }
195
- continue;
196
- }
197
- if (date.toMillis() === firstDate) {
198
- const expectedSecond = date.second + 1;
199
- const expectedMinute = date.minute + (expectedSecond === 60 ? 1 : 0);
200
- const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
201
- date = date.set({ second: expectedSecond });
202
- if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
203
- const [isDone, newDate] = this._findPreviousDSTJump(date);
204
- date = newDate;
205
- if (isDone)
206
- break;
207
- }
164
+ if (date.toMillis() === firstDate ||
165
+ (!(date.second in this.second) &&
166
+ Object.keys(this.second).length !== 60)) {
167
+ date = date.plus({ second: 1 });
208
168
  continue;
209
169
  }
210
170
  break;
211
171
  }
212
- return date;
213
- }
214
- _findPreviousDSTJump(date) {
215
- var _a;
216
- let expectedMinute, expectedHour, actualMinute, actualHour;
217
- let maybeJumpingPoint = date;
218
- const iterationLimit = 60 * 24;
219
- let iteration = 0;
220
- do {
221
- if (++iteration > iterationLimit) {
222
- throw new errors_1.CronError(`ERROR: This DST checking related function assumes the input DateTime (${(_a = date.toISO()) !== null && _a !== void 0 ? _a : date.toMillis()}) is within 24 hours of a DST jump.`);
223
- }
224
- expectedMinute = maybeJumpingPoint.minute - 1;
225
- expectedHour = maybeJumpingPoint.hour;
226
- if (expectedMinute < 0) {
227
- expectedMinute += 60;
228
- expectedHour = (expectedHour + 24 - 1) % 24;
172
+ const expectedHour = date.hour;
173
+ const expectedMinute = date.minute;
174
+ date = luxon_1.DateTime.fromFormat(`${date.year}-${date.month}-${date.day} ${date.hour}:${date.minute}:${date.second}`, 'yyyy-M-d H:m:s', {
175
+ zone: timeZone
176
+ });
177
+ const nonDSTReferenceDate = luxon_1.DateTime.fromFormat(`${date.year}-1-1 0:0:0`, 'yyyy-M-d H:m:s', { zone: timeZone });
178
+ if ((expectedHour !== date.hour || expectedMinute !== date.minute) &&
179
+ nonDSTReferenceDate.offset !== date.offset) {
180
+ while (date.minus({ minute: 1 }).offset !== nonDSTReferenceDate.offset) {
181
+ date = date.minus({ minute: 1 });
229
182
  }
230
- maybeJumpingPoint = maybeJumpingPoint.minus({ minute: 1 });
231
- actualMinute = maybeJumpingPoint.minute;
232
- actualHour = maybeJumpingPoint.hour;
233
- } while (expectedMinute === actualMinute && expectedHour === actualHour);
234
- const afterJumpingPoint = maybeJumpingPoint
235
- .plus({ minute: 1 })
236
- .set({ second: 0, millisecond: 0 });
237
- const beforeJumpingPoint = afterJumpingPoint.minus({ second: 1 });
238
- if (date.month in this.month &&
239
- date.day in this.dayOfMonth &&
240
- this._getWeekDay(date) in this.dayOfWeek) {
241
- return [
242
- this._checkTimeInSkippedRange(beforeJumpingPoint, afterJumpingPoint),
243
- afterJumpingPoint
244
- ];
245
- }
246
- return [false, afterJumpingPoint];
247
- }
248
- _checkTimeInSkippedRange(beforeJumpingPoint, afterJumpingPoint) {
249
- const startingMinute = (beforeJumpingPoint.minute + 1) % 60;
250
- const startingHour = (beforeJumpingPoint.hour + (startingMinute === 0 ? 1 : 0)) % 24;
251
- const hourRangeSize = afterJumpingPoint.hour - startingHour + 1;
252
- const isHourJump = startingMinute === 0 && afterJumpingPoint.minute === 0;
253
- if (hourRangeSize === 2 && isHourJump) {
254
- return startingHour in this.hour;
255
- }
256
- else if (hourRangeSize === 1) {
257
- return (startingHour in this.hour &&
258
- this._checkTimeInSkippedRangeSingleHour(startingMinute, afterJumpingPoint.minute));
259
- }
260
- else {
261
- return this._checkTimeInSkippedRangeMultiHour(startingHour, startingMinute, afterJumpingPoint.hour, afterJumpingPoint.minute);
262
- }
263
- }
264
- _checkTimeInSkippedRangeSingleHour(startMinute, endMinute) {
265
- for (let minute = startMinute; minute < endMinute; ++minute) {
266
- if (minute in this.minute)
267
- return true;
183
+ return date;
268
184
  }
269
- return endMinute in this.minute && 0 in this.second;
270
- }
271
- _checkTimeInSkippedRangeMultiHour(startHour, startMinute, endHour, endMinute) {
272
- if (startHour >= endHour) {
273
- throw new errors_1.CronError(`ERROR: This DST checking related function assumes the forward jump starting hour (${startHour}) is less than the end hour (${endHour})`);
185
+ const hourTestDate = date.minus({ hour: 1 });
186
+ const twoHourTestDate = date.minus({ hour: 2 });
187
+ if ((hourTestDate.hour === date.hour ||
188
+ twoHourTestDate.hour === hourTestDate.hour) &&
189
+ hourTestDate > start) {
190
+ date = hourTestDate;
274
191
  }
275
- const firstHourMinuteRange = Array.from({ length: 60 - startMinute }, (_, k) => startMinute + k);
276
- const lastHourMinuteRange = Array.from({ length: endMinute }, (_, k) => k);
277
- const middleHourMinuteRange = Array.from({ length: 60 }, (_, k) => k);
278
- const selectRange = (forHour) => {
279
- if (forHour === startHour) {
280
- return firstHourMinuteRange;
281
- }
282
- else if (forHour === endHour) {
283
- return lastHourMinuteRange;
284
- }
285
- else {
286
- return middleHourMinuteRange;
287
- }
288
- };
289
- for (let hour = startHour; hour <= endHour; ++hour) {
290
- if (!(hour in this.hour))
291
- continue;
292
- const usingRange = selectRange(hour);
293
- for (const minute of usingRange) {
294
- if (minute in this.minute)
295
- return true;
296
- }
192
+ const halfHourTestDate = date.minus({ minute: 30 });
193
+ if ((halfHourTestDate.minute === date.minute ||
194
+ hourTestDate.minute === halfHourTestDate.minute) &&
195
+ halfHourTestDate > start) {
196
+ date = halfHourTestDate;
297
197
  }
298
- return endHour in this.hour && endMinute in this.minute && 0 in this.second;
299
- }
300
- _forwardDSTJump(expectedHour, expectedMinute, actualDate) {
301
- const actualHour = actualDate.hour;
302
- const actualMinute = actualDate.minute;
303
- const didHoursJumped = expectedHour % 24 < actualHour;
304
- const didMinutesJumped = expectedMinute % 60 < actualMinute;
305
- return didHoursJumped || didMinutesJumped;
198
+ return date;
306
199
  }
307
200
  _wcOrAll(unit) {
308
201
  if (this._hasAll(unit)) {
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.0.0",
4
+ "version": "4.1.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"
@@ -28,9 +28,9 @@
28
28
  "luxon": "~3.5.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@commitlint/cli": "19.6.1",
32
- "@eslint/js": "9.17.0",
33
- "@fast-check/jest": "2.0.3",
31
+ "@commitlint/cli": "19.8.0",
32
+ "@eslint/js": "9.23.0",
33
+ "@fast-check/jest": "2.1.0",
34
34
  "@insurgent/commitlint-config": "20.0.0",
35
35
  "@insurgent/conventional-changelog-preset": "10.0.0",
36
36
  "@semantic-release/changelog": "6.0.3",
@@ -39,22 +39,23 @@
39
39
  "@semantic-release/github": "11.0.1",
40
40
  "@semantic-release/npm": "12.0.1",
41
41
  "@semantic-release/release-notes-generator": "14.0.3",
42
+ "@swc/core": "^1.10.18",
43
+ "@swc/jest": "^0.2.37",
42
44
  "@types/jest": "29.5.14",
43
- "@types/node": "22.10.5",
44
- "@types/sinon": "17.0.3",
45
- "chai": "5.1.2",
45
+ "@types/node": "22.13.11",
46
+ "@types/sinon": "17.0.4",
47
+ "chai": "5.2.0",
46
48
  "eslint": "8.57.1",
47
49
  "eslint-config-prettier": "9.1.0",
48
50
  "eslint-plugin-jest": "27.9.0",
49
- "eslint-plugin-prettier": "5.2.1",
51
+ "eslint-plugin-prettier": "5.2.3",
50
52
  "husky": "9.1.7",
51
53
  "jest": "29.7.0",
52
- "lint-staged": "15.3.0",
53
- "prettier": "3.4.2",
54
- "semantic-release": "24.2.1",
55
- "sinon": "19.0.2",
56
- "ts-jest": "29.2.5",
57
- "typescript": "5.7.2",
54
+ "lint-staged": "15.5.0",
55
+ "prettier": "3.5.3",
56
+ "semantic-release": "24.2.3",
57
+ "sinon": "19.0.4",
58
+ "typescript": "5.8.2",
58
59
  "typescript-eslint": "7.18.0"
59
60
  },
60
61
  "keywords": [