croner 11.0.0-dev.7 → 11.0.0-dev.9
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/README.md +14 -13
- package/dist/croner.cjs +1 -1
- package/dist/croner.d.cts +100 -52
- package/dist/croner.d.ts +100 -52
- package/dist/croner.js +1 -1
- package/dist/croner.umd.js +1 -1
- package/package.json +24 -4
package/README.md
CHANGED
|
@@ -39,8 +39,8 @@ const msLeft = new Cron('59 59 23 24 DEC *').nextRun() - new Date();
|
|
|
39
39
|
console.log(Math.floor(msLeft/1000/3600/24) + " days left to next christmas eve");
|
|
40
40
|
|
|
41
41
|
// Run a function at a specific date/time using a non-local timezone (time is ISO 8601 local time)
|
|
42
|
-
// This will run
|
|
43
|
-
new Cron('
|
|
42
|
+
// This will run 2030-01-23 00:00:00 according to the time in Asia/Kolkata
|
|
43
|
+
new Cron('2030-01-23T00:00:00', { timezone: 'Asia/Kolkata' }, () => { console.log('Yay!') });
|
|
44
44
|
|
|
45
45
|
// Check if a date matches a cron pattern
|
|
46
46
|
const mondayCheck = new Cron('0 0 0 * * MON');
|
|
@@ -73,17 +73,13 @@ const { Cron } = require("croner");
|
|
|
73
73
|
Using Deno
|
|
74
74
|
|
|
75
75
|
```typescript
|
|
76
|
-
|
|
77
|
-
import { Cron } from "https://deno.land/x/croner@11.0.0-dev.7/dist/croner.js";
|
|
78
|
-
|
|
79
|
-
// ... or jsr.io
|
|
80
|
-
import { Cron } from "jsr:@hexagon/croner@11.0.0-dev.7";
|
|
76
|
+
import { Cron } from "jsr:@hexagon/croner@11.0.0-dev.9";
|
|
81
77
|
```
|
|
82
78
|
|
|
83
79
|
In a webpage using the UMD-module
|
|
84
80
|
|
|
85
81
|
```html
|
|
86
|
-
<script src="https://cdn.jsdelivr.net/npm/croner@11.0.0-dev.
|
|
82
|
+
<script src="https://cdn.jsdelivr.net/npm/croner@11.0.0-dev.9/dist/croner.umd.js"></script>
|
|
87
83
|
```
|
|
88
84
|
|
|
89
85
|
## Documentation
|
|
@@ -104,7 +100,7 @@ Cron takes three arguments
|
|
|
104
100
|
const job = new Cron("* * * * * *", { maxRuns: 1 }, () => {} );
|
|
105
101
|
|
|
106
102
|
// If function is omitted in constructor, it can be scheduled later
|
|
107
|
-
job.schedule(job, /* optional */ context) => {});
|
|
103
|
+
job.schedule((job, /* optional */ context) => {});
|
|
108
104
|
```
|
|
109
105
|
|
|
110
106
|
The job will be sceduled to run at next matching time unless you supply option `{ paused: true }`. The `new Cron(...)` constructor will return a Cron instance, later called `job`, which have a couple of methods and properties listed below.
|
|
@@ -154,8 +150,8 @@ job.name // Optional job name, populated if a name were passed to options
|
|
|
154
150
|
| maxRuns | Infinite | Number | |
|
|
155
151
|
| catch | false | Boolean\|Function | Catch unhandled errors in triggered function. Passing `true` will silently ignore errors. Passing a callback function will trigger this callback on error. |
|
|
156
152
|
| timezone | undefined | String | Timezone in Europe/Stockholm format |
|
|
157
|
-
| startAt | undefined | String | ISO 8601 formatted datetime (2021-10-17T23:43:00)<br>in local time (according to timezone
|
|
158
|
-
| stopAt | undefined | String | ISO 8601 formatted datetime (2021-10-17T23:43:00)<br>in local time (according to timezone
|
|
153
|
+
| startAt | undefined | String | ISO 8601 formatted datetime (2021-10-17T23:43:00)<br>in local time (according to the timezone or utcOffset option if passed). Inclusive, a run exactly at startAt is included |
|
|
154
|
+
| stopAt | undefined | String | ISO 8601 formatted datetime (2021-10-17T23:43:00)<br>in local time (according to the timezone or utcOffset option if passed). Exclusive, a run exactly at stopAt is not included |
|
|
159
155
|
| interval | 0 | Number | Minimum number of seconds between triggers. |
|
|
160
156
|
| paused | false | Boolean | If the job should be paused from start. |
|
|
161
157
|
| context | undefined | Any | Passed as the second parameter to triggered function |
|
|
@@ -166,7 +162,7 @@ job.name // Optional job name, populated if a name were passed to options
|
|
|
166
162
|
| protect | undefined | boolean\|Function | Enabled over-run protection. Will block new triggers as long as an old trigger is in progress. Pass either `true` or a callback function to enable |
|
|
167
163
|
| alternativeWeekdays | false | boolean | Enable Quartz-style weekday numbering (1=Sunday, 2=Monday, ..., 7=Saturday). When false (default), uses standard cron format (0=Sunday, 1=Monday, ..., 6=Saturday). |
|
|
168
164
|
| allowPast | false | boolean | If true, date-based jobs scheduled in the past will fire immediately. If false, only jobs scheduled within the past second will fire (to handle timing edge cases). |
|
|
169
|
-
| dayOffset | 0 | number | Offset the scheduled date by a number of days. Positive values shift forward, negative values shift backward. For example, `dayOffset: -1` schedules one day before the pattern match. |
|
|
165
|
+
| dayOffset | 0 | number | Offset the scheduled date by a number of days. Positive values shift forward, negative values shift backward. For example, `dayOffset: -1` schedules one day before the pattern match. `nextRun()`, `nextRuns()`, `previousRuns()`, `msToNext()`, `enumerate()`, `startAt` and `stopAt` all refer to the shifted run time. |
|
|
170
166
|
| mode | "auto" | string | Controls how the cron pattern field count is interpreted. Options: `"auto"` (detect automatically), `"5-part"` (minute-level), `"6-part"` (second-level), `"7-part"` (second+year), `"5-or-6-parts"`, `"6-or-7-parts"`. |
|
|
171
167
|
| sloppyRanges | false | boolean | If true, allows non-standard stepping formats for backward compatibility (e.g. `/10`, `5/5`, `30/30`). When false (default), only `*/step` or `min-max/step` formats are allowed. |
|
|
172
168
|
|
|
@@ -204,7 +200,12 @@ Croner uses [Vixie Cron](https://en.wikipedia.org/wiki/Cron#CRON_expression) bas
|
|
|
204
200
|
* **Enhanced logical control**:
|
|
205
201
|
- *+*: Explicit AND logic modifier. Prefix the day-of-week field with `+` to require both day-of-month AND day-of-week to match. Example: `0 12 1 * +MON` only triggers when the 1st is also a Monday.
|
|
206
202
|
- *?*: Wildcard alias (behaves identically to `*`). **Non-portable**: Its use is discouraged in patterns intended for cross-system use. Supported in all fields for compatibility, but primarily meaningful in day-of-month and day-of-week fields.
|
|
207
|
-
-
|
|
203
|
+
- DST handling, the same as [croner-rust](https://github.com/Hexagon/croner-rust) and Vixie cron, which deviates from OCPS 1.4 §4.3.1 (see below):
|
|
204
|
+
- **Fixed-time jobs**, with a single value in each of seconds, minutes and hours (e.g. `0 30 2 * * *`): A time that occurs twice (DST fall back) runs once, at the first occurrence. A time that doesn't exist (DST spring forward) runs at the first valid time after the gap, on the same day.
|
|
205
|
+
- **Interval jobs**, with a wildcard, step, range or list in seconds, minutes or hours (e.g. `*/5 * * * *` or `0 30 1,2 * * *`): A time that occurs twice runs on both occurrences, so the job keeps running through the repeated hour. A time that doesn't exist is skipped.
|
|
206
|
+
- `nextRun()`, `nextRuns()`, `previousRuns()` and `enumerate()` move in real time. They never return a time they have passed, and cover the first pass through a repeated hour before the second.
|
|
207
|
+
|
|
208
|
+
> **Deviation from OCPS 1.4:** OCPS 1.4 §4.3.1 recommends that every job skips times in a DST gap, and runs only once when a time occurs twice. The same section asks implementations to align with Vixie cron, which runs interval jobs on both occurrences and runs fixed-time jobs after a gap. Croner follows Vixie cron, as croner-rust does, so that both libraries schedule the same.
|
|
208
209
|
|
|
209
210
|
* Croner allows you to pass a JavaScript Date object or an ISO 8601 formatted string as a pattern. The scheduled function will trigger at the specified date/time and only once. If you use a timezone different from the local timezone, you should pass the ISO 8601 local time in the target location and specify the timezone using the options (2nd parameter).
|
|
210
211
|
|
package/dist/croner.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var M=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var B=(s,e)=>{for(var t in e)M(s,t,{get:e[t],enumerable:!0})},J=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of H(e))!V.call(s,n)&&n!==t&&M(s,n,{get:()=>e[n],enumerable:!(r=j(e,n))||r.enumerable});return s};var K=s=>J(M({},"__esModule",{value:!0}),s);var X={};B(X,{Cron:()=>R,CronDate:()=>c,CronIterator:()=>v,CronPattern:()=>T,scheduledJobs:()=>b});module.exports=K(X);function p(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function U(s,e){return p(y(s,e))-s.getTime()}function w(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function q(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?D(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):D(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function _(s,e,t){return N(q(s,e),t)}function N(s,e,t){let r=new Date(p(s)),n=y(r,s.tz),a=p(s),i=p(n),o=a-i,h=new Date(r.getTime()+o),l=y(h,s.tz);if(w(l,s)){let d=U(new Date(h.getTime()-864e5),s.tz)-U(new Date(h.getTime()+864e5),s.tz),g=d>0?d:36e5,E=new Date(h.getTime()-g),Y=y(E,s.tz),x=new Date(h.getTime()+g),F=y(x,s.tz),O=w(Y,s),Z=w(F,s);if(O||Z){let k=O?E:h,$=O?h:x;return t!==void 0?k.getTime()>=t?k:$:k}return h}let u=new Date(h.getTime()+p(s)-p(l)),m=y(u,s.tz);if(w(m,s))return u;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>u.getTime()?h:u}function y(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}catch(a){let i=a instanceof Error?a.message:String(a);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${i}`)}let n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let a of r)(a.type==="year"||a.type==="month"||a.type==="day"||a.type==="hour"||a.type==="minute"||a.type==="second")&&(n[a.type]=parseInt(a.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function D(s,e,t,r,n,a,i){return{y:s,m:e,d:t,h:r,i:n,s:a,tz:i}}var P=[1,2,4,8,16],T=class s{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=Array(1e4).fill(0),this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let i=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${i} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let a=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return a.fill(n);let i=t.split(",");if(i.length>1)for(let o of i)this.partToArray(e,o,r,n);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,n):t.includes("-")?this.handleRange(t,e,r,n):t.includes("/")?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,r,n){let a=this.extractNth(e,t),i=e.toUpperCase().includes("W");if(t!=="day"&&i)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");i&&(t="nearestWeekdays");let o=parseInt(a[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,a[1]||n)}setPart(e,t,r){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,r);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,a){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+a+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let a=this.extractNth(e,t),i=a[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(i===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,h,l]=i,u=parseInt(o,10)+r,m=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(u,m,d,t,e);for(let g=u;g<=m;g+=d)this.setPart(t,g,a[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let a=this.extractNth(e,t),i=a[0].split("-");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(i[0],10)+r,h=parseInt(i[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,a[1]||n)}handleStepping(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let a=this.extractNth(e,t),i=a[0].split("/");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)i[0]===""&&(i[0]="*");else{if(i[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(i[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;i[0]!=="*"&&(o=parseInt(i[0],10)+r);let h=parseInt(i[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)t==="year"&&l===0||this.setPart(t,l,a[1]||n)}replaceAlpha(e,t){let r=e;for(let[n,a]of Object.entries(t))r=r.replace(new RegExp(n,"gi"),a);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|P[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var Q=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],c=class s{tz;afterMs;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?Q[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r-2:a===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r===n?r-2:r+1:i===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let i=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===i&&o++;if(n&63&&P[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(e,t,l)).getUTCDay()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}catch(t){let r=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear()}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.afterMs=e.afterMs}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){let t=_(e);this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(_(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_matchDayValue(e,t,r,n){let a=e;if(!a){for(let i=0;i<r.nearestWeekdays.length;i++)if(r.nearestWeekdays[i]){let o=this.getNearestWeekday(this.year,this.month,i+1);if(o!==-1&&o===t){a=1;break}}}if(r.lastWeekday){let i=this.getLastWeekday(this.year,this.month);t===i&&(a=1)}if(r.lastDayOfMonth){let i=this.getLastDayOfMonth(this.year,this.month);t===i&&(a=1)}if(!r.starDOW){let i=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(i+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?a=a&&o:!n.domAndDow&&!r.starDOM?a=a||o:a=a&&o}return a}_findMatch(e,t,r,n,a){let i=this[t],o=this[t]+n,h=a===1?l=>l<r[t].length:l=>l>=0;for(let l=o;h(l);l+=a){let u=r[t][l];if(t==="day"&&(u=this._matchDayValue(u,l-n,r,e)),u)return this[t]=l-n,i!==this[t]?2:1}return 3}recurse(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let i=this.year+1;i<e.year.length&&i<1e4;i++)if(e.year[i]===1){a=i;break}if(a===-1)return null;this.year=a,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let n=this.findNext(t,f[r][0],e,f[r][2]);if(n>1){let a=r+1;for(;a<f.length;)this[f[a][0]]=-f[a][2],a++;if(n===3){if(this[f[r][1]]++,this[f[r][0]]=-f[r][2],this.apply(),r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){i=o;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let a=this.findPrevious(t,f[r][0],e,f[r][2]);if(a>1){let i=r+1;for(;i<f.length;){let o=f[i][0],h=f[i][2],l=this.getMaxPatternValue(o,e,h);o==="day"?this[o]=Math.min(l,this.getLastDayOfMonth(this.year,this.month)):this[o]=l,i++}if(a===3){if(this[f[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,m=this.month;for(;m<0;)m+=12,u--;for(;m>11;)m-=12,u++;let d=this.getLastDayOfMonth(u,m);this.day>d&&(this.day=d)}this.apply();let o=f[r][0],h=f[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let u=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,u)}else this[o]=l;if(this.apply(),r===0){let u=f[1][2],m=this.getMaxPatternValue("day",e,u),d=this.getLastDayOfMonth(this.year,this.month),g=Math.min(m,d);g!==this.day&&(this.day=g,this.hour=this.getMaxPatternValue("hour",e,f[2][2]),this.minute=this.getMaxPatternValue("minute",e,f[3][2]),this.second=this.getMaxPatternValue("second",e,f[4][2]))}if(r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=f.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e,t){let r=t??this.afterMs;return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):N(D(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1,r)}getTime(e){return this.getDate(!1,e).getTime()}setAfterMs(e){this.afterMs=e}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<f.length;r++){let n=f[r][0],a=f[r][2],i=this[n];if(i+a<0||i+a>=e[n].length)return!1;let o=e[n][i+a];if(n==="day"&&(o=this._matchDayValue(o,i,e,t)),!o)return!1}return!0}};function W(s){s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow;let e=(t,r)=>t===void 0?r:t;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(s.startAt&&(s.startAt=new c(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new c(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function C(s){return typeof s=="function"}function z(s){return C(s)}function I(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var A=1440*60*1e3,L=30*1e3,b=[],R=class{name;options;_states;fn;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*A;return new Date(e.getTime()+t)}return e}_nextTarget(e,t){let r=(this.options.dayOffset??0)*A;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),a=h=>h?new c(new Date(h.getTime()-r),this.getTz()):void 0,i={startAt:a(this.options.startAt),stopAt:a(this.options.stopAt),includeStartAt:r!==0},o=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;o;){let h=this.applyDayOffset(o.getDate(!1));if(this.options.startAt&&h.getTime()<this.options.startAt.getTime()){o=this._next(o,n,i);continue}return this.options.stopAt&&h.getTime()>=this.options.stopAt.getTime()?null:h}return null}constructor(e,t,r){let n,a;for(let i of[t,r])if(C(i))a=i;else if(typeof i=="object")n=i;else if(i!==void 0)throw new Error("Cron: Invalid argument passed. Should be one of function, or object (options).");if(this.name=n?.name,this.options=W(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new T("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new c(e,this.getTz()):this._states.pattern=new T(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(b.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");b.push(this)}return a!==void 0&&z(a)&&(this.fn=a,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new v(this,e)}_enumerateRuns(e,t,r){let n=[],a=t?new c(t,this.getTz()):null,i=r==="next"?this._next:this._previous;for(;e--;){let o=i.call(this,a);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),a=o}return n}match(e){if(this._states.once){let r=new c(e,this.getTz());r.ms=0;let n=new c(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new c(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this.nextRun(this._states.currentRun)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=this._next(e);if(t){if(e instanceof c||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new c(e,r).getTime()}}else return null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=b.indexOf(this);e>=0&&b.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,a=n&&n.getTime()>r.getTime()?void 0:n,i=this._nextTarget(void 0,r),o=i?i.getTime()-r.getTime():null,h=this._nextTarget(a,r);return o==null||isNaN(o)||h===null?this:(o>L&&(o=L),o<0&&(o=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(h),o),this._states.currentTimeout&&this.options.unref&&I(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new c(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new c(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):r&&n&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,a=r?r.stopAt:this.options.stopAt,i=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,i]=this._calculatePreviousRun(e,i,t,n),o=!e),e=new c(e??t,this.getTz());let h=r?.includeStartAt&&n&&!o?new c(new Date(n.getTime()-1e3),this.getTz()):n;h&&e&&e.getTime()<h.getTime()&&(e=h);let l=this._states.once||new c(e,this.getTz());if(!o&&l!==this._states.once&&(l=l.increment(this._states.pattern,this.options,i)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let u=e.getTime()-this._states.once.getTime();if(u>0&&!this.options.allowPast&&u>1e3)return null}return l=this._resolveDSTOverlap(l,e,i),l===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||a&&l.getTime()>=a.getTime()?null:l}_previous(e){let t=new c(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new c(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_resolveDSTOverlap(e,t,r){if(e===null||e===this._states.once||typeof this.getTz()!="string")return e;let n=t.getTime(),a=e.getTime(),i=(this.options.interval&&r?this.options.interval:1)*1e3,o=a-n,h=Date.UTC(t.year,t.month,t.day,t.hour,t.minute,t.second)-n,l=Date.UTC(e.year,e.month,e.day,e.hour,e.minute,e.second)-a,u=h-l;if(u>0&&(o>=i+u||o<0)){let m=o<0?a+u:a-u,d=new Date(m),g=new c(d,this.getTz());if(g.match(this._states.pattern,this.options)&&m>n)return g.setAfterMs(m),g}return e}_calculatePreviousRun(e,t,r,n){let a=new c(r,this.getTz()),i=e;if(n&&n.getTime()<=a.getTime()){i=n;let o=i.getTime()+this.options.interval*1e3;for(;o<=a.getTime();){let h=new c(i,this.getTz()).increment(this._states.pattern,this.options,!0);if(h===null)break;i=h,o=i.getTime()+this.options.interval*1e3}t=!0}return i===null&&(i=void 0),[i,t]}},v=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*A;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};0&&(module.exports={Cron,CronDate,CronIterator,CronPattern,scheduledJobs});
|
|
1
|
+
var O=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var B=(s,e)=>{for(var t in e)O(s,t,{get:e[t],enumerable:!0})},V=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $(e))!H.call(s,i)&&i!==t&&O(s,i,{get:()=>e[i],enumerable:!(r=Z(e,i))||r.enumerable});return s};var J=s=>V(O({},"__esModule",{value:!0}),s);var G={};B(G,{Cron:()=>E,CronDate:()=>f,CronIterator:()=>M,CronPattern:()=>T,scheduledJobs:()=>b});module.exports=J(G);function D(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function w(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function N(s){let e=s.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function K(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return N(s)?y(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):y(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function v(s,e,t){return R(K(s,e),t)}function R(s,e){let t=_(s);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function _(s){let e=D(s),t=a=>P(new Date(a),s.tz),r=e-t(e),i=g(new Date(r),s.tz);if(w(i,s)){let a=D(i)-r,o=r-(t(r-U)-a);if(o<r&&w(g(new Date(o),s.tz),s))return{kind:"ambiguous",earlier:new Date(o),later:new Date(r)};let u=r+(a-t(r+U));return u>r&&w(g(new Date(u),s.tz),s)?{kind:"ambiguous",earlier:new Date(r),later:new Date(u)}:{kind:"single",date:new Date(r)}}let n=e-(D(i)-r);return w(g(new Date(n),s.tz),s)?{kind:"single",date:new Date(n)}:{kind:"gap",before:new Date(Math.min(r,n)),after:new Date(Math.max(r,n))}}var U=3*36e5;function P(s,e){return D(g(s,e))-(s.getTime()-s.getUTCMilliseconds())}function k(s,e,t){let r=P(new Date(s),t);for(;e-s>1e3;){let i=s+Math.floor((e-s)/2e3)*1e3;P(new Date(i),t)===r?s=i:e=i}return e}function W(s,e){let t=_(g(new Date(s),e));if(t.kind==="ambiguous")return s<t.later.getTime()?"earlier":"later"}var S=new Map;function g(s,e){if(e===void 0)return y(s.getFullYear(),s.getMonth()+1,s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds());let t=S.get(e),r;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),S.set(e,t)),r=t.formatToParts(s)}catch(n){let a=n instanceof Error?n.message:String(n);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let i={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let n of r)(n.type==="year"||n.type==="month"||n.type==="day"||n.type==="hour"||n.type==="minute"||n.type==="second")&&(i[n.type]=parseInt(n.value,10));if(isNaN(i.year)||isNaN(i.month)||isNaN(i.day)||isNaN(i.hour)||isNaN(i.minute)||isNaN(i.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(i)}`);return i.hour===24&&(i.hour=0),{y:i.year,m:i.month,d:i.day,h:i.hour,i:i.minute,s:i.second,tz:e}}function y(s,e,t,r,i,n,a){return{y:s,m:e,d:t,h:r,i,s:n,tz:a}}var A=[1,2,4,8,16],T=class s{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=Array(1e4).fill(0),this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let o=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${o} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let i=(n,a)=>!n.includes("*")&&!n.includes("/")&&a.filter(o=>o).length===1;this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,r,i){let n=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return n.fill(i);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,r,i);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,i):t.includes("-")?this.handleRange(t,e,r,i):t.includes("/")?this.handleStepping(t,e,r,i):t!==""&&this.handleNumber(t,e,r,i)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,r,i){let n=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=parseInt(n[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,n[1]||i)}setPart(e,t,r){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,r);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,i,n){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+n+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[i].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[i].length+")")}}handleRangeWithStepping(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let n=this.extractNth(e,t),a=n[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,c=parseInt(o,10)+r,d=parseInt(u,10)+r,m=parseInt(l,10);this.validateNotNaN(c,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(c,d,m,t,e);for(let p=c;p<=d;p+=m)this.setPart(t,p,n[1]||i)}extractNth(e,t){let r=e,i;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");i=r.split("#")[1],r=r.split("#")[0]}else if(r.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");i="L",r=r.slice(0,-1)}return[r,i]}handleRange(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let n=this.extractNth(e,t),a=n[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+r,u=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,n[1]||i)}handleStepping(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let n=this.extractNth(e,t),a=n[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=parseInt(a[0],10)+r);let u=parseInt(a[1],10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,n[1]||i)}replaceAlpha(e,t){let r=e;for(let[i,n]of Object.entries(t))r=r.replace(new RegExp(i,"gi"),n);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|A[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var Q=[31,28,31,30,31,30,31,31,30,31,30,31],h=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],f=class s{tz;instantMs;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?Q[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),n=new Date(Date.UTC(e,t,r)).getUTCDay();return n===0?r-2:n===6?r-1:r}getNearestWeekday(e,t,r){let i=this.getLastDayOfMonth(e,t);if(r>i)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===i?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,i){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let u=1;u<=r;u++)new Date(Date.UTC(e,t,u)).getUTCDay()===a&&o++;if(i&63&&A[o-1]&i)return!0;if(i&32){let u=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=u;l++)if(new Date(Date.UTC(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=g(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.instantMs=e.getTime()-this.ms}catch(t){let r=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.instantMs=e.getTime()-this.ms}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(N(e))return this.fromDate(v(e));let t=v(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(v(e,this.tz))}findNext(e,t,r,i){return this._findMatch(e,t,r,i,1)}_matchDayValue(e,t,r,i){let n=e;if(!n){for(let a=0;a<r.nearestWeekdays.length;a++)if(r.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){n=1;break}}}if(r.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(n=1)}if(r.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(n=1)}if(!r.starDOW){let a=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?n=n&&o:!i.domAndDow&&!r.starDOM?n=n||o:n=n&&o}return n}_findMatch(e,t,r,i,n){let a=this[t],o=this[t]+i,u=n===1?l=>l<r[t].length:l=>l>=0;for(let l=o;u(l);l+=n){let c=r[t][l];if(t==="day"&&(c=this._matchDayValue(c,l-i,r,e)),c)return this[t]=l-i,a!==this[t]?2:1}return 3}recurse(e,t,r){let i=this.year,n=r;for(;typeof n=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;n=this.recurseStep(e,t,n)}return n}recurseStep(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let n=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){n=a;break}if(n===-1)return null;this.year=n,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let i=this.findNext(t,h[r][0],e,h[r][2]);if(i>1){let n=r+1;for(;n<h.length;)this[h[n][0]]=-h[n][2],n++;if(i===3){if(this[h[r][1]]++,this[h[r][0]]=-h[r][2],this.apply(),r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return r-1}return r+=1,r>=h.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:r}increment(e,t,r){return this.instantMs=void 0,this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,r){let i=this.year,n=r;for(;typeof n=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;n=this.recurseBackwardStep(e,t,n)}return n}recurseBackwardStep(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let n=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){n=a;break}if(n===-1)return null;this.year=n,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let i=this.findPrevious(t,h[r][0],e,h[r][2]);if(i>1){let n=r+1;for(;n<h.length;){let a=h[n][0],o=h[n][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,n++}if(i===3){if(this[h[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let c=this.getLastDayOfMonth(u,l);this.day>c&&(this.day=c)}this.apply();let a=h[r][0],o=h[r][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),r===0){let u=h[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,h[2][2]),this.minute=this.getMaxPatternValue("minute",e,h[3][2]),this.second=this.getMaxPatternValue("second",e,h[4][2]))}if(r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return r-1}return r+=1,r>=h.length?this:this.year<0?null:r}getMaxPatternValue(e,t,r){let i=t[e].length-1-r;for(let n=t[e].length-1;n>=0;n--)if(t[e][n]){i=n-r;break}if(e==="day"){let n=this.getLastDayOfMonth(this.year,this.month);return t.lastDayOfMonth||!t.starDOW?n:Math.min(i,n)}return i}findPrevious(e,t,r,i){return this._findMatch(e,t,r,i,-1)}getDate(e){return!e&&this.instantMs!==void 0&&typeof this.tz!="number"?new Date(this.instantMs+(this.tz===void 0?this.ms:0)):e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):R(y(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<h.length;r++){let i=h[r][0],n=h[r][2],a=this[i];if(a+n<0||a+n>=e[i].length)return!1;let o=e[i][a+n];if(i==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}};function L(s){s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow;let e=(r,i)=>r===void 0?i:r;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");s.timezone===""&&(s.timezone=void 0);let t=s.timezone??s.utcOffset;if(s.startAt&&(s.startAt=I(new f(s.startAt,t))),s.stopAt&&(s.stopAt=I(new f(s.stopAt,t))),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function I(s){return s.ms?(s.ms=0,new f(new Date(s.getTime()+1e3),s.tz)):s}function C(s){return typeof s=="function"}function F(s){return C(s)}function Y(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var x=1440*60*1e3,j=30*1e3,b=[],E=class{name;options;_states;fn;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*x}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let r=this._offsetMs(),i=this._next(this._shift(e),new Date(t.getTime()-r),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return i?this.applyDayOffset(i.getDate(!1)):null}_previousTarget(e,t){let r=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return r?this.applyDayOffset(r.getDate(!1)):null}_shift(e){if(e!=null)return new f(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,r){let i,n;if(C(t))n=t;else if(typeof t=="object")i=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(C(r))n=r;else if(typeof r=="object")i=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=i?.name,this.options=L(i),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:i?i.maxRuns:void 0,paused:i?i.paused:!1,pattern:new T("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new f(e,this.getTz()):this._states.pattern=new T(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(b.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");b.push(this)}return n!==void 0&&F(n)&&(this.fn=n,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new M(this,e)}_enumerateRuns(e,t,r){let i=[],n=new Date,a=t;for(;e-- >0;){let o=r==="next"?this._nextTarget(a,n):this._previousTarget(a,n);if(!o)break;i.push(o),a=o}return i}match(e){if(this._states.once){let r=new f(e,this.getTz());r.ms=0;let i=new f(this._states.once,this.getTz());return i.ms=0,r.getTime()===i.getTime()}let t=new f(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,r=this._nextTarget(e,t);return r?r.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=b.indexOf(this);e>=0&&b.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,i=this._nextTarget(void 0,r),n=i?i.getTime()-r.getTime():null,a=this._states.currentRun;a&&a.getTime()>r.getTime()&&(a=void 0);let o=this._nextTarget(a,r);return n===null||isNaN(n)||o===null?this:(n>j&&(n=j),n<0&&(n=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),n),this._states.currentTimeout&&this.options.unref&&Y(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new f(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new f(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),i=this._states.blocking&&this.options.protect;r&&!i?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):r&&i&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let i=r?r.startAt:this._startAt,n=r?r.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&i&&this.options.interval&&(e=this._calculatePreviousRun(i,t),e&&(o=!0),u=!e);let l=e??t??new Date,c=this._toMs(l);e=new f(l,this.getTz()),i&&c<i.getTime()&&(e=u?i:new f(new Date(i.getTime()-1e3),this.getTz()),c=e.getTime());let d=this._states.once||new f(e,this.getTz());if(!u&&d!==this._states.once&&(d=this._findOccurrence(e,c,1,o)),this._states.once){let m=this._states.once.getTime(),p=c-m;if(i&&m<i.getTime()||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?p>=0:p>1e3&&!this.options.allowPast))return null}return d===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||n&&d.getTime()>=n.getTime()?null:d}_previous(e,t){let r=this._toMs(e??new Date);if(t.stopAt&&r>t.stopAt.getTime()&&(r=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<r?this._states.once:null;let i=this._findOccurrence(new f(new Date(r),this.getTz()),r,-1);return i===null||t.startAt&&i.getTime()<t.startAt.getTime()?null:i}_toMs(e){return e instanceof Date?e.getTime():new f(e,this.getTz()).getTime()}_findOccurrence(e,t,r,i=!1){let n=this._walk(e,t,r,i),a=this.getTz();if(this._states.pattern.isFixedTime&&r===1||typeof a=="number"||W(t,a)!==(r===1?"earlier":"later"))return n;let o=Math.floor(t/1e3)*1e3,u=r===1?k(o,o+x,a):k(o-x,o,a)-1e3;if(n&&(u-n.getTime())*r>0)return n;let l=this._walk(new f(new Date(u),a),u-r,r,!1,!0);return!n||!l?n??l:(n.getTime()-l.getTime())*r>0?l:n}_walk(e,t,r,i,n=!1){let a=this._states.pattern,o=(l,c)=>r===1?l.increment(a,this.options,c):l.decrement(a,this.options),u=new f(e,this.getTz());for((!n||!u.match(a,this.options))&&(u=o(u,i));u;){let l=this._runAt(u,t,r);if(l)return new f(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,r){let i=m=>(m.getTime()-t)*r>0,n=e.tz;if(typeof n=="number"){let m=e.getDate();return i(m)?m:null}let a=y(e.year,e.month+1,e.day,e.hour,e.minute,e.second,n),o=_(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return i(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:m,later:p}=o;return(u?[m]:r===1?[m,p]:[p,m]).find(i)??null}if(!u)return null;let l=new Date(k(o.before.getTime(),o.after.getTime(),n)),c=g(l,n);return c.y===a.y&&c.m===a.m&&c.d===a.d&&i(l)?l:null}_calculatePreviousRun(e,t){let r=new f(t,this.getTz()).getTime();if(e.getTime()>r)return;let i=this.options.interval*1e3,n=e;for(;n.getTime()+i<=r;){let a=new f(n,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;n=a}return n}},M=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.options.maxRuns??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};0&&(module.exports={Cron,CronDate,CronIterator,CronPattern,scheduledJobs});
|
package/dist/croner.d.cts
CHANGED
|
@@ -29,6 +29,11 @@ declare class CronPattern {
|
|
|
29
29
|
starDOW: boolean;
|
|
30
30
|
starYear: boolean;
|
|
31
31
|
useAndLogic: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* True if seconds, minutes and hours each have a single value, without wildcard or step.
|
|
34
|
+
* Fixed-time and interval jobs handle DST transitions differently, as in croner-rust.
|
|
35
|
+
*/
|
|
36
|
+
isFixedTime: boolean;
|
|
32
37
|
constructor(pattern: string, timezone?: string, options?: {
|
|
33
38
|
mode?: CronMode;
|
|
34
39
|
alternativeWeekdays?: boolean;
|
|
@@ -119,12 +124,17 @@ declare class CronPattern {
|
|
|
119
124
|
*/
|
|
120
125
|
private replaceAlpha;
|
|
121
126
|
/**
|
|
122
|
-
*
|
|
127
|
+
* Day names to day-of-week numbers. Names are replaced in this order, so "-sun" must come
|
|
128
|
+
* before "sun".
|
|
123
129
|
* @private
|
|
124
130
|
*/
|
|
125
131
|
private static DAY_NAMES;
|
|
126
132
|
private static DAY_NAMES_QUARTZ;
|
|
127
133
|
private static MONTH_NAMES;
|
|
134
|
+
/**
|
|
135
|
+
* Map of cron nickname patterns to their equivalent cron expressions.
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
128
138
|
private static NICKNAME_MAP;
|
|
129
139
|
/**
|
|
130
140
|
* Replace nicknames with actual cron patterns
|
|
@@ -195,11 +205,13 @@ interface CronOptions<T = undefined> {
|
|
|
195
205
|
*/
|
|
196
206
|
protect?: boolean | ProtectCallbackFn;
|
|
197
207
|
/**
|
|
198
|
-
* The date and time at which the job should start running.
|
|
208
|
+
* The date and time at which the job should start running. Inclusive, a run exactly at startAt
|
|
209
|
+
* is included. Strings are read in the timezone or UTC offset of the job.
|
|
199
210
|
*/
|
|
200
211
|
startAt?: string | Date | CronDate<T>;
|
|
201
212
|
/**
|
|
202
|
-
* The date and time at which the job should stop running.
|
|
213
|
+
* The date and time at which the job should stop running. Exclusive, a run exactly at stopAt
|
|
214
|
+
* is not included. Strings are read in the timezone or UTC offset of the job.
|
|
203
215
|
*/
|
|
204
216
|
stopAt?: string | Date | CronDate<T>;
|
|
205
217
|
/**
|
|
@@ -220,6 +232,8 @@ interface CronOptions<T = undefined> {
|
|
|
220
232
|
* Offset the scheduled date by a number of days.
|
|
221
233
|
* Positive values shift the date forward, negative values shift it backward.
|
|
222
234
|
* For example, dayOffset: -1 schedules the job one day before the pattern match.
|
|
235
|
+
* nextRun(), nextRuns(), previousRuns(), msToNext(), enumerate(), startAt and stopAt all
|
|
236
|
+
* refer to the shifted run time.
|
|
223
237
|
* @default 0
|
|
224
238
|
*/
|
|
225
239
|
dayOffset?: number;
|
|
@@ -278,12 +292,10 @@ interface CronOptions<T = undefined> {
|
|
|
278
292
|
declare class CronDate<T = undefined> {
|
|
279
293
|
tz: string | number | undefined;
|
|
280
294
|
/**
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* that is at or after this threshold.
|
|
284
|
-
* @private
|
|
295
|
+
* The instant (whole seconds) this CronDate was created from, if its time has not changed since.
|
|
296
|
+
* A local time that occurs twice (DST fall back) then keeps the occurrence it was created from.
|
|
285
297
|
*/
|
|
286
|
-
private
|
|
298
|
+
private instantMs?;
|
|
287
299
|
/**
|
|
288
300
|
* Current milliseconds
|
|
289
301
|
* @type {number}
|
|
@@ -383,20 +395,6 @@ declare class CronDate<T = undefined> {
|
|
|
383
395
|
* Find next match of current part
|
|
384
396
|
*/
|
|
385
397
|
private findNext;
|
|
386
|
-
/**
|
|
387
|
-
* Internal unified method to find a matching time component in either direction.
|
|
388
|
-
* This method searches through the pattern to find the next or previous valid value
|
|
389
|
-
* for the specified target component (second, minute, hour, day, or month).
|
|
390
|
-
*
|
|
391
|
-
* @param options Cron options
|
|
392
|
-
* @param target Target property (second, minute, hour, day, month)
|
|
393
|
-
* @param pattern Pattern to use
|
|
394
|
-
* @param offset Offset to use
|
|
395
|
-
* @param direction 1 for forward (next), -1 for backward (previous)
|
|
396
|
-
* @returns Status code: 1 = same value matches, 2 = value changed, 3 = no match found
|
|
397
|
-
*
|
|
398
|
-
* @private
|
|
399
|
-
*/
|
|
400
398
|
/**
|
|
401
399
|
* Evaluate whether a specific day value matches, applying all day-specific
|
|
402
400
|
* special-case logic (W, LW, L modifiers and DOW AND/OR combination).
|
|
@@ -411,6 +409,20 @@ declare class CronDate<T = undefined> {
|
|
|
411
409
|
* @private
|
|
412
410
|
*/
|
|
413
411
|
private _matchDayValue;
|
|
412
|
+
/**
|
|
413
|
+
* Internal unified method to find a matching time component in either direction.
|
|
414
|
+
* This method searches through the pattern to find the next or previous valid value
|
|
415
|
+
* for the specified target component (second, minute, hour, day, or month).
|
|
416
|
+
*
|
|
417
|
+
* @param options Cron options
|
|
418
|
+
* @param target Target property (second, minute, hour, day, month)
|
|
419
|
+
* @param pattern Pattern to use
|
|
420
|
+
* @param offset Offset to use
|
|
421
|
+
* @param direction 1 for forward (next), -1 for backward (previous)
|
|
422
|
+
* @returns Status code: 1 = same value matches, 2 = value changed, 3 = no match found
|
|
423
|
+
*
|
|
424
|
+
* @private
|
|
425
|
+
*/
|
|
414
426
|
private _findMatch;
|
|
415
427
|
/**
|
|
416
428
|
* Increment to next run time recursively.
|
|
@@ -435,6 +447,12 @@ declare class CronDate<T = undefined> {
|
|
|
435
447
|
* @private
|
|
436
448
|
*/
|
|
437
449
|
private recurse;
|
|
450
|
+
/**
|
|
451
|
+
* One step of recurse(). Returns the level to continue at, or the result.
|
|
452
|
+
*
|
|
453
|
+
* @private
|
|
454
|
+
*/
|
|
455
|
+
private recurseStep;
|
|
438
456
|
/**
|
|
439
457
|
* Increment to next run time
|
|
440
458
|
*
|
|
@@ -469,6 +487,12 @@ declare class CronDate<T = undefined> {
|
|
|
469
487
|
* @private
|
|
470
488
|
*/
|
|
471
489
|
private recurseBackward;
|
|
490
|
+
/**
|
|
491
|
+
* One step of recurseBackward(). Returns the level to continue at, or the result.
|
|
492
|
+
*
|
|
493
|
+
* @private
|
|
494
|
+
*/
|
|
495
|
+
private recurseBackwardStep;
|
|
472
496
|
/**
|
|
473
497
|
* Get the maximum value in a pattern for a given target.
|
|
474
498
|
* Used when resetting components during backward recursion.
|
|
@@ -498,23 +522,12 @@ declare class CronDate<T = undefined> {
|
|
|
498
522
|
* Convert current state back to a javascript Date()
|
|
499
523
|
*
|
|
500
524
|
* @param internal If this is an internal call
|
|
501
|
-
* @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
|
|
502
525
|
*/
|
|
503
|
-
getDate(internal?: boolean
|
|
526
|
+
getDate(internal?: boolean): Date;
|
|
504
527
|
/**
|
|
505
528
|
* Convert current state back to a javascript Date() and return UTC milliseconds
|
|
506
|
-
*
|
|
507
|
-
* @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
|
|
508
|
-
*/
|
|
509
|
-
getTime(afterMs?: number): number;
|
|
510
|
-
/**
|
|
511
|
-
* Set the afterMs threshold for DST overlap resolution.
|
|
512
|
-
* When set, getTime()/getDate() will return the earliest occurrence
|
|
513
|
-
* that is at or after this threshold.
|
|
514
|
-
*
|
|
515
|
-
* @param ms UTC milliseconds threshold
|
|
516
529
|
*/
|
|
517
|
-
|
|
530
|
+
getTime(): number;
|
|
518
531
|
/**
|
|
519
532
|
* Check if the current CronDate matches a cron pattern
|
|
520
533
|
*
|
|
@@ -561,14 +574,35 @@ declare class Cron<T = undefined> {
|
|
|
561
574
|
private getTz;
|
|
562
575
|
/**
|
|
563
576
|
* Internal helper to apply dayOffset to a date if configured.
|
|
564
|
-
* Reduces duplication of dayOffset calculation logic.
|
|
565
577
|
*
|
|
566
578
|
* @param date - The base date to apply offset to
|
|
567
579
|
* @returns The date with dayOffset applied, or the original date if no offset is configured
|
|
568
580
|
* @private
|
|
569
581
|
*/
|
|
570
582
|
private applyDayOffset;
|
|
583
|
+
/**
|
|
584
|
+
* The dayOffset option in milliseconds
|
|
585
|
+
*/
|
|
586
|
+
private _offsetMs;
|
|
587
|
+
/**
|
|
588
|
+
* The startAt and stopAt options, which CronOptionsHandler has made CronDates
|
|
589
|
+
*/
|
|
590
|
+
private get _startAt();
|
|
591
|
+
private get _stopAt();
|
|
592
|
+
/**
|
|
593
|
+
* Find the next time the job runs, after a reference (default: now). With dayOffset, the
|
|
594
|
+
* pattern is searched in shifted time, so the reference, startAt and stopAt are all compared
|
|
595
|
+
* with the actual run time.
|
|
596
|
+
*/
|
|
571
597
|
private _nextTarget;
|
|
598
|
+
/**
|
|
599
|
+
* Find the previous time the job ran, before a reference (default: now). See _nextTarget.
|
|
600
|
+
*/
|
|
601
|
+
private _previousTarget;
|
|
602
|
+
/**
|
|
603
|
+
* Move a run time back by dayOffset, to the pattern match it was shifted from
|
|
604
|
+
*/
|
|
605
|
+
private _shift;
|
|
572
606
|
constructor(pattern: string | Date, fnOrOptions1?: CronOptions<T> | CronCallback<T>, fnOrOptions2?: CronOptions<T> | CronCallback<T>);
|
|
573
607
|
/**
|
|
574
608
|
* Find next runtime, based on supplied date. Strips milliseconds.
|
|
@@ -609,7 +643,7 @@ declare class Cron<T = undefined> {
|
|
|
609
643
|
* @param n - Number of runs to enumerate
|
|
610
644
|
* @param startDate - Date to start from
|
|
611
645
|
* @param direction - Direction to enumerate ("next" or "previous")
|
|
612
|
-
* @returns Array of run times
|
|
646
|
+
* @returns Array of run times
|
|
613
647
|
* @private
|
|
614
648
|
*/
|
|
615
649
|
private _enumerateRuns;
|
|
@@ -725,17 +759,35 @@ declare class Cron<T = undefined> {
|
|
|
725
759
|
*/
|
|
726
760
|
private _previous;
|
|
727
761
|
/**
|
|
728
|
-
*
|
|
729
|
-
|
|
730
|
-
|
|
762
|
+
* The exact instant of a reference date. Strings are read in the timezone of the job.
|
|
763
|
+
*/
|
|
764
|
+
private _toMs;
|
|
765
|
+
/**
|
|
766
|
+
* Find the first occurrence after (direction 1) or before (direction -1) referenceMs,
|
|
767
|
+
* walking the wall clock from `start`. Same algorithm as find_occurrence in croner-rust.
|
|
731
768
|
*
|
|
732
|
-
*
|
|
769
|
+
* When the clock goes back (DST fall back), a range of wall clock times repeats, and one
|
|
770
|
+
* walk covers only one pass of it. If the reference is on the pass the search meets first,
|
|
771
|
+
* the other pass still lies ahead, so it is walked too, and the nearer match wins.
|
|
772
|
+
*/
|
|
773
|
+
private _findOccurrence;
|
|
774
|
+
/**
|
|
775
|
+
* Walk the wall clock from `start` until a time matches the pattern, and runs after
|
|
776
|
+
* (direction 1) or before (direction -1) referenceMs. Same algorithm as walk in croner-rust.
|
|
777
|
+
*/
|
|
778
|
+
private _walk;
|
|
779
|
+
/**
|
|
780
|
+
* When a matching wall clock time runs, if that is after (direction 1) or
|
|
781
|
+
* before (direction -1) referenceMs. DST rules, shared with croner-rust:
|
|
782
|
+
* - A time that occurs twice (fall back) runs once, at its first occurrence, for
|
|
783
|
+
* fixed-time jobs, and on both occurrences for interval jobs.
|
|
784
|
+
* - A time that doesn't exist (spring forward) is skipped by interval jobs, and runs
|
|
785
|
+
* when the clock has jumped forward for fixed-time jobs, if that is on the same day.
|
|
733
786
|
*/
|
|
734
|
-
private
|
|
787
|
+
private _runAt;
|
|
735
788
|
/**
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
* Should only be called from the _next function.
|
|
789
|
+
* When startAt and interval are set and there is no previous run, find the last run there
|
|
790
|
+
* would have been between startAt and now. Returns undefined if startAt is in the future.
|
|
739
791
|
*/
|
|
740
792
|
private _calculatePreviousRun;
|
|
741
793
|
}
|
|
@@ -749,7 +801,10 @@ declare class Cron<T = undefined> {
|
|
|
749
801
|
*/
|
|
750
802
|
declare class CronIterator<T = undefined> implements Iterator<Date, undefined>, Iterable<Date> {
|
|
751
803
|
private cron;
|
|
804
|
+
/** Last returned date, or the user supplied start date */
|
|
752
805
|
private cursor;
|
|
806
|
+
/** Time of creation or reset, used as reference while there is no cursor */
|
|
807
|
+
private now;
|
|
753
808
|
private done;
|
|
754
809
|
private initialMaxRuns;
|
|
755
810
|
private remainingRuns;
|
|
@@ -758,13 +813,6 @@ declare class CronIterator<T = undefined> implements Iterator<Date, undefined>,
|
|
|
758
813
|
* @param startAt - Optional starting date for iteration. Defaults to current time if omitted.
|
|
759
814
|
*/
|
|
760
815
|
constructor(cron: Cron<T>, startAt?: Date | string | null);
|
|
761
|
-
/**
|
|
762
|
-
* Normalizes a cursor argument: Date objects are cloned to prevent external mutation;
|
|
763
|
-
* strings are preserved as-is so that nextRun() can parse them using the Cron instance's
|
|
764
|
-
* configured timezone (via CronDate/fromTZISO), matching the behaviour of nextRun() and nextRuns().
|
|
765
|
-
* @private
|
|
766
|
-
*/
|
|
767
|
-
private static _normalizeCursor;
|
|
768
816
|
/**
|
|
769
817
|
* Returns the next scheduled date and advances the cursor.
|
|
770
818
|
* Implements the ECMAScript Iterator protocol.
|
package/dist/croner.d.ts
CHANGED
|
@@ -29,6 +29,11 @@ declare class CronPattern {
|
|
|
29
29
|
starDOW: boolean;
|
|
30
30
|
starYear: boolean;
|
|
31
31
|
useAndLogic: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* True if seconds, minutes and hours each have a single value, without wildcard or step.
|
|
34
|
+
* Fixed-time and interval jobs handle DST transitions differently, as in croner-rust.
|
|
35
|
+
*/
|
|
36
|
+
isFixedTime: boolean;
|
|
32
37
|
constructor(pattern: string, timezone?: string, options?: {
|
|
33
38
|
mode?: CronMode;
|
|
34
39
|
alternativeWeekdays?: boolean;
|
|
@@ -119,12 +124,17 @@ declare class CronPattern {
|
|
|
119
124
|
*/
|
|
120
125
|
private replaceAlpha;
|
|
121
126
|
/**
|
|
122
|
-
*
|
|
127
|
+
* Day names to day-of-week numbers. Names are replaced in this order, so "-sun" must come
|
|
128
|
+
* before "sun".
|
|
123
129
|
* @private
|
|
124
130
|
*/
|
|
125
131
|
private static DAY_NAMES;
|
|
126
132
|
private static DAY_NAMES_QUARTZ;
|
|
127
133
|
private static MONTH_NAMES;
|
|
134
|
+
/**
|
|
135
|
+
* Map of cron nickname patterns to their equivalent cron expressions.
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
128
138
|
private static NICKNAME_MAP;
|
|
129
139
|
/**
|
|
130
140
|
* Replace nicknames with actual cron patterns
|
|
@@ -195,11 +205,13 @@ interface CronOptions<T = undefined> {
|
|
|
195
205
|
*/
|
|
196
206
|
protect?: boolean | ProtectCallbackFn;
|
|
197
207
|
/**
|
|
198
|
-
* The date and time at which the job should start running.
|
|
208
|
+
* The date and time at which the job should start running. Inclusive, a run exactly at startAt
|
|
209
|
+
* is included. Strings are read in the timezone or UTC offset of the job.
|
|
199
210
|
*/
|
|
200
211
|
startAt?: string | Date | CronDate<T>;
|
|
201
212
|
/**
|
|
202
|
-
* The date and time at which the job should stop running.
|
|
213
|
+
* The date and time at which the job should stop running. Exclusive, a run exactly at stopAt
|
|
214
|
+
* is not included. Strings are read in the timezone or UTC offset of the job.
|
|
203
215
|
*/
|
|
204
216
|
stopAt?: string | Date | CronDate<T>;
|
|
205
217
|
/**
|
|
@@ -220,6 +232,8 @@ interface CronOptions<T = undefined> {
|
|
|
220
232
|
* Offset the scheduled date by a number of days.
|
|
221
233
|
* Positive values shift the date forward, negative values shift it backward.
|
|
222
234
|
* For example, dayOffset: -1 schedules the job one day before the pattern match.
|
|
235
|
+
* nextRun(), nextRuns(), previousRuns(), msToNext(), enumerate(), startAt and stopAt all
|
|
236
|
+
* refer to the shifted run time.
|
|
223
237
|
* @default 0
|
|
224
238
|
*/
|
|
225
239
|
dayOffset?: number;
|
|
@@ -278,12 +292,10 @@ interface CronOptions<T = undefined> {
|
|
|
278
292
|
declare class CronDate<T = undefined> {
|
|
279
293
|
tz: string | number | undefined;
|
|
280
294
|
/**
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* that is at or after this threshold.
|
|
284
|
-
* @private
|
|
295
|
+
* The instant (whole seconds) this CronDate was created from, if its time has not changed since.
|
|
296
|
+
* A local time that occurs twice (DST fall back) then keeps the occurrence it was created from.
|
|
285
297
|
*/
|
|
286
|
-
private
|
|
298
|
+
private instantMs?;
|
|
287
299
|
/**
|
|
288
300
|
* Current milliseconds
|
|
289
301
|
* @type {number}
|
|
@@ -383,20 +395,6 @@ declare class CronDate<T = undefined> {
|
|
|
383
395
|
* Find next match of current part
|
|
384
396
|
*/
|
|
385
397
|
private findNext;
|
|
386
|
-
/**
|
|
387
|
-
* Internal unified method to find a matching time component in either direction.
|
|
388
|
-
* This method searches through the pattern to find the next or previous valid value
|
|
389
|
-
* for the specified target component (second, minute, hour, day, or month).
|
|
390
|
-
*
|
|
391
|
-
* @param options Cron options
|
|
392
|
-
* @param target Target property (second, minute, hour, day, month)
|
|
393
|
-
* @param pattern Pattern to use
|
|
394
|
-
* @param offset Offset to use
|
|
395
|
-
* @param direction 1 for forward (next), -1 for backward (previous)
|
|
396
|
-
* @returns Status code: 1 = same value matches, 2 = value changed, 3 = no match found
|
|
397
|
-
*
|
|
398
|
-
* @private
|
|
399
|
-
*/
|
|
400
398
|
/**
|
|
401
399
|
* Evaluate whether a specific day value matches, applying all day-specific
|
|
402
400
|
* special-case logic (W, LW, L modifiers and DOW AND/OR combination).
|
|
@@ -411,6 +409,20 @@ declare class CronDate<T = undefined> {
|
|
|
411
409
|
* @private
|
|
412
410
|
*/
|
|
413
411
|
private _matchDayValue;
|
|
412
|
+
/**
|
|
413
|
+
* Internal unified method to find a matching time component in either direction.
|
|
414
|
+
* This method searches through the pattern to find the next or previous valid value
|
|
415
|
+
* for the specified target component (second, minute, hour, day, or month).
|
|
416
|
+
*
|
|
417
|
+
* @param options Cron options
|
|
418
|
+
* @param target Target property (second, minute, hour, day, month)
|
|
419
|
+
* @param pattern Pattern to use
|
|
420
|
+
* @param offset Offset to use
|
|
421
|
+
* @param direction 1 for forward (next), -1 for backward (previous)
|
|
422
|
+
* @returns Status code: 1 = same value matches, 2 = value changed, 3 = no match found
|
|
423
|
+
*
|
|
424
|
+
* @private
|
|
425
|
+
*/
|
|
414
426
|
private _findMatch;
|
|
415
427
|
/**
|
|
416
428
|
* Increment to next run time recursively.
|
|
@@ -435,6 +447,12 @@ declare class CronDate<T = undefined> {
|
|
|
435
447
|
* @private
|
|
436
448
|
*/
|
|
437
449
|
private recurse;
|
|
450
|
+
/**
|
|
451
|
+
* One step of recurse(). Returns the level to continue at, or the result.
|
|
452
|
+
*
|
|
453
|
+
* @private
|
|
454
|
+
*/
|
|
455
|
+
private recurseStep;
|
|
438
456
|
/**
|
|
439
457
|
* Increment to next run time
|
|
440
458
|
*
|
|
@@ -469,6 +487,12 @@ declare class CronDate<T = undefined> {
|
|
|
469
487
|
* @private
|
|
470
488
|
*/
|
|
471
489
|
private recurseBackward;
|
|
490
|
+
/**
|
|
491
|
+
* One step of recurseBackward(). Returns the level to continue at, or the result.
|
|
492
|
+
*
|
|
493
|
+
* @private
|
|
494
|
+
*/
|
|
495
|
+
private recurseBackwardStep;
|
|
472
496
|
/**
|
|
473
497
|
* Get the maximum value in a pattern for a given target.
|
|
474
498
|
* Used when resetting components during backward recursion.
|
|
@@ -498,23 +522,12 @@ declare class CronDate<T = undefined> {
|
|
|
498
522
|
* Convert current state back to a javascript Date()
|
|
499
523
|
*
|
|
500
524
|
* @param internal If this is an internal call
|
|
501
|
-
* @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
|
|
502
525
|
*/
|
|
503
|
-
getDate(internal?: boolean
|
|
526
|
+
getDate(internal?: boolean): Date;
|
|
504
527
|
/**
|
|
505
528
|
* Convert current state back to a javascript Date() and return UTC milliseconds
|
|
506
|
-
*
|
|
507
|
-
* @param afterMs Optional UTC ms threshold for resolving DST overlap ambiguity
|
|
508
|
-
*/
|
|
509
|
-
getTime(afterMs?: number): number;
|
|
510
|
-
/**
|
|
511
|
-
* Set the afterMs threshold for DST overlap resolution.
|
|
512
|
-
* When set, getTime()/getDate() will return the earliest occurrence
|
|
513
|
-
* that is at or after this threshold.
|
|
514
|
-
*
|
|
515
|
-
* @param ms UTC milliseconds threshold
|
|
516
529
|
*/
|
|
517
|
-
|
|
530
|
+
getTime(): number;
|
|
518
531
|
/**
|
|
519
532
|
* Check if the current CronDate matches a cron pattern
|
|
520
533
|
*
|
|
@@ -561,14 +574,35 @@ declare class Cron<T = undefined> {
|
|
|
561
574
|
private getTz;
|
|
562
575
|
/**
|
|
563
576
|
* Internal helper to apply dayOffset to a date if configured.
|
|
564
|
-
* Reduces duplication of dayOffset calculation logic.
|
|
565
577
|
*
|
|
566
578
|
* @param date - The base date to apply offset to
|
|
567
579
|
* @returns The date with dayOffset applied, or the original date if no offset is configured
|
|
568
580
|
* @private
|
|
569
581
|
*/
|
|
570
582
|
private applyDayOffset;
|
|
583
|
+
/**
|
|
584
|
+
* The dayOffset option in milliseconds
|
|
585
|
+
*/
|
|
586
|
+
private _offsetMs;
|
|
587
|
+
/**
|
|
588
|
+
* The startAt and stopAt options, which CronOptionsHandler has made CronDates
|
|
589
|
+
*/
|
|
590
|
+
private get _startAt();
|
|
591
|
+
private get _stopAt();
|
|
592
|
+
/**
|
|
593
|
+
* Find the next time the job runs, after a reference (default: now). With dayOffset, the
|
|
594
|
+
* pattern is searched in shifted time, so the reference, startAt and stopAt are all compared
|
|
595
|
+
* with the actual run time.
|
|
596
|
+
*/
|
|
571
597
|
private _nextTarget;
|
|
598
|
+
/**
|
|
599
|
+
* Find the previous time the job ran, before a reference (default: now). See _nextTarget.
|
|
600
|
+
*/
|
|
601
|
+
private _previousTarget;
|
|
602
|
+
/**
|
|
603
|
+
* Move a run time back by dayOffset, to the pattern match it was shifted from
|
|
604
|
+
*/
|
|
605
|
+
private _shift;
|
|
572
606
|
constructor(pattern: string | Date, fnOrOptions1?: CronOptions<T> | CronCallback<T>, fnOrOptions2?: CronOptions<T> | CronCallback<T>);
|
|
573
607
|
/**
|
|
574
608
|
* Find next runtime, based on supplied date. Strips milliseconds.
|
|
@@ -609,7 +643,7 @@ declare class Cron<T = undefined> {
|
|
|
609
643
|
* @param n - Number of runs to enumerate
|
|
610
644
|
* @param startDate - Date to start from
|
|
611
645
|
* @param direction - Direction to enumerate ("next" or "previous")
|
|
612
|
-
* @returns Array of run times
|
|
646
|
+
* @returns Array of run times
|
|
613
647
|
* @private
|
|
614
648
|
*/
|
|
615
649
|
private _enumerateRuns;
|
|
@@ -725,17 +759,35 @@ declare class Cron<T = undefined> {
|
|
|
725
759
|
*/
|
|
726
760
|
private _previous;
|
|
727
761
|
/**
|
|
728
|
-
*
|
|
729
|
-
|
|
730
|
-
|
|
762
|
+
* The exact instant of a reference date. Strings are read in the timezone of the job.
|
|
763
|
+
*/
|
|
764
|
+
private _toMs;
|
|
765
|
+
/**
|
|
766
|
+
* Find the first occurrence after (direction 1) or before (direction -1) referenceMs,
|
|
767
|
+
* walking the wall clock from `start`. Same algorithm as find_occurrence in croner-rust.
|
|
731
768
|
*
|
|
732
|
-
*
|
|
769
|
+
* When the clock goes back (DST fall back), a range of wall clock times repeats, and one
|
|
770
|
+
* walk covers only one pass of it. If the reference is on the pass the search meets first,
|
|
771
|
+
* the other pass still lies ahead, so it is walked too, and the nearer match wins.
|
|
772
|
+
*/
|
|
773
|
+
private _findOccurrence;
|
|
774
|
+
/**
|
|
775
|
+
* Walk the wall clock from `start` until a time matches the pattern, and runs after
|
|
776
|
+
* (direction 1) or before (direction -1) referenceMs. Same algorithm as walk in croner-rust.
|
|
777
|
+
*/
|
|
778
|
+
private _walk;
|
|
779
|
+
/**
|
|
780
|
+
* When a matching wall clock time runs, if that is after (direction 1) or
|
|
781
|
+
* before (direction -1) referenceMs. DST rules, shared with croner-rust:
|
|
782
|
+
* - A time that occurs twice (fall back) runs once, at its first occurrence, for
|
|
783
|
+
* fixed-time jobs, and on both occurrences for interval jobs.
|
|
784
|
+
* - A time that doesn't exist (spring forward) is skipped by interval jobs, and runs
|
|
785
|
+
* when the clock has jumped forward for fixed-time jobs, if that is on the same day.
|
|
733
786
|
*/
|
|
734
|
-
private
|
|
787
|
+
private _runAt;
|
|
735
788
|
/**
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
* Should only be called from the _next function.
|
|
789
|
+
* When startAt and interval are set and there is no previous run, find the last run there
|
|
790
|
+
* would have been between startAt and now. Returns undefined if startAt is in the future.
|
|
739
791
|
*/
|
|
740
792
|
private _calculatePreviousRun;
|
|
741
793
|
}
|
|
@@ -749,7 +801,10 @@ declare class Cron<T = undefined> {
|
|
|
749
801
|
*/
|
|
750
802
|
declare class CronIterator<T = undefined> implements Iterator<Date, undefined>, Iterable<Date> {
|
|
751
803
|
private cron;
|
|
804
|
+
/** Last returned date, or the user supplied start date */
|
|
752
805
|
private cursor;
|
|
806
|
+
/** Time of creation or reset, used as reference while there is no cursor */
|
|
807
|
+
private now;
|
|
753
808
|
private done;
|
|
754
809
|
private initialMaxRuns;
|
|
755
810
|
private remainingRuns;
|
|
@@ -758,13 +813,6 @@ declare class CronIterator<T = undefined> implements Iterator<Date, undefined>,
|
|
|
758
813
|
* @param startAt - Optional starting date for iteration. Defaults to current time if omitted.
|
|
759
814
|
*/
|
|
760
815
|
constructor(cron: Cron<T>, startAt?: Date | string | null);
|
|
761
|
-
/**
|
|
762
|
-
* Normalizes a cursor argument: Date objects are cloned to prevent external mutation;
|
|
763
|
-
* strings are preserved as-is so that nextRun() can parse them using the Cron instance's
|
|
764
|
-
* configured timezone (via CronDate/fromTZISO), matching the behaviour of nextRun() and nextRuns().
|
|
765
|
-
* @private
|
|
766
|
-
*/
|
|
767
|
-
private static _normalizeCursor;
|
|
768
816
|
/**
|
|
769
817
|
* Returns the next scheduled date and advances the cursor.
|
|
770
818
|
* Implements the ECMAScript Iterator protocol.
|
package/dist/croner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function p(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function E(s,e){return p(y(s,e))-s.getTime()}function b(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function $(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?w(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):w(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function k(s,e,t){return M($(s,e),t)}function M(s,e,t){let r=new Date(p(s)),n=y(r,s.tz),a=p(s),i=p(n),o=a-i,h=new Date(r.getTime()+o),l=y(h,s.tz);if(b(l,s)){let d=E(new Date(h.getTime()-864e5),s.tz)-E(new Date(h.getTime()+864e5),s.tz),g=d>0?d:36e5,A=new Date(h.getTime()-g),L=y(A,s.tz),R=new Date(h.getTime()+g),Y=y(R,s.tz),v=b(L,s),F=b(Y,s);if(v||F){let O=v?A:h,Z=v?h:R;return t!==void 0?O.getTime()>=t?O:Z:O}return h}let u=new Date(h.getTime()+p(s)-p(l)),m=y(u,s.tz);if(b(m,s))return u;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>u.getTime()?h:u}function y(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}catch(a){let i=a instanceof Error?a.message:String(a);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${i}`)}let n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let a of r)(a.type==="year"||a.type==="month"||a.type==="day"||a.type==="hour"||a.type==="minute"||a.type==="second")&&(n[a.type]=parseInt(a.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function w(s,e,t,r,n,a,i){return{y:s,m:e,d:t,h:r,i:n,s:a,tz:i}}var _=[1,2,4,8,16],T=class s{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=Array(1e4).fill(0),this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let i=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${i} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let a=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return a.fill(n);let i=t.split(",");if(i.length>1)for(let o of i)this.partToArray(e,o,r,n);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,n):t.includes("-")?this.handleRange(t,e,r,n):t.includes("/")?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,r,n){let a=this.extractNth(e,t),i=e.toUpperCase().includes("W");if(t!=="day"&&i)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");i&&(t="nearestWeekdays");let o=parseInt(a[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,a[1]||n)}setPart(e,t,r){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,r);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,a){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+a+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let a=this.extractNth(e,t),i=a[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(i===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,h,l]=i,u=parseInt(o,10)+r,m=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(u,m,d,t,e);for(let g=u;g<=m;g+=d)this.setPart(t,g,a[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let a=this.extractNth(e,t),i=a[0].split("-");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(i[0],10)+r,h=parseInt(i[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,a[1]||n)}handleStepping(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let a=this.extractNth(e,t),i=a[0].split("/");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)i[0]===""&&(i[0]="*");else{if(i[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(i[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;i[0]!=="*"&&(o=parseInt(i[0],10)+r);let h=parseInt(i[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)t==="year"&&l===0||this.setPart(t,l,a[1]||n)}replaceAlpha(e,t){let r=e;for(let[n,a]of Object.entries(t))r=r.replace(new RegExp(n,"gi"),a);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|_[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var H=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],c=class s{tz;afterMs;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?H[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r-2:a===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r===n?r-2:r+1:i===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let i=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===i&&o++;if(n&63&&_[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(e,t,l)).getUTCDay()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}catch(t){let r=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear()}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.afterMs=e.afterMs}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){let t=k(e);this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(k(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_matchDayValue(e,t,r,n){let a=e;if(!a){for(let i=0;i<r.nearestWeekdays.length;i++)if(r.nearestWeekdays[i]){let o=this.getNearestWeekday(this.year,this.month,i+1);if(o!==-1&&o===t){a=1;break}}}if(r.lastWeekday){let i=this.getLastWeekday(this.year,this.month);t===i&&(a=1)}if(r.lastDayOfMonth){let i=this.getLastDayOfMonth(this.year,this.month);t===i&&(a=1)}if(!r.starDOW){let i=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(i+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?a=a&&o:!n.domAndDow&&!r.starDOM?a=a||o:a=a&&o}return a}_findMatch(e,t,r,n,a){let i=this[t],o=this[t]+n,h=a===1?l=>l<r[t].length:l=>l>=0;for(let l=o;h(l);l+=a){let u=r[t][l];if(t==="day"&&(u=this._matchDayValue(u,l-n,r,e)),u)return this[t]=l-n,i!==this[t]?2:1}return 3}recurse(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let i=this.year+1;i<e.year.length&&i<1e4;i++)if(e.year[i]===1){a=i;break}if(a===-1)return null;this.year=a,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let n=this.findNext(t,f[r][0],e,f[r][2]);if(n>1){let a=r+1;for(;a<f.length;)this[f[a][0]]=-f[a][2],a++;if(n===3){if(this[f[r][1]]++,this[f[r][0]]=-f[r][2],this.apply(),r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){i=o;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let a=this.findPrevious(t,f[r][0],e,f[r][2]);if(a>1){let i=r+1;for(;i<f.length;){let o=f[i][0],h=f[i][2],l=this.getMaxPatternValue(o,e,h);o==="day"?this[o]=Math.min(l,this.getLastDayOfMonth(this.year,this.month)):this[o]=l,i++}if(a===3){if(this[f[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,m=this.month;for(;m<0;)m+=12,u--;for(;m>11;)m-=12,u++;let d=this.getLastDayOfMonth(u,m);this.day>d&&(this.day=d)}this.apply();let o=f[r][0],h=f[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let u=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,u)}else this[o]=l;if(this.apply(),r===0){let u=f[1][2],m=this.getMaxPatternValue("day",e,u),d=this.getLastDayOfMonth(this.year,this.month),g=Math.min(m,d);g!==this.day&&(this.day=g,this.hour=this.getMaxPatternValue("hour",e,f[2][2]),this.minute=this.getMaxPatternValue("minute",e,f[3][2]),this.second=this.getMaxPatternValue("second",e,f[4][2]))}if(r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=f.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e,t){let r=t??this.afterMs;return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):M(w(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1,r)}getTime(e){return this.getDate(!1,e).getTime()}setAfterMs(e){this.afterMs=e}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<f.length;r++){let n=f[r][0],a=f[r][2],i=this[n];if(i+a<0||i+a>=e[n].length)return!1;let o=e[n][i+a];if(n==="day"&&(o=this._matchDayValue(o,i,e,t)),!o)return!1}return!0}};function U(s){s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow;let e=(t,r)=>t===void 0?r:t;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(s.startAt&&(s.startAt=new c(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new c(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function C(s){return typeof s=="function"}function S(s){return C(s)}function W(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var N=1440*60*1e3,z=30*1e3,D=[],I=class{name;options;_states;fn;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*N;return new Date(e.getTime()+t)}return e}_nextTarget(e,t){let r=(this.options.dayOffset??0)*N;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),a=h=>h?new c(new Date(h.getTime()-r),this.getTz()):void 0,i={startAt:a(this.options.startAt),stopAt:a(this.options.stopAt),includeStartAt:r!==0},o=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;o;){let h=this.applyDayOffset(o.getDate(!1));if(this.options.startAt&&h.getTime()<this.options.startAt.getTime()){o=this._next(o,n,i);continue}return this.options.stopAt&&h.getTime()>=this.options.stopAt.getTime()?null:h}return null}constructor(e,t,r){let n,a;for(let i of[t,r])if(C(i))a=i;else if(typeof i=="object")n=i;else if(i!==void 0)throw new Error("Cron: Invalid argument passed. Should be one of function, or object (options).");if(this.name=n?.name,this.options=U(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new T("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new c(e,this.getTz()):this._states.pattern=new T(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(D.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");D.push(this)}return a!==void 0&&S(a)&&(this.fn=a,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new P(this,e)}_enumerateRuns(e,t,r){let n=[],a=t?new c(t,this.getTz()):null,i=r==="next"?this._next:this._previous;for(;e--;){let o=i.call(this,a);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),a=o}return n}match(e){if(this._states.once){let r=new c(e,this.getTz());r.ms=0;let n=new c(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new c(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this.nextRun(this._states.currentRun)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=this._next(e);if(t){if(e instanceof c||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new c(e,r).getTime()}}else return null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=D.indexOf(this);e>=0&&D.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,a=n&&n.getTime()>r.getTime()?void 0:n,i=this._nextTarget(void 0,r),o=i?i.getTime()-r.getTime():null,h=this._nextTarget(a,r);return o==null||isNaN(o)||h===null?this:(o>z&&(o=z),o<0&&(o=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(h),o),this._states.currentTimeout&&this.options.unref&&W(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new c(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new c(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):r&&n&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,a=r?r.stopAt:this.options.stopAt,i=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,i]=this._calculatePreviousRun(e,i,t,n),o=!e),e=new c(e??t,this.getTz());let h=r?.includeStartAt&&n&&!o?new c(new Date(n.getTime()-1e3),this.getTz()):n;h&&e&&e.getTime()<h.getTime()&&(e=h);let l=this._states.once||new c(e,this.getTz());if(!o&&l!==this._states.once&&(l=l.increment(this._states.pattern,this.options,i)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let u=e.getTime()-this._states.once.getTime();if(u>0&&!this.options.allowPast&&u>1e3)return null}return l=this._resolveDSTOverlap(l,e,i),l===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||a&&l.getTime()>=a.getTime()?null:l}_previous(e){let t=new c(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new c(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_resolveDSTOverlap(e,t,r){if(e===null||e===this._states.once||typeof this.getTz()!="string")return e;let n=t.getTime(),a=e.getTime(),i=(this.options.interval&&r?this.options.interval:1)*1e3,o=a-n,h=Date.UTC(t.year,t.month,t.day,t.hour,t.minute,t.second)-n,l=Date.UTC(e.year,e.month,e.day,e.hour,e.minute,e.second)-a,u=h-l;if(u>0&&(o>=i+u||o<0)){let m=o<0?a+u:a-u,d=new Date(m),g=new c(d,this.getTz());if(g.match(this._states.pattern,this.options)&&m>n)return g.setAfterMs(m),g}return e}_calculatePreviousRun(e,t,r,n){let a=new c(r,this.getTz()),i=e;if(n&&n.getTime()<=a.getTime()){i=n;let o=i.getTime()+this.options.interval*1e3;for(;o<=a.getTime();){let h=new c(i,this.getTz()).increment(this._states.pattern,this.options,!0);if(h===null)break;i=h,o=i.getTime()+this.options.interval*1e3}t=!0}return i===null&&(i=void 0),[i,t]}},P=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*N;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};export{I as Cron,c as CronDate,P as CronIterator,T as CronPattern,D as scheduledJobs};
|
|
1
|
+
function w(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function b(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function O(s){let e=s.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function j(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return O(s)?y(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):y(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function D(s,e,t){return P(j(s,e),t)}function P(s,e){let t=v(s);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function v(s){let e=w(s),t=a=>M(new Date(a),s.tz),r=e-t(e),i=g(new Date(r),s.tz);if(b(i,s)){let a=w(i)-r,o=r-(t(r-x)-a);if(o<r&&b(g(new Date(o),s.tz),s))return{kind:"ambiguous",earlier:new Date(o),later:new Date(r)};let u=r+(a-t(r+x));return u>r&&b(g(new Date(u),s.tz),s)?{kind:"ambiguous",earlier:new Date(r),later:new Date(u)}:{kind:"single",date:new Date(r)}}let n=e-(w(i)-r);return b(g(new Date(n),s.tz),s)?{kind:"single",date:new Date(n)}:{kind:"gap",before:new Date(Math.min(r,n)),after:new Date(Math.max(r,n))}}var x=3*36e5;function M(s,e){return w(g(s,e))-(s.getTime()-s.getUTCMilliseconds())}function _(s,e,t){let r=M(new Date(s),t);for(;e-s>1e3;){let i=s+Math.floor((e-s)/2e3)*1e3;M(new Date(i),t)===r?s=i:e=i}return e}function U(s,e){let t=v(g(new Date(s),e));if(t.kind==="ambiguous")return s<t.later.getTime()?"earlier":"later"}var E=new Map;function g(s,e){if(e===void 0)return y(s.getFullYear(),s.getMonth()+1,s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds());let t=E.get(e),r;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),E.set(e,t)),r=t.formatToParts(s)}catch(n){let a=n instanceof Error?n.message:String(n);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let i={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let n of r)(n.type==="year"||n.type==="month"||n.type==="day"||n.type==="hour"||n.type==="minute"||n.type==="second")&&(i[n.type]=parseInt(n.value,10));if(isNaN(i.year)||isNaN(i.month)||isNaN(i.day)||isNaN(i.hour)||isNaN(i.minute)||isNaN(i.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(i)}`);return i.hour===24&&(i.hour=0),{y:i.year,m:i.month,d:i.day,h:i.hour,i:i.minute,s:i.second,tz:e}}function y(s,e,t,r,i,n,a){return{y:s,m:e,d:t,h:r,i,s:n,tz:a}}var N=[1,2,4,8,16],C=class s{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=Array(1e4).fill(0),this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let o=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${o} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let i=(n,a)=>!n.includes("*")&&!n.includes("/")&&a.filter(o=>o).length===1;this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,r,i){let n=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return n.fill(i);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,r,i);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,i):t.includes("-")?this.handleRange(t,e,r,i):t.includes("/")?this.handleStepping(t,e,r,i):t!==""&&this.handleNumber(t,e,r,i)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,r,i){let n=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=parseInt(n[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,n[1]||i)}setPart(e,t,r){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,r);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,i,n){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+n+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[i].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[i].length+")")}}handleRangeWithStepping(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let n=this.extractNth(e,t),a=n[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,c=parseInt(o,10)+r,d=parseInt(u,10)+r,m=parseInt(l,10);this.validateNotNaN(c,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(c,d,m,t,e);for(let p=c;p<=d;p+=m)this.setPart(t,p,n[1]||i)}extractNth(e,t){let r=e,i;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");i=r.split("#")[1],r=r.split("#")[0]}else if(r.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");i="L",r=r.slice(0,-1)}return[r,i]}handleRange(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let n=this.extractNth(e,t),a=n[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+r,u=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,n[1]||i)}handleStepping(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let n=this.extractNth(e,t),a=n[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=parseInt(a[0],10)+r);let u=parseInt(a[1],10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,n[1]||i)}replaceAlpha(e,t){let r=e;for(let[i,n]of Object.entries(t))r=r.replace(new RegExp(i,"gi"),n);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|N[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var $=[31,28,31,30,31,30,31,31,30,31,30,31],h=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],f=class s{tz;instantMs;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?$[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),n=new Date(Date.UTC(e,t,r)).getUTCDay();return n===0?r-2:n===6?r-1:r}getNearestWeekday(e,t,r){let i=this.getLastDayOfMonth(e,t);if(r>i)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===i?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,i){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let u=1;u<=r;u++)new Date(Date.UTC(e,t,u)).getUTCDay()===a&&o++;if(i&63&&N[o-1]&i)return!0;if(i&32){let u=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=u;l++)if(new Date(Date.UTC(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=g(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.instantMs=e.getTime()-this.ms}catch(t){let r=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.instantMs=e.getTime()-this.ms}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(O(e))return this.fromDate(D(e));let t=D(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(D(e,this.tz))}findNext(e,t,r,i){return this._findMatch(e,t,r,i,1)}_matchDayValue(e,t,r,i){let n=e;if(!n){for(let a=0;a<r.nearestWeekdays.length;a++)if(r.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){n=1;break}}}if(r.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(n=1)}if(r.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(n=1)}if(!r.starDOW){let a=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?n=n&&o:!i.domAndDow&&!r.starDOM?n=n||o:n=n&&o}return n}_findMatch(e,t,r,i,n){let a=this[t],o=this[t]+i,u=n===1?l=>l<r[t].length:l=>l>=0;for(let l=o;u(l);l+=n){let c=r[t][l];if(t==="day"&&(c=this._matchDayValue(c,l-i,r,e)),c)return this[t]=l-i,a!==this[t]?2:1}return 3}recurse(e,t,r){let i=this.year,n=r;for(;typeof n=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;n=this.recurseStep(e,t,n)}return n}recurseStep(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let n=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){n=a;break}if(n===-1)return null;this.year=n,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let i=this.findNext(t,h[r][0],e,h[r][2]);if(i>1){let n=r+1;for(;n<h.length;)this[h[n][0]]=-h[n][2],n++;if(i===3){if(this[h[r][1]]++,this[h[r][0]]=-h[r][2],this.apply(),r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return r-1}return r+=1,r>=h.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:r}increment(e,t,r){return this.instantMs=void 0,this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,r){let i=this.year,n=r;for(;typeof n=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;n=this.recurseBackwardStep(e,t,n)}return n}recurseBackwardStep(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let n=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){n=a;break}if(n===-1)return null;this.year=n,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let i=this.findPrevious(t,h[r][0],e,h[r][2]);if(i>1){let n=r+1;for(;n<h.length;){let a=h[n][0],o=h[n][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,n++}if(i===3){if(this[h[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let c=this.getLastDayOfMonth(u,l);this.day>c&&(this.day=c)}this.apply();let a=h[r][0],o=h[r][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),r===0){let u=h[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,h[2][2]),this.minute=this.getMaxPatternValue("minute",e,h[3][2]),this.second=this.getMaxPatternValue("second",e,h[4][2]))}if(r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return r-1}return r+=1,r>=h.length?this:this.year<0?null:r}getMaxPatternValue(e,t,r){let i=t[e].length-1-r;for(let n=t[e].length-1;n>=0;n--)if(t[e][n]){i=n-r;break}if(e==="day"){let n=this.getLastDayOfMonth(this.year,this.month);return t.lastDayOfMonth||!t.starDOW?n:Math.min(i,n)}return i}findPrevious(e,t,r,i){return this._findMatch(e,t,r,i,-1)}getDate(e){return!e&&this.instantMs!==void 0&&typeof this.tz!="number"?new Date(this.instantMs+(this.tz===void 0?this.ms:0)):e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):P(y(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<h.length;r++){let i=h[r][0],n=h[r][2],a=this[i];if(a+n<0||a+n>=e[i].length)return!1;let o=e[i][a+n];if(i==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}};function z(s){s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow;let e=(r,i)=>r===void 0?i:r;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");s.timezone===""&&(s.timezone=void 0);let t=s.timezone??s.utcOffset;if(s.startAt&&(s.startAt=W(new f(s.startAt,t))),s.stopAt&&(s.stopAt=W(new f(s.stopAt,t))),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function W(s){return s.ms?(s.ms=0,new f(new Date(s.getTime()+1e3),s.tz)):s}function T(s){return typeof s=="function"}function I(s){return T(s)}function L(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var R=1440*60*1e3,F=30*1e3,k=[],Y=class{name;options;_states;fn;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*R}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let r=this._offsetMs(),i=this._next(this._shift(e),new Date(t.getTime()-r),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return i?this.applyDayOffset(i.getDate(!1)):null}_previousTarget(e,t){let r=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return r?this.applyDayOffset(r.getDate(!1)):null}_shift(e){if(e!=null)return new f(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,r){let i,n;if(T(t))n=t;else if(typeof t=="object")i=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(T(r))n=r;else if(typeof r=="object")i=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=i?.name,this.options=z(i),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:i?i.maxRuns:void 0,paused:i?i.paused:!1,pattern:new C("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new f(e,this.getTz()):this._states.pattern=new C(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(k.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");k.push(this)}return n!==void 0&&I(n)&&(this.fn=n,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new A(this,e)}_enumerateRuns(e,t,r){let i=[],n=new Date,a=t;for(;e-- >0;){let o=r==="next"?this._nextTarget(a,n):this._previousTarget(a,n);if(!o)break;i.push(o),a=o}return i}match(e){if(this._states.once){let r=new f(e,this.getTz());r.ms=0;let i=new f(this._states.once,this.getTz());return i.ms=0,r.getTime()===i.getTime()}let t=new f(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,r=this._nextTarget(e,t);return r?r.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=k.indexOf(this);e>=0&&k.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,i=this._nextTarget(void 0,r),n=i?i.getTime()-r.getTime():null,a=this._states.currentRun;a&&a.getTime()>r.getTime()&&(a=void 0);let o=this._nextTarget(a,r);return n===null||isNaN(n)||o===null?this:(n>F&&(n=F),n<0&&(n=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),n),this._states.currentTimeout&&this.options.unref&&L(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new f(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(T(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new f(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),i=this._states.blocking&&this.options.protect;r&&!i?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):r&&i&&T(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let i=r?r.startAt:this._startAt,n=r?r.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&i&&this.options.interval&&(e=this._calculatePreviousRun(i,t),e&&(o=!0),u=!e);let l=e??t??new Date,c=this._toMs(l);e=new f(l,this.getTz()),i&&c<i.getTime()&&(e=u?i:new f(new Date(i.getTime()-1e3),this.getTz()),c=e.getTime());let d=this._states.once||new f(e,this.getTz());if(!u&&d!==this._states.once&&(d=this._findOccurrence(e,c,1,o)),this._states.once){let m=this._states.once.getTime(),p=c-m;if(i&&m<i.getTime()||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?p>=0:p>1e3&&!this.options.allowPast))return null}return d===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||n&&d.getTime()>=n.getTime()?null:d}_previous(e,t){let r=this._toMs(e??new Date);if(t.stopAt&&r>t.stopAt.getTime()&&(r=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<r?this._states.once:null;let i=this._findOccurrence(new f(new Date(r),this.getTz()),r,-1);return i===null||t.startAt&&i.getTime()<t.startAt.getTime()?null:i}_toMs(e){return e instanceof Date?e.getTime():new f(e,this.getTz()).getTime()}_findOccurrence(e,t,r,i=!1){let n=this._walk(e,t,r,i),a=this.getTz();if(this._states.pattern.isFixedTime&&r===1||typeof a=="number"||U(t,a)!==(r===1?"earlier":"later"))return n;let o=Math.floor(t/1e3)*1e3,u=r===1?_(o,o+R,a):_(o-R,o,a)-1e3;if(n&&(u-n.getTime())*r>0)return n;let l=this._walk(new f(new Date(u),a),u-r,r,!1,!0);return!n||!l?n??l:(n.getTime()-l.getTime())*r>0?l:n}_walk(e,t,r,i,n=!1){let a=this._states.pattern,o=(l,c)=>r===1?l.increment(a,this.options,c):l.decrement(a,this.options),u=new f(e,this.getTz());for((!n||!u.match(a,this.options))&&(u=o(u,i));u;){let l=this._runAt(u,t,r);if(l)return new f(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,r){let i=m=>(m.getTime()-t)*r>0,n=e.tz;if(typeof n=="number"){let m=e.getDate();return i(m)?m:null}let a=y(e.year,e.month+1,e.day,e.hour,e.minute,e.second,n),o=v(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return i(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:m,later:p}=o;return(u?[m]:r===1?[m,p]:[p,m]).find(i)??null}if(!u)return null;let l=new Date(_(o.before.getTime(),o.after.getTime(),n)),c=g(l,n);return c.y===a.y&&c.m===a.m&&c.d===a.d&&i(l)?l:null}_calculatePreviousRun(e,t){let r=new f(t,this.getTz()).getTime();if(e.getTime()>r)return;let i=this.options.interval*1e3,n=e;for(;n.getTime()+i<=r;){let a=new f(n,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;n=a}return n}},A=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.options.maxRuns??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}};export{Y as Cron,f as CronDate,A as CronIterator,C as CronPattern,k as scheduledJobs};
|
package/dist/croner.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Cron=(()=>{var p=(s,e,t)=>()=>{if(t)throw t[0];try{return s&&(e=s(s=0)),e}catch(r){throw t=[r],r}};var G=(s,e)=>()=>{try{return e||s((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};function T(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function W(s,e){return T(y(s,e))-s.getTime()}function w(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function Q(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?D(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):D(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function _(s,e,t){return N(Q(s,e),t)}function N(s,e,t){let r=new Date(T(s)),n=y(r,s.tz),a=T(s),i=T(n),o=a-i,h=new Date(r.getTime()+o),l=y(h,s.tz);if(w(l,s)){let d=W(new Date(h.getTime()-864e5),s.tz)-W(new Date(h.getTime()+864e5),s.tz),g=d>0?d:36e5,U=new Date(h.getTime()-g),B=y(U,s.tz),S=new Date(h.getTime()+g),J=y(S,s.tz),k=w(B,s),K=w(J,s);if(k||K){let M=k?U:h,q=k?h:S;return t!==void 0?M.getTime()>=t?M:q:M}return h}let u=new Date(h.getTime()+T(s)-T(l)),m=y(u,s.tz);if(w(m,s))return u;if(e)throw new Error("Invalid date passed to fromTZ()");return h.getTime()>u.getTime()?h:u}function y(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}catch(a){let i=a instanceof Error?a.message:String(a);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${i}`)}let n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let a of r)(a.type==="year"||a.type==="month"||a.type==="day"||a.type==="hour"||a.type==="minute"||a.type==="second")&&(n[a.type]=parseInt(a.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function D(s,e,t,r,n,a,i){return{y:s,m:e,d:t,h:r,i:n,s:a,tz:i}}var z=p(()=>{});var P,C,A=p(()=>{P=[1,2,4,8,16],C=class s{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=Array(1e4).fill(0),this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let i=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${i} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let a=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return a.fill(n);let i=t.split(",");if(i.length>1)for(let o of i)this.partToArray(e,o,r,n);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,n):t.includes("-")?this.handleRange(t,e,r,n):t.includes("/")?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,r,n){let a=this.extractNth(e,t),i=e.toUpperCase().includes("W");if(t!=="day"&&i)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");i&&(t="nearestWeekdays");let o=parseInt(a[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,a[1]||n)}setPart(e,t,r){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,r);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,a){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+a+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let a=this.extractNth(e,t),i=a[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(i===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,h,l]=i,u=parseInt(o,10)+r,m=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(u,m,d,t,e);for(let g=u;g<=m;g+=d)this.setPart(t,g,a[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let a=this.extractNth(e,t),i=a[0].split("-");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(i[0],10)+r,h=parseInt(i[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,a[1]||n)}handleStepping(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let a=this.extractNth(e,t),i=a[0].split("/");if(i.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)i[0]===""&&(i[0]="*");else{if(i[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(i[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;i[0]!=="*"&&(o=parseInt(i[0],10)+r);let h=parseInt(i[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)t==="year"&&l===0||this.setPart(t,l,a[1]||n)}replaceAlpha(e,t){let r=e;for(let[n,a]of Object.entries(t))r=r.replace(new RegExp(n,"gi"),a);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|P[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}}});var ee,f,c,R=p(()=>{z();A();ee=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],c=class s{tz;afterMs;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?ee[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r-2:a===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r===n?r-2:r+1:i===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let i=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===i&&o++;if(n&63&&P[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(e,t,l)).getUTCDay()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=y(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.afterMs=e.getTime()-e.getUTCMilliseconds()}catch(t){let r=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear()}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.afterMs=e.afterMs}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){let t=_(e);this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(_(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_matchDayValue(e,t,r,n){let a=e;if(!a){for(let i=0;i<r.nearestWeekdays.length;i++)if(r.nearestWeekdays[i]){let o=this.getNearestWeekday(this.year,this.month,i+1);if(o!==-1&&o===t){a=1;break}}}if(r.lastWeekday){let i=this.getLastWeekday(this.year,this.month);t===i&&(a=1)}if(r.lastDayOfMonth){let i=this.getLastDayOfMonth(this.year,this.month);t===i&&(a=1)}if(!r.starDOW){let i=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(i+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?a=a&&o:!n.domAndDow&&!r.starDOM?a=a||o:a=a&&o}return a}_findMatch(e,t,r,n,a){let i=this[t],o=this[t]+n,h=a===1?l=>l<r[t].length:l=>l>=0;for(let l=o;h(l);l+=a){let u=r[t][l];if(t==="day"&&(u=this._matchDayValue(u,l-n,r,e)),u)return this[t]=l-n,i!==this[t]?2:1}return 3}recurse(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let i=this.year+1;i<e.year.length&&i<1e4;i++)if(e.year[i]===1){a=i;break}if(a===-1)return null;this.year=a,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let n=this.findNext(t,f[r][0],e,f[r][2]);if(n>1){let a=r+1;for(;a<f.length;)this[f[a][0]]=-f[a][2],a++;if(n===3){if(this[f[r][1]]++,this[f[r][0]]=-f[r][2],this.apply(),r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){i=o;break}if(i===-1)return null;this.year=i,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let a=this.findPrevious(t,f[r][0],e,f[r][2]);if(a>1){let i=r+1;for(;i<f.length;){let o=f[i][0],h=f[i][2],l=this.getMaxPatternValue(o,e,h);o==="day"?this[o]=Math.min(l,this.getLastDayOfMonth(this.year,this.month)):this[o]=l,i++}if(a===3){if(this[f[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,m=this.month;for(;m<0;)m+=12,u--;for(;m>11;)m-=12,u++;let d=this.getLastDayOfMonth(u,m);this.day>d&&(this.day=d)}this.apply();let o=f[r][0],h=f[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let u=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,u)}else this[o]=l;if(this.apply(),r===0){let u=f[1][2],m=this.getMaxPatternValue("day",e,u),d=this.getLastDayOfMonth(this.year,this.month),g=Math.min(m,d);g!==this.day&&(this.day=g,this.hour=this.getMaxPatternValue("hour",e,f[2][2]),this.minute=this.getMaxPatternValue("minute",e,f[3][2]),this.second=this.getMaxPatternValue("second",e,f[4][2]))}if(r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=f.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e,t){let r=t??this.afterMs;return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):N(D(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1,r)}getTime(e){return this.getDate(!1,e).getTime()}setAfterMs(e){this.afterMs=e}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<f.length;r++){let n=f[r][0],a=f[r][2],i=this[n];if(i+a<0||i+a>=e[n].length)return!1;let o=e[n][i+a];if(n==="day"&&(o=this._matchDayValue(o,i,e,t)),!o)return!1}return!0}}});function L(s){s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow;let e=(t,r)=>t===void 0?r:t;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(s.startAt&&(s.startAt=new c(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new c(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}var Y=p(()=>{R()});function b(s){return typeof s=="function"}function F(s){return b(s)}function Z(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var $=p(()=>{});var E,j,v,O,x,H=p(()=>{R();A();Y();$();E=1440*60*1e3,j=30*1e3,v=[],O=class{name;options;_states;fn;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*E;return new Date(e.getTime()+t)}return e}_nextTarget(e,t){let r=(this.options.dayOffset??0)*E;if(this._states.once&&this._states.currentRun&&this._states.once.getTime()+r<=this._states.currentRun.getTime())return null;let n=new Date(t.getTime()-r),a=h=>h?new c(new Date(h.getTime()-r),this.getTz()):void 0,i={startAt:a(this.options.startAt),stopAt:a(this.options.stopAt),includeStartAt:r!==0},o=this._next(e?new Date(e.getTime()-r):void 0,n,i);for(;o;){let h=this.applyDayOffset(o.getDate(!1));if(this.options.startAt&&h.getTime()<this.options.startAt.getTime()){o=this._next(o,n,i);continue}return this.options.stopAt&&h.getTime()>=this.options.stopAt.getTime()?null:h}return null}constructor(e,t,r){let n,a;for(let i of[t,r])if(b(i))a=i;else if(typeof i=="object")n=i;else if(i!==void 0)throw new Error("Cron: Invalid argument passed. Should be one of function, or object (options).");if(this.name=n?.name,this.options=L(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new C("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new c(e,this.getTz()):this._states.pattern=new C(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(v.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");v.push(this)}return a!==void 0&&F(a)&&(this.fn=a,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new x(this,e)}_enumerateRuns(e,t,r){let n=[],a=t?new c(t,this.getTz()):null,i=r==="next"?this._next:this._previous;for(;e--;){let o=i.call(this,a);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),a=o}return n}match(e){if(this._states.once){let r=new c(e,this.getTz());r.ms=0;let n=new c(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new c(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this.nextRun(this._states.currentRun)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=this._next(e);if(t){if(e instanceof c||e instanceof Date)return t.getTime()-e.getTime();{let r=typeof e=="string"?this.getTz():void 0;return t.getTime()-new c(e,r).getTime()}}else return null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=v.indexOf(this);e>=0&&v.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,n=this._states.blocking&&this.options.protect?void 0:this._states.currentRun,a=n&&n.getTime()>r.getTime()?void 0:n,i=this._nextTarget(void 0,r),o=i?i.getTime()-r.getTime():null,h=this._nextTarget(a,r);return o==null||isNaN(o)||h===null?this:(o>j&&(o=j),o<0&&(o=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(h),o),this._states.currentTimeout&&this.options.unref&&Z(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new c(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(b(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new c(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):r&&n&&b(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let n=r?r.startAt:this.options.startAt,a=r?r.stopAt:this.options.stopAt,i=!!(e||this._states.currentRun),o=!1;!e&&n&&this.options.interval&&([e,i]=this._calculatePreviousRun(e,i,t,n),o=!e),e=new c(e??t,this.getTz());let h=r?.includeStartAt&&n&&!o?new c(new Date(n.getTime()-1e3),this.getTz()):n;h&&e&&e.getTime()<h.getTime()&&(e=h);let l=this._states.once||new c(e,this.getTz());if(!o&&l!==this._states.once&&(l=l.increment(this._states.pattern,this.options,i)),this._states.once){if(n&&this._states.once.getTime()<n.getTime()||this._states.currentRun&&this._states.once.getTime()<=this._states.currentRun.getTime()||e.getTime()===this._states.once.getTime())return null;let u=e.getTime()-this._states.once.getTime();if(u>0&&!this.options.allowPast&&u>1e3)return null}return l=this._resolveDSTOverlap(l,e,i),l===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||a&&l.getTime()>=a.getTime()?null:l}_previous(e){let t=new c(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new c(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_resolveDSTOverlap(e,t,r){if(e===null||e===this._states.once||typeof this.getTz()!="string")return e;let n=t.getTime(),a=e.getTime(),i=(this.options.interval&&r?this.options.interval:1)*1e3,o=a-n,h=Date.UTC(t.year,t.month,t.day,t.hour,t.minute,t.second)-n,l=Date.UTC(e.year,e.month,e.day,e.hour,e.minute,e.second)-a,u=h-l;if(u>0&&(o>=i+u||o<0)){let m=o<0?a+u:a-u,d=new Date(m),g=new c(d,this.getTz());if(g.match(this._states.pattern,this.options)&&m>n)return g.setAfterMs(m),g}return e}_calculatePreviousRun(e,t,r,n){let a=new c(r,this.getTz()),i=e;if(n&&n.getTime()<=a.getTime()){i=n;let o=i.getTime()+this.options.interval*1e3;for(;o<=a.getTime();){let h=new c(i,this.getTz()).increment(this._states.pattern,this.options,!0);if(h===null)break;i=h,o=i.getTime()+this.options.interval*1e3}t=!0}return i===null&&(i=void 0),[i,t]}},x=class s{cron;cursor;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.cursor=s._normalizeCursor(t),this.done=!1,this.initialMaxRuns=e.options.maxRuns??1/0,this.remainingRuns=this.initialMaxRuns}static _normalizeCursor(e){if(e!=null)return e instanceof Date?new Date(e.getTime()):e}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron.nextRun(this.cursor??null);if(e===null)return this.done=!0,{value:void 0,done:!0};let r=this.cron.options.dayOffset??0,n=e.getTime()-r*E;return this.cursor=new Date(n),this.remainingRuns--,{value:e,done:!1}}peek(){return this.done||this.remainingRuns<=0?null:this.cron.nextRun(this.cursor??null)}reset(e){this.cursor=s._normalizeCursor(e),this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}}});var te=G((pe,V)=>{H();V.exports=O});return te();})();
|
|
1
|
+
var Cron=(()=>{var T=(s,e,t)=>()=>{if(t)throw t[0];try{return s&&(e=s(s=0)),e}catch(r){throw t=[r],r}};var q=(s,e)=>()=>{try{return e||s((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};function D(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function w(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function N(s){let e=s.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function Q(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return N(s)?y(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):y(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function v(s,e,t){return R(Q(s,e),t)}function R(s,e){let t=_(s);if(t.kind==="single")return t.date;if(t.kind==="ambiguous")return t.earlier;if(e)throw new Error("Invalid date passed to fromTZ()");return t.after}function _(s){let e=D(s),t=a=>P(new Date(a),s.tz),r=e-t(e),i=g(new Date(r),s.tz);if(w(i,s)){let a=D(i)-r,o=r-(t(r-z)-a);if(o<r&&w(g(new Date(o),s.tz),s))return{kind:"ambiguous",earlier:new Date(o),later:new Date(r)};let u=r+(a-t(r+z));return u>r&&w(g(new Date(u),s.tz),s)?{kind:"ambiguous",earlier:new Date(r),later:new Date(u)}:{kind:"single",date:new Date(r)}}let n=e-(D(i)-r);return w(g(new Date(n),s.tz),s)?{kind:"single",date:new Date(n)}:{kind:"gap",before:new Date(Math.min(r,n)),after:new Date(Math.max(r,n))}}function P(s,e){return D(g(s,e))-(s.getTime()-s.getUTCMilliseconds())}function k(s,e,t){let r=P(new Date(s),t);for(;e-s>1e3;){let i=s+Math.floor((e-s)/2e3)*1e3;P(new Date(i),t)===r?s=i:e=i}return e}function L(s,e){let t=_(g(new Date(s),e));if(t.kind==="ambiguous")return s<t.later.getTime()?"earlier":"later"}function g(s,e){if(e===void 0)return y(s.getFullYear(),s.getMonth()+1,s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds());let t=I.get(e),r;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),I.set(e,t)),r=t.formatToParts(s)}catch(n){let a=n instanceof Error?n.message:String(n);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let i={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let n of r)(n.type==="year"||n.type==="month"||n.type==="day"||n.type==="hour"||n.type==="minute"||n.type==="second")&&(i[n.type]=parseInt(n.value,10));if(isNaN(i.year)||isNaN(i.month)||isNaN(i.day)||isNaN(i.hour)||isNaN(i.minute)||isNaN(i.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(i)}`);return i.hour===24&&(i.hour=0),{y:i.year,m:i.month,d:i.day,h:i.hour,i:i.minute,s:i.second,tz:e}}function y(s,e,t,r,i,n,a){return{y:s,m:e,d:t,h:r,i,s:n,tz:a}}var z,I,A=T(()=>{z=3*36e5;I=new Map});var x,b,E=T(()=>{x=[1,2,4,8,16],b=class s{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=Array(1e4).fill(0),this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.isFixedTime=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let o=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${o} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),this.pattern.indexOf("?")>=0)for(let n=0;n<e.length;n++)e[n]=e[n].replace(/\?/g,"*");if(e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlpha(e[4],s.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],s.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],s.DAY_NAMES)),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let i=(n,a)=>!n.includes("*")&&!n.includes("/")&&a.filter(o=>o).length===1;this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,r,i){let n=this[e];if(t===""&&!(e==="day"&&(this.lastDayOfMonth||this.lastWeekday)))throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return n.fill(i);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,r,i);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,r,i):t.includes("-")?this.handleRange(t,e,r,i):t.includes("/")?this.handleStepping(t,e,r,i):t!==""&&this.handleNumber(t,e,r,i)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,r,i){let n=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=parseInt(n[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,n[1]||i)}setPart(e,t,r){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,r);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,i,n){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+n+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[i].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[i].length+")")}}handleRangeWithStepping(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let n=this.extractNth(e,t),a=n[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,c=parseInt(o,10)+r,d=parseInt(u,10)+r,m=parseInt(l,10);this.validateNotNaN(c,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(c,d,m,t,e);for(let p=c;p<=d;p+=m)this.setPart(t,p,n[1]||i)}extractNth(e,t){let r=e,i;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");i=r.split("#")[1],r=r.split("#")[0]}else if(r.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");i="L",r=r.slice(0,-1)}return[r,i]}handleRange(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let n=this.extractNth(e,t),a=n[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+r,u=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,u,void 0,t,e);for(let l=o;l<=u;l++)this.setPart(t,l,n[1]||i)}handleStepping(e,t,r,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let n=this.extractNth(e,t),a=n[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=parseInt(a[0],10)+r);let u=parseInt(a[1],10);this.validateNotNaN(u,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,u,t,e);for(let l=o;l<this[t].length;l+=u)t==="year"&&l===0||this.setPart(t,l,n[1]||i)}replaceAlpha(e,t){let r=e;for(let[i,n]of Object.entries(t))r=r.replace(new RegExp(i,"gi"),n);return r}static DAY_NAMES={"-sun":"-7",sun:"0",mon:"1",tue:"2",wed:"3",thu:"4",fri:"5",sat:"6"};static DAY_NAMES_QUARTZ={sun:"1",mon:"2",tue:"3",wed:"4",thu:"5",fri:"6",sat:"7"};static MONTH_NAMES={jan:"1",feb:"2",mar:"3",apr:"4",may:"5",jun:"6",jul:"7",aug:"8",sep:"9",oct:"10",nov:"11",dec:"12"};static NICKNAME_MAP={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"};handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return s.NICKNAME_MAP[t]||e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|x[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}}});var X,h,f,U=T(()=>{A();E();X=[31,28,31,30,31,30,31,31,30,31,30,31],h=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],f=class s{tz;instantMs;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?X[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),n=new Date(Date.UTC(e,t,r)).getUTCDay();return n===0?r-2:n===6?r-1:r}getNearestWeekday(e,t,r){let i=this.getLastDayOfMonth(e,t);if(r>i)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===i?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,i){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let u=1;u<=r;u++)new Date(Date.UTC(e,t,u)).getUTCDay()===a&&o++;if(i&63&&x[o-1]&i)return!0;if(i&32){let u=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=u;l++)if(new Date(Date.UTC(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=g(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y,this.instantMs=e.getTime()-this.ms}catch(t){let r=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear(),this.instantMs=e.getTime()-this.ms}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms,this.instantMs=e.instantMs}apply(){if(this.month>11||this.month<0||this.day>this.getLastDayOfMonth(this.year,this.month)||this.day<1||this.hour>23||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(0);return e.setUTCFullYear(this.year,this.month,this.day),e.setUTCHours(this.hour,this.minute,this.second,this.ms),this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){if(N(e))return this.fromDate(v(e));let t=v(e,"Etc/UTC");this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(v(e,this.tz))}findNext(e,t,r,i){return this._findMatch(e,t,r,i,1)}_matchDayValue(e,t,r,i){let n=e;if(!n){for(let a=0;a<r.nearestWeekdays.length;a++)if(r.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){n=1;break}}}if(r.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(n=1)}if(r.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(n=1)}if(!r.starDOW){let a=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=r.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),r.useAndLogic?n=n&&o:!i.domAndDow&&!r.starDOM?n=n||o:n=n&&o}return n}_findMatch(e,t,r,i,n){let a=this[t],o=this[t]+i,u=n===1?l=>l<r[t].length:l=>l>=0;for(let l=o;u(l);l+=n){let c=r[t][l];if(t==="day"&&(c=this._matchDayValue(c,l-i,r,e)),c)return this[t]=l-i,a!==this[t]?2:1}return 3}recurse(e,t,r){let i=this.year,n=r;for(;typeof n=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;n=this.recurseStep(e,t,n)}return n}recurseStep(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let n=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){n=a;break}if(n===-1)return null;this.year=n,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let i=this.findNext(t,h[r][0],e,h[r][2]);if(i>1){let n=r+1;for(;n<h.length;)this[h[n][0]]=-h[n][2],n++;if(i===3){if(this[h[r][1]]++,this[h[r][0]]=-h[r][2],this.apply(),r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return 0}else if(this.apply())return r-1}return r+=1,r>=h.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:r}increment(e,t,r){return this.instantMs=void 0,this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0)}recurseBackward(e,t,r){let i=this.year,n=r;for(;typeof n=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;n=this.recurseBackwardStep(e,t,n)}return n}recurseBackwardStep(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let n=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){n=a;break}if(n===-1)return null;this.year=n,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let i=this.findPrevious(t,h[r][0],e,h[r][2]);if(i>1){let n=r+1;for(;n<h.length;){let a=h[n][0],o=h[n][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,n++}if(i===3){if(this[h[r][1]]--,r===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(r===1)if(this.day<=0)this.day=1;else{let u=this.year,l=this.month;for(;l<0;)l+=12,u--;for(;l>11;)l-=12,u++;let c=this.getLastDayOfMonth(u,l);this.day>c&&(this.day=c)}this.apply();let a=h[r][0],o=h[r][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),r===0){let u=h[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,h[2][2]),this.minute=this.getMaxPatternValue("minute",e,h[3][2]),this.second=this.getMaxPatternValue("second",e,h[4][2]))}if(r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return 0}else if(this.apply())return r-1}return r+=1,r>=h.length?this:this.year<0?null:r}getMaxPatternValue(e,t,r){let i=t[e].length-1-r;for(let n=t[e].length-1;n>=0;n--)if(t[e][n]){i=n-r;break}if(e==="day"){let n=this.getLastDayOfMonth(this.year,this.month);return t.lastDayOfMonth||!t.starDOW?n:Math.min(i,n)}return i}findPrevious(e,t,r,i){return this._findMatch(e,t,r,i,-1)}getDate(e){return!e&&this.instantMs!==void 0&&typeof this.tz!="number"?new Date(this.instantMs+(this.tz===void 0?this.ms:0)):e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):R(y(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<h.length;r++){let i=h[r][0],n=h[r][2],a=this[i];if(a+n<0||a+n>=e[i].length)return!1;let o=e[i][a+n];if(i==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}}});function j(s){s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow;let e=(r,i)=>r===void 0?i:r;if(s.paused=e(s.paused,!1),s.maxRuns=e(s.maxRuns,1/0),s.catch=e(s.catch,!1),s.unref=e(s.unref,!1),s.mode=e(s.mode,"auto"),s.alternativeWeekdays=e(s.alternativeWeekdays,!1),s.sloppyRanges=e(s.sloppyRanges,!1),s.allowPast=e(s.allowPast,!1),s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");s.timezone===""&&(s.timezone=void 0);let t=s.timezone??s.utcOffset;if(s.startAt&&(s.startAt=Y(new f(s.startAt,t))),s.stopAt&&(s.stopAt=Y(new f(s.stopAt,t))),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function Y(s){return s.ms?(s.ms=0,new f(new Date(s.getTime()+1e3),s.tz)):s}var Z=T(()=>{U()});function C(s){return typeof s=="function"}function $(s){return C(s)}function H(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var B=T(()=>{});var S,V,M,O,W,J=T(()=>{U();E();Z();B();A();S=1440*60*1e3,V=30*1e3,M=[],O=class{name;options;_states;fn;getTz(){return this.options.timezone??this.options.utcOffset}applyDayOffset(e){let t=this._offsetMs();return t?new Date(e.getTime()+t):e}_offsetMs(){return(this.options.dayOffset??0)*S}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let r=this._offsetMs(),i=this._next(this._shift(e),new Date(t.getTime()-r),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return i?this.applyDayOffset(i.getDate(!1)):null}_previousTarget(e,t){let r=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return r?this.applyDayOffset(r.getDate(!1)):null}_shift(e){if(e!=null)return new f(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,r){let i,n;if(C(t))n=t;else if(typeof t=="object")i=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(C(r))n=r;else if(typeof r=="object")i=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=i?.name,this.options=j(i),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:i?i.maxRuns:void 0,paused:i?i.paused:!1,pattern:new b("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new f(e,this.getTz()):this._states.pattern=new b(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(M.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");M.push(this)}return n!==void 0&&$(n)&&(this.fn=n,this.schedule()),this}nextRun(e){return this._nextTarget(e,new Date)}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new W(this,e)}_enumerateRuns(e,t,r){let i=[],n=new Date,a=t;for(;e-- >0;){let o=r==="next"?this._nextTarget(a,n):this._previousTarget(a,n);if(!o)break;i.push(o),a=o}return i}match(e){if(this._states.once){let r=new f(e,this.getTz());r.ms=0;let i=new f(this._states.once,this.getTz());return i.ms=0,r.getTime()===i.getTime()}let t=new f(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){return!this._states.paused&&!this._states.kill&&this.fn!==void 0&&this._nextTarget(this._states.currentRun,new Date)!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=new Date,r=this._nextTarget(e,t);return r?r.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=M.indexOf(this);e>=0&&M.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){return this._schedule(e)}_schedule(e,t){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let r=t??new Date,i=this._nextTarget(void 0,r),n=i?i.getTime()-r.getTime():null,a=this._states.currentRun;a&&a.getTime()>r.getTime()&&(a=void 0);let o=this._nextTarget(a,r);return n===null||isNaN(n)||o===null?this:(n>V&&(n=V),n<0&&(n=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),n),this._states.currentTimeout&&this.options.unref&&H(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new f(e,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(C(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new f(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),i=this._states.blocking&&this.options.protect;r&&!i?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):r&&i&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,r?void 0:t)}_next(e,t,r){let i=r?r.startAt:this._startAt,n=r?r.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&i&&this.options.interval&&(e=this._calculatePreviousRun(i,t),e&&(o=!0),u=!e);let l=e??t??new Date,c=this._toMs(l);e=new f(l,this.getTz()),i&&c<i.getTime()&&(e=u?i:new f(new Date(i.getTime()-1e3),this.getTz()),c=e.getTime());let d=this._states.once||new f(e,this.getTz());if(!u&&d!==this._states.once&&(d=this._findOccurrence(e,c,1,o)),this._states.once){let m=this._states.once.getTime(),p=c-m;if(i&&m<i.getTime()||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?p>=0:p>1e3&&!this.options.allowPast))return null}return d===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||n&&d.getTime()>=n.getTime()?null:d}_previous(e,t){let r=this._toMs(e??new Date);if(t.stopAt&&r>t.stopAt.getTime()&&(r=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<r?this._states.once:null;let i=this._findOccurrence(new f(new Date(r),this.getTz()),r,-1);return i===null||t.startAt&&i.getTime()<t.startAt.getTime()?null:i}_toMs(e){return e instanceof Date?e.getTime():new f(e,this.getTz()).getTime()}_findOccurrence(e,t,r,i=!1){let n=this._walk(e,t,r,i),a=this.getTz();if(this._states.pattern.isFixedTime&&r===1||typeof a=="number"||L(t,a)!==(r===1?"earlier":"later"))return n;let o=Math.floor(t/1e3)*1e3,u=r===1?k(o,o+S,a):k(o-S,o,a)-1e3;if(n&&(u-n.getTime())*r>0)return n;let l=this._walk(new f(new Date(u),a),u-r,r,!1,!0);return!n||!l?n??l:(n.getTime()-l.getTime())*r>0?l:n}_walk(e,t,r,i,n=!1){let a=this._states.pattern,o=(l,c)=>r===1?l.increment(a,this.options,c):l.decrement(a,this.options),u=new f(e,this.getTz());for((!n||!u.match(a,this.options))&&(u=o(u,i));u;){let l=this._runAt(u,t,r);if(l)return new f(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,r){let i=m=>(m.getTime()-t)*r>0,n=e.tz;if(typeof n=="number"){let m=e.getDate();return i(m)?m:null}let a=y(e.year,e.month+1,e.day,e.hour,e.minute,e.second,n),o=_(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return i(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:m,later:p}=o;return(u?[m]:r===1?[m,p]:[p,m]).find(i)??null}if(!u)return null;let l=new Date(k(o.before.getTime(),o.after.getTime(),n)),c=g(l,n);return c.y===a.y&&c.m===a.m&&c.d===a.d&&i(l)?l:null}_calculatePreviousRun(e,t){let r=new f(t,this.getTz()).getTime();if(e.getTime()>r)return;let i=this.options.interval*1e3,n=e;for(;n.getTime()+i<=r;){let a=new f(n,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;n=a}return n}},W=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.options.maxRuns??1/0,this.reset(t)}next(){if(this.done||this.remainingRuns<=0)return this.done=!0,{value:void 0,done:!0};let e=this.cron._nextTarget(this.cursor,this.now);return e===null?(this.done=!0,{value:void 0,done:!0}):(this.cursor=e,this.remainingRuns--,{value:e,done:!1})}peek(){return this.done||this.remainingRuns<=0?null:this.cron._nextTarget(this.cursor,this.now)}reset(e){this.cursor=e instanceof Date?new Date(e.getTime()):e??void 0,this.now=new Date,this.done=!1,this.remainingRuns=this.initialMaxRuns}[Symbol.iterator](){return this}}});var ee=q((Te,K)=>{J();K.exports=O});return ee();})();
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "croner",
|
|
3
|
+
"version": "11.0.0-dev.9",
|
|
3
4
|
"description": "Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.",
|
|
4
5
|
"author": "Hexagon <github.com/hexagon>",
|
|
5
6
|
"homepage": "https://croner.56k.guru",
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
},
|
|
24
25
|
{
|
|
25
26
|
"type": "github",
|
|
26
|
-
"url": "https://github.com/sponsors/
|
|
27
|
+
"url": "https://github.com/sponsors/hexagon"
|
|
27
28
|
}
|
|
28
29
|
],
|
|
29
30
|
"files": [
|
|
@@ -68,6 +69,25 @@
|
|
|
68
69
|
"browser": "./dist/croner.umd.js"
|
|
69
70
|
}
|
|
70
71
|
},
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
"scripts": {
|
|
73
|
+
"test": "tsx --test test/*.test.ts",
|
|
74
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
75
|
+
"pre-commit": "npm run typecheck && npm test",
|
|
76
|
+
"build:clean": "tsx build/build.ts clean",
|
|
77
|
+
"build:dist": "tsx build/build.ts build",
|
|
78
|
+
"build": "npm run build:clean && npm run check-version && npm run typecheck && npm test && npm run build:dist",
|
|
79
|
+
"check-version": "tsx build/build.ts check-version",
|
|
80
|
+
"version": "tsx build/build.ts sync-version && git add deno.json"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@cross/test": "npm:@jsr/cross__test@~0.0.14",
|
|
84
|
+
"@std/assert": "npm:@jsr/std__assert@~1.0.6",
|
|
85
|
+
"@typescript/typescript6": "~6.0.2",
|
|
86
|
+
"esbuild": "0.28.2",
|
|
87
|
+
"rollup": "~4.65.0",
|
|
88
|
+
"rollup-plugin-dts": "~6.5.1",
|
|
89
|
+
"tsx": "^4.20.0",
|
|
90
|
+
"typescript": "~7.0.0"
|
|
91
|
+
},
|
|
92
|
+
"license": "MIT"
|
|
93
|
+
}
|