croner 11.0.1-dev.1 → 11.0.1-dev.2

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 CHANGED
@@ -73,13 +73,13 @@ const { Cron } = require("croner");
73
73
  Using Deno
74
74
 
75
75
  ```typescript
76
- import { Cron } from "jsr:@hexagon/croner@11.0.1-dev.1";
76
+ import { Cron } from "jsr:@hexagon/croner@11.0.1-dev.2";
77
77
  ```
78
78
 
79
79
  In a webpage using the UMD-module
80
80
 
81
81
  ```html
82
- <script src="https://cdn.jsdelivr.net/npm/croner@11.0.1-dev.1/dist/croner.umd.js"></script>
82
+ <script src="https://cdn.jsdelivr.net/npm/croner@11.0.1-dev.2/dist/croner.umd.js"></script>
83
83
  ```
84
84
 
85
85
  ## Documentation
@@ -165,6 +165,7 @@ job.name // Optional job name, populated if a name were passed to options
165
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. |
166
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"`. |
167
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. |
168
+ | fixedTimeRule | "single-value" | string | Which jobs are fixed-time jobs in DST handling. `"single-value"` (default, as croner-rust): a single value in each of seconds, minutes and hours. `"no-wildcard"` (closer to Vixie cron): no wildcard or step in seconds, minutes and hours, so lists and ranges such as `30 2,14 * * *` count too. See [Pattern](#pattern). |
168
169
 
169
170
  > **Warning**
170
171
  > Unreferencing timers (option `unref`) is only supported by Node.js and Deno.
@@ -200,12 +201,13 @@ Croner uses [Vixie Cron](https://en.wikipedia.org/wiki/Cron#CRON_expression) bas
200
201
  * **Enhanced logical control**:
201
202
  - *+*: 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.
202
203
  - *?*: 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.
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.
204
+ - DST handling, the same as [croner-rust](https://github.com/Hexagon/croner-rust) and based on Vixie cron, which deviates from OCPS 1.4 §4.3.1 (see below):
205
+ - **Fixed-time jobs**, with a single value in each of seconds, minutes and hours by default (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
206
  - **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.
207
+ - Which jobs are fixed-time jobs differs from Vixie cron. Vixie cron treats a job as wild only when its minute or hour field starts with `*`, so a list or range (e.g. `30 2,14 * * *`) is a fixed-time job there, but an interval job in Croner by default. Set the option `fixedTimeRule: "no-wildcard"` to treat every job without a wildcard (`*` or `?`) or step in seconds, minutes and hours as a fixed-time job. Steps without `*` (e.g. `0 0-23/2 * * *`) are still interval jobs, and times in a gap that meet at its end run once.
206
208
  - `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
209
 
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.
210
+ > **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. Croner and croner-rust are stricter than Vixie cron about which jobs are fixed-time jobs, see above.
209
211
 
210
212
  * 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).
211
213
 
package/dist/croner.cjs CHANGED
@@ -1 +1 @@
1
- var R=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var V=(s,e)=>{for(var t in e)R(s,t,{get:e[t],enumerable:!0})},J=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $(e))!B.call(s,i)&&i!==t&&R(s,i,{get:()=>e[i],enumerable:!(n=H(e,i))||n.enumerable});return s};var G=s=>J(R({},"__esModule",{value:!0}),s);var X={};V(X,{Cron:()=>S,CronDate:()=>l,CronIterator:()=>O,CronPattern:()=>b,scheduledJobs:()=>w});module.exports=G(X);function d(s,e,t,n=0,i=0,r=0,a=0){let o=s>=0&&s<100,u=Date.UTC(o?s+400:s,e,t,n,i,r,a);return o?u-126227808e5:u}function v(s){return d(s.y,s.m-1,s.d,s.h,s.i,s.s)}function D(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)?{tp:T(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:T(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function _(s,e,t){let{tp:n,ms:i}=K(s,e);return new Date(A(n,t).getTime()+i)}function A(s,e){let t=k(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 k(s){let e=v(s),t=a=>P(new Date(a),s.tz),n=e-t(e),i=p(new Date(n),s.tz);if(D(i,s)){let a=v(i)-n,o=n-(t(n-W)-a);if(o<n&&D(p(new Date(o),s.tz),s))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+W));return u>n&&D(p(new Date(u),s.tz),s)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let r=e-(v(i)-n);return D(p(new Date(r),s.tz),s)?{kind:"single",date:new Date(r)}:{kind:"gap",before:new Date(Math.min(n,r)),after:new Date(Math.max(n,r))}}var W=3*36e5;function P(s,e){return v(p(s,e))-(s.getTime()-s.getUTCMilliseconds())}function M(s,e,t){let n=P(new Date(s),t);for(;e-s>1e3;){let i=s+Math.floor((e-s)/2e3)*1e3;P(new Date(i),t)===n?s=i:e=i}return e}function I(s,e){let t=k(p(new Date(s),e));if(t.kind==="ambiguous")return s<t.later.getTime()?"earlier":"later"}var U=new Map;function p(s,e){if(e===void 0)return T(s.getFullYear(),s.getMonth()+1,s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds());let t=U.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),U.set(e,t)),n=t.formatToParts(s)}catch(r){let a=r instanceof Error?r.message:String(r);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 r of n)(r.type==="year"||r.type==="month"||r.type==="day"||r.type==="hour"||r.type==="minute"||r.type==="second")&&(i[r.type]=parseInt(r.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 T(s,e,t,n,i,r,a){return{y:s,m:e,d:t,h:n,i,s:r,tz:a}}var 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,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.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 r;switch(this.mode){case"5-part":r=5;break;case"6-part":r=6;break;case"7-part":r=7;break;case"5-or-6-parts":r=[5,6];break;case"6-or-7-parts":r=[6,7];break;default:r=0}if(!(Array.isArray(r)?r.includes(t):t===r)){let o=Array.isArray(r)?r.join(" or "):r.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 r=0;r<e.length;r++)e[r]=e[r].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 n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let i=(r,a)=>!r.includes("*")&&!r.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,n,i){let r=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 r.fill(i);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,i);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,i):t.includes("-")?this.handleRange(t,e,n,i):t.includes("/")?this.handleStepping(t,e,n,i):t!==""&&this.handleNumber(t,e,n,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,n,i){let r=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(r[0],10)+n;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,r[1]||i)}setPart(e,t,n){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,n);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]=n}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,i,r){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+r+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[i].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[i].length+")")}}handleRangeWithStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let r=this.extractNth(e,t),a=r[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,h]=a,c=parseInt(o,10)+n,g=parseInt(u,10)+n,m=parseInt(h,10);this.validateNotNaN(c,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(g,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(c,g,m,t,e);for(let y=c;y<=g;y+=m)this.setPart(t,y,r[1]||i)}extractNth(e,t){let n=e,i;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");i=n.split("#")[1],n=n.split("#")[0]}else if(n.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",n=n.slice(0,-1)}return[n,i]}handleRange(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let r=this.extractNth(e,t),a=r[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+n,u=parseInt(a[1],10)+n;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 h=o;h<=u;h++)this.setPart(t,h,r[1]||i)}handleStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let r=this.extractNth(e,t),a=r[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)+n);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 h=o;h<this[t].length;h+=u)t==="year"&&h===0||this.setPart(t,h,r[1]||i)}replaceAlpha(e,t){let n=e;for(let[i,r]of Object.entries(t))n=n.replace(new RegExp(i,"gi"),r);return n}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 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]],l=class s{tz;instantMs;instantFields;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(d(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),r=new Date(d(e,t,n)).getUTCDay();return r===0?n-2:r===6?n-1:n}getNearestWeekday(e,t,n){let i=this.getLastDayOfMonth(e,t);if(n>i)return-1;let a=new Date(d(e,t,n)).getUTCDay();return a===0?n===i?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,i){let a=new Date(d(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(d(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 h=n+1;h<=u;h++)if(new Date(d(e,t,h)).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=p(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.cacheInstant(e.getTime()-this.ms)}catch(t){let n=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: ${n}`)}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.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:i,hour:r,minute:a,second:o}=this;this.instantFields=[t,n,i,r,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}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,this.instantFields=e.instantFields}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(_(e));let t=_(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(_(e,this.tz))}findNext(e,t,n,i){return this._findMatch(e,t,n,i,1)}_matchDayValue(e,t,n,i){let r=e;if(!r){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){r=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(r=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(r=1)}if(!n.starDOW){let a=new Date(d(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?r=r&&o:!i.domAndDow&&!n.starDOM?r=r||o:r=r&&o}return r}_findMatch(e,t,n,i,r){let a=this[t],o=this[t]+i,u=r===1?h=>h<n[t].length:h=>h>=0;for(let h=o;u(h);h+=r){let c=n[t][h];if(t==="day"&&(c=this._matchDayValue(c,h-i,n,e)),c)return this[t]=h-i,a!==this[t]?2:1}return 3}recurse(e,t,n){let i=this.year,r=n;for(;typeof r=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;r=this.recurseStep(e,t,r)}return r}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let r=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){r=a;break}if(r===-1)return null;this.year=r,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,f[n][0],e,f[n][2]);if(i>1){let r=n+1;for(;r<f.length;)this[f[r][0]]=-f[r][2],r++;if(i===3){if(this[f[n][1]]++,this[f[n][0]]=-f[n][2],this.apply(),n===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 n-1}return n+=1,n>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.instantFields=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,n){let i=this.year,r=n;for(;typeof r=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;r=this.recurseBackwardStep(e,t,r)}return r}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let r=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){r=a;break}if(r===-1)return null;this.year=r,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,f[n][0],e,f[n][2]);if(i>1){let r=n+1;for(;r<f.length;){let a=f[r][0],o=f[r][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,r++}if(i===3){if(this[f[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,h=this.month;for(;h<0;)h+=12,u--;for(;h>11;)h-=12,u++;let c=this.getLastDayOfMonth(u,h);this.day>c&&(this.day=c)}this.apply();let a=f[n][0],o=f[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=f[1][2],h=this.getMaxPatternValue("day",e,u);h!==this.day&&(this.day=h,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(n===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 n-1}return n+=1,n>=f.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let i=t[e].length-1-n;for(let r=t[e].length-1;r>=0;r--)if(t[e][r]){i=r-n;break}if(e==="day"){let r=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?r:Math.min(i,r)}return i}findPrevious(e,t,n,i){return this._findMatch(e,t,n,i,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(d(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):A(T(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 n=0;n<f.length;n++){let i=f[n][0],r=f[n][2],a=this[i];if(a+r<0||a+r>=e[i].length)return!1;let o=e[i][a+r];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=(n,i)=>n===void 0?i:n;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=F(new l(s.startAt,t))),s.stopAt&&(s.stopAt=F(new l(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 F(s){return s.ms?(s.ms=0,new l(new Date(s.getTime()+1e3),s.tz)):s}function C(s){return typeof s=="function"}function Y(s){return C(s)}function j(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var E=1440*60*1e3,Z=30*1e3,w=[],S=class{name;options;_states;fn;_startAtRoundingMs=0;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)*E}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),i=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return i?this.applyDayOffset(i.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new l(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let i,r;if(C(t))r=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(n))r=n;else if(typeof n=="object")i=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=i?.name;let a=i?.startAt;if(this.options=L(i),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new l(a,this.getTz()).getTime()),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 l(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(w.find(u=>u.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");w.push(this)}return r!==void 0&&Y(r)&&(this.fn=r,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 n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new O(this,e)}_enumerateRuns(e,t,n){let i=[],r=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,r):this._previousTarget(a,r);if(!o)break;i.push(o),a=o}return i}match(e){if(this._states.once){let n=new l(e,this.getTz());n.ms=0;let i=new l(this._states.once,this.getTz());return i.ms=0,n.getTime()===i.getTime()}let t=new l(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,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=w.indexOf(this);e>=0&&w.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 n=t??new Date,i=this._nextTarget(void 0,n),r=i?i.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return r===null||isNaN(r)||o===null?this:(r>Z&&(r=Z),r<0&&(r=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),r),this._states.currentTimeout&&this.options.unref&&j(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new l(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{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new l(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),i=this._states.blocking&&this.options.protect;n&&!i?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&i&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let i=n?n.startAt:this._startAt,r=n?n.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 h=e??t??new Date,c=this._toMs(h);e=new l(h,this.getTz()),i&&c<i.getTime()&&(e=u?i:new l(new Date(i.getTime()-1e3),this.getTz()),c=e.getTime());let g=this._states.once||new l(e,this.getTz());if(!u&&g!==this._states.once&&(g=this._findOccurrence(e,c,1,o)),this._states.once){let m=this._states.once.getTime(),y=c-m;if(i&&m<i.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?y>=0:y>1e3&&!this.options.allowPast))return null}return g===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||r&&g.getTime()>=r.getTime()?null:g}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let i=this._findOccurrence(new l(new Date(n),this.getTz()),n,-1);return i===null||t.startAt&&i.getTime()<t.startAt.getTime()?null:i}_toMs(e){return e instanceof Date?e.getTime():new l(e,this.getTz()).getTime()}_findOccurrence(e,t,n,i=!1){let r=this._walk(e,t,n,i),a=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof a=="number"||I(t,a)!==(n===1?"earlier":"later"))return r;let o=Math.floor(t/1e3)*1e3,u=n===1?M(o,o+E,a):M(o-E,o,a)-1e3;if(r&&(u-r.getTime())*n>0)return r;let h=this._walk(new l(new Date(u),a),u-n,n,!1,!0);return!r||!h?r??h:(r.getTime()-h.getTime())*n>0?h:r}_walk(e,t,n,i,r=!1){let a=this._states.pattern,o=(h,c)=>n===1?h.increment(a,this.options,c):h.decrement(a,this.options),u=new l(e,this.getTz());for((!r||!u.match(a,this.options))&&(u=o(u,i));u;){let h=this._runAt(u,t,n);if(h)return new l(h,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let i=m=>(m.getTime()-t)*n>0,r=e.tz;if(typeof r=="number"){let m=e.getDate();return i(m)?m:null}let a=T(e.year,e.month+1,e.day,e.hour,e.minute,e.second,r),o=k(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:y}=o;return(u?[m]:n===1?[m,y]:[y,m]).find(i)??null}if(!u)return null;let h=new Date(M(o.before.getTime(),o.after.getTime(),r)),c=p(h,r);return c.y===a.y&&c.m===a.m&&c.d===a.d&&i(h)?h:null}_calculatePreviousRun(e,t){let n=new l(t,this.getTz()).getTime();if(e.getTime()>n)return;let i=this.options.interval*1e3,r=e;for(;r.getTime()+i<=n;){let a=new l(r,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;r=a}return r}},O=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??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});
1
+ var O=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var t in e)O(r,t,{get:e[t],enumerable:!0})},J=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of $(e))!V.call(r,s)&&s!==t&&O(r,s,{get:()=>e[s],enumerable:!(n=H(e,s))||n.enumerable});return r};var G=r=>J(O({},"__esModule",{value:!0}),r);var X={};B(X,{Cron:()=>S,CronDate:()=>f,CronIterator:()=>M,CronPattern:()=>b,scheduledJobs:()=>w});module.exports=G(X);function g(r,e,t,n=0,s=0,i=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,s,i,a);return o?u-126227808e5:u}function v(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function D(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function P(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function K(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return P(r)?{tp:T(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:T(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function _(r,e,t){let{tp:n,ms:s}=K(r,e);return new Date(N(n,t).getTime()+s)}function N(r,e){let t=k(r);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 k(r){let e=v(r),t=a=>x(new Date(a),r.tz),n=e-t(e),s=p(new Date(n),r.tz);if(D(s,r)){let a=v(s)-n,o=n-(t(n-W)-a);if(o<n&&D(p(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+W));return u>n&&D(p(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let i=e-(v(s)-n);return D(p(new Date(i),r.tz),r)?{kind:"single",date:new Date(i)}:{kind:"gap",before:new Date(Math.min(n,i)),after:new Date(Math.max(n,i))}}var W=3*36e5;function x(r,e){return v(p(r,e))-(r.getTime()-r.getUTCMilliseconds())}function R(r,e,t){let n=x(new Date(r),t);for(;e-r>1e3;){let s=r+Math.floor((e-r)/2e3)*1e3;x(new Date(s),t)===n?r=s:e=s}return e}function I(r,e){let t=k(p(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}var U=new Map;function p(r,e){if(e===void 0)return T(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=U.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),U.set(e,t)),n=t.formatToParts(r)}catch(i){let a=i instanceof Error?i.message:String(i);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 s={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of n)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(s[i.type]=parseInt(i.value,10));if(isNaN(s.year)||isNaN(s.month)||isNaN(s.day)||isNaN(s.hour)||isNaN(s.minute)||isNaN(s.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(s)}`);return s.hour===24&&(s.hour=0),{y:s.year,m:s.month,d:s.day,h:s.hour,i:s.minute,s:s.second,tz:e}}function T(r,e,t,n,s,i,a){return{y:r,m:e,d:t,h:n,i:s,s:i,tz:a}}var A=[1,2,4,8,16],b=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",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 a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} 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 a=0;a<e.length;a++)e[a]=e[a].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],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.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 n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let s=this.fixedTimeRule==="single-value",i=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!s||o.filter(u=>u).length===1);this.isFixedTime=i(e[0],this.second)&&i(e[1],this.minute)&&i(e[2],this.hour)}partToArray(e,t,n,s){let i=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 i.fill(s);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,s);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,s):t.includes("-")?this.handleRange(t,e,n,s):t.includes("/")?this.handleStepping(t,e,n,s):t!==""&&this.handleNumber(t,e,n,s)}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,n,s){let i=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(i[0],10)+n;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,i[1]||s)}setPart(e,t,n){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,n);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]=n}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,s,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[s].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[s].length+")")}}handleRangeWithStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,d=parseInt(u,10)+n,m=parseInt(l,10);this.validateNotNaN(h,"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(h,d,m,t,e);for(let y=h;y<=d;y+=m)this.setPart(t,y,i[1]||s)}extractNth(e,t){let n=e,s;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");s=n.split("#")[1],n=n.split("#")[0]}else if(n.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)");s="L",n=n.slice(0,-1)}return[n,s]}handleRange(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let i=this.extractNth(e,t),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+n,u=parseInt(a[1],10)+n;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,i[1]||s)}handleStepping(e,t,n,s){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let i=this.extractNth(e,t),a=i[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)+n);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,i[1]||s)}replaceAlpha(e,t){let n=e;for(let[s,i]of Object.entries(t))n=n.replace(new RegExp(s,"gi"),i);return n}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 r.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],c=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],f=class r{tz;instantMs;instantFields;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 r)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(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),i=new Date(g(e,t,n)).getUTCDay();return i===0?n-2:i===6?n-1:n}getNearestWeekday(e,t,n){let s=this.getLastDayOfMonth(e,t);if(n>s)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===s?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,s){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(s&63&&A[o-1]&s)return!0;if(s&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(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=p(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.cacheInstant(e.getTime()-this.ms)}catch(t){let n=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: ${n}`)}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.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:s,hour:i,minute:a,second:o}=this;this.instantFields=[t,n,s,i,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}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,this.instantFields=e.instantFields}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(P(e))return this.fromDate(_(e));let t=_(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(_(e,this.tz))}findNext(e,t,n,s){return this._findMatch(e,t,n,s,1)}_matchDayValue(e,t,n,s){let i=e;if(!i){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){i=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(i=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(i=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?i=i&&o:!s.domAndDow&&!n.starDOM?i=i||o:i=i&&o}return i}_findMatch(e,t,n,s,i){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+s,l=i===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=i){let d=n[t][h];if(t==="day"){if(h-s>o)continue;d=this._matchDayValue(d,h-s,n,e)}if(d)return this[t]=h-s,a!==this[t]?2:1}return 3}recurse(e,t,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseStep(e,t,i)}return i}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,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 s=this.findNext(t,c[n][0],e,c[n][2]);if(s>1){let i=n+1;for(;i<c.length;)this[c[i][0]]=-c[i][2],i++;if(s===3){if(this[c[n][1]]++,this[c[n][0]]=-c[n][2],this.apply(),n===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 n-1}return n+=1,n>=c.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.instantFields=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,n){let s=this.year,i=n;for(;typeof i=="number";){if(e.starYear&&Math.abs(this.year-s)>400)return null;i=this.recurseBackwardStep(e,t,i)}return i}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){i=a;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 s=this.findPrevious(t,c[n][0],e,c[n][2]);if(s>1){let i=n+1;for(;i<c.length;){let a=c[i][0],o=c[i][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,i++}if(s===3){if(this[c[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===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 h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=c[n][0],o=c[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=c[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,this.hour=this.getMaxPatternValue("hour",e,c[2][2]),this.minute=this.getMaxPatternValue("minute",e,c[3][2]),this.second=this.getMaxPatternValue("second",e,c[4][2]))}if(n===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 n-1}return n+=1,n>=c.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let s=t[e].length-1-n;for(let i=t[e].length-1;i>=0;i--)if(t[e][i]){s=i-n;break}if(e==="day"){let i=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?i:Math.min(s,i)}return s}findPrevious(e,t,n,s){return this._findMatch(e,t,n,s,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):N(T(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 n=0;n<c.length;n++){let s=c[n][0],i=c[n][2],a=this[s];if(a+i<0||a+i>=e[s].length)return!1;let o=e[s][a+i];if(s==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}};function L(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,s)=>n===void 0?s:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.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(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=F(new f(r.startAt,t))),r.stopAt&&(r.stopAt=F(new f(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function F(r){return r.ms?(r.ms=0,new f(new Date(r.getTime()+1e3),r.tz)):r}function C(r){return typeof r=="function"}function Y(r){return C(r)}function j(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var E=1440*60*1e3,Z=30*1e3,w=[],S=class{name;options;_states;fn;_startAtRoundingMs=0;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)*E}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),s=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return s?this.applyDayOffset(s.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new f(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let s,i;if(C(t))i=t;else if(typeof t=="object")s=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(n))i=n;else if(typeof n=="object")s=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=s?.name;let a=s?.startAt;if(this.options=L(s),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new f(a,this.getTz()).getTime()),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:s?s.maxRuns:void 0,paused:s?s.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,fixedTimeRule:this.options.fixedTimeRule}),this.name){if(w.find(u=>u.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");w.push(this)}return i!==void 0&&Y(i)&&(this.fn=i,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 n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new M(this,e)}_enumerateRuns(e,t,n){let s=[],i=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,i):this._previousTarget(a,i);if(!o)break;s.push(o),a=o}return s}match(e){if(this._states.once){let n=new f(e,this.getTz());n.ms=0;let s=new f(this._states.once,this.getTz());return s.ms=0,n.getTime()===s.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,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=w.indexOf(this);e>=0&&w.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 n=t??new Date,s=this._nextTarget(void 0,n),i=s?s.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return i===null||isNaN(i)||o===null?this:(i>Z&&(i=Z),i<0&&(i=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),i),this._states.currentTimeout&&this.options.unref&&j(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{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}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,n=!this._states.paused&&t.getTime()>=e.getTime(),s=this._states.blocking&&this.options.protect;n&&!s?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&s&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let s=n?n.startAt:this._startAt,i=n?n.stopAt:this._stopAt,a=!!e,o=!!(e||this._states.currentRun),u=!1;!e&&s&&this.options.interval&&(e=this._calculatePreviousRun(s,t),e&&(o=!0),u=!e);let l=e??t??new Date,h=this._toMs(l);e=new f(l,this.getTz()),s&&h<s.getTime()&&(e=u?s:new f(new Date(s.getTime()-1e3),this.getTz()),h=e.getTime());let d=this._states.once||new f(e,this.getTz());if(!u&&d!==this._states.once&&(d=this._findOccurrence(e,h,1,o)),this._states.once){let m=this._states.once.getTime(),y=h-m;if(s&&m<s.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?y>=0:y>1e3&&!this.options.allowPast))return null}return d===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||i&&d.getTime()>=i.getTime()?null:d}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let s=this._findOccurrence(new f(new Date(n),this.getTz()),n,-1);return s===null||t.startAt&&s.getTime()<t.startAt.getTime()?null:s}_toMs(e){return e instanceof Date?e.getTime():new f(e,this.getTz()).getTime()}_findOccurrence(e,t,n,s=!1){let i=this._walk(e,t,n,s),a=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof a=="number"||I(t,a)!==(n===1?"earlier":"later"))return i;let o=Math.floor(t/1e3)*1e3,u=n===1?R(o,o+E,a):R(o-E,o,a)-1e3;if(i&&(u-i.getTime())*n>0)return i;let l=this._walk(new f(new Date(u),a),u-n,n,!1,!0);return!i||!l?i??l:(i.getTime()-l.getTime())*n>0?l:i}_walk(e,t,n,s,i=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options),u=new f(e,this.getTz());for((!i||!u.match(a,this.options))&&(u=o(u,s));u;){let l=this._runAt(u,t,n);if(l)return new f(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let s=m=>(m.getTime()-t)*n>0,i=e.tz;if(typeof i=="number"){let m=e.getDate();return s(m)?m:null}let a=T(e.year,e.month+1,e.day,e.hour,e.minute,e.second,i),o=k(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return s(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:m,later:y}=o;return(u?[m]:n===1?[m,y]:[y,m]).find(s)??null}if(!u)return null;let l=new Date(R(o.before.getTime(),o.after.getTime(),i)),h=p(l,i);return h.y===a.y&&h.m===a.m&&h.d===a.d&&s(l)?l:null}_calculatePreviousRun(e,t){let n=new f(t,this.getTz()).getTime();if(e.getTime()>n)return;let s=this.options.interval*1e3,i=e;for(;i.getTime()+s<=n;){let a=new f(i,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;i=a}return i}},M=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??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
@@ -2,6 +2,10 @@
2
2
  * Cron pattern mode for controlling precision level
3
3
  */
4
4
  type CronMode = "auto" | "5-part" | "6-part" | "7-part" | "5-or-6-parts" | "6-or-7-parts";
5
+ /**
6
+ * Rule for which jobs count as fixed-time jobs in DST handling, see CronOptions.fixedTimeRule
7
+ */
8
+ type CronFixedTimeRule = "single-value" | "no-wildcard";
5
9
  /**
6
10
  * Create a CronPattern instance from pattern string ('* * * * * *')
7
11
  * @constructor
@@ -15,6 +19,7 @@ declare class CronPattern {
15
19
  mode: CronMode;
16
20
  alternativeWeekdays: boolean;
17
21
  sloppyRanges: boolean;
22
+ fixedTimeRule: CronFixedTimeRule;
18
23
  second: number[];
19
24
  minute: number[];
20
25
  hour: number[];
@@ -31,13 +36,15 @@ declare class CronPattern {
31
36
  useAndLogic: boolean;
32
37
  /**
33
38
  * 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.
39
+ * With fixedTimeRule "no-wildcard", true if they have no wildcard or step, so lists and
40
+ * ranges count too. Fixed-time and interval jobs handle DST transitions differently.
35
41
  */
36
42
  isFixedTime: boolean;
37
43
  constructor(pattern: string, timezone?: string, options?: {
38
44
  mode?: CronMode;
39
45
  alternativeWeekdays?: boolean;
40
46
  sloppyRanges?: boolean;
47
+ fixedTimeRule?: CronFixedTimeRule;
41
48
  });
42
49
  /**
43
50
  * Parse current pattern, will throw on any type of failure
@@ -275,6 +282,18 @@ interface CronOptions<T = undefined> {
275
282
  * @default false
276
283
  */
277
284
  sloppyRanges?: boolean;
285
+ /**
286
+ * Which jobs count as fixed-time jobs, for DST handling. A fixed-time job in a DST gap runs
287
+ * at the first valid time after the gap, and runs once when a time occurs twice. Other jobs
288
+ * are interval jobs, which skip times in a gap and run on both occurrences of a repeated time.
289
+ * - "single-value" (default): seconds, minutes and hours each have a single value, without
290
+ * wildcard or step (e.g. `30 2 * * *`). The same rule as croner-rust.
291
+ * - "no-wildcard": seconds, minutes and hours have no wildcard (`*` or `?`) and no step, so a
292
+ * list or range is fixed-time too (e.g. `30 2,14 * * *` or `30 2-3 * * *`). Close to Vixie
293
+ * cron, which classifies a job as wild only when its minute or hour field starts with `*`.
294
+ * @default "single-value"
295
+ */
296
+ fixedTimeRule?: CronFixedTimeRule;
278
297
  /**
279
298
  * If true, date-based jobs scheduled in the past will fire immediately.
280
299
  * If false, only jobs scheduled within the past second will fire immediately (to handle timing edge cases).
@@ -862,4 +881,4 @@ declare class CronIterator<T = undefined> implements Iterator<Date, undefined>,
862
881
  }
863
882
 
864
883
  export { Cron, CronDate, CronIterator, CronPattern, scheduledJobs };
865
- export type { CatchCallbackFn, CronCallback, CronMode, CronOptions, ProtectCallbackFn };
884
+ export type { CatchCallbackFn, CronCallback, CronFixedTimeRule, CronMode, CronOptions, ProtectCallbackFn };
package/dist/croner.d.ts CHANGED
@@ -2,6 +2,10 @@
2
2
  * Cron pattern mode for controlling precision level
3
3
  */
4
4
  type CronMode = "auto" | "5-part" | "6-part" | "7-part" | "5-or-6-parts" | "6-or-7-parts";
5
+ /**
6
+ * Rule for which jobs count as fixed-time jobs in DST handling, see CronOptions.fixedTimeRule
7
+ */
8
+ type CronFixedTimeRule = "single-value" | "no-wildcard";
5
9
  /**
6
10
  * Create a CronPattern instance from pattern string ('* * * * * *')
7
11
  * @constructor
@@ -15,6 +19,7 @@ declare class CronPattern {
15
19
  mode: CronMode;
16
20
  alternativeWeekdays: boolean;
17
21
  sloppyRanges: boolean;
22
+ fixedTimeRule: CronFixedTimeRule;
18
23
  second: number[];
19
24
  minute: number[];
20
25
  hour: number[];
@@ -31,13 +36,15 @@ declare class CronPattern {
31
36
  useAndLogic: boolean;
32
37
  /**
33
38
  * 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.
39
+ * With fixedTimeRule "no-wildcard", true if they have no wildcard or step, so lists and
40
+ * ranges count too. Fixed-time and interval jobs handle DST transitions differently.
35
41
  */
36
42
  isFixedTime: boolean;
37
43
  constructor(pattern: string, timezone?: string, options?: {
38
44
  mode?: CronMode;
39
45
  alternativeWeekdays?: boolean;
40
46
  sloppyRanges?: boolean;
47
+ fixedTimeRule?: CronFixedTimeRule;
41
48
  });
42
49
  /**
43
50
  * Parse current pattern, will throw on any type of failure
@@ -275,6 +282,18 @@ interface CronOptions<T = undefined> {
275
282
  * @default false
276
283
  */
277
284
  sloppyRanges?: boolean;
285
+ /**
286
+ * Which jobs count as fixed-time jobs, for DST handling. A fixed-time job in a DST gap runs
287
+ * at the first valid time after the gap, and runs once when a time occurs twice. Other jobs
288
+ * are interval jobs, which skip times in a gap and run on both occurrences of a repeated time.
289
+ * - "single-value" (default): seconds, minutes and hours each have a single value, without
290
+ * wildcard or step (e.g. `30 2 * * *`). The same rule as croner-rust.
291
+ * - "no-wildcard": seconds, minutes and hours have no wildcard (`*` or `?`) and no step, so a
292
+ * list or range is fixed-time too (e.g. `30 2,14 * * *` or `30 2-3 * * *`). Close to Vixie
293
+ * cron, which classifies a job as wild only when its minute or hour field starts with `*`.
294
+ * @default "single-value"
295
+ */
296
+ fixedTimeRule?: CronFixedTimeRule;
278
297
  /**
279
298
  * If true, date-based jobs scheduled in the past will fire immediately.
280
299
  * If false, only jobs scheduled within the past second will fire immediately (to handle timing edge cases).
@@ -862,4 +881,4 @@ declare class CronIterator<T = undefined> implements Iterator<Date, undefined>,
862
881
  }
863
882
 
864
883
  export { Cron, CronDate, CronIterator, CronPattern, scheduledJobs };
865
- export type { CatchCallbackFn, CronCallback, CronMode, CronOptions, ProtectCallbackFn };
884
+ export type { CatchCallbackFn, CronCallback, CronFixedTimeRule, CronMode, CronOptions, ProtectCallbackFn };
package/dist/croner.js CHANGED
@@ -1 +1 @@
1
- function d(s,e,t,n=0,i=0,r=0,a=0){let o=s>=0&&s<100,u=Date.UTC(o?s+400:s,e,t,n,i,r,a);return o?u-126227808e5:u}function D(s){return d(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 R(s){let e=s.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function Z(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return R(s)?{tp:T(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:T(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function v(s,e,t){let{tp:n,ms:i}=Z(s,e);return new Date(P(n,t).getTime()+i)}function P(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=>O(new Date(a),s.tz),n=e-t(e),i=p(new Date(n),s.tz);if(w(i,s)){let a=D(i)-n,o=n-(t(n-E)-a);if(o<n&&w(p(new Date(o),s.tz),s))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+E));return u>n&&w(p(new Date(u),s.tz),s)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let r=e-(D(i)-n);return w(p(new Date(r),s.tz),s)?{kind:"single",date:new Date(r)}:{kind:"gap",before:new Date(Math.min(n,r)),after:new Date(Math.max(n,r))}}var E=3*36e5;function O(s,e){return D(p(s,e))-(s.getTime()-s.getUTCMilliseconds())}function k(s,e,t){let n=O(new Date(s),t);for(;e-s>1e3;){let i=s+Math.floor((e-s)/2e3)*1e3;O(new Date(i),t)===n?s=i:e=i}return e}function W(s,e){let t=_(p(new Date(s),e));if(t.kind==="ambiguous")return s<t.later.getTime()?"earlier":"later"}var S=new Map;function p(s,e){if(e===void 0)return T(s.getFullYear(),s.getMonth()+1,s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds());let t=S.get(e),n;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)),n=t.formatToParts(s)}catch(r){let a=r instanceof Error?r.message:String(r);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 r of n)(r.type==="year"||r.type==="month"||r.type==="day"||r.type==="hour"||r.type==="minute"||r.type==="second")&&(i[r.type]=parseInt(r.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 T(s,e,t,n,i,r,a){return{y:s,m:e,d:t,h:n,i,s:r,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,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.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 r;switch(this.mode){case"5-part":r=5;break;case"6-part":r=6;break;case"7-part":r=7;break;case"5-or-6-parts":r=[5,6];break;case"6-or-7-parts":r=[6,7];break;default:r=0}if(!(Array.isArray(r)?r.includes(t):t===r)){let o=Array.isArray(r)?r.join(" or "):r.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 r=0;r<e.length;r++)e[r]=e[r].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 n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let i=(r,a)=>!r.includes("*")&&!r.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,n,i){let r=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 r.fill(i);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,i);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,i):t.includes("-")?this.handleRange(t,e,n,i):t.includes("/")?this.handleStepping(t,e,n,i):t!==""&&this.handleNumber(t,e,n,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,n,i){let r=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(r[0],10)+n;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,r[1]||i)}setPart(e,t,n){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,n);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]=n}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,i,r){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+r+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[i].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[i].length+")")}}handleRangeWithStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let r=this.extractNth(e,t),a=r[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,h]=a,c=parseInt(o,10)+n,g=parseInt(u,10)+n,m=parseInt(h,10);this.validateNotNaN(c,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(g,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(c,g,m,t,e);for(let y=c;y<=g;y+=m)this.setPart(t,y,r[1]||i)}extractNth(e,t){let n=e,i;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");i=n.split("#")[1],n=n.split("#")[0]}else if(n.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",n=n.slice(0,-1)}return[n,i]}handleRange(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let r=this.extractNth(e,t),a=r[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+n,u=parseInt(a[1],10)+n;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 h=o;h<=u;h++)this.setPart(t,h,r[1]||i)}handleStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let r=this.extractNth(e,t),a=r[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)+n);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 h=o;h<this[t].length;h+=u)t==="year"&&h===0||this.setPart(t,h,r[1]||i)}replaceAlpha(e,t){let n=e;for(let[i,r]of Object.entries(t))n=n.replace(new RegExp(i,"gi"),r);return n}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],l=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],f=class s{tz;instantMs;instantFields;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(d(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),r=new Date(d(e,t,n)).getUTCDay();return r===0?n-2:r===6?n-1:n}getNearestWeekday(e,t,n){let i=this.getLastDayOfMonth(e,t);if(n>i)return-1;let a=new Date(d(e,t,n)).getUTCDay();return a===0?n===i?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,i){let a=new Date(d(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(d(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 h=n+1;h<=u;h++)if(new Date(d(e,t,h)).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=p(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.cacheInstant(e.getTime()-this.ms)}catch(t){let n=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: ${n}`)}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.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:i,hour:r,minute:a,second:o}=this;this.instantFields=[t,n,i,r,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}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,this.instantFields=e.instantFields}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(R(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,n,i){return this._findMatch(e,t,n,i,1)}_matchDayValue(e,t,n,i){let r=e;if(!r){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){r=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(r=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(r=1)}if(!n.starDOW){let a=new Date(d(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?r=r&&o:!i.domAndDow&&!n.starDOM?r=r||o:r=r&&o}return r}_findMatch(e,t,n,i,r){let a=this[t],o=this[t]+i,u=r===1?h=>h<n[t].length:h=>h>=0;for(let h=o;u(h);h+=r){let c=n[t][h];if(t==="day"&&(c=this._matchDayValue(c,h-i,n,e)),c)return this[t]=h-i,a!==this[t]?2:1}return 3}recurse(e,t,n){let i=this.year,r=n;for(;typeof r=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;r=this.recurseStep(e,t,r)}return r}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let r=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){r=a;break}if(r===-1)return null;this.year=r,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,l[n][0],e,l[n][2]);if(i>1){let r=n+1;for(;r<l.length;)this[l[r][0]]=-l[r][2],r++;if(i===3){if(this[l[n][1]]++,this[l[n][0]]=-l[n][2],this.apply(),n===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 n-1}return n+=1,n>=l.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.instantFields=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,n){let i=this.year,r=n;for(;typeof r=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;r=this.recurseBackwardStep(e,t,r)}return r}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let r=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){r=a;break}if(r===-1)return null;this.year=r,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,l[n][0],e,l[n][2]);if(i>1){let r=n+1;for(;r<l.length;){let a=l[r][0],o=l[r][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,r++}if(i===3){if(this[l[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,h=this.month;for(;h<0;)h+=12,u--;for(;h>11;)h-=12,u++;let c=this.getLastDayOfMonth(u,h);this.day>c&&(this.day=c)}this.apply();let a=l[n][0],o=l[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=l[1][2],h=this.getMaxPatternValue("day",e,u);h!==this.day&&(this.day=h,this.hour=this.getMaxPatternValue("hour",e,l[2][2]),this.minute=this.getMaxPatternValue("minute",e,l[3][2]),this.second=this.getMaxPatternValue("second",e,l[4][2]))}if(n===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 n-1}return n+=1,n>=l.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let i=t[e].length-1-n;for(let r=t[e].length-1;r>=0;r--)if(t[e][r]){i=r-n;break}if(e==="day"){let r=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?r:Math.min(i,r)}return i}findPrevious(e,t,n,i){return this._findMatch(e,t,n,i,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(d(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):P(T(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 n=0;n<l.length;n++){let i=l[n][0],r=l[n][2],a=this[i];if(a+r<0||a+r>=e[i].length)return!1;let o=e[i][a+r];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=(n,i)=>n===void 0?i:n;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 b(s){return typeof s=="function"}function F(s){return b(s)}function L(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var A=1440*60*1e3,Y=30*1e3,M=[],j=class{name;options;_states;fn;_startAtRoundingMs=0;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)*A}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),i=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return i?this.applyDayOffset(i.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new f(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let i,r;if(b(t))r=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(b(n))r=n;else if(typeof n=="object")i=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=i?.name;let a=i?.startAt;if(this.options=z(i),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new f(a,this.getTz()).getTime()),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(M.find(u=>u.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");M.push(this)}return r!==void 0&&F(r)&&(this.fn=r,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 n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new x(this,e)}_enumerateRuns(e,t,n){let i=[],r=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,r):this._previousTarget(a,r);if(!o)break;i.push(o),a=o}return i}match(e){if(this._states.once){let n=new f(e,this.getTz());n.ms=0;let i=new f(this._states.once,this.getTz());return i.ms=0,n.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,n=this._nextTarget(e,t);return n?n.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 n=t??new Date,i=this._nextTarget(void 0,n),r=i?i.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return r===null||isNaN(r)||o===null?this:(r>Y&&(r=Y),r<0&&(r=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),r),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(b(this.options.catch))try{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}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,n=!this._states.paused&&t.getTime()>=e.getTime(),i=this._states.blocking&&this.options.protect;n&&!i?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&i&&b(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let i=n?n.startAt:this._startAt,r=n?n.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 h=e??t??new Date,c=this._toMs(h);e=new f(h,this.getTz()),i&&c<i.getTime()&&(e=u?i:new f(new Date(i.getTime()-1e3),this.getTz()),c=e.getTime());let g=this._states.once||new f(e,this.getTz());if(!u&&g!==this._states.once&&(g=this._findOccurrence(e,c,1,o)),this._states.once){let m=this._states.once.getTime(),y=c-m;if(i&&m<i.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?y>=0:y>1e3&&!this.options.allowPast))return null}return g===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||r&&g.getTime()>=r.getTime()?null:g}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let i=this._findOccurrence(new f(new Date(n),this.getTz()),n,-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,n,i=!1){let r=this._walk(e,t,n,i),a=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof a=="number"||W(t,a)!==(n===1?"earlier":"later"))return r;let o=Math.floor(t/1e3)*1e3,u=n===1?k(o,o+A,a):k(o-A,o,a)-1e3;if(r&&(u-r.getTime())*n>0)return r;let h=this._walk(new f(new Date(u),a),u-n,n,!1,!0);return!r||!h?r??h:(r.getTime()-h.getTime())*n>0?h:r}_walk(e,t,n,i,r=!1){let a=this._states.pattern,o=(h,c)=>n===1?h.increment(a,this.options,c):h.decrement(a,this.options),u=new f(e,this.getTz());for((!r||!u.match(a,this.options))&&(u=o(u,i));u;){let h=this._runAt(u,t,n);if(h)return new f(h,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let i=m=>(m.getTime()-t)*n>0,r=e.tz;if(typeof r=="number"){let m=e.getDate();return i(m)?m:null}let a=T(e.year,e.month+1,e.day,e.hour,e.minute,e.second,r),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:y}=o;return(u?[m]:n===1?[m,y]:[y,m]).find(i)??null}if(!u)return null;let h=new Date(k(o.before.getTime(),o.after.getTime(),r)),c=p(h,r);return c.y===a.y&&c.m===a.m&&c.d===a.d&&i(h)?h:null}_calculatePreviousRun(e,t){let n=new f(t,this.getTz()).getTime();if(e.getTime()>n)return;let i=this.options.interval*1e3,r=e;for(;r.getTime()+i<=n;){let a=new f(r,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;r=a}return r}},x=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??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{j as Cron,f as CronDate,x as CronIterator,C as CronPattern,M as scheduledJobs};
1
+ function g(r,e,t,n=0,i=0,s=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,i,s,a);return o?u-126227808e5:u}function D(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function w(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function O(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function Z(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return O(r)?{tp:T(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:T(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function v(r,e,t){let{tp:n,ms:i}=Z(r,e);return new Date(x(n,t).getTime()+i)}function x(r,e){let t=_(r);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 _(r){let e=D(r),t=a=>M(new Date(a),r.tz),n=e-t(e),i=p(new Date(n),r.tz);if(w(i,r)){let a=D(i)-n,o=n-(t(n-E)-a);if(o<n&&w(p(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+E));return u>n&&w(p(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let s=e-(D(i)-n);return w(p(new Date(s),r.tz),r)?{kind:"single",date:new Date(s)}:{kind:"gap",before:new Date(Math.min(n,s)),after:new Date(Math.max(n,s))}}var E=3*36e5;function M(r,e){return D(p(r,e))-(r.getTime()-r.getUTCMilliseconds())}function k(r,e,t){let n=M(new Date(r),t);for(;e-r>1e3;){let i=r+Math.floor((e-r)/2e3)*1e3;M(new Date(i),t)===n?r=i:e=i}return e}function W(r,e){let t=_(p(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}var S=new Map;function p(r,e){if(e===void 0)return T(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=S.get(e),n;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)),n=t.formatToParts(r)}catch(s){let a=s instanceof Error?s.message:String(s);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 s of n)(s.type==="year"||s.type==="month"||s.type==="day"||s.type==="hour"||s.type==="minute"||s.type==="second")&&(i[s.type]=parseInt(s.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 T(r,e,t,n,i,s,a){return{y:r,m:e,d:t,h:n,i,s,tz:a}}var P=[1,2,4,8,16],C=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",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 a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} 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 a=0;a<e.length;a++)e[a]=e[a].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],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.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 n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let i=this.fixedTimeRule==="single-value",s=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!i||o.filter(u=>u).length===1);this.isFixedTime=s(e[0],this.second)&&s(e[1],this.minute)&&s(e[2],this.hour)}partToArray(e,t,n,i){let s=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 s.fill(i);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,i);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,i):t.includes("-")?this.handleRange(t,e,n,i):t.includes("/")?this.handleStepping(t,e,n,i):t!==""&&this.handleNumber(t,e,n,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,n,i){let s=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(s[0],10)+n;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,s[1]||i)}setPart(e,t,n){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,n);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]=n}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,i,s){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+s+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[i].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[i].length+")")}}handleRangeWithStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let s=this.extractNth(e,t),a=s[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,d=parseInt(u,10)+n,m=parseInt(l,10);this.validateNotNaN(h,"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(h,d,m,t,e);for(let y=h;y<=d;y+=m)this.setPart(t,y,s[1]||i)}extractNth(e,t){let n=e,i;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");i=n.split("#")[1],n=n.split("#")[0]}else if(n.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",n=n.slice(0,-1)}return[n,i]}handleRange(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let s=this.extractNth(e,t),a=s[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+n,u=parseInt(a[1],10)+n;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,s[1]||i)}handleStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let s=this.extractNth(e,t),a=s[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)+n);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,s[1]||i)}replaceAlpha(e,t){let n=e;for(let[i,s]of Object.entries(t))n=n.replace(new RegExp(i,"gi"),s);return n}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 r.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 $=[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 r{tz;instantMs;instantFields;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 r)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(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),s=new Date(g(e,t,n)).getUTCDay();return s===0?n-2:s===6?n-1:n}getNearestWeekday(e,t,n){let i=this.getLastDayOfMonth(e,t);if(n>i)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===i?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,i){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(i&63&&P[o-1]&i)return!0;if(i&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(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=p(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.cacheInstant(e.getTime()-this.ms)}catch(t){let n=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: ${n}`)}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.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:i,hour:s,minute:a,second:o}=this;this.instantFields=[t,n,i,s,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}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,this.instantFields=e.instantFields}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(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,n,i){return this._findMatch(e,t,n,i,1)}_matchDayValue(e,t,n,i){let s=e;if(!s){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){s=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(s=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(s=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?s=s&&o:!i.domAndDow&&!n.starDOM?s=s||o:s=s&&o}return s}_findMatch(e,t,n,i,s){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+i,l=s===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=s){let d=n[t][h];if(t==="day"){if(h-i>o)continue;d=this._matchDayValue(d,h-i,n,e)}if(d)return this[t]=h-i,a!==this[t]?2:1}return 3}recurse(e,t,n){let i=this.year,s=n;for(;typeof s=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;s=this.recurseStep(e,t,s)}return s}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let s=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){s=a;break}if(s===-1)return null;this.year=s,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,f[n][0],e,f[n][2]);if(i>1){let s=n+1;for(;s<f.length;)this[f[s][0]]=-f[s][2],s++;if(i===3){if(this[f[n][1]]++,this[f[n][0]]=-f[n][2],this.apply(),n===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 n-1}return n+=1,n>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.instantFields=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,n){let i=this.year,s=n;for(;typeof s=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;s=this.recurseBackwardStep(e,t,s)}return s}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let s=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){s=a;break}if(s===-1)return null;this.year=s,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,f[n][0],e,f[n][2]);if(i>1){let s=n+1;for(;s<f.length;){let a=f[s][0],o=f[s][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,s++}if(i===3){if(this[f[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===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 h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=f[n][0],o=f[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=f[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,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(n===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 n-1}return n+=1,n>=f.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let i=t[e].length-1-n;for(let s=t[e].length-1;s>=0;s--)if(t[e][s]){i=s-n;break}if(e==="day"){let s=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?s:Math.min(i,s)}return i}findPrevious(e,t,n,i){return this._findMatch(e,t,n,i,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):x(T(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 n=0;n<f.length;n++){let i=f[n][0],s=f[n][2],a=this[i];if(a+s<0||a+s>=e[i].length)return!1;let o=e[i][a+s];if(i==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}};function z(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,i)=>n===void 0?i:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.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(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=I(new c(r.startAt,t))),r.stopAt&&(r.stopAt=I(new c(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function I(r){return r.ms?(r.ms=0,new c(new Date(r.getTime()+1e3),r.tz)):r}function b(r){return typeof r=="function"}function F(r){return b(r)}function L(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var N=1440*60*1e3,Y=30*1e3,R=[],j=class{name;options;_states;fn;_startAtRoundingMs=0;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)*N}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),i=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return i?this.applyDayOffset(i.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new c(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let i,s;if(b(t))s=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(b(n))s=n;else if(typeof n=="object")i=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=i?.name;let a=i?.startAt;if(this.options=z(i),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new c(a,this.getTz()).getTime()),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 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,fixedTimeRule:this.options.fixedTimeRule}),this.name){if(R.find(u=>u.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");R.push(this)}return s!==void 0&&F(s)&&(this.fn=s,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 n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new A(this,e)}_enumerateRuns(e,t,n){let i=[],s=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,s):this._previousTarget(a,s);if(!o)break;i.push(o),a=o}return i}match(e){if(this._states.once){let n=new c(e,this.getTz());n.ms=0;let i=new c(this._states.once,this.getTz());return i.ms=0,n.getTime()===i.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._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,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=R.indexOf(this);e>=0&&R.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 n=t??new Date,i=this._nextTarget(void 0,n),s=i?i.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return s===null||isNaN(s)||o===null?this:(s>Y&&(s=Y),s<0&&(s=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),s),this._states.currentTimeout&&this.options.unref&&L(this._states.currentTimeout),this)}async _trigger(e=new Date){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{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}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,n=!this._states.paused&&t.getTime()>=e.getTime(),i=this._states.blocking&&this.options.protect;n&&!i?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&i&&b(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let i=n?n.startAt:this._startAt,s=n?n.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,h=this._toMs(l);e=new c(l,this.getTz()),i&&h<i.getTime()&&(e=u?i:new c(new Date(i.getTime()-1e3),this.getTz()),h=e.getTime());let d=this._states.once||new c(e,this.getTz());if(!u&&d!==this._states.once&&(d=this._findOccurrence(e,h,1,o)),this._states.once){let m=this._states.once.getTime(),y=h-m;if(i&&m<i.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?y>=0:y>1e3&&!this.options.allowPast))return null}return d===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||s&&d.getTime()>=s.getTime()?null:d}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let i=this._findOccurrence(new c(new Date(n),this.getTz()),n,-1);return i===null||t.startAt&&i.getTime()<t.startAt.getTime()?null:i}_toMs(e){return e instanceof Date?e.getTime():new c(e,this.getTz()).getTime()}_findOccurrence(e,t,n,i=!1){let s=this._walk(e,t,n,i),a=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof a=="number"||W(t,a)!==(n===1?"earlier":"later"))return s;let o=Math.floor(t/1e3)*1e3,u=n===1?k(o,o+N,a):k(o-N,o,a)-1e3;if(s&&(u-s.getTime())*n>0)return s;let l=this._walk(new c(new Date(u),a),u-n,n,!1,!0);return!s||!l?s??l:(s.getTime()-l.getTime())*n>0?l:s}_walk(e,t,n,i,s=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options),u=new c(e,this.getTz());for((!s||!u.match(a,this.options))&&(u=o(u,i));u;){let l=this._runAt(u,t,n);if(l)return new c(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let i=m=>(m.getTime()-t)*n>0,s=e.tz;if(typeof s=="number"){let m=e.getDate();return i(m)?m:null}let a=T(e.year,e.month+1,e.day,e.hour,e.minute,e.second,s),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:y}=o;return(u?[m]:n===1?[m,y]:[y,m]).find(i)??null}if(!u)return null;let l=new Date(k(o.before.getTime(),o.after.getTime(),s)),h=p(l,s);return h.y===a.y&&h.m===a.m&&h.d===a.d&&i(l)?l:null}_calculatePreviousRun(e,t){let n=new c(t,this.getTz()).getTime();if(e.getTime()>n)return;let i=this.options.interval*1e3,s=e;for(;s.getTime()+i<=n;){let a=new c(s,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;s=a}return s}},A=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??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{j as Cron,c as CronDate,A as CronIterator,C as CronPattern,R as scheduledJobs};
@@ -1 +1 @@
1
- var Cron=(()=>{var T=(s,e,t)=>()=>{if(t)throw t[0];try{return s&&(e=s(s=0)),e}catch(n){throw t=[n],n}};var Q=(s,e)=>()=>{try{return e||s((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};function d(s,e,t,n=0,i=0,r=0,a=0){let o=s>=0&&s<100,u=Date.UTC(o?s+400:s,e,t,n,i,r,a);return o?u-126227808e5:u}var P=T(()=>{});function v(s){return d(s.y,s.m-1,s.d,s.h,s.i,s.s)}function D(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 A(s){let e=s.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function X(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return A(s)?{tp:b(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:b(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function _(s,e,t){let{tp:n,ms:i}=X(s,e);return new Date(x(n,t).getTime()+i)}function x(s,e){let t=k(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 k(s){let e=v(s),t=a=>N(new Date(a),s.tz),n=e-t(e),i=p(new Date(n),s.tz);if(D(i,s)){let a=v(i)-n,o=n-(t(n-F)-a);if(o<n&&D(p(new Date(o),s.tz),s))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+F));return u>n&&D(p(new Date(u),s.tz),s)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let r=e-(v(i)-n);return D(p(new Date(r),s.tz),s)?{kind:"single",date:new Date(r)}:{kind:"gap",before:new Date(Math.min(n,r)),after:new Date(Math.max(n,r))}}function N(s,e){return v(p(s,e))-(s.getTime()-s.getUTCMilliseconds())}function M(s,e,t){let n=N(new Date(s),t);for(;e-s>1e3;){let i=s+Math.floor((e-s)/2e3)*1e3;N(new Date(i),t)===n?s=i:e=i}return e}function Y(s,e){let t=k(p(new Date(s),e));if(t.kind==="ambiguous")return s<t.later.getTime()?"earlier":"later"}function p(s,e){if(e===void 0)return b(s.getFullYear(),s.getMonth()+1,s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds());let t=L.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),L.set(e,t)),n=t.formatToParts(s)}catch(r){let a=r instanceof Error?r.message:String(r);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 r of n)(r.type==="year"||r.type==="month"||r.type==="day"||r.type==="hour"||r.type==="minute"||r.type==="second")&&(i[r.type]=parseInt(r.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 b(s,e,t,n,i,r,a){return{y:s,m:e,d:t,h:n,i,s:r,tz:a}}var F,L,E=T(()=>{P();F=3*36e5;L=new Map});var S,w,W=T(()=>{S=[1,2,4,8,16],w=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,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.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 r;switch(this.mode){case"5-part":r=5;break;case"6-part":r=6;break;case"7-part":r=7;break;case"5-or-6-parts":r=[5,6];break;case"6-or-7-parts":r=[6,7];break;default:r=0}if(!(Array.isArray(r)?r.includes(t):t===r)){let o=Array.isArray(r)?r.join(" or "):r.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 r=0;r<e.length;r++)e[r]=e[r].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 n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let i=(r,a)=>!r.includes("*")&&!r.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,n,i){let r=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 r.fill(i);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,i);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,i):t.includes("-")?this.handleRange(t,e,n,i):t.includes("/")?this.handleStepping(t,e,n,i):t!==""&&this.handleNumber(t,e,n,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,n,i){let r=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(r[0],10)+n;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,r[1]||i)}setPart(e,t,n){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,n);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]=n}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,i,r){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+r+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[i].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[i].length+")")}}handleRangeWithStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let r=this.extractNth(e,t),a=r[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,h]=a,c=parseInt(o,10)+n,g=parseInt(u,10)+n,m=parseInt(h,10);this.validateNotNaN(c,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(g,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(m,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(c,g,m,t,e);for(let y=c;y<=g;y+=m)this.setPart(t,y,r[1]||i)}extractNth(e,t){let n=e,i;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");i=n.split("#")[1],n=n.split("#")[0]}else if(n.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",n=n.slice(0,-1)}return[n,i]}handleRange(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let r=this.extractNth(e,t),a=r[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+n,u=parseInt(a[1],10)+n;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 h=o;h<=u;h++)this.setPart(t,h,r[1]||i)}handleStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let r=this.extractNth(e,t),a=r[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)+n);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 h=o;h<this[t].length;h+=u)t==="year"&&h===0||this.setPart(t,h,r[1]||i)}replaceAlpha(e,t){let n=e;for(let[i,r]of Object.entries(t))n=n.replace(new RegExp(i,"gi"),r);return n}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]|S[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}}});var te,l,f,U=T(()=>{E();P();W();te=[31,28,31,30,31,30,31,31,30,31,30,31],l=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],f=class s{tz;instantMs;instantFields;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?te[t]:new Date(d(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),r=new Date(d(e,t,n)).getUTCDay();return r===0?n-2:r===6?n-1:n}getNearestWeekday(e,t,n){let i=this.getLastDayOfMonth(e,t);if(n>i)return-1;let a=new Date(d(e,t,n)).getUTCDay();return a===0?n===i?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,i){let a=new Date(d(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(d(e,t,u)).getUTCDay()===a&&o++;if(i&63&&S[o-1]&i)return!0;if(i&32){let u=this.getLastDayOfMonth(e,t);for(let h=n+1;h<=u;h++)if(new Date(d(e,t,h)).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=p(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.cacheInstant(e.getTime()-this.ms)}catch(t){let n=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: ${n}`)}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.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:i,hour:r,minute:a,second:o}=this;this.instantFields=[t,n,i,r,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}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,this.instantFields=e.instantFields}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(A(e))return this.fromDate(_(e));let t=_(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(_(e,this.tz))}findNext(e,t,n,i){return this._findMatch(e,t,n,i,1)}_matchDayValue(e,t,n,i){let r=e;if(!r){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){r=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(r=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(r=1)}if(!n.starDOW){let a=new Date(d(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?r=r&&o:!i.domAndDow&&!n.starDOM?r=r||o:r=r&&o}return r}_findMatch(e,t,n,i,r){let a=this[t],o=this[t]+i,u=r===1?h=>h<n[t].length:h=>h>=0;for(let h=o;u(h);h+=r){let c=n[t][h];if(t==="day"&&(c=this._matchDayValue(c,h-i,n,e)),c)return this[t]=h-i,a!==this[t]?2:1}return 3}recurse(e,t,n){let i=this.year,r=n;for(;typeof r=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;r=this.recurseStep(e,t,r)}return r}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let r=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){r=a;break}if(r===-1)return null;this.year=r,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,l[n][0],e,l[n][2]);if(i>1){let r=n+1;for(;r<l.length;)this[l[r][0]]=-l[r][2],r++;if(i===3){if(this[l[n][1]]++,this[l[n][0]]=-l[n][2],this.apply(),n===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 n-1}return n+=1,n>=l.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.instantFields=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,n){let i=this.year,r=n;for(;typeof r=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;r=this.recurseBackwardStep(e,t,r)}return r}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let r=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){r=a;break}if(r===-1)return null;this.year=r,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,l[n][0],e,l[n][2]);if(i>1){let r=n+1;for(;r<l.length;){let a=l[r][0],o=l[r][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,r++}if(i===3){if(this[l[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===1)if(this.day<=0)this.day=1;else{let u=this.year,h=this.month;for(;h<0;)h+=12,u--;for(;h>11;)h-=12,u++;let c=this.getLastDayOfMonth(u,h);this.day>c&&(this.day=c)}this.apply();let a=l[n][0],o=l[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=l[1][2],h=this.getMaxPatternValue("day",e,u);h!==this.day&&(this.day=h,this.hour=this.getMaxPatternValue("hour",e,l[2][2]),this.minute=this.getMaxPatternValue("minute",e,l[3][2]),this.second=this.getMaxPatternValue("second",e,l[4][2]))}if(n===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 n-1}return n+=1,n>=l.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let i=t[e].length-1-n;for(let r=t[e].length-1;r>=0;r--)if(t[e][r]){i=r-n;break}if(e==="day"){let r=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?r:Math.min(i,r)}return i}findPrevious(e,t,n,i){return this._findMatch(e,t,n,i,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(d(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):x(b(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 n=0;n<l.length;n++){let i=l[n][0],r=l[n][2],a=this[i];if(a+r<0||a+r>=e[i].length)return!1;let o=e[i][a+r];if(i==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}}});function H(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=(n,i)=>n===void 0?i:n;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=Z(new f(s.startAt,t))),s.stopAt&&(s.stopAt=Z(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 Z(s){return s.ms?(s.ms=0,new f(new Date(s.getTime()+1e3),s.tz)):s}var $=T(()=>{U()});function C(s){return typeof s=="function"}function B(s){return C(s)}function V(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var J=T(()=>{});var I,G,O,R,z,K=T(()=>{U();W();$();J();E();I=1440*60*1e3,G=30*1e3,O=[],R=class{name;options;_states;fn;_startAtRoundingMs=0;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)*I}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),i=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return i?this.applyDayOffset(i.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new f(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let i,r;if(C(t))r=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(n))r=n;else if(typeof n=="object")i=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=i?.name;let a=i?.startAt;if(this.options=H(i),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new f(a,this.getTz()).getTime()),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 w("* * * * *",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 w(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(O.find(u=>u.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");O.push(this)}return r!==void 0&&B(r)&&(this.fn=r,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 n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new z(this,e)}_enumerateRuns(e,t,n){let i=[],r=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,r):this._previousTarget(a,r);if(!o)break;i.push(o),a=o}return i}match(e){if(this._states.once){let n=new f(e,this.getTz());n.ms=0;let i=new f(this._states.once,this.getTz());return i.ms=0,n.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,n=this._nextTarget(e,t);return n?n.getTime()-this._toMs(e??t):null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=O.indexOf(this);e>=0&&O.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 n=t??new Date,i=this._nextTarget(void 0,n),r=i?i.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return r===null||isNaN(r)||o===null?this:(r>G&&(r=G),r<0&&(r=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),r),this._states.currentTimeout&&this.options.unref&&V(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{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}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,n=!this._states.paused&&t.getTime()>=e.getTime(),i=this._states.blocking&&this.options.protect;n&&!i?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&i&&C(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let i=n?n.startAt:this._startAt,r=n?n.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 h=e??t??new Date,c=this._toMs(h);e=new f(h,this.getTz()),i&&c<i.getTime()&&(e=u?i:new f(new Date(i.getTime()-1e3),this.getTz()),c=e.getTime());let g=this._states.once||new f(e,this.getTz());if(!u&&g!==this._states.once&&(g=this._findOccurrence(e,c,1,o)),this._states.once){let m=this._states.once.getTime(),y=c-m;if(i&&m<i.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?y>=0:y>1e3&&!this.options.allowPast))return null}return g===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||r&&g.getTime()>=r.getTime()?null:g}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let i=this._findOccurrence(new f(new Date(n),this.getTz()),n,-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,n,i=!1){let r=this._walk(e,t,n,i),a=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof a=="number"||Y(t,a)!==(n===1?"earlier":"later"))return r;let o=Math.floor(t/1e3)*1e3,u=n===1?M(o,o+I,a):M(o-I,o,a)-1e3;if(r&&(u-r.getTime())*n>0)return r;let h=this._walk(new f(new Date(u),a),u-n,n,!1,!0);return!r||!h?r??h:(r.getTime()-h.getTime())*n>0?h:r}_walk(e,t,n,i,r=!1){let a=this._states.pattern,o=(h,c)=>n===1?h.increment(a,this.options,c):h.decrement(a,this.options),u=new f(e,this.getTz());for((!r||!u.match(a,this.options))&&(u=o(u,i));u;){let h=this._runAt(u,t,n);if(h)return new f(h,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let i=m=>(m.getTime()-t)*n>0,r=e.tz;if(typeof r=="number"){let m=e.getDate();return i(m)?m:null}let a=b(e.year,e.month+1,e.day,e.hour,e.minute,e.second,r),o=k(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:y}=o;return(u?[m]:n===1?[m,y]:[y,m]).find(i)??null}if(!u)return null;let h=new Date(M(o.before.getTime(),o.after.getTime(),r)),c=p(h,r);return c.y===a.y&&c.m===a.m&&c.d===a.d&&i(h)?h:null}_calculatePreviousRun(e,t){let n=new f(t,this.getTz()).getTime();if(e.getTime()>n)return;let i=this.options.interval*1e3,r=e;for(;r.getTime()+i<=n;){let a=new f(r,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;r=a}return r}},z=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??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 ne=Q((ve,q)=>{K();q.exports=R});return ne();})();
1
+ var Cron=(()=>{var T=(r,e,t)=>()=>{if(t)throw t[0];try{return r&&(e=r(r=0)),e}catch(n){throw t=[n],n}};var Q=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};function g(r,e,t,n=0,i=0,s=0,a=0){let o=r>=0&&r<100,u=Date.UTC(o?r+400:r,e,t,n,i,s,a);return o?u-126227808e5:u}var x=T(()=>{});function v(r){return g(r.y,r.m-1,r.d,r.h,r.i,r.s)}function D(r,e){return r.y===e.y&&r.m===e.m&&r.d===e.d&&r.h===e.h&&r.i===e.i&&r.s===e.s}function N(r){let e=r.substring(9);return e.includes("Z")||e.includes("+")||e.includes("-")}function X(r,e){let t=new Date(Date.parse(r));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");return N(r)?{tp:C(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"),ms:t.getUTCMilliseconds()}:{tp:C(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e),ms:t.getMilliseconds()}}function _(r,e,t){let{tp:n,ms:i}=X(r,e);return new Date(A(n,t).getTime()+i)}function A(r,e){let t=k(r);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 k(r){let e=v(r),t=a=>P(new Date(a),r.tz),n=e-t(e),i=p(new Date(n),r.tz);if(D(i,r)){let a=v(i)-n,o=n-(t(n-F)-a);if(o<n&&D(p(new Date(o),r.tz),r))return{kind:"ambiguous",earlier:new Date(o),later:new Date(n)};let u=n+(a-t(n+F));return u>n&&D(p(new Date(u),r.tz),r)?{kind:"ambiguous",earlier:new Date(n),later:new Date(u)}:{kind:"single",date:new Date(n)}}let s=e-(v(i)-n);return D(p(new Date(s),r.tz),r)?{kind:"single",date:new Date(s)}:{kind:"gap",before:new Date(Math.min(n,s)),after:new Date(Math.max(n,s))}}function P(r,e){return v(p(r,e))-(r.getTime()-r.getUTCMilliseconds())}function R(r,e,t){let n=P(new Date(r),t);for(;e-r>1e3;){let i=r+Math.floor((e-r)/2e3)*1e3;P(new Date(i),t)===n?r=i:e=i}return e}function Y(r,e){let t=k(p(new Date(r),e));if(t.kind==="ambiguous")return r<t.later.getTime()?"earlier":"later"}function p(r,e){if(e===void 0)return C(r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds());let t=L.get(e),n;try{t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),L.set(e,t)),n=t.formatToParts(r)}catch(s){let a=s instanceof Error?s.message:String(s);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 s of n)(s.type==="year"||s.type==="month"||s.type==="day"||s.type==="hour"||s.type==="minute"||s.type==="second")&&(i[s.type]=parseInt(s.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 C(r,e,t,n,i,s,a){return{y:r,m:e,d:t,h:n,i,s,tz:a}}var F,L,E=T(()=>{x();F=3*36e5;L=new Map});var S,w,W=T(()=>{S=[1,2,4,8,16],w=class r{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;fixedTimeRule;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;isFixedTime;constructor(e,t,n){this.pattern=e,this.timezone=t,this.mode=n?.mode??"auto",this.alternativeWeekdays=n?.alternativeWeekdays??!1,this.sloppyRanges=n?.sloppyRanges??!1,this.fixedTimeRule=n?.fixedTimeRule??"single-value",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 a;switch(this.mode){case"5-part":a=5;break;case"6-part":a=6;break;case"7-part":a=7;break;case"5-or-6-parts":a=[5,6];break;case"6-or-7-parts":a=[6,7];break;default:a=0}if(!(Array.isArray(a)?a.includes(t):t===a)){let u=Array.isArray(a)?a.join(" or "):a.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${u} 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 a=0;a<e.length;a++)e[a]=e[a].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],r.MONTH_NAMES)),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlpha(e[5],r.DAY_NAMES_QUARTZ):this.replaceAlpha(e[5],r.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 n=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],n,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7]);let i=this.fixedTimeRule==="single-value",s=(a,o)=>!a.includes("*")&&!a.includes("/")&&(!i||o.filter(u=>u).length===1);this.isFixedTime=s(e[0],this.second)&&s(e[1],this.minute)&&s(e[2],this.hour)}partToArray(e,t,n,i){let s=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 s.fill(i);let a=t.split(",");if(a.length>1)for(let o of a)this.partToArray(e,o,n,i);else t.includes("-")&&t.includes("/")?this.handleRangeWithStepping(t,e,n,i):t.includes("-")?this.handleRange(t,e,n,i):t.includes("/")?this.handleStepping(t,e,n,i):t!==""&&this.handleNumber(t,e,n,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,n,i){let s=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(s[0],10)+n;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,s[1]||i)}setPart(e,t,n){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,n);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]=n}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,n,i,s){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+s+"'");if(n!==void 0){if(n===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(n>this[i].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[i].length+")")}}handleRangeWithStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let s=this.extractNth(e,t),a=s[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,u,l]=a,h=parseInt(o,10)+n,d=parseInt(u,10)+n,c=parseInt(l,10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(c,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(h,d,c,t,e);for(let y=h;y<=d;y+=c)this.setPart(t,y,s[1]||i)}extractNth(e,t){let n=e,i;if(n.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");i=n.split("#")[1],n=n.split("#")[0]}else if(n.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",n=n.slice(0,-1)}return[n,i]}handleRange(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let s=this.extractNth(e,t),a=s[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+n,u=parseInt(a[1],10)+n;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,s[1]||i)}handleStepping(e,t,n,i){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let s=this.extractNth(e,t),a=s[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)+n);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,s[1]||i)}replaceAlpha(e,t){let n=e;for(let[i,s]of Object.entries(t))n=n.replace(new RegExp(i,"gi"),s);return n}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 r.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]|S[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}}});var te,f,m,U=T(()=>{E();x();W();te=[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]],m=class r{tz;instantMs;instantFields;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 r)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?te[t]:new Date(g(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let n=this.getLastDayOfMonth(e,t),s=new Date(g(e,t,n)).getUTCDay();return s===0?n-2:s===6?n-1:n}getNearestWeekday(e,t,n){let i=this.getLastDayOfMonth(e,t);if(n>i)return-1;let a=new Date(g(e,t,n)).getUTCDay();return a===0?n===i?n-2:n+1:a===6?n===1?n+2:n-1:n}isNthWeekdayOfMonth(e,t,n,i){let a=new Date(g(e,t,n)).getUTCDay(),o=0;for(let u=1;u<=n;u++)new Date(g(e,t,u)).getUTCDay()===a&&o++;if(i&63&&S[o-1]&i)return!0;if(i&32){let u=this.getLastDayOfMonth(e,t);for(let l=n+1;l<=u;l++)if(new Date(g(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=p(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.cacheInstant(e.getTime()-this.ms)}catch(t){let n=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: ${n}`)}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.cacheInstant(e.getTime()-this.ms)}cacheInstant(e){this.instantMs=e;let{year:t,month:n,day:i,hour:s,minute:a,second:o}=this;this.instantFields=[t,n,i,s,a,o,this.tz]}cachedInstant(){let e=this.instantFields;if(!(e===void 0||e[6]!==this.tz)&&!(e[5]!==this.second||e[4]!==this.minute||e[3]!==this.hour)&&!(e[2]!==this.day||e[1]!==this.month||e[0]!==this.year))return this.instantMs}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,this.instantFields=e.instantFields}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(_(e));let t=_(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(_(e,this.tz))}findNext(e,t,n,i){return this._findMatch(e,t,n,i,1)}_matchDayValue(e,t,n,i){let s=e;if(!s){for(let a=0;a<n.nearestWeekdays.length;a++)if(n.nearestWeekdays[a]){let o=this.getNearestWeekday(this.year,this.month,a+1);if(o!==-1&&o===t){s=1;break}}}if(n.lastWeekday){let a=this.getLastWeekday(this.year,this.month);t===a&&(s=1)}if(n.lastDayOfMonth){let a=this.getLastDayOfMonth(this.year,this.month);t===a&&(s=1)}if(!n.starDOW){let a=new Date(g(this.year,this.month,1,0,0,0,0)).getUTCDay(),o=n.dayOfWeek[(a+(t-1))%7];o&&o&63&&(o=this.isNthWeekdayOfMonth(this.year,this.month,t,o)?1:0),n.useAndLogic?s=s&&o:!i.domAndDow&&!n.starDOM?s=s||o:s=s&&o}return s}_findMatch(e,t,n,i,s){let a=this[t],o=t==="day"?this.getLastDayOfMonth(this.year,this.month):0,u=this[t]+i,l=s===1?h=>h<n[t].length:h=>h>=0;for(let h=u;l(h);h+=s){let d=n[t][h];if(t==="day"){if(h-i>o)continue;d=this._matchDayValue(d,h-i,n,e)}if(d)return this[t]=h-i,a!==this[t]?2:1}return 3}recurse(e,t,n){let i=this.year,s=n;for(;typeof s=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;s=this.recurseStep(e,t,s)}return s}recurseStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let s=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){s=a;break}if(s===-1)return null;this.year=s,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,f[n][0],e,f[n][2]);if(i>1){let s=n+1;for(;s<f.length;)this[f[s][0]]=-f[s][2],s++;if(i===3){if(this[f[n][1]]++,this[f[n][0]]=-f[n][2],this.apply(),n===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 n-1}return n+=1,n>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:n}increment(e,t,n){return this.instantMs=void 0,this.instantFields=void 0,this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.instantMs=void 0,this.instantFields=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,n){let i=this.year,s=n;for(;typeof s=="number";){if(e.starYear&&Math.abs(this.year-i)>400)return null;s=this.recurseBackwardStep(e,t,s)}return s}recurseBackwardStep(e,t,n){if(n===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let s=-1;for(let a=this.year-1;a>=0;a--)if(e.year[a]===1){s=a;break}if(s===-1)return null;this.year=s,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,f[n][0],e,f[n][2]);if(i>1){let s=n+1;for(;s<f.length;){let a=f[s][0],o=f[s][2],u=this.getMaxPatternValue(a,e,o);this[a]=u,s++}if(i===3){if(this[f[n][1]]--,n===0){let u=this.getLastDayOfMonth(this.year,this.month);this.day>u&&(this.day=u)}if(n===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 h=this.getLastDayOfMonth(u,l);this.day>h&&(this.day=h)}this.apply();let a=f[n][0],o=f[n][2];if(this[a]=this.getMaxPatternValue(a,e,o),this.apply(),n===0){let u=f[1][2],l=this.getMaxPatternValue("day",e,u);l!==this.day&&(this.day=l,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(n===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 n-1}return n+=1,n>=f.length?this:this.year<0?null:n}getMaxPatternValue(e,t,n){let i=t[e].length-1-n;for(let s=t[e].length-1;s>=0;s--)if(t[e][s]){i=s-n;break}if(e==="day"){let s=this.getLastDayOfMonth(this.year,this.month);return t.lastWeekday||t.nearestWeekdays.some(a=>a)||t.lastDayOfMonth||!t.starDOW?s:Math.min(i,s)}return i}findPrevious(e,t,n,i){return this._findMatch(e,t,n,i,-1)}getDate(e){if(!e&&typeof this.tz!="number"){let t=this.cachedInstant();if(t!==void 0)return new Date(t+(this.tz===void 0?this.ms:0))}if(e||this.tz===void 0){if(this.year>=0&&this.year<100){let t=new Date(0);return t.setFullYear(this.year,this.month,this.day),t.setHours(this.hour,this.minute,this.second,this.ms),t}return new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms)}else return typeof this.tz=="number"?new Date(g(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):A(C(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 n=0;n<f.length;n++){let i=f[n][0],s=f[n][2],a=this[i];if(a+s<0||a+s>=e[i].length)return!1;let o=e[i][a+s];if(i==="day"&&(o=this._matchDayValue(o,a,e,t)),!o)return!1}return!0}}});function H(r){r===void 0&&(r={}),delete r.name,r.legacyMode!==void 0&&r.domAndDow===void 0?r.domAndDow=!r.legacyMode:r.domAndDow===void 0&&(r.domAndDow=!1),r.legacyMode=!r.domAndDow;let e=(n,i)=>n===void 0?i:n;if(r.paused=e(r.paused,!1),r.maxRuns=e(r.maxRuns,1/0),r.catch=e(r.catch,!1),r.unref=e(r.unref,!1),r.mode=e(r.mode,"auto"),r.alternativeWeekdays=e(r.alternativeWeekdays,!1),r.sloppyRanges=e(r.sloppyRanges,!1),r.fixedTimeRule=e(r.fixedTimeRule,"single-value"),r.allowPast=e(r.allowPast,!1),r.interval=r.interval===void 0?0:parseInt(r.interval.toString(),10),r.utcOffset=r.utcOffset===void 0?void 0:parseInt(r.utcOffset.toString(),10),r.dayOffset=r.dayOffset===void 0?0:parseInt(r.dayOffset.toString(),10),!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(r.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(!["single-value","no-wildcard"].includes(r.fixedTimeRule))throw new Error("CronOptions: fixedTimeRule must be one of 'single-value' or 'no-wildcard'.");r.timezone===""&&(r.timezone=void 0);let t=r.timezone??r.utcOffset;if(r.startAt&&(r.startAt=Z(new m(r.startAt,t))),r.stopAt&&(r.stopAt=Z(new m(r.stopAt,t))),r.interval!==null){if(isNaN(r.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(r.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(r.utcOffset!==void 0){if(isNaN(r.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(r.utcOffset<-870||r.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(r.utcOffset!==void 0&&r.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(r.unref!==!0&&r.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(r.dayOffset!==void 0&&r.dayOffset!==0&&isNaN(r.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return r}function Z(r){return r.ms?(r.ms=0,new m(new Date(r.getTime()+1e3),r.tz)):r}var $=T(()=>{U()});function b(r){return typeof r=="function"}function V(r){return b(r)}function B(r){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(r):r&&typeof r.unref<"u"&&r.unref()}var J=T(()=>{});var I,G,M,O,z,K=T(()=>{U();W();$();J();E();I=1440*60*1e3,G=30*1e3,M=[],O=class{name;options;_states;fn;_startAtRoundingMs=0;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)*I}get _startAt(){return this.options.startAt}get _stopAt(){return this.options.stopAt}_nextTarget(e,t){let n=this._offsetMs(),i=this._next(this._shift(e),new Date(t.getTime()-n),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return i?this.applyDayOffset(i.getDate(!1)):null}_previousTarget(e,t){let n=this._previous(this._shift(e??t),{startAt:this._shift(this._startAt),stopAt:this._shift(this._stopAt)});return n?this.applyDayOffset(n.getDate(!1)):null}_shift(e){if(e!=null)return new m(new Date(this._toMs(e)-this._offsetMs()),this.getTz())}constructor(e,t,n){let i,s;if(b(t))s=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(b(n))s=n;else if(typeof n=="object")i=n;else if(n!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");this.name=i?.name;let a=i?.startAt;if(this.options=H(i),a&&this._startAt&&(this._startAtRoundingMs=this._startAt.getTime()-new m(a,this.getTz()).getTime()),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 w("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new m(e,this.getTz()):this._states.pattern=new w(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges,fixedTimeRule:this.options.fixedTimeRule}),this.name){if(M.find(u=>u.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");M.push(this)}return s!==void 0&&V(s)&&(this.fn=s,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 n=t||this._states.currentRun||void 0;return this._enumerateRuns(e,n,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}enumerate(e){return new z(this,e)}_enumerateRuns(e,t,n){let i=[],s=new Date,a=t;for(;e-- >0;){let o=n==="next"?this._nextTarget(a,s):this._previousTarget(a,s);if(!o)break;i.push(o),a=o}return i}match(e){if(this._states.once){let n=new m(e,this.getTz());n.ms=0;let i=new m(this._states.once,this.getTz());return i.ms=0,n.getTime()===i.getTime()}let t=new m(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,n=this._nextTarget(e,t);return n?n.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 n=t??new Date,i=this._nextTarget(void 0,n),s=i?i.getTime()-n.getTime():null,a=this._states.currentRun;a&&a.getTime()>n.getTime()&&(a=void 0);let o=this._nextTarget(a,n);return s===null||isNaN(s)||o===null?this:(s>G&&(s=G),s<0&&(s=this._states.paused?1e3:0),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(o),s),this._states.currentTimeout&&this.options.unref&&B(this._states.currentTimeout),this)}async _trigger(e=new Date){this._states.blocking=!0,this._states.currentRun=new m(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{Promise.resolve(this.options.catch(t,this)).catch(()=>{})}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new m(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),i=this._states.blocking&&this.options.protect;n&&!i?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger(t)):n&&i&&b(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this._schedule(void 0,n?void 0:t)}_next(e,t,n){let i=n?n.startAt:this._startAt,s=n?n.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,h=this._toMs(l);e=new m(l,this.getTz()),i&&h<i.getTime()&&(e=u?i:new m(new Date(i.getTime()-1e3),this.getTz()),h=e.getTime());let d=this._states.once||new m(e,this.getTz());if(!u&&d!==this._states.once&&(d=this._findOccurrence(e,h,1,o)),this._states.once){let c=this._states.once.getTime(),y=h-c;if(i&&c<i.getTime()-this._startAtRoundingMs||this._states.currentRun&&this.applyDayOffset(this._states.once.getDate()).getTime()<=this._states.currentRun.getTime()||(a?y>=0:y>1e3&&!this.options.allowPast))return null}return d===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||s&&d.getTime()>=s.getTime()?null:d}_previous(e,t){let n=this._toMs(e??new Date);if(t.stopAt&&n>t.stopAt.getTime()&&(n=t.stopAt.getTime()),this._states.once)return this._states.once.getTime()<n?this._states.once:null;let i=this._findOccurrence(new m(new Date(n),this.getTz()),n,-1);return i===null||t.startAt&&i.getTime()<t.startAt.getTime()?null:i}_toMs(e){return e instanceof Date?e.getTime():new m(e,this.getTz()).getTime()}_findOccurrence(e,t,n,i=!1){let s=this._walk(e,t,n,i),a=this.getTz();if(this._states.pattern.isFixedTime&&n===1||typeof a=="number"||Y(t,a)!==(n===1?"earlier":"later"))return s;let o=Math.floor(t/1e3)*1e3,u=n===1?R(o,o+I,a):R(o-I,o,a)-1e3;if(s&&(u-s.getTime())*n>0)return s;let l=this._walk(new m(new Date(u),a),u-n,n,!1,!0);return!s||!l?s??l:(s.getTime()-l.getTime())*n>0?l:s}_walk(e,t,n,i,s=!1){let a=this._states.pattern,o=(l,h)=>n===1?l.increment(a,this.options,h):l.decrement(a,this.options),u=new m(e,this.getTz());for((!s||!u.match(a,this.options))&&(u=o(u,i));u;){let l=this._runAt(u,t,n);if(l)return new m(l,this.getTz());u=o(u,!1)}return null}_runAt(e,t,n){let i=c=>(c.getTime()-t)*n>0,s=e.tz;if(typeof s=="number"){let c=e.getDate();return i(c)?c:null}let a=C(e.year,e.month+1,e.day,e.hour,e.minute,e.second,s),o=k(a),u=this._states.pattern.isFixedTime;if(o.kind==="single")return i(o.date)?o.date:null;if(o.kind==="ambiguous"){let{earlier:c,later:y}=o;return(u?[c]:n===1?[c,y]:[y,c]).find(i)??null}if(!u)return null;let l=new Date(R(o.before.getTime(),o.after.getTime(),s)),h=p(l,s);return h.y===a.y&&h.m===a.m&&h.d===a.d&&i(l)?l:null}_calculatePreviousRun(e,t){let n=new m(t,this.getTz()).getTime();if(e.getTime()>n)return;let i=this.options.interval*1e3,s=e;for(;s.getTime()+i<=n;){let a=new m(s,this.getTz()).increment(this._states.pattern,this.options,!0);if(a===null)break;s=a}return s}},z=class{cron;cursor;now;done;initialMaxRuns;remainingRuns;constructor(e,t){this.cron=e,this.initialMaxRuns=e.runsLeft()??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 ne=Q((ve,q)=>{K();q.exports=O});return ne();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "croner",
3
- "version": "11.0.1-dev.1",
3
+ "version": "11.0.1-dev.2",
4
4
  "description": "Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.",
5
5
  "author": "Hexagon <github.com/hexagon>",
6
6
  "homepage": "https://croner.56k.guru",
@@ -84,7 +84,7 @@
84
84
  "@std/assert": "npm:@jsr/std__assert@~1.0.6",
85
85
  "@typescript/typescript6": "~6.0.2",
86
86
  "esbuild": "0.28.2",
87
- "rollup": "~4.65.0",
87
+ "rollup": "~4.67.0",
88
88
  "rollup-plugin-dts": "~6.5.1",
89
89
  "tsx": "^4.20.0",
90
90
  "typescript": "~7.0.0"