croner 11.0.0-dev.1 → 11.0.0-dev.3

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/dist/croner.d.cts CHANGED
@@ -1,9 +1,7 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
1
  /**
4
2
  * Cron pattern mode for controlling precision level
5
3
  */
6
- export type CronMode = "auto" | "5-part" | "6-part" | "7-part" | "5-or-6-parts" | "6-or-7-parts";
4
+ type CronMode = "auto" | "5-part" | "6-part" | "7-part" | "5-or-6-parts" | "6-or-7-parts";
7
5
  /**
8
6
  * Create a CronPattern instance from pattern string ('* * * * * *')
9
7
  * @constructor
@@ -11,518 +9,521 @@ export type CronMode = "auto" | "5-part" | "6-part" | "7-part" | "5-or-6-parts"
11
9
  * @param {string} timezone - Input timezone, used for '?'-substitution
12
10
  * @param {object} options - Cron options including mode
13
11
  */
14
- export declare class CronPattern {
15
- pattern: string;
16
- timezone?: string;
17
- mode: CronMode;
18
- alternativeWeekdays: boolean;
19
- sloppyRanges: boolean;
20
- second: number[];
21
- minute: number[];
22
- hour: number[];
23
- day: number[];
24
- month: number[];
25
- dayOfWeek: number[];
26
- year: number[];
27
- lastDayOfMonth: boolean;
28
- lastWeekday: boolean;
29
- nearestWeekdays: number[];
30
- starDOM: boolean;
31
- starDOW: boolean;
32
- starYear: boolean;
33
- useAndLogic: boolean;
34
- constructor(pattern: string, timezone?: string, options?: {
35
- mode?: CronMode;
36
- alternativeWeekdays?: boolean;
37
- sloppyRanges?: boolean;
38
- });
39
- /**
40
- * Parse current pattern, will throw on any type of failure
41
- * @private
42
- */
43
- private parse;
44
- /**
45
- * Convert current part (seconds/minutes etc) to an array of 1 or 0 depending on if the part is about to trigger a run or not.
46
- */
47
- private partToArray;
48
- /**
49
- * After converting JAN-DEC, SUN-SAT only 0-9 * , / - are allowed, throw if anything else pops up
50
- * @throws On error
51
- */
52
- private throwAtIllegalCharacters;
53
- /**
54
- * Nothing but a number, potentially with a modifier, left - handle that
55
- *
56
- * @param conf Current part, expected to be a number, as a string
57
- * @param type One of "seconds", "minutes" etc
58
- * @param valueIndexOffset -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
59
- */
60
- private handleNumber;
61
- /**
62
- * Set a specific value for a specific part of the CronPattern.
63
- *
64
- * @param part The specific part of the CronPattern, e.g., "second", "minute", etc.
65
- * @param index The index to modify.
66
- * @param value The value to set, typically 0 or 1, in case of "nth weekday" it will be the weekday number used for further processing
67
- */
68
- private setPart;
69
- /**
70
- * Validates that a parsed number is not NaN.
71
- * Throws a TypeError with a descriptive message if the value is NaN.
72
- *
73
- * @param value - The value to validate
74
- * @param errorMessage - The error message to throw if validation fails
75
- * @throws {TypeError} If the value is NaN
76
- * @private
77
- */
78
- private validateNotNaN;
79
- /**
80
- * Validates that a range is valid (lower <= upper) and that steps are valid (> 0 and <= array length).
81
- *
82
- * @param lower - Lower bound of range
83
- * @param upper - Upper bound of range
84
- * @param steps - Optional step value to validate
85
- * @param type - The type of pattern part being validated
86
- * @param conf - The original configuration string for error messages
87
- * @throws {TypeError} If validation fails
88
- * @private
89
- */
90
- private validateRange;
91
- /**
92
- * Take care of ranges with stepping (e.g. 3-23/5)
93
- *
94
- * @param conf Current part, expected to be a string like 3-23/5
95
- * @param type One of "seconds", "minutes" etc
96
- * @param valueIndexOffset -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
97
- */
98
- private handleRangeWithStepping;
99
- private extractNth;
100
- /**
101
- * Take care of ranges (e.g. 1-20)
102
- *
103
- * @param conf - Current part, expected to be a string like 1-20, can contain L for last
104
- * @param type - One of "seconds", "minutes" etc
105
- * @param valueIndexOffset - -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
106
- */
107
- private handleRange;
108
- /**
109
- * Handle stepping (e.g. * / 14)
110
- *
111
- * @param conf Current part, expected to be a string like * /20 (without the space)
112
- * @param type One of "seconds", "minutes" etc
113
- */
114
- private handleStepping;
115
- /**
116
- * Replace day name with day numbers
117
- *
118
- * @param conf Current part, expected to be a string that might contain sun,mon etc.
119
- *
120
- * @returns Conf with 0 instead of sun etc.
121
- */
122
- private replaceAlphaDays;
123
- /**
124
- * Replace day name with day numbers (Quartz mode)
125
- * In Quartz mode: Sunday=1, Monday=2, ..., Saturday=7
126
- *
127
- * @param conf Current part, expected to be a string that might contain sun,mon etc.
128
- *
129
- * @returns Conf with Quartz-style numbering
130
- */
131
- private replaceAlphaDaysQuartz;
132
- /**
133
- * Replace month name with month numbers
134
- *
135
- * @param conf Current part, expected to be a string that might contain jan,feb etc.
136
- *
137
- * @returns conf with 0 instead of sun etc.
138
- */
139
- private replaceAlphaMonths;
140
- /**
141
- * Replace nicknames with actual cron patterns
142
- *
143
- * @param pattern Pattern, may contain nicknames, or not
144
- *
145
- * @returns Pattern, with cron expression insted of nicknames
146
- */
147
- private handleNicknames;
148
- /**
149
- * Handle the nth weekday of the month logic using hash sign (e.g. FRI#2 for the second Friday of the month)
150
- *
151
- * @param index Weekday, example: 5 for friday
152
- * @param nthWeekday bitmask, 2 (0x00010) for 2nd friday, 31 (ANY_OCCURRENCE, 0b100000) for any day
153
- */
154
- private setNthWeekdayOfMonth;
12
+ declare class CronPattern {
13
+ pattern: string;
14
+ timezone?: string;
15
+ mode: CronMode;
16
+ alternativeWeekdays: boolean;
17
+ sloppyRanges: boolean;
18
+ second: number[];
19
+ minute: number[];
20
+ hour: number[];
21
+ day: number[];
22
+ month: number[];
23
+ dayOfWeek: number[];
24
+ year: number[];
25
+ lastDayOfMonth: boolean;
26
+ lastWeekday: boolean;
27
+ nearestWeekdays: number[];
28
+ starDOM: boolean;
29
+ starDOW: boolean;
30
+ starYear: boolean;
31
+ useAndLogic: boolean;
32
+ constructor(pattern: string, timezone?: string, options?: {
33
+ mode?: CronMode;
34
+ alternativeWeekdays?: boolean;
35
+ sloppyRanges?: boolean;
36
+ });
37
+ /**
38
+ * Parse current pattern, will throw on any type of failure
39
+ * @private
40
+ */
41
+ private parse;
42
+ /**
43
+ * Convert current part (seconds/minutes etc) to an array of 1 or 0 depending on if the part is about to trigger a run or not.
44
+ */
45
+ private partToArray;
46
+ /**
47
+ * After converting JAN-DEC, SUN-SAT only 0-9 * , / - are allowed, throw if anything else pops up
48
+ * @throws On error
49
+ */
50
+ private throwAtIllegalCharacters;
51
+ /**
52
+ * Nothing but a number, potentially with a modifier, left - handle that
53
+ *
54
+ * @param conf Current part, expected to be a number, as a string
55
+ * @param type One of "seconds", "minutes" etc
56
+ * @param valueIndexOffset -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
57
+ */
58
+ private handleNumber;
59
+ /**
60
+ * Set a specific value for a specific part of the CronPattern.
61
+ *
62
+ * @param part The specific part of the CronPattern, e.g., "second", "minute", etc.
63
+ * @param index The index to modify.
64
+ * @param value The value to set, typically 0 or 1, in case of "nth weekday" it will be the weekday number used for further processing
65
+ */
66
+ private setPart;
67
+ /**
68
+ * Validates that a parsed number is not NaN.
69
+ * Throws a TypeError with a descriptive message if the value is NaN.
70
+ *
71
+ * @param value - The value to validate
72
+ * @param errorMessage - The error message to throw if validation fails
73
+ * @throws {TypeError} If the value is NaN
74
+ * @private
75
+ */
76
+ private validateNotNaN;
77
+ /**
78
+ * Validates that a range is valid (lower <= upper) and that steps are valid (> 0 and <= array length).
79
+ *
80
+ * @param lower - Lower bound of range
81
+ * @param upper - Upper bound of range
82
+ * @param steps - Optional step value to validate
83
+ * @param type - The type of pattern part being validated
84
+ * @param conf - The original configuration string for error messages
85
+ * @throws {TypeError} If validation fails
86
+ * @private
87
+ */
88
+ private validateRange;
89
+ /**
90
+ * Take care of ranges with stepping (e.g. 3-23/5)
91
+ *
92
+ * @param conf Current part, expected to be a string like 3-23/5
93
+ * @param type One of "seconds", "minutes" etc
94
+ * @param valueIndexOffset -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
95
+ */
96
+ private handleRangeWithStepping;
97
+ private extractNth;
98
+ /**
99
+ * Take care of ranges (e.g. 1-20)
100
+ *
101
+ * @param conf - Current part, expected to be a string like 1-20, can contain L for last
102
+ * @param type - One of "seconds", "minutes" etc
103
+ * @param valueIndexOffset - -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
104
+ */
105
+ private handleRange;
106
+ /**
107
+ * Handle stepping (e.g. * / 14)
108
+ *
109
+ * @param conf Current part, expected to be a string like * /20 (without the space)
110
+ * @param type One of "seconds", "minutes" etc
111
+ */
112
+ private handleStepping;
113
+ /**
114
+ * Replace day name with day numbers
115
+ *
116
+ * @param conf Current part, expected to be a string that might contain sun,mon etc.
117
+ *
118
+ * @returns Conf with 0 instead of sun etc.
119
+ */
120
+ private replaceAlphaDays;
121
+ /**
122
+ * Replace day name with day numbers (Quartz mode)
123
+ * In Quartz mode: Sunday=1, Monday=2, ..., Saturday=7
124
+ *
125
+ * @param conf Current part, expected to be a string that might contain sun,mon etc.
126
+ *
127
+ * @returns Conf with Quartz-style numbering
128
+ */
129
+ private replaceAlphaDaysQuartz;
130
+ /**
131
+ * Replace month name with month numbers
132
+ *
133
+ * @param conf Current part, expected to be a string that might contain jan,feb etc.
134
+ *
135
+ * @returns conf with 0 instead of sun etc.
136
+ */
137
+ private replaceAlphaMonths;
138
+ /**
139
+ * Replace nicknames with actual cron patterns
140
+ *
141
+ * @param pattern Pattern, may contain nicknames, or not
142
+ *
143
+ * @returns Pattern, with cron expression insted of nicknames
144
+ */
145
+ private handleNicknames;
146
+ /**
147
+ * Handle the nth weekday of the month logic using hash sign (e.g. FRI#2 for the second Friday of the month)
148
+ *
149
+ * @param index Weekday, example: 5 for friday
150
+ * @param nthWeekday bitmask, 2 (0x00010) for 2nd friday, 31 (ANY_OCCURRENCE, 0b100000) for any day
151
+ */
152
+ private setNthWeekdayOfMonth;
155
153
  }
156
- export type CatchCallbackFn = (e: unknown, job: Cron) => void;
157
- export type ProtectCallbackFn = (job: Cron) => void;
154
+
155
+ type CatchCallbackFn = (e: unknown, job: Cron) => void;
156
+ type ProtectCallbackFn = (job: Cron) => void;
158
157
  /**
159
158
  * Options for configuring cron jobs.
160
159
  *
161
160
  * @interface
162
161
  */
163
- export interface CronOptions<T = undefined> {
164
- /**
165
- * The name of the cron job. If provided, the job will be added to the
166
- * `scheduledJobs` array, allowing it to be accessed by name.
167
- */
168
- name?: string;
169
- /**
170
- * If true, the job will be paused initially.
171
- * @default false
172
- */
173
- paused?: boolean;
174
- /**
175
- * If true, the job will be stopped permanently.
176
- * @default false
177
- */
178
- kill?: boolean;
179
- /**
180
- * If true, errors thrown by the job function will be caught.
181
- * If a function is provided, it will be called with the error and the job instance.
182
- * @default false
183
- */
184
- catch?: boolean | CatchCallbackFn;
185
- /**
186
- * If true, the underlying timer will be unreferenced, allowing the Node.js
187
- * process to exit even if the job is still running.
188
- * @default false
189
- */
190
- unref?: boolean;
191
- /**
192
- * The maximum number of times the job will run.
193
- * @default Infinity
194
- */
195
- maxRuns?: number;
196
- /**
197
- * The minimum interval between job executions, in seconds.
198
- * @default 1
199
- */
200
- interval?: number;
201
- /**
202
- * If true, prevents the job from running if the previous execution is still in progress.
203
- * If a function is provided, it will be called if the job is blocked.
204
- * @default false
205
- */
206
- protect?: boolean | ProtectCallbackFn;
207
- /**
208
- * The date and time at which the job should start running.
209
- */
210
- startAt?: string | Date | CronDate<T>;
211
- /**
212
- * The date and time at which the job should stop running.
213
- */
214
- stopAt?: string | Date | CronDate<T>;
215
- /**
216
- * The timezone for the cron job.
217
- */
218
- timezone?: string;
219
- /**
220
- * The UTC offset for the cron job, in minutes.
221
- */
222
- utcOffset?: number;
223
- /**
224
- * If true, uses AND logic when combining day-of-month and day-of-week.
225
- * If false, uses OR logic for combining day-of-month and day-of-week (legacy behavior).
226
- * @default false
227
- */
228
- domAndDow?: boolean;
229
- /**
230
- * Offset the scheduled date by a number of days.
231
- * Positive values shift the date forward, negative values shift it backward.
232
- * For example, dayOffset: -1 schedules the job one day before the pattern match.
233
- * @default 0
234
- */
235
- dayOffset?: number;
236
- /**
237
- * @deprecated Use domAndDow instead. This option will be removed in a future version.
238
- * If true, enables legacy mode (OR logic) for compatibility with older cron implementations.
239
- * @default true
240
- */
241
- legacyMode?: boolean;
242
- /**
243
- * Specifies the cron pattern mode to use for parsing and execution.
244
- *
245
- * - "auto": Automatically detect pattern format (default behavior)
246
- * - "5-part": Traditional 5-field cron (minute-level precision, seconds forced to 0, years wildcarded)
247
- * - "6-part": Extended 6-field cron (second-level precision, years wildcarded)
248
- * - "7-part": Full 7-field cron (second-level and year-specific precision)
249
- * - "5-or-6-parts": Accept 5 or 6 field patterns (years wildcarded)
250
- * - "6-or-7-parts": Accept 6 or 7 field patterns (no additional constraints)
251
- *
252
- * @default "auto"
253
- */
254
- mode?: CronMode;
255
- /**
256
- * An optional context object that will be passed to the job function.
257
- */
258
- context?: T;
259
- /**
260
- * If true, enables alternative weekday numbering (Quartz mode).
261
- * In standard mode (false): Sunday=0, Monday=1, ..., Saturday=6
262
- * In Quartz mode (true): Sunday=1, Monday=2, ..., Saturday=7
263
- * @default false
264
- */
265
- alternativeWeekdays?: boolean;
266
- /**
267
- * If true, allows non-standard stepping formats for backward compatibility.
268
- * When false (default), only wildcard (*\/step) or range (min-max\/step) formats are allowed.
269
- * When true, allows numeric prefix formats like /10, 5/5, 30/30.
270
- * @default false
271
- */
272
- sloppyRanges?: boolean;
273
- /**
274
- * If true, date-based jobs scheduled in the past will fire immediately.
275
- * If false, only jobs scheduled within the past second will fire immediately (to handle timing edge cases).
276
- * Jobs scheduled more than 1 second in the past will be rejected unless this is true.
277
- * @default false
278
- */
279
- allowPast?: boolean;
162
+ interface CronOptions<T = undefined> {
163
+ /**
164
+ * The name of the cron job. If provided, the job will be added to the
165
+ * `scheduledJobs` array, allowing it to be accessed by name.
166
+ */
167
+ name?: string;
168
+ /**
169
+ * If true, the job will be paused initially.
170
+ * @default false
171
+ */
172
+ paused?: boolean;
173
+ /**
174
+ * If true, the job will be stopped permanently.
175
+ * @default false
176
+ */
177
+ kill?: boolean;
178
+ /**
179
+ * If true, errors thrown by the job function will be caught.
180
+ * If a function is provided, it will be called with the error and the job instance.
181
+ * @default false
182
+ */
183
+ catch?: boolean | CatchCallbackFn;
184
+ /**
185
+ * If true, the underlying timer will be unreferenced, allowing the Node.js
186
+ * process to exit even if the job is still running.
187
+ * @default false
188
+ */
189
+ unref?: boolean;
190
+ /**
191
+ * The maximum number of times the job will run.
192
+ * @default Infinity
193
+ */
194
+ maxRuns?: number;
195
+ /**
196
+ * The minimum interval between job executions, in seconds.
197
+ * @default 1
198
+ */
199
+ interval?: number;
200
+ /**
201
+ * If true, prevents the job from running if the previous execution is still in progress.
202
+ * If a function is provided, it will be called if the job is blocked.
203
+ * @default false
204
+ */
205
+ protect?: boolean | ProtectCallbackFn;
206
+ /**
207
+ * The date and time at which the job should start running.
208
+ */
209
+ startAt?: string | Date | CronDate<T>;
210
+ /**
211
+ * The date and time at which the job should stop running.
212
+ */
213
+ stopAt?: string | Date | CronDate<T>;
214
+ /**
215
+ * The timezone for the cron job.
216
+ */
217
+ timezone?: string;
218
+ /**
219
+ * The UTC offset for the cron job, in minutes.
220
+ */
221
+ utcOffset?: number;
222
+ /**
223
+ * If true, uses AND logic when combining day-of-month and day-of-week.
224
+ * If false, uses OR logic for combining day-of-month and day-of-week (legacy behavior).
225
+ * @default false
226
+ */
227
+ domAndDow?: boolean;
228
+ /**
229
+ * Offset the scheduled date by a number of days.
230
+ * Positive values shift the date forward, negative values shift it backward.
231
+ * For example, dayOffset: -1 schedules the job one day before the pattern match.
232
+ * @default 0
233
+ */
234
+ dayOffset?: number;
235
+ /**
236
+ * @deprecated Use domAndDow instead. This option will be removed in a future version.
237
+ * If true, enables legacy mode (OR logic) for compatibility with older cron implementations.
238
+ * @default true
239
+ */
240
+ legacyMode?: boolean;
241
+ /**
242
+ * Specifies the cron pattern mode to use for parsing and execution.
243
+ *
244
+ * - "auto": Automatically detect pattern format (default behavior)
245
+ * - "5-part": Traditional 5-field cron (minute-level precision, seconds forced to 0, years wildcarded)
246
+ * - "6-part": Extended 6-field cron (second-level precision, years wildcarded)
247
+ * - "7-part": Full 7-field cron (second-level and year-specific precision)
248
+ * - "5-or-6-parts": Accept 5 or 6 field patterns (years wildcarded)
249
+ * - "6-or-7-parts": Accept 6 or 7 field patterns (no additional constraints)
250
+ *
251
+ * @default "auto"
252
+ */
253
+ mode?: CronMode;
254
+ /**
255
+ * An optional context object that will be passed to the job function.
256
+ */
257
+ context?: T;
258
+ /**
259
+ * If true, enables alternative weekday numbering (Quartz mode).
260
+ * In standard mode (false): Sunday=0, Monday=1, ..., Saturday=6
261
+ * In Quartz mode (true): Sunday=1, Monday=2, ..., Saturday=7
262
+ * @default false
263
+ */
264
+ alternativeWeekdays?: boolean;
265
+ /**
266
+ * If true, allows non-standard stepping formats for backward compatibility.
267
+ * When false (default), only wildcard (*\/step) or range (min-max\/step) formats are allowed.
268
+ * When true, allows numeric prefix formats like /10, 5/5, 30/30.
269
+ * @default false
270
+ */
271
+ sloppyRanges?: boolean;
272
+ /**
273
+ * If true, date-based jobs scheduled in the past will fire immediately.
274
+ * If false, only jobs scheduled within the past second will fire immediately (to handle timing edge cases).
275
+ * Jobs scheduled more than 1 second in the past will be rejected unless this is true.
276
+ * @default false
277
+ */
278
+ allowPast?: boolean;
280
279
  }
280
+
281
281
  /**
282
282
  * Converts date to CronDate
283
283
  *
284
284
  * @param d Input date, if using string representation ISO 8001 (2015-11-24T19:40:00) local timezone is expected
285
285
  * @param tz String representation of target timezone in Europe/Stockholm format, or a number representing offset in minutes.
286
286
  */
287
- export declare class CronDate<T = undefined> {
288
- tz: string | number | undefined;
289
- /**
290
- * Optional UTC ms threshold for resolving DST overlap ambiguity.
291
- * When set, getTime()/getDate() will return the earliest occurrence
292
- * that is at or after this threshold.
293
- * @private
294
- */
295
- private afterMs?;
296
- /**
297
- * Current milliseconds
298
- * @type {number}
299
- */
300
- ms: number;
301
- /**
302
- * Current second (0-59), in local time or target timezone specified by `this.tz`
303
- * @type {number}
304
- */
305
- second: number;
306
- /**
307
- * Current minute (0-59), in local time or target timezone specified by `this.tz`
308
- * @type {number}
309
- */
310
- minute: number;
311
- /**
312
- * Current hour (0-23), in local time or target timezone specified by `this.tz`
313
- * @type {number}
314
- */
315
- hour: number;
316
- /**
317
- * Current day (1-31), in local time or target timezone specified by `this.tz`
318
- * @type {number}
319
- */
320
- day: number;
321
- /**
322
- * Current month (1-12), in local time or target timezone specified by `this.tz`
323
- * @type {number}
324
- */
325
- month: number;
326
- /**
327
- * Current full year, in local time or target timezone specified by `this.tz`
328
- */
329
- year: number;
330
- constructor(d?: CronDate<T> | Date | string | null, tz?: string | number);
331
- /**
332
- * Calculates the last day of a given month.
333
- * Uses a performance optimization for months other than February.
334
- *
335
- * @param year The year
336
- * @param month The month (0-11)
337
- * @returns The last day of the month (1-31)
338
- * @private
339
- */
340
- private getLastDayOfMonth;
341
- /**
342
- * Calculates the last weekday (Mon-Fri) of a given month.
343
- *
344
- * @param year The target year.
345
- * @param month The target month (0-11).
346
- * @returns The day of the month (1-31) that is the last weekday.
347
- * @private
348
- */
349
- private getLastWeekday;
350
- /**
351
- * Calculates the nearest weekday (Mon-Fri) to a given day of the month.
352
- * Handles month boundaries.
353
- *
354
- * @param year The target year.
355
- * @param month The target month (0-11).
356
- * @param day The target day (1-31).
357
- * @returns The day of the month (1-31) that is the nearest weekday, or -1 if the day doesn't exist in the month.
358
- */
359
- private getNearestWeekday;
360
- /**
361
- * Check if the given date is the nth occurrence of a weekday in its month.
362
- *
363
- * @param year The year.
364
- * @param month The month (0 for January, 11 for December).
365
- * @param day The day of the month.
366
- * @param nth The nth occurrence (bitmask).
367
- *
368
- * @return True if the date is the nth occurrence of its weekday, false otherwise.
369
- */
370
- private isNthWeekdayOfMonth;
371
- /**
372
- * Sets internals using a Date
373
- */
374
- private fromDate;
375
- /**
376
- * Sets internals by deep copying another CronDate
377
- *
378
- * @param {CronDate} d - Input date
379
- */
380
- private fromCronDate;
381
- /**
382
- * Reset internal parameters (seconds, minutes, hours) if any of them have exceeded (or could have exceeded) their normal ranges
383
- *
384
- * Will alway return true on february 29th, as that is a date that _could_ be out of bounds
385
- */
386
- private apply;
387
- /**
388
- * Sets internals by parsing a string
389
- */
390
- private fromString;
391
- /**
392
- * Find next match of current part
393
- */
394
- private findNext;
395
- /**
396
- * Internal unified method to find a matching time component in either direction.
397
- * This method searches through the pattern to find the next or previous valid value
398
- * for the specified target component (second, minute, hour, day, or month).
399
- *
400
- * @param options Cron options
401
- * @param target Target property (second, minute, hour, day, month)
402
- * @param pattern Pattern to use
403
- * @param offset Offset to use
404
- * @param direction 1 for forward (next), -1 for backward (previous)
405
- * @returns Status code: 1 = same value matches, 2 = value changed, 3 = no match found
406
- *
407
- * @private
408
- */
409
- private _findMatch;
410
- /**
411
- * Increment to next run time recursively.
412
- *
413
- * This function traverses the date components (year, month, day, hour, minute, second)
414
- * to find the next date and time that matches the cron pattern. It uses a recursive
415
- * approach to handle the dependencies between different components. For example,
416
- * if the day changes, the hour, minute, and second need to be reset.
417
- *
418
- * The recursion is limited to the year 10000 to prevent potential
419
- * infinite loops or excessive stack depth, and to match the maximum supported
420
- * year in OCPS 1.2 (years 1-9999).
421
- *
422
- * @param pattern The cron pattern used to determine the next run time.
423
- * @param options The cron options that influence the incrementing behavior.
424
- * @param doing The index of the `RecursionSteps` array indicating the current
425
- * date component being processed. 0 represents "month", 1 represents "day", etc.
426
- *
427
- * @returns This `CronDate` instance for chaining, or null if incrementing
428
- * was not possible (e.g., reached year 10000 limit or no matching date).
429
- *
430
- * @private
431
- */
432
- private recurse;
433
- /**
434
- * Increment to next run time
435
- *
436
- * @param pattern The pattern used to increment the current date.
437
- * @param options Cron options used for incrementing.
438
- * @param hasPreviousRun True if there was a previous run, false otherwise. This is used to determine whether to apply the minimum interval.
439
- * @returns This CronDate instance for chaining, or null if incrementing was not possible (e.g., reached year 3000 limit).
440
- */
441
- increment(pattern: CronPattern, options: CronOptions<T>, hasPreviousRun: boolean): CronDate<T> | null;
442
- /**
443
- * Decrement to previous run time
444
- *
445
- * @param pattern The pattern used to decrement the current date.
446
- * @param options Cron options used for decrementing.
447
- * @returns This CronDate instance for chaining, or null if decrementing was not possible (e.g., reached year 0).
448
- */
449
- decrement(pattern: CronPattern, options: CronOptions<T>): CronDate<T> | null;
450
- /**
451
- * Find previous match by recursively checking pattern parts in reverse.
452
- *
453
- * This is the backward equivalent of the recurse() method. It searches backwards
454
- * through time to find the previous date/time that matches the cron pattern.
455
- *
456
- * @param pattern The cron pattern used to determine the previous run time.
457
- * @param options The cron options that influence the decrementing behavior.
458
- * @param doing The index of the `RecursionSteps` array indicating the current
459
- * date component being processed.
460
- *
461
- * @returns This `CronDate` instance for chaining, or null if decrementing
462
- * was not possible (e.g., reached year 0 or no matching date).
463
- *
464
- * @private
465
- */
466
- private recurseBackward;
467
- /**
468
- * Get the maximum value in a pattern for a given target.
469
- * Used when resetting components during backward recursion.
470
- *
471
- * @param target The target component (second, minute, hour, day, month)
472
- * @param pattern The cron pattern
473
- * @param offset The offset to apply
474
- * @returns The maximum valid value for the target component
475
- *
476
- * @private
477
- */
478
- private getMaxPatternValue;
479
- /**
480
- * Find previous match for a specific component going backwards in time.
481
- * This is the backward equivalent of the findNext() method.
482
- *
483
- * @param options Cron options
484
- * @param target Target property (second, minute, hour, day, month)
485
- * @param pattern Pattern to use
486
- * @param offset Offset to use
487
- * @returns Status code: 1 = same value matches, 2 = value changed to earlier value, 3 = no match found
488
- *
489
- * @private
490
- */
491
- private findPrevious;
492
- /**
493
- * Convert current state back to a javascript Date()
494
- *
495
- * @param internal If this is an internal call
496
- * @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
497
- */
498
- getDate(internal?: boolean, afterMs?: number): Date;
499
- /**
500
- * Convert current state back to a javascript Date() and return UTC milliseconds
501
- *
502
- * @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
503
- */
504
- getTime(afterMs?: number): number;
505
- /**
506
- * Set the afterMs threshold for DST overlap resolution.
507
- * When set, getTime()/getDate() will return the earliest occurrence
508
- * that is at or after this threshold.
509
- *
510
- * @param ms UTC milliseconds threshold
511
- */
512
- setAfterMs(ms: number): void;
513
- /**
514
- * Check if the current CronDate matches a cron pattern
515
- *
516
- * @param pattern The cron pattern to match against
517
- * @param options The cron options that influence matching
518
- * @returns true if the date matches the pattern, false otherwise
519
- */
520
- match(pattern: CronPattern, options: CronOptions<T>): boolean;
287
+ declare class CronDate<T = undefined> {
288
+ tz: string | number | undefined;
289
+ /**
290
+ * Optional UTC ms threshold for resolving DST overlap ambiguity.
291
+ * When set, getTime()/getDate() will return the earliest occurrence
292
+ * that is at or after this threshold.
293
+ * @private
294
+ */
295
+ private afterMs?;
296
+ /**
297
+ * Current milliseconds
298
+ * @type {number}
299
+ */
300
+ ms: number;
301
+ /**
302
+ * Current second (0-59), in local time or target timezone specified by `this.tz`
303
+ * @type {number}
304
+ */
305
+ second: number;
306
+ /**
307
+ * Current minute (0-59), in local time or target timezone specified by `this.tz`
308
+ * @type {number}
309
+ */
310
+ minute: number;
311
+ /**
312
+ * Current hour (0-23), in local time or target timezone specified by `this.tz`
313
+ * @type {number}
314
+ */
315
+ hour: number;
316
+ /**
317
+ * Current day (1-31), in local time or target timezone specified by `this.tz`
318
+ * @type {number}
319
+ */
320
+ day: number;
321
+ /**
322
+ * Current month (1-12), in local time or target timezone specified by `this.tz`
323
+ * @type {number}
324
+ */
325
+ month: number;
326
+ /**
327
+ * Current full year, in local time or target timezone specified by `this.tz`
328
+ */
329
+ year: number;
330
+ constructor(d?: CronDate<T> | Date | string | null, tz?: string | number);
331
+ /**
332
+ * Calculates the last day of a given month.
333
+ * Uses a performance optimization for months other than February.
334
+ *
335
+ * @param year The year
336
+ * @param month The month (0-11)
337
+ * @returns The last day of the month (1-31)
338
+ * @private
339
+ */
340
+ private getLastDayOfMonth;
341
+ /**
342
+ * Calculates the last weekday (Mon-Fri) of a given month.
343
+ *
344
+ * @param year The target year.
345
+ * @param month The target month (0-11).
346
+ * @returns The day of the month (1-31) that is the last weekday.
347
+ * @private
348
+ */
349
+ private getLastWeekday;
350
+ /**
351
+ * Calculates the nearest weekday (Mon-Fri) to a given day of the month.
352
+ * Handles month boundaries.
353
+ *
354
+ * @param year The target year.
355
+ * @param month The target month (0-11).
356
+ * @param day The target day (1-31).
357
+ * @returns The day of the month (1-31) that is the nearest weekday, or -1 if the day doesn't exist in the month.
358
+ */
359
+ private getNearestWeekday;
360
+ /**
361
+ * Check if the given date is the nth occurrence of a weekday in its month.
362
+ *
363
+ * @param year The year.
364
+ * @param month The month (0 for January, 11 for December).
365
+ * @param day The day of the month.
366
+ * @param nth The nth occurrence (bitmask).
367
+ *
368
+ * @return True if the date is the nth occurrence of its weekday, false otherwise.
369
+ */
370
+ private isNthWeekdayOfMonth;
371
+ /**
372
+ * Sets internals using a Date
373
+ */
374
+ private fromDate;
375
+ /**
376
+ * Sets internals by deep copying another CronDate
377
+ *
378
+ * @param {CronDate} d - Input date
379
+ */
380
+ private fromCronDate;
381
+ /**
382
+ * Reset internal parameters (seconds, minutes, hours) if any of them have exceeded (or could have exceeded) their normal ranges
383
+ *
384
+ * Will alway return true on february 29th, as that is a date that _could_ be out of bounds
385
+ */
386
+ private apply;
387
+ /**
388
+ * Sets internals by parsing a string
389
+ */
390
+ private fromString;
391
+ /**
392
+ * Find next match of current part
393
+ */
394
+ private findNext;
395
+ /**
396
+ * Internal unified method to find a matching time component in either direction.
397
+ * This method searches through the pattern to find the next or previous valid value
398
+ * for the specified target component (second, minute, hour, day, or month).
399
+ *
400
+ * @param options Cron options
401
+ * @param target Target property (second, minute, hour, day, month)
402
+ * @param pattern Pattern to use
403
+ * @param offset Offset to use
404
+ * @param direction 1 for forward (next), -1 for backward (previous)
405
+ * @returns Status code: 1 = same value matches, 2 = value changed, 3 = no match found
406
+ *
407
+ * @private
408
+ */
409
+ private _findMatch;
410
+ /**
411
+ * Increment to next run time recursively.
412
+ *
413
+ * This function traverses the date components (year, month, day, hour, minute, second)
414
+ * to find the next date and time that matches the cron pattern. It uses a recursive
415
+ * approach to handle the dependencies between different components. For example,
416
+ * if the day changes, the hour, minute, and second need to be reset.
417
+ *
418
+ * The recursion is limited to the year 10000 to prevent potential
419
+ * infinite loops or excessive stack depth, and to match the maximum supported
420
+ * year in OCPS 1.2 (years 1-9999).
421
+ *
422
+ * @param pattern The cron pattern used to determine the next run time.
423
+ * @param options The cron options that influence the incrementing behavior.
424
+ * @param doing The index of the `RecursionSteps` array indicating the current
425
+ * date component being processed. 0 represents "month", 1 represents "day", etc.
426
+ *
427
+ * @returns This `CronDate` instance for chaining, or null if incrementing
428
+ * was not possible (e.g., reached year 10000 limit or no matching date).
429
+ *
430
+ * @private
431
+ */
432
+ private recurse;
433
+ /**
434
+ * Increment to next run time
435
+ *
436
+ * @param pattern The pattern used to increment the current date.
437
+ * @param options Cron options used for incrementing.
438
+ * @param hasPreviousRun True if there was a previous run, false otherwise. This is used to determine whether to apply the minimum interval.
439
+ * @returns This CronDate instance for chaining, or null if incrementing was not possible (e.g., reached year 3000 limit).
440
+ */
441
+ increment(pattern: CronPattern, options: CronOptions<T>, hasPreviousRun: boolean): CronDate<T> | null;
442
+ /**
443
+ * Decrement to previous run time
444
+ *
445
+ * @param pattern The pattern used to decrement the current date.
446
+ * @param options Cron options used for decrementing.
447
+ * @returns This CronDate instance for chaining, or null if decrementing was not possible (e.g., reached year 0).
448
+ */
449
+ decrement(pattern: CronPattern, options: CronOptions<T>): CronDate<T> | null;
450
+ /**
451
+ * Find previous match by recursively checking pattern parts in reverse.
452
+ *
453
+ * This is the backward equivalent of the recurse() method. It searches backwards
454
+ * through time to find the previous date/time that matches the cron pattern.
455
+ *
456
+ * @param pattern The cron pattern used to determine the previous run time.
457
+ * @param options The cron options that influence the decrementing behavior.
458
+ * @param doing The index of the `RecursionSteps` array indicating the current
459
+ * date component being processed.
460
+ *
461
+ * @returns This `CronDate` instance for chaining, or null if decrementing
462
+ * was not possible (e.g., reached year 0 or no matching date).
463
+ *
464
+ * @private
465
+ */
466
+ private recurseBackward;
467
+ /**
468
+ * Get the maximum value in a pattern for a given target.
469
+ * Used when resetting components during backward recursion.
470
+ *
471
+ * @param target The target component (second, minute, hour, day, month)
472
+ * @param pattern The cron pattern
473
+ * @param offset The offset to apply
474
+ * @returns The maximum valid value for the target component
475
+ *
476
+ * @private
477
+ */
478
+ private getMaxPatternValue;
479
+ /**
480
+ * Find previous match for a specific component going backwards in time.
481
+ * This is the backward equivalent of the findNext() method.
482
+ *
483
+ * @param options Cron options
484
+ * @param target Target property (second, minute, hour, day, month)
485
+ * @param pattern Pattern to use
486
+ * @param offset Offset to use
487
+ * @returns Status code: 1 = same value matches, 2 = value changed to earlier value, 3 = no match found
488
+ *
489
+ * @private
490
+ */
491
+ private findPrevious;
492
+ /**
493
+ * Convert current state back to a javascript Date()
494
+ *
495
+ * @param internal If this is an internal call
496
+ * @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
497
+ */
498
+ getDate(internal?: boolean, afterMs?: number): Date;
499
+ /**
500
+ * Convert current state back to a javascript Date() and return UTC milliseconds
501
+ *
502
+ * @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
503
+ */
504
+ getTime(afterMs?: number): number;
505
+ /**
506
+ * Set the afterMs threshold for DST overlap resolution.
507
+ * When set, getTime()/getDate() will return the earliest occurrence
508
+ * that is at or after this threshold.
509
+ *
510
+ * @param ms UTC milliseconds threshold
511
+ */
512
+ setAfterMs(ms: number): void;
513
+ /**
514
+ * Check if the current CronDate matches a cron pattern
515
+ *
516
+ * @param pattern The cron pattern to match against
517
+ * @param options The cron options that influence matching
518
+ * @returns true if the date matches the pattern, false otherwise
519
+ */
520
+ match(pattern: CronPattern, options: CronOptions<T>): boolean;
521
521
  }
522
+
522
523
  /**
523
524
  * An array containing all named cron jobs.
524
525
  */
525
- export declare const scheduledJobs: Cron<any>[];
526
+ declare const scheduledJobs: Cron<any>[];
526
527
  /**
527
528
  * Callback function type
528
529
  *
@@ -531,7 +532,7 @@ export declare const scheduledJobs: Cron<any>[];
531
532
  *
532
533
  * @returns void or Promise<void> for async callbacks
533
534
  */
534
- export type CronCallback<T = undefined> = (self: InstanceType<typeof Cron<T>>, context: T) => void | Promise<void>;
535
+ type CronCallback<T = undefined> = (self: InstanceType<typeof Cron<T>>, context: T) => void | Promise<void>;
535
536
  /**
536
537
  * Cron entrypoint
537
538
  *
@@ -540,188 +541,190 @@ export type CronCallback<T = undefined> = (self: InstanceType<typeof Cron<T>>, c
540
541
  * @param [fnOrOptions1] - Options or function to be run each iteration of pattern
541
542
  * @param [fnOrOptions2] - Options or function to be run each iteration of pattern
542
543
  */
543
- export declare class Cron<T = undefined> {
544
- name: string | undefined;
545
- options: CronOptions<T>;
546
- private _states;
547
- private fn?;
548
- /**
549
- * Internal helper to get the timezone or UTC offset for date operations.
550
- * Reduces duplication of `this.options.timezone || this.options.utcOffset` throughout the codebase.
551
- *
552
- * @returns The timezone string or UTC offset number
553
- * @private
554
- */
555
- private getTz;
556
- /**
557
- * Internal helper to apply dayOffset to a date if configured.
558
- * Reduces duplication of dayOffset calculation logic.
559
- *
560
- * @param date - The base date to apply offset to
561
- * @returns The date with dayOffset applied, or the original date if no offset is configured
562
- * @private
563
- */
564
- private applyDayOffset;
565
- constructor(pattern: string | Date, fnOrOptions1?: CronOptions<T> | CronCallback<T>, fnOrOptions2?: CronOptions<T> | CronCallback<T>);
566
- /**
567
- * Find next runtime, based on supplied date. Strips milliseconds.
568
- *
569
- * @param prev - Optional. Date to start from. Can be a CronDate, Date object, or a string representing a date.
570
- * @returns The next run time as a Date object, or null if there is no next run.
571
- */
572
- nextRun(prev?: CronDate<T> | Date | string | null): Date | null;
573
- /**
574
- * Find next n runs, based on supplied date. Strips milliseconds.
575
- *
576
- * @param n - Number of runs to enumerate
577
- * @param previous - Date to start from
578
- * @returns - Next n run times
579
- */
580
- nextRuns(n: number, previous?: Date | string): Date[];
581
- /**
582
- * Find previous n runs, based on supplied date. Strips milliseconds.
583
- *
584
- * @param n - Number of runs to enumerate
585
- * @param reference - Date to start from (defaults to now)
586
- * @returns - Previous n run times in reverse chronological order (most recent first)
587
- */
588
- previousRuns(n: number, reference?: Date | string): Date[];
589
- /**
590
- * Create a stateful iterator for sequential date traversal of this schedule.
591
- *
592
- * Returns a {@link CronIterator} that implements both the ECMAScript Iterator and
593
- * Iterable protocols, enabling `for...of` loops and destructuring assignment.
594
- *
595
- * @param startAt - Optional. The date to start iterating from. Defaults to current time.
596
- * @returns A new CronIterator instance
597
- */
598
- enumerate(startAt?: Date | string | null): CronIterator<T>;
599
- /**
600
- * Internal helper to enumerate runs in either direction.
601
- *
602
- * @param n - Number of runs to enumerate
603
- * @param startDate - Date to start from
604
- * @param direction - Direction to enumerate ("next" or "previous")
605
- * @returns Array of run times with dayOffset applied
606
- * @private
607
- */
608
- private _enumerateRuns;
609
- /**
610
- * Check if a given date matches the cron pattern
611
- *
612
- * @param date - Date to check. Can be a Date object or a string representing a date.
613
- * @returns true if the date matches the pattern, false otherwise
614
- */
615
- match(date: Date | string): boolean;
616
- /**
617
- * Return the original pattern, if there was one.
618
- * Returns undefined when the job was created with a Date or ISO 8601 string instead of a cron pattern.
619
- *
620
- * @returns Original cron pattern, or undefined for date-based jobs
621
- */
622
- getPattern(): string | undefined;
623
- /**
624
- * Return the original run-once date, if there was one
625
- *
626
- * @returns Original run-once date, or null if not a run-once job
627
- */
628
- getOnce(): Date | null;
629
- /**
630
- * Indicates whether or not the cron job is scheduled and running, e.g. awaiting next trigger
631
- *
632
- * @returns Running or not
633
- */
634
- isRunning(): boolean;
635
- /**
636
- * Indicates whether or not the cron job is permanently stopped
637
- *
638
- * @returns Running or not
639
- */
640
- isStopped(): boolean;
641
- /**
642
- * Indicates whether or not the cron job is currently working
643
- *
644
- * @returns Running or not
645
- */
646
- isBusy(): boolean;
647
- /**
648
- * Return current/previous run start time
649
- *
650
- * @returns Current (if running) or previous run time
651
- */
652
- currentRun(): Date | null;
653
- /**
654
- * Return previous run start time
655
- *
656
- * @returns Previous run time
657
- */
658
- previousRun(): Date | null;
659
- /**
660
- * Returns number of milliseconds to next run
661
- *
662
- * @param prev Starting date, defaults to now - minimum interval
663
- */
664
- msToNext(prev?: CronDate<T> | Date | string): number | null;
665
- /**
666
- * Stop execution
667
- *
668
- * Running this will forcefully stop the job, and prevent furter exection. `.resume()` will not work after stopping.
669
- * It will also be removed from the scheduledJobs array if it were named.
670
- */
671
- stop(): void;
672
- /**
673
- * Pause execution
674
- *
675
- * @returns Wether pause was successful
676
- */
677
- pause(): boolean;
678
- /**
679
- * Resume execution
680
- *
681
- * @returns Wether resume was successful
682
- */
683
- resume(): boolean;
684
- /**
685
- * Schedule a new job
686
- *
687
- * @param func - Function to be run each iteration of pattern
688
- */
689
- schedule(func?: CronCallback<T>): Cron<T>;
690
- /**
691
- * Internal function to trigger a run, used by both scheduled and manual trigger
692
- */
693
- private _trigger;
694
- /**
695
- * Trigger a run manually
696
- */
697
- trigger(): Promise<void>;
698
- /**
699
- * Returns number of runs left, undefined = unlimited
700
- */
701
- runsLeft(): number | undefined;
702
- /**
703
- * Called when it's time to trigger.
704
- * Checks if all conditions are currently met,
705
- * then instantly triggers the scheduled function.
706
- */
707
- private _checkTrigger;
708
- /**
709
- * Internal version of next. Cron needs millseconds internally, hence _next.
710
- */
711
- private _next;
712
- /**
713
- * Internal version of previous. Finds the previous scheduled run time.
714
- *
715
- * @param referenceDate - Optional reference date to search backwards from (defaults to now)
716
- * @returns Previous scheduled run time, or null if no previous run exists
717
- */
718
- private _previous;
719
- /**
720
- * Calculate the previous run if no previous run is supplied, but startAt and interval are set.
721
- * This calculation is only necessary if the startAt time is before the current time.
722
- * Should only be called from the _next function.
723
- */
724
- private _calculatePreviousRun;
544
+ declare class Cron<T = undefined> {
545
+ name: string | undefined;
546
+ options: CronOptions<T>;
547
+ private _states;
548
+ private fn?;
549
+ /**
550
+ * Internal helper to get the timezone or UTC offset for date operations.
551
+ * Reduces duplication of `this.options.timezone || this.options.utcOffset` throughout the codebase.
552
+ *
553
+ * @returns The timezone string or UTC offset number
554
+ * @private
555
+ */
556
+ private getTz;
557
+ /**
558
+ * Internal helper to apply dayOffset to a date if configured.
559
+ * Reduces duplication of dayOffset calculation logic.
560
+ *
561
+ * @param date - The base date to apply offset to
562
+ * @returns The date with dayOffset applied, or the original date if no offset is configured
563
+ * @private
564
+ */
565
+ private applyDayOffset;
566
+ private _nextTarget;
567
+ constructor(pattern: string | Date, fnOrOptions1?: CronOptions<T> | CronCallback<T>, fnOrOptions2?: CronOptions<T> | CronCallback<T>);
568
+ /**
569
+ * Find next runtime, based on supplied date. Strips milliseconds.
570
+ *
571
+ * @param prev - Optional. Date to start from. Can be a CronDate, Date object, or a string representing a date.
572
+ * @returns The next run time as a Date object, or null if there is no next run.
573
+ */
574
+ nextRun(prev?: CronDate<T> | Date | string | null): Date | null;
575
+ /**
576
+ * Find next n runs, based on supplied date. Strips milliseconds.
577
+ *
578
+ * @param n - Number of runs to enumerate
579
+ * @param previous - Date to start from
580
+ * @returns - Next n run times
581
+ */
582
+ nextRuns(n: number, previous?: Date | string): Date[];
583
+ /**
584
+ * Find previous n runs, based on supplied date. Strips milliseconds.
585
+ *
586
+ * @param n - Number of runs to enumerate
587
+ * @param reference - Date to start from (defaults to now)
588
+ * @returns - Previous n run times in reverse chronological order (most recent first)
589
+ */
590
+ previousRuns(n: number, reference?: Date | string): Date[];
591
+ /**
592
+ * Create a stateful iterator for sequential date traversal of this schedule.
593
+ *
594
+ * Returns a {@link CronIterator} that implements both the ECMAScript Iterator and
595
+ * Iterable protocols, enabling `for...of` loops and destructuring assignment.
596
+ *
597
+ * @param startAt - Optional. The date to start iterating from. Defaults to current time.
598
+ * @returns A new CronIterator instance
599
+ */
600
+ enumerate(startAt?: Date | string | null): CronIterator<T>;
601
+ /**
602
+ * Internal helper to enumerate runs in either direction.
603
+ *
604
+ * @param n - Number of runs to enumerate
605
+ * @param startDate - Date to start from
606
+ * @param direction - Direction to enumerate ("next" or "previous")
607
+ * @returns Array of run times with dayOffset applied
608
+ * @private
609
+ */
610
+ private _enumerateRuns;
611
+ /**
612
+ * Check if a given date matches the cron pattern
613
+ *
614
+ * @param date - Date to check. Can be a Date object or a string representing a date.
615
+ * @returns true if the date matches the pattern, false otherwise
616
+ */
617
+ match(date: Date | string): boolean;
618
+ /**
619
+ * Return the original pattern, if there was one.
620
+ * Returns undefined when the job was created with a Date or ISO 8601 string instead of a cron pattern.
621
+ *
622
+ * @returns Original cron pattern, or undefined for date-based jobs
623
+ */
624
+ getPattern(): string | undefined;
625
+ /**
626
+ * Return the original run-once date, if there was one
627
+ *
628
+ * @returns Original run-once date, or null if not a run-once job
629
+ */
630
+ getOnce(): Date | null;
631
+ /**
632
+ * Indicates whether or not the cron job is scheduled and running, e.g. awaiting next trigger
633
+ *
634
+ * @returns Running or not
635
+ */
636
+ isRunning(): boolean;
637
+ /**
638
+ * Indicates whether or not the cron job is permanently stopped
639
+ *
640
+ * @returns Running or not
641
+ */
642
+ isStopped(): boolean;
643
+ /**
644
+ * Indicates whether or not the cron job is currently working
645
+ *
646
+ * @returns Running or not
647
+ */
648
+ isBusy(): boolean;
649
+ /**
650
+ * Return current/previous run start time
651
+ *
652
+ * @returns Current (if running) or previous run time
653
+ */
654
+ currentRun(): Date | null;
655
+ /**
656
+ * Return previous run start time
657
+ *
658
+ * @returns Previous run time
659
+ */
660
+ previousRun(): Date | null;
661
+ /**
662
+ * Returns number of milliseconds to next run
663
+ *
664
+ * @param prev Starting date, defaults to now - minimum interval
665
+ */
666
+ msToNext(prev?: CronDate<T> | Date | string): number | null;
667
+ /**
668
+ * Stop execution
669
+ *
670
+ * Running this will forcefully stop the job, and prevent furter exection. `.resume()` will not work after stopping.
671
+ * It will also be removed from the scheduledJobs array if it were named.
672
+ */
673
+ stop(): void;
674
+ /**
675
+ * Pause execution
676
+ *
677
+ * @returns Wether pause was successful
678
+ */
679
+ pause(): boolean;
680
+ /**
681
+ * Resume execution
682
+ *
683
+ * @returns Wether resume was successful
684
+ */
685
+ resume(): boolean;
686
+ /**
687
+ * Schedule a new job
688
+ *
689
+ * @param func - Function to be run each iteration of pattern
690
+ */
691
+ schedule(func?: CronCallback<T>): Cron<T>;
692
+ private _schedule;
693
+ /**
694
+ * Internal function to trigger a run, used by both scheduled and manual trigger
695
+ */
696
+ private _trigger;
697
+ /**
698
+ * Trigger a run manually
699
+ */
700
+ trigger(): Promise<void>;
701
+ /**
702
+ * Returns number of runs left, undefined = unlimited
703
+ */
704
+ runsLeft(): number | undefined;
705
+ /**
706
+ * Called when it's time to trigger.
707
+ * Checks if all conditions are currently met,
708
+ * then instantly triggers the scheduled function.
709
+ */
710
+ private _checkTrigger;
711
+ /**
712
+ * Internal version of next. Cron needs millseconds internally, hence _next.
713
+ */
714
+ private _next;
715
+ /**
716
+ * Internal version of previous. Finds the previous scheduled run time.
717
+ *
718
+ * @param referenceDate - Optional reference date to search backwards from (defaults to now)
719
+ * @returns Previous scheduled run time, or null if no previous run exists
720
+ */
721
+ private _previous;
722
+ /**
723
+ * Calculate the previous run if no previous run is supplied, but startAt and interval are set.
724
+ * This calculation is only necessary if the startAt time is before the current time.
725
+ * Should only be called from the _next function.
726
+ */
727
+ private _calculatePreviousRun;
725
728
  }
726
729
  /**
727
730
  * Stateful iterator for sequential date traversal of a Cron schedule.
@@ -731,46 +734,47 @@ export declare class Cron<T = undefined> {
731
734
  *
732
735
  * Obtain an instance via {@link Cron#enumerate}.
733
736
  */
734
- export declare class CronIterator<T = undefined> implements Iterator<Date, undefined>, Iterable<Date> {
735
- private cron;
736
- private cursor;
737
- private done;
738
- /**
739
- * @param cron - The Cron instance to iterate over
740
- * @param startAt - Optional starting date for iteration. Defaults to current time if omitted.
741
- */
742
- constructor(cron: Cron<T>, startAt?: Date | string | null);
743
- /**
744
- * Normalizes a cursor argument: Date objects are cloned to prevent external mutation;
745
- * strings are preserved as-is so that nextRun() can parse them using the Cron instance's
746
- * configured timezone (via CronDate/fromTZISO), matching the behaviour of nextRun() and nextRuns().
747
- * @private
748
- */
749
- private static _normalizeCursor;
750
- /**
751
- * Returns the next scheduled date and advances the cursor.
752
- * Implements the ECMAScript Iterator protocol.
753
- *
754
- * @returns `{ value: Date, done: false }` for the next occurrence,
755
- * or `{ value: undefined, done: true }` when the schedule is exhausted.
756
- */
757
- next(): IteratorResult<Date, undefined>;
758
- /**
759
- * Returns the next scheduled date without advancing the cursor.
760
- *
761
- * @returns The next scheduled date, or null if the schedule is exhausted.
762
- */
763
- peek(): Date | null;
764
- /**
765
- * Resets the cursor, optionally to a new starting date.
766
- *
767
- * @param newStartAt - New starting date. Defaults to current time if omitted.
768
- */
769
- reset(newStartAt?: Date | string | null): void;
770
- /**
771
- * Implements the ECMAScript Iterable protocol, enabling `for...of` and destructuring.
772
- */
773
- [Symbol.iterator](): CronIterator<T>;
737
+ declare class CronIterator<T = undefined> implements Iterator<Date, undefined>, Iterable<Date> {
738
+ private cron;
739
+ private cursor;
740
+ private done;
741
+ /**
742
+ * @param cron - The Cron instance to iterate over
743
+ * @param startAt - Optional starting date for iteration. Defaults to current time if omitted.
744
+ */
745
+ constructor(cron: Cron<T>, startAt?: Date | string | null);
746
+ /**
747
+ * Normalizes a cursor argument: Date objects are cloned to prevent external mutation;
748
+ * strings are preserved as-is so that nextRun() can parse them using the Cron instance's
749
+ * configured timezone (via CronDate/fromTZISO), matching the behaviour of nextRun() and nextRuns().
750
+ * @private
751
+ */
752
+ private static _normalizeCursor;
753
+ /**
754
+ * Returns the next scheduled date and advances the cursor.
755
+ * Implements the ECMAScript Iterator protocol.
756
+ *
757
+ * @returns `{ value: Date, done: false }` for the next occurrence,
758
+ * or `{ value: undefined, done: true }` when the schedule is exhausted.
759
+ */
760
+ next(): IteratorResult<Date, undefined>;
761
+ /**
762
+ * Returns the next scheduled date without advancing the cursor.
763
+ *
764
+ * @returns The next scheduled date, or null if the schedule is exhausted.
765
+ */
766
+ peek(): Date | null;
767
+ /**
768
+ * Resets the cursor, optionally to a new starting date.
769
+ *
770
+ * @param newStartAt - New starting date. Defaults to current time if omitted.
771
+ */
772
+ reset(newStartAt?: Date | string | null): void;
773
+ /**
774
+ * Implements the ECMAScript Iterable protocol, enabling `for...of` and destructuring.
775
+ */
776
+ [Symbol.iterator](): CronIterator<T>;
774
777
  }
775
778
 
776
- export {};
779
+ export { Cron, CronDate, CronIterator, CronPattern, scheduledJobs };
780
+ export type { CatchCallbackFn, CronCallback, CronMode, CronOptions, ProtectCallbackFn };