@push.rocks/smarttime 4.0.6 → 4.0.8

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.
@@ -28,9 +28,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  mod
29
29
  ));
30
30
 
31
- // node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js
31
+ // node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js
32
32
  var require_dayjs_min = __commonJS({
33
- "node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js"(exports, module) {
33
+ "node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js"(exports, module) {
34
34
  !function(t, e) {
35
35
  "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e();
36
36
  }(exports, function() {
@@ -322,9 +322,9 @@ var require_dayjs_min = __commonJS({
322
322
  }
323
323
  });
324
324
 
325
- // node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/plugin/isToday.js
325
+ // node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/plugin/isToday.js
326
326
  var require_isToday = __commonJS({
327
- "node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/plugin/isToday.js"(exports, module) {
327
+ "node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/plugin/isToday.js"(exports, module) {
328
328
  !function(e, o) {
329
329
  "object" == typeof exports && "undefined" != typeof module ? module.exports = o() : "function" == typeof define && define.amd ? define(o) : (e = "undefined" != typeof globalThis ? globalThis : e || self).dayjs_plugin_isToday = o();
330
330
  }(exports, function() {
@@ -1161,10 +1161,11 @@ var require_SymbolTree = __commonJS({
1161
1161
  }
1162
1162
  });
1163
1163
 
1164
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/index.js
1164
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/index.js
1165
1165
  var dist_ts_exports5 = {};
1166
1166
  __export(dist_ts_exports5, {
1167
1167
  AsyncExecutionStack: () => AsyncExecutionStack,
1168
+ BackpressuredArray: () => BackpressuredArray,
1168
1169
  FastMap: () => FastMap,
1169
1170
  Interest: () => Interest,
1170
1171
  InterestMap: () => InterestMap,
@@ -1466,7 +1467,7 @@ var SmartMatch = class {
1466
1467
  }
1467
1468
  };
1468
1469
 
1469
- // node_modules/.pnpm/@push.rocks+smartrx@3.0.6/node_modules/@push.rocks/smartrx/dist_ts/index.js
1470
+ // node_modules/.pnpm/@push.rocks+smartrx@3.0.7/node_modules/@push.rocks/smartrx/dist_ts/index.js
1470
1471
  var dist_ts_exports4 = {};
1471
1472
  __export(dist_ts_exports4, {
1472
1473
  ObservableIntake: () => ObservableIntake,
@@ -1474,7 +1475,7 @@ __export(dist_ts_exports4, {
1474
1475
  rxjs: () => smartrx_plugins_rxjs_exports
1475
1476
  });
1476
1477
 
1477
- // node_modules/.pnpm/@push.rocks+smartrx@3.0.6/node_modules/@push.rocks/smartrx/dist_ts/smartrx.plugins.rxjs.js
1478
+ // node_modules/.pnpm/@push.rocks+smartrx@3.0.7/node_modules/@push.rocks/smartrx/dist_ts/smartrx.plugins.rxjs.js
1478
1479
  var smartrx_plugins_rxjs_exports = {};
1479
1480
  __export(smartrx_plugins_rxjs_exports, {
1480
1481
  Observable: () => Observable,
@@ -1483,10 +1484,11 @@ __export(smartrx_plugins_rxjs_exports, {
1483
1484
  Subscription: () => Subscription,
1484
1485
  from: () => from,
1485
1486
  fromEvent: () => fromEvent,
1487
+ of: () => of,
1486
1488
  ops: () => ops
1487
1489
  });
1488
1490
 
1489
- // node_modules/.pnpm/tslib@2.6.0/node_modules/tslib/tslib.es6.mjs
1491
+ // node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.es6.mjs
1490
1492
  var extendStatics = function(d, b) {
1491
1493
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
1492
1494
  d2.__proto__ = b2;
@@ -3157,6 +3159,16 @@ function from(input, scheduler) {
3157
3159
  return scheduler ? scheduled(input, scheduler) : innerFrom(input);
3158
3160
  }
3159
3161
 
3162
+ // node_modules/.pnpm/rxjs@7.8.1/node_modules/rxjs/dist/esm5/internal/observable/of.js
3163
+ function of() {
3164
+ var args = [];
3165
+ for (var _i = 0; _i < arguments.length; _i++) {
3166
+ args[_i] = arguments[_i];
3167
+ }
3168
+ var scheduler = popScheduler(args);
3169
+ return from(args, scheduler);
3170
+ }
3171
+
3160
3172
  // node_modules/.pnpm/rxjs@7.8.1/node_modules/rxjs/dist/esm5/internal/util/isDate.js
3161
3173
  function isValidDate(value) {
3162
3174
  return value instanceof Date && !isNaN(value);
@@ -3538,7 +3550,7 @@ function throttleTime(duration, scheduler, config2) {
3538
3550
  }, config2);
3539
3551
  }
3540
3552
 
3541
- // node_modules/.pnpm/@push.rocks+smartrx@3.0.6/node_modules/@push.rocks/smartrx/dist_ts/smartrx.plugins.rxjs.js
3553
+ // node_modules/.pnpm/@push.rocks+smartrx@3.0.7/node_modules/@push.rocks/smartrx/dist_ts/smartrx.plugins.rxjs.js
3542
3554
  var ops = {
3543
3555
  debounce,
3544
3556
  debounceTime,
@@ -3549,7 +3561,7 @@ var ops = {
3549
3561
  filter
3550
3562
  };
3551
3563
 
3552
- // node_modules/.pnpm/@push.rocks+smartrx@3.0.6/node_modules/@push.rocks/smartrx/dist_ts/smartrx.classes.observablemap.js
3564
+ // node_modules/.pnpm/@push.rocks+smartrx@3.0.7/node_modules/@push.rocks/smartrx/dist_ts/smartrx.classes.observablemap.js
3553
3565
  var Observablemap = class {
3554
3566
  constructor() {
3555
3567
  this.observableEventEmitterBundleArray = new Array();
@@ -3597,7 +3609,7 @@ var Observablemap = class {
3597
3609
  }
3598
3610
  };
3599
3611
 
3600
- // node_modules/.pnpm/@push.rocks+smartrx@3.0.6/node_modules/@push.rocks/smartrx/dist_ts/smartrx.classes.observableintake.js
3612
+ // node_modules/.pnpm/@push.rocks+smartrx@3.0.7/node_modules/@push.rocks/smartrx/dist_ts/smartrx.classes.observableintake.js
3601
3613
  var ObservableIntake = class {
3602
3614
  constructor() {
3603
3615
  this.observableFunctions = {
@@ -3682,7 +3694,7 @@ var ObservableIntake = class {
3682
3694
  }
3683
3695
  };
3684
3696
 
3685
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/index.js
3697
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/index.js
3686
3698
  var dist_ts_exports6 = {};
3687
3699
  __export(dist_ts_exports6, {
3688
3700
  CronJob: () => CronJob,
@@ -3697,7 +3709,7 @@ __export(dist_ts_exports6, {
3697
3709
  units: () => units
3698
3710
  });
3699
3711
 
3700
- // node_modules/.pnpm/croner@5.7.0/node_modules/croner/dist/croner.min.mjs
3712
+ // node_modules/.pnpm/croner@7.0.7/node_modules/croner/dist/croner.min.js
3701
3713
  function minitz(y, m, d, h, i, s, tz, throwOnInvalid) {
3702
3714
  return minitz.fromTZ(minitz.tp(y, m, d, h, i, s, tz), throwOnInvalid);
3703
3715
  }
@@ -3722,14 +3734,16 @@ minitz.fromTZ = function(tp, throwOnInvalid) {
3722
3734
  }
3723
3735
  };
3724
3736
  minitz.toTZ = function(d, tzStr) {
3725
- const td = new Date(d.toLocaleString("sv-SE", { timeZone: tzStr }));
3737
+ const localDateString = d.toLocaleString("en-US", { timeZone: tzStr }).replace(/[\u202f]/, " ");
3738
+ const td = new Date(localDateString);
3726
3739
  return { y: td.getFullYear(), m: td.getMonth() + 1, d: td.getDate(), h: td.getHours(), i: td.getMinutes(), s: td.getSeconds(), tz: tzStr };
3727
3740
  };
3728
3741
  minitz.tp = (y, m, d, h, i, s, tz) => {
3729
3742
  return { y, m, d, h, i, s, tz };
3730
3743
  };
3731
3744
  function getTimezoneOffset(timeZone, date = /* @__PURE__ */ new Date()) {
3732
- const tz = date.toLocaleString("en", { timeZone, timeStyle: "long" }).split(" ").slice(-1)[0];
3745
+ let tz = date.toLocaleString("en-US", { timeZone, timeZoneName: "short" }).split(" ").slice(-1)[0];
3746
+ tz = tz.replace(/\bAKST\b/g, "-0900").replace(/\bAKDT\b/g, "-0800").replace(/\bAST\b/g, "-0400");
3733
3747
  const dateString = date.toLocaleString("en-US").replace(/[\u202f]/, " ");
3734
3748
  return Date.parse(`${dateString} GMT`) - Date.parse(`${dateString} ${tz}`);
3735
3749
  }
@@ -3758,7 +3772,6 @@ function CronOptions(options) {
3758
3772
  options.interval = options.interval === void 0 ? 0 : parseInt(options.interval, 10);
3759
3773
  options.utcOffset = options.utcOffset === void 0 ? void 0 : parseInt(options.utcOffset, 10);
3760
3774
  options.unref = options.unref === void 0 ? false : options.unref;
3761
- options.kill = false;
3762
3775
  if (options.startAt) {
3763
3776
  options.startAt = new CronDate(options.startAt, options.timezone);
3764
3777
  }
@@ -3787,166 +3800,9 @@ function CronOptions(options) {
3787
3800
  }
3788
3801
  return options;
3789
3802
  }
3790
- var DaysOfMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
3791
- var RecursionSteps = [["month", "year", 0], ["day", "month", -1], ["hour", "day", 0], ["minute", "hour", 0], ["second", "minute", 0]];
3792
- function CronDate(d, tz) {
3793
- this.tz = tz;
3794
- if (d && d instanceof Date) {
3795
- if (!isNaN(d)) {
3796
- this.fromDate(d);
3797
- } else {
3798
- throw new TypeError("CronDate: Invalid date passed to CronDate constructor");
3799
- }
3800
- } else if (d === void 0) {
3801
- this.fromDate(/* @__PURE__ */ new Date());
3802
- } else if (d && typeof d === "string") {
3803
- this.fromString(d);
3804
- } else if (d instanceof CronDate) {
3805
- this.fromCronDate(d);
3806
- } else {
3807
- throw new TypeError("CronDate: Invalid type (" + typeof d + ") passed to CronDate constructor");
3808
- }
3809
- }
3810
- CronDate.prototype.fromDate = function(inDate) {
3811
- if (this.tz !== void 0) {
3812
- if (typeof this.tz === "number") {
3813
- this.ms = inDate.getUTCMilliseconds();
3814
- this.second = inDate.getUTCSeconds();
3815
- this.minute = inDate.getUTCMinutes() + this.tz;
3816
- this.hour = inDate.getUTCHours();
3817
- this.day = inDate.getUTCDate();
3818
- this.month = inDate.getUTCMonth();
3819
- this.year = inDate.getUTCFullYear();
3820
- this.apply();
3821
- } else {
3822
- const d = minitz.toTZ(inDate, this.tz);
3823
- this.ms = inDate.getMilliseconds();
3824
- this.second = d.s;
3825
- this.minute = d.i;
3826
- this.hour = d.h;
3827
- this.day = d.d;
3828
- this.month = d.m - 1;
3829
- this.year = d.y;
3830
- }
3831
- } else {
3832
- this.ms = inDate.getMilliseconds();
3833
- this.second = inDate.getSeconds();
3834
- this.minute = inDate.getMinutes();
3835
- this.hour = inDate.getHours();
3836
- this.day = inDate.getDate();
3837
- this.month = inDate.getMonth();
3838
- this.year = inDate.getFullYear();
3839
- }
3840
- };
3841
- CronDate.prototype.fromCronDate = function(d) {
3842
- this.tz = d.tz;
3843
- this.year = d.year;
3844
- this.month = d.month;
3845
- this.day = d.day;
3846
- this.hour = d.hour;
3847
- this.minute = d.minute;
3848
- this.second = d.second;
3849
- this.ms = d.ms;
3850
- };
3851
- CronDate.prototype.apply = function() {
3852
- if (this.month > 11 || this.day > DaysOfMonth[this.month] || this.hour > 59 || this.minute > 59 || this.second > 59 || this.hour < 0 || this.minute < 0 || this.second < 0) {
3853
- const d = new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms));
3854
- this.ms = d.getUTCMilliseconds();
3855
- this.second = d.getUTCSeconds();
3856
- this.minute = d.getUTCMinutes();
3857
- this.hour = d.getUTCHours();
3858
- this.day = d.getUTCDate();
3859
- this.month = d.getUTCMonth();
3860
- this.year = d.getUTCFullYear();
3861
- return true;
3862
- } else {
3863
- return false;
3864
- }
3865
- };
3866
- CronDate.prototype.fromString = function(str) {
3867
- return this.fromDate(minitz.fromTZISO(str, this.tz));
3868
- };
3869
- CronDate.prototype.findNext = function(options, target, pattern, offset) {
3870
- const originalTarget = this[target];
3871
- let lastDayOfMonth;
3872
- if (pattern.lastDayOfMonth) {
3873
- if (this.month !== 1) {
3874
- lastDayOfMonth = DaysOfMonth[this.month];
3875
- } else {
3876
- lastDayOfMonth = new Date(Date.UTC(this.year, this.month + 1, 0, 0, 0, 0, 0)).getUTCDate();
3877
- }
3878
- }
3879
- const fDomWeekDay = !pattern.starDOW && target == "day" ? new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay() : void 0;
3880
- for (let i = this[target] + offset; i < pattern[target].length; i++) {
3881
- let match = pattern[target][i];
3882
- if (target === "day" && pattern.lastDayOfMonth && i - offset == lastDayOfMonth) {
3883
- match = true;
3884
- }
3885
- if (target === "day" && !pattern.starDOW) {
3886
- const dowMatch = pattern.dow[(fDomWeekDay + (i - offset - 1)) % 7];
3887
- if (options.legacyMode && !pattern.starDOM) {
3888
- match = match || dowMatch;
3889
- } else {
3890
- match = match && dowMatch;
3891
- }
3892
- }
3893
- if (match) {
3894
- this[target] = i - offset;
3895
- return originalTarget !== this[target] ? 2 : 1;
3896
- }
3897
- }
3898
- return 3;
3899
- };
3900
- CronDate.prototype.recurse = function(pattern, options, doing) {
3901
- const res = this.findNext(options, RecursionSteps[doing][0], pattern, RecursionSteps[doing][2]);
3902
- if (res > 1) {
3903
- let resetLevel = doing + 1;
3904
- while (resetLevel < RecursionSteps.length) {
3905
- this[RecursionSteps[resetLevel][0]] = -RecursionSteps[resetLevel][2];
3906
- resetLevel++;
3907
- }
3908
- if (res === 3) {
3909
- this[RecursionSteps[doing][1]]++;
3910
- this[RecursionSteps[doing][0]] = -RecursionSteps[doing][2];
3911
- this.apply();
3912
- return this.recurse(pattern, options, 0);
3913
- } else if (this.apply()) {
3914
- return this.recurse(pattern, options, doing - 1);
3915
- }
3916
- }
3917
- doing += 1;
3918
- if (doing >= RecursionSteps.length) {
3919
- return this;
3920
- } else if (this.year >= 3e3) {
3921
- return null;
3922
- } else {
3923
- return this.recurse(pattern, options, doing);
3924
- }
3925
- };
3926
- CronDate.prototype.increment = function(pattern, options, hasPreviousRun) {
3927
- if (options.interval > 1 && hasPreviousRun) {
3928
- this.second += options.interval;
3929
- } else {
3930
- this.second += 1;
3931
- }
3932
- this.ms = 0;
3933
- this.apply();
3934
- return this.recurse(pattern, options, 0);
3935
- };
3936
- CronDate.prototype.getDate = function(internal) {
3937
- if (internal || this.tz === void 0 && this.utcOffset === void 0) {
3938
- return new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms);
3939
- } else {
3940
- if (typeof this.tz === "number") {
3941
- return new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute - this.tz, this.second, this.ms));
3942
- } else {
3943
- return minitz(this.year, this.month + 1, this.day, this.hour, this.minute, this.second, this.tz);
3944
- }
3945
- }
3946
- };
3947
- CronDate.prototype.getTime = function() {
3948
- return this.getDate().getTime();
3949
- };
3803
+ var LAST_OCCURRENCE = 32;
3804
+ var ANY_OCCURRENCE = 1 | 2 | 4 | 8 | 16 | LAST_OCCURRENCE;
3805
+ var OCCURRENCE_BITMASKS = [1, 2, 4, 16, 16];
3950
3806
  function CronPattern(pattern, timezone) {
3951
3807
  this.pattern = pattern;
3952
3808
  this.timezone = timezone;
@@ -3955,7 +3811,7 @@ function CronPattern(pattern, timezone) {
3955
3811
  this.hour = Array(24).fill(0);
3956
3812
  this.day = Array(31).fill(0);
3957
3813
  this.month = Array(12).fill(0);
3958
- this.dow = Array(8).fill(0);
3814
+ this.dayOfWeek = Array(7).fill(0);
3959
3815
  this.lastDayOfMonth = false;
3960
3816
  this.starDOM = false;
3961
3817
  this.starDOW = false;
@@ -4000,55 +3856,89 @@ CronPattern.prototype.parse = function() {
4000
3856
  parts[5] = parts[5].replace("?", initDate.getDay());
4001
3857
  }
4002
3858
  this.throwAtIllegalCharacters(parts);
4003
- this.partToArray("second", parts[0], 0);
4004
- this.partToArray("minute", parts[1], 0);
4005
- this.partToArray("hour", parts[2], 0);
4006
- this.partToArray("day", parts[3], -1);
4007
- this.partToArray("month", parts[4], -1);
4008
- this.partToArray("dow", parts[5], 0);
4009
- if (this.dow[7]) {
4010
- this.dow[0] = 1;
3859
+ this.partToArray("second", parts[0], 0, 1);
3860
+ this.partToArray("minute", parts[1], 0, 1);
3861
+ this.partToArray("hour", parts[2], 0, 1);
3862
+ this.partToArray("day", parts[3], -1, 1);
3863
+ this.partToArray("month", parts[4], -1, 1);
3864
+ this.partToArray("dayOfWeek", parts[5], 0, ANY_OCCURRENCE);
3865
+ if (this.dayOfWeek[7]) {
3866
+ this.dayOfWeek[0] = this.dayOfWeek[7];
4011
3867
  }
4012
3868
  };
4013
- CronPattern.prototype.partToArray = function(type, conf, valueIndexOffset) {
3869
+ CronPattern.prototype.partToArray = function(type, conf, valueIndexOffset, defaultValue) {
4014
3870
  const arr = this[type];
3871
+ const lastDayOfMonth = type === "day" && this.lastDayOfMonth;
3872
+ if (conf === "" && !lastDayOfMonth)
3873
+ throw new TypeError("CronPattern: configuration entry " + type + " (" + conf + ") is empty, check for trailing spaces.");
4015
3874
  if (conf === "*")
4016
- return arr.fill(1);
3875
+ return arr.fill(defaultValue);
4017
3876
  const split = conf.split(",");
4018
3877
  if (split.length > 1) {
4019
3878
  for (let i = 0; i < split.length; i++) {
4020
- this.partToArray(type, split[i], valueIndexOffset);
3879
+ this.partToArray(type, split[i], valueIndexOffset, defaultValue);
4021
3880
  }
4022
3881
  } else if (conf.indexOf("-") !== -1 && conf.indexOf("/") !== -1) {
4023
- this.handleRangeWithStepping(conf, type, valueIndexOffset);
3882
+ this.handleRangeWithStepping(conf, type, valueIndexOffset, defaultValue);
4024
3883
  } else if (conf.indexOf("-") !== -1) {
4025
- this.handleRange(conf, type, valueIndexOffset);
3884
+ this.handleRange(conf, type, valueIndexOffset, defaultValue);
4026
3885
  } else if (conf.indexOf("/") !== -1) {
4027
- this.handleStepping(conf, type, valueIndexOffset);
3886
+ this.handleStepping(conf, type, valueIndexOffset, defaultValue);
4028
3887
  } else if (conf !== "") {
4029
- this.handleNumber(conf, type, valueIndexOffset);
3888
+ this.handleNumber(conf, type, valueIndexOffset, defaultValue);
4030
3889
  }
4031
3890
  };
4032
3891
  CronPattern.prototype.throwAtIllegalCharacters = function(parts) {
4033
- const reValidCron = /[^/*0-9,-]+/;
4034
3892
  for (let i = 0; i < parts.length; i++) {
3893
+ const reValidCron = i === 5 ? /[^/*0-9,\-#L]+/ : /[^/*0-9,-]+/;
4035
3894
  if (reValidCron.test(parts[i])) {
4036
3895
  throw new TypeError("CronPattern: configuration entry " + i + " (" + parts[i] + ") contains illegal characters.");
4037
3896
  }
4038
3897
  }
4039
3898
  };
4040
- CronPattern.prototype.handleNumber = function(conf, type, valueIndexOffset) {
4041
- const i = parseInt(conf, 10) + valueIndexOffset;
3899
+ CronPattern.prototype.handleNumber = function(conf, type, valueIndexOffset, defaultValue) {
3900
+ const result = this.extractNth(conf, type);
3901
+ const i = parseInt(result[0], 10) + valueIndexOffset;
4042
3902
  if (isNaN(i)) {
4043
3903
  throw new TypeError("CronPattern: " + type + " is not a number: '" + conf + "'");
4044
3904
  }
4045
- if (i < 0 || i >= this[type].length) {
4046
- throw new TypeError("CronPattern: " + type + " value out of range: '" + conf + "'");
3905
+ this.setPart(type, i, result[1] || defaultValue);
3906
+ };
3907
+ CronPattern.prototype.setPart = function(part, index, value) {
3908
+ if (!Object.prototype.hasOwnProperty.call(this, part)) {
3909
+ throw new TypeError("CronPattern: Invalid part specified: " + part);
3910
+ }
3911
+ if (part === "dayOfWeek") {
3912
+ if (index === 7)
3913
+ index = 0;
3914
+ if ((index < 0 || index > 6) && index !== "L") {
3915
+ throw new RangeError("CronPattern: Invalid value for dayOfWeek: " + index);
3916
+ }
3917
+ this.setNthWeekdayOfMonth(index, value);
3918
+ return;
3919
+ }
3920
+ if (part === "second" || part === "minute") {
3921
+ if (index < 0 || index >= 60) {
3922
+ throw new RangeError("CronPattern: Invalid value for " + part + ": " + index);
3923
+ }
3924
+ } else if (part === "hour") {
3925
+ if (index < 0 || index >= 24) {
3926
+ throw new RangeError("CronPattern: Invalid value for " + part + ": " + index);
3927
+ }
3928
+ } else if (part === "day") {
3929
+ if (index < 0 || index >= 31) {
3930
+ throw new RangeError("CronPattern: Invalid value for " + part + ": " + index);
3931
+ }
3932
+ } else if (part === "month") {
3933
+ if (index < 0 || index >= 12) {
3934
+ throw new RangeError("CronPattern: Invalid value for " + part + ": " + index);
3935
+ }
4047
3936
  }
4048
- this[type][i] = 1;
3937
+ this[part][index] = value;
4049
3938
  };
4050
- CronPattern.prototype.handleRangeWithStepping = function(conf, type, valueIndexOffset) {
4051
- const matches = conf.match(/^(\d+)-(\d+)\/(\d+)$/);
3939
+ CronPattern.prototype.handleRangeWithStepping = function(conf, type, valueIndexOffset, defaultValue) {
3940
+ const result = this.extractNth(conf, type);
3941
+ const matches = result[0].match(/^(\d+)-(\d+)\/(\d+)$/);
4052
3942
  if (matches === null)
4053
3943
  throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '" + conf + "'");
4054
3944
  let [, lower, upper, steps] = matches;
@@ -4065,16 +3955,27 @@ CronPattern.prototype.handleRangeWithStepping = function(conf, type, valueIndexO
4065
3955
  throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");
4066
3956
  if (steps > this[type].length)
4067
3957
  throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part (" + this[type].length + ")");
4068
- if (lower < 0 || upper >= this[type].length)
4069
- throw new TypeError("CronPattern: Value out of range: '" + conf + "'");
4070
3958
  if (lower > upper)
4071
3959
  throw new TypeError("CronPattern: From value is larger than to value: '" + conf + "'");
4072
3960
  for (let i = lower; i <= upper; i += steps) {
4073
- this[type][i] = 1;
3961
+ this.setPart(type, i, result[1] || defaultValue);
3962
+ }
3963
+ };
3964
+ CronPattern.prototype.extractNth = function(conf, type) {
3965
+ let rest = conf;
3966
+ let nth;
3967
+ if (rest.includes("#")) {
3968
+ if (type !== "dayOfWeek") {
3969
+ throw new Error("CronPattern: nth (#) only allowed in day-of-week field");
3970
+ }
3971
+ nth = rest.split("#")[1];
3972
+ rest = rest.split("#")[0];
4074
3973
  }
3974
+ return [rest, nth];
4075
3975
  };
4076
- CronPattern.prototype.handleRange = function(conf, type, valueIndexOffset) {
4077
- const split = conf.split("-");
3976
+ CronPattern.prototype.handleRange = function(conf, type, valueIndexOffset, defaultValue) {
3977
+ const result = this.extractNth(conf, type);
3978
+ const split = result[0].split("-");
4078
3979
  if (split.length !== 2) {
4079
3980
  throw new TypeError("CronPattern: Syntax error, illegal range: '" + conf + "'");
4080
3981
  }
@@ -4084,24 +3985,22 @@ CronPattern.prototype.handleRange = function(conf, type, valueIndexOffset) {
4084
3985
  } else if (isNaN(upper)) {
4085
3986
  throw new TypeError("CronPattern: Syntax error, illegal upper range (NaN)");
4086
3987
  }
4087
- if (lower < 0 || upper >= this[type].length) {
4088
- throw new TypeError("CronPattern: Value out of range: '" + conf + "'");
4089
- }
4090
3988
  if (lower > upper) {
4091
3989
  throw new TypeError("CronPattern: From value is larger than to value: '" + conf + "'");
4092
3990
  }
4093
3991
  for (let i = lower; i <= upper; i++) {
4094
- this[type][i] = 1;
3992
+ this.setPart(type, i, result[1] || defaultValue);
4095
3993
  }
4096
3994
  };
4097
- CronPattern.prototype.handleStepping = function(conf, type) {
4098
- const split = conf.split("/");
3995
+ CronPattern.prototype.handleStepping = function(conf, type, valueIndexOffset, defaultValue) {
3996
+ const result = this.extractNth(conf, type);
3997
+ const split = result[0].split("/");
4099
3998
  if (split.length !== 2) {
4100
3999
  throw new TypeError("CronPattern: Syntax error, illegal stepping: '" + conf + "'");
4101
4000
  }
4102
4001
  let start = 0;
4103
4002
  if (split[0] !== "*") {
4104
- start = parseInt(split[0], 10);
4003
+ start = parseInt(split[0], 10) + valueIndexOffset;
4105
4004
  }
4106
4005
  const steps = parseInt(split[1], 10);
4107
4006
  if (isNaN(steps))
@@ -4111,7 +4010,7 @@ CronPattern.prototype.handleStepping = function(conf, type) {
4111
4010
  if (steps > this[type].length)
4112
4011
  throw new TypeError("CronPattern: Syntax error, max steps for part is (" + this[type].length + ")");
4113
4012
  for (let i = start; i < this[type].length; i += steps) {
4114
- this[type][i] = 1;
4013
+ this.setPart(type, i, result[1] || defaultValue);
4115
4014
  }
4116
4015
  };
4117
4016
  CronPattern.prototype.replaceAlphaDays = function(conf) {
@@ -4136,31 +4035,226 @@ CronPattern.prototype.handleNicknames = function(pattern) {
4136
4035
  return pattern;
4137
4036
  }
4138
4037
  };
4139
- var maxDelay = Math.pow(2, 32 - 1) - 1;
4140
- var scheduledJobs = [];
4141
- function isFn(v) {
4142
- return Object.prototype.toString.call(v) === "[object Function]" || "function" === typeof v || v instanceof Function;
4143
- }
4144
- function unref(timer2) {
4145
- if (typeof Deno !== "undefined" && typeof Deno.unrefTimer !== "undefined") {
4146
- Deno.unrefTimer(timer2);
4147
- } else if (timer2 && typeof timer2.unref !== "undefined") {
4148
- timer2.unref();
4038
+ CronPattern.prototype.setNthWeekdayOfMonth = function(index, nthWeekday) {
4039
+ if (nthWeekday === "L") {
4040
+ this["dayOfWeek"][index] = this["dayOfWeek"][index] | LAST_OCCURRENCE;
4041
+ } else if (nthWeekday < 6 && nthWeekday > 0) {
4042
+ this["dayOfWeek"][index] = this["dayOfWeek"][index] | OCCURRENCE_BITMASKS[nthWeekday - 1];
4043
+ } else if (nthWeekday === ANY_OCCURRENCE) {
4044
+ this["dayOfWeek"][index] = ANY_OCCURRENCE;
4045
+ } else {
4046
+ throw new TypeError(`CronPattern: nth weekday of of range, should be 1-5 or L. Value: ${nthWeekday}`);
4149
4047
  }
4150
- }
4151
- function Cron(pattern, fnOrOptions1, fnOrOptions2) {
4048
+ };
4049
+ var DaysOfMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
4050
+ var RecursionSteps = [["month", "year", 0], ["day", "month", -1], ["hour", "day", 0], ["minute", "hour", 0], ["second", "minute", 0]];
4051
+ function CronDate(d, tz) {
4052
+ this.tz = tz;
4053
+ if (d && d instanceof Date) {
4054
+ if (!isNaN(d)) {
4055
+ this.fromDate(d);
4056
+ } else {
4057
+ throw new TypeError("CronDate: Invalid date passed to CronDate constructor");
4058
+ }
4059
+ } else if (d === void 0) {
4060
+ this.fromDate(/* @__PURE__ */ new Date());
4061
+ } else if (d && typeof d === "string") {
4062
+ this.fromString(d);
4063
+ } else if (d instanceof CronDate) {
4064
+ this.fromCronDate(d);
4065
+ } else {
4066
+ throw new TypeError("CronDate: Invalid type (" + typeof d + ") passed to CronDate constructor");
4067
+ }
4068
+ }
4069
+ CronDate.prototype.isNthWeekdayOfMonth = function(year, month, day, nth) {
4070
+ const date = new Date(Date.UTC(year, month, day));
4071
+ const weekday = date.getUTCDay();
4072
+ let count = 0;
4073
+ for (let d = 1; d <= day; d++) {
4074
+ if (new Date(Date.UTC(year, month, d)).getUTCDay() === weekday) {
4075
+ count++;
4076
+ }
4077
+ }
4078
+ if (nth & ANY_OCCURRENCE && OCCURRENCE_BITMASKS[count - 1] & nth) {
4079
+ return true;
4080
+ }
4081
+ if (nth & LAST_OCCURRENCE) {
4082
+ const daysInMonth = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
4083
+ for (let d = day + 1; d <= daysInMonth; d++) {
4084
+ if (new Date(Date.UTC(year, month, d)).getUTCDay() === weekday) {
4085
+ return false;
4086
+ }
4087
+ }
4088
+ return true;
4089
+ }
4090
+ return false;
4091
+ };
4092
+ CronDate.prototype.fromDate = function(inDate) {
4093
+ if (this.tz !== void 0) {
4094
+ if (typeof this.tz === "number") {
4095
+ this.ms = inDate.getUTCMilliseconds();
4096
+ this.second = inDate.getUTCSeconds();
4097
+ this.minute = inDate.getUTCMinutes() + this.tz;
4098
+ this.hour = inDate.getUTCHours();
4099
+ this.day = inDate.getUTCDate();
4100
+ this.month = inDate.getUTCMonth();
4101
+ this.year = inDate.getUTCFullYear();
4102
+ this.apply();
4103
+ } else {
4104
+ const d = minitz.toTZ(inDate, this.tz);
4105
+ this.ms = inDate.getMilliseconds();
4106
+ this.second = d.s;
4107
+ this.minute = d.i;
4108
+ this.hour = d.h;
4109
+ this.day = d.d;
4110
+ this.month = d.m - 1;
4111
+ this.year = d.y;
4112
+ }
4113
+ } else {
4114
+ this.ms = inDate.getMilliseconds();
4115
+ this.second = inDate.getSeconds();
4116
+ this.minute = inDate.getMinutes();
4117
+ this.hour = inDate.getHours();
4118
+ this.day = inDate.getDate();
4119
+ this.month = inDate.getMonth();
4120
+ this.year = inDate.getFullYear();
4121
+ }
4122
+ };
4123
+ CronDate.prototype.fromCronDate = function(d) {
4124
+ this.tz = d.tz;
4125
+ this.year = d.year;
4126
+ this.month = d.month;
4127
+ this.day = d.day;
4128
+ this.hour = d.hour;
4129
+ this.minute = d.minute;
4130
+ this.second = d.second;
4131
+ this.ms = d.ms;
4132
+ };
4133
+ CronDate.prototype.apply = function() {
4134
+ if (this.month > 11 || this.day > DaysOfMonth[this.month] || this.hour > 59 || this.minute > 59 || this.second > 59 || this.hour < 0 || this.minute < 0 || this.second < 0) {
4135
+ const d = new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms));
4136
+ this.ms = d.getUTCMilliseconds();
4137
+ this.second = d.getUTCSeconds();
4138
+ this.minute = d.getUTCMinutes();
4139
+ this.hour = d.getUTCHours();
4140
+ this.day = d.getUTCDate();
4141
+ this.month = d.getUTCMonth();
4142
+ this.year = d.getUTCFullYear();
4143
+ return true;
4144
+ } else {
4145
+ return false;
4146
+ }
4147
+ };
4148
+ CronDate.prototype.fromString = function(str) {
4149
+ return this.fromDate(minitz.fromTZISO(str, this.tz));
4150
+ };
4151
+ CronDate.prototype.findNext = function(options, target, pattern, offset) {
4152
+ const originalTarget = this[target];
4153
+ let lastDayOfMonth;
4154
+ if (pattern.lastDayOfMonth) {
4155
+ if (this.month !== 1) {
4156
+ lastDayOfMonth = DaysOfMonth[this.month];
4157
+ } else {
4158
+ lastDayOfMonth = new Date(Date.UTC(this.year, this.month + 1, 0, 0, 0, 0, 0)).getUTCDate();
4159
+ }
4160
+ }
4161
+ const fDomWeekDay = !pattern.starDOW && target == "day" ? new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay() : void 0;
4162
+ for (let i = this[target] + offset; i < pattern[target].length; i++) {
4163
+ let match = pattern[target][i];
4164
+ if (target === "day" && pattern.lastDayOfMonth && i - offset == lastDayOfMonth) {
4165
+ match = true;
4166
+ }
4167
+ if (target === "day" && !pattern.starDOW) {
4168
+ let dowMatch = pattern.dayOfWeek[(fDomWeekDay + (i - offset - 1)) % 7];
4169
+ if (dowMatch && dowMatch & ANY_OCCURRENCE) {
4170
+ dowMatch = this.isNthWeekdayOfMonth(this.year, this.month, i - offset, dowMatch);
4171
+ } else if (dowMatch) {
4172
+ throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${dowMatch}`);
4173
+ }
4174
+ if (options.legacyMode && !pattern.starDOM) {
4175
+ match = match || dowMatch;
4176
+ } else {
4177
+ match = match && dowMatch;
4178
+ }
4179
+ }
4180
+ if (match) {
4181
+ this[target] = i - offset;
4182
+ return originalTarget !== this[target] ? 2 : 1;
4183
+ }
4184
+ }
4185
+ return 3;
4186
+ };
4187
+ CronDate.prototype.recurse = function(pattern, options, doing) {
4188
+ const res = this.findNext(options, RecursionSteps[doing][0], pattern, RecursionSteps[doing][2]);
4189
+ if (res > 1) {
4190
+ let resetLevel = doing + 1;
4191
+ while (resetLevel < RecursionSteps.length) {
4192
+ this[RecursionSteps[resetLevel][0]] = -RecursionSteps[resetLevel][2];
4193
+ resetLevel++;
4194
+ }
4195
+ if (res === 3) {
4196
+ this[RecursionSteps[doing][1]]++;
4197
+ this[RecursionSteps[doing][0]] = -RecursionSteps[doing][2];
4198
+ this.apply();
4199
+ return this.recurse(pattern, options, 0);
4200
+ } else if (this.apply()) {
4201
+ return this.recurse(pattern, options, doing - 1);
4202
+ }
4203
+ }
4204
+ doing += 1;
4205
+ if (doing >= RecursionSteps.length) {
4206
+ return this;
4207
+ } else if (this.year >= 3e3) {
4208
+ return null;
4209
+ } else {
4210
+ return this.recurse(pattern, options, doing);
4211
+ }
4212
+ };
4213
+ CronDate.prototype.increment = function(pattern, options, hasPreviousRun) {
4214
+ this.second += options.interval > 1 && hasPreviousRun ? options.interval : 1;
4215
+ this.ms = 0;
4216
+ this.apply();
4217
+ return this.recurse(pattern, options, 0);
4218
+ };
4219
+ CronDate.prototype.getDate = function(internal) {
4220
+ if (internal || this.tz === void 0) {
4221
+ return new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms);
4222
+ } else {
4223
+ if (typeof this.tz === "number") {
4224
+ return new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute - this.tz, this.second, this.ms));
4225
+ } else {
4226
+ return minitz(this.year, this.month + 1, this.day, this.hour, this.minute, this.second, this.tz);
4227
+ }
4228
+ }
4229
+ };
4230
+ CronDate.prototype.getTime = function() {
4231
+ return this.getDate().getTime();
4232
+ };
4233
+ function isFunction2(v) {
4234
+ return Object.prototype.toString.call(v) === "[object Function]" || "function" === typeof v || v instanceof Function;
4235
+ }
4236
+ function unrefTimer(timer2) {
4237
+ if (typeof Deno !== "undefined" && typeof Deno.unrefTimer !== "undefined") {
4238
+ Deno.unrefTimer(timer2);
4239
+ } else if (timer2 && typeof timer2.unref !== "undefined") {
4240
+ timer2.unref();
4241
+ }
4242
+ }
4243
+ var maxDelay = 30 * 1e3;
4244
+ var scheduledJobs = [];
4245
+ function Cron(pattern, fnOrOptions1, fnOrOptions2) {
4152
4246
  if (!(this instanceof Cron)) {
4153
4247
  return new Cron(pattern, fnOrOptions1, fnOrOptions2);
4154
4248
  }
4155
4249
  let options, func;
4156
- if (typeof fnOrOptions1 === "function") {
4250
+ if (isFunction2(fnOrOptions1)) {
4157
4251
  func = fnOrOptions1;
4158
4252
  } else if (typeof fnOrOptions1 === "object") {
4159
4253
  options = fnOrOptions1;
4160
4254
  } else if (fnOrOptions1 !== void 0) {
4161
4255
  throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");
4162
4256
  }
4163
- if (typeof fnOrOptions2 === "function") {
4257
+ if (isFunction2(fnOrOptions2)) {
4164
4258
  func = fnOrOptions2;
4165
4259
  } else if (typeof fnOrOptions2 === "object") {
4166
4260
  options = fnOrOptions2;
@@ -4169,19 +4263,11 @@ function Cron(pattern, fnOrOptions1, fnOrOptions2) {
4169
4263
  }
4170
4264
  this.name = options ? options.name : void 0;
4171
4265
  this.options = CronOptions(options);
4172
- this.once = void 0;
4173
- this.pattern = void 0;
4174
- this.blocking = false;
4175
- this.previousrun = void 0;
4176
- this.runstarted = void 0;
4266
+ this._states = { kill: false, blocking: false, previousRun: void 0, currentRun: void 0, once: void 0, currentTimeout: void 0, maxRuns: options ? options.maxRuns : void 0, paused: options ? options.paused : false, pattern: void 0 };
4177
4267
  if (pattern && (pattern instanceof Date || typeof pattern === "string" && pattern.indexOf(":") > 0)) {
4178
- this.once = new CronDate(pattern, this.options.timezone || this.options.utcOffset);
4268
+ this._states.once = new CronDate(pattern, this.options.timezone || this.options.utcOffset);
4179
4269
  } else {
4180
- this.pattern = new CronPattern(pattern, this.options.timezone);
4181
- }
4182
- if (func !== void 0) {
4183
- this.fn = func;
4184
- this.schedule();
4270
+ this._states.pattern = new CronPattern(pattern, this.options.timezone);
4185
4271
  }
4186
4272
  if (this.name) {
4187
4273
  const existing = scheduledJobs.find((j) => j.name === this.name);
@@ -4191,119 +4277,137 @@ function Cron(pattern, fnOrOptions1, fnOrOptions2) {
4191
4277
  scheduledJobs.push(this);
4192
4278
  }
4193
4279
  }
4280
+ if (func !== void 0) {
4281
+ this.fn = func;
4282
+ this.schedule();
4283
+ }
4194
4284
  return this;
4195
4285
  }
4196
- Cron.prototype.next = function(prev) {
4286
+ Cron.prototype.nextRun = function(prev) {
4197
4287
  const next = this._next(prev);
4198
4288
  return next ? next.getDate() : null;
4199
4289
  };
4200
- Cron.prototype.enumerate = function(n, previous) {
4201
- if (n > this.options.maxRuns) {
4202
- n = this.options.maxRuns;
4290
+ Cron.prototype.nextRuns = function(n, previous) {
4291
+ if (n > this._states.maxRuns) {
4292
+ n = this._states.maxRuns;
4203
4293
  }
4204
4294
  const enumeration = [];
4205
- let prev = previous || this.previousrun;
4206
- while (n-- && (prev = this.next(prev))) {
4295
+ let prev = previous || this._states.currentRun;
4296
+ while (n-- && (prev = this.nextRun(prev))) {
4207
4297
  enumeration.push(prev);
4208
4298
  }
4209
4299
  return enumeration;
4210
4300
  };
4211
- Cron.prototype.running = function() {
4212
- const msLeft = this.msToNext(this.previousrun);
4213
- const running = !this.options.paused && this.fn !== void 0;
4214
- return msLeft !== null && running;
4301
+ Cron.prototype.getPattern = function() {
4302
+ return this._states.pattern ? this._states.pattern.pattern : void 0;
4303
+ };
4304
+ Cron.prototype.isRunning = function() {
4305
+ const nextRunTime = this.nextRun(this._states.currentRun);
4306
+ const isRunning = !this._states.paused;
4307
+ const isScheduled = this.fn !== void 0;
4308
+ const notIsKilled = !this._states.kill;
4309
+ return isRunning && isScheduled && notIsKilled && nextRunTime !== null;
4310
+ };
4311
+ Cron.prototype.isStopped = function() {
4312
+ return this._states.kill;
4215
4313
  };
4216
- Cron.prototype.busy = function() {
4217
- return this.blocking;
4314
+ Cron.prototype.isBusy = function() {
4315
+ return this._states.blocking;
4218
4316
  };
4219
- Cron.prototype.started = function() {
4220
- return this.runstarted ? this.runstarted.getDate() : null;
4317
+ Cron.prototype.currentRun = function() {
4318
+ return this._states.currentRun ? this._states.currentRun.getDate() : null;
4221
4319
  };
4222
- Cron.prototype.previous = function() {
4223
- return this.previousrun ? this.previousrun.getDate() : null;
4320
+ Cron.prototype.previousRun = function() {
4321
+ return this._states.previousRun ? this._states.previousRun.getDate() : null;
4224
4322
  };
4225
4323
  Cron.prototype.msToNext = function(prev) {
4324
+ prev = prev || /* @__PURE__ */ new Date();
4226
4325
  const next = this._next(prev);
4227
- prev = new CronDate(prev, this.options.timezone || this.options.utcOffset);
4228
4326
  if (next) {
4229
- return next.getTime(true) - prev.getTime(true);
4327
+ return next.getTime() - prev.getTime();
4230
4328
  } else {
4231
4329
  return null;
4232
4330
  }
4233
4331
  };
4234
4332
  Cron.prototype.stop = function() {
4235
- this.options.kill = true;
4236
- if (this.currentTimeout) {
4237
- clearTimeout(this.currentTimeout);
4333
+ this._states.kill = true;
4334
+ if (this._states.currentTimeout) {
4335
+ clearTimeout(this._states.currentTimeout);
4336
+ }
4337
+ const jobIndex = scheduledJobs.indexOf(this);
4338
+ if (jobIndex >= 0) {
4339
+ scheduledJobs.splice(jobIndex, 1);
4238
4340
  }
4239
4341
  };
4240
4342
  Cron.prototype.pause = function() {
4241
- return (this.options.paused = true) && !this.options.kill;
4343
+ this._states.paused = true;
4344
+ return !this._states.kill;
4242
4345
  };
4243
4346
  Cron.prototype.resume = function() {
4244
- return !(this.options.paused = false) && !this.options.kill;
4347
+ this._states.paused = false;
4348
+ return !this._states.kill;
4245
4349
  };
4246
- Cron.prototype.schedule = function(func, partial) {
4350
+ Cron.prototype.schedule = function(func) {
4247
4351
  if (func && this.fn) {
4248
4352
  throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");
4249
4353
  } else if (func) {
4250
4354
  this.fn = func;
4251
4355
  }
4252
- let waitMs = this.msToNext(partial ? partial : this.previousrun);
4253
- const target = this.next(partial ? partial : this.previousrun);
4356
+ let waitMs = this.msToNext();
4357
+ const target = this.nextRun(this._states.currentRun);
4254
4358
  if (waitMs === null || target === null)
4255
4359
  return this;
4256
4360
  if (waitMs > maxDelay) {
4257
4361
  waitMs = maxDelay;
4258
4362
  }
4259
- this.currentTimeout = setTimeout(() => this._checkTrigger(target), waitMs);
4260
- if (this.currentTimeout && this.options.unref) {
4261
- unref(this.currentTimeout);
4363
+ this._states.currentTimeout = setTimeout(() => this._checkTrigger(target), waitMs);
4364
+ if (this._states.currentTimeout && this.options.unref) {
4365
+ unrefTimer(this._states.currentTimeout);
4262
4366
  }
4263
4367
  return this;
4264
4368
  };
4265
4369
  Cron.prototype._trigger = async function(initiationDate) {
4266
- this.blocking = true;
4267
- this.runstarted = new CronDate(initiationDate, this.options.timezone || this.options.utcOffset);
4370
+ this._states.blocking = true;
4371
+ this._states.currentRun = new CronDate(void 0, this.options.timezone || this.options.utcOffset);
4268
4372
  if (this.options.catch) {
4269
4373
  try {
4270
4374
  await this.fn(this, this.options.context);
4271
4375
  } catch (_e) {
4272
- if (isFn(this.options.catch)) {
4273
- ((inst) => inst.options.catch(_e, inst))(this);
4376
+ if (isFunction2(this.options.catch)) {
4377
+ this.options.catch(_e, this);
4274
4378
  }
4275
- } finally {
4276
- this.blocking = false;
4277
4379
  }
4278
4380
  } else {
4279
4381
  await this.fn(this, this.options.context);
4280
- this.blocking = false;
4281
4382
  }
4383
+ this._states.previousRun = new CronDate(initiationDate, this.options.timezone || this.options.utcOffset);
4384
+ this._states.blocking = false;
4385
+ };
4386
+ Cron.prototype.trigger = async function() {
4387
+ await this._trigger();
4282
4388
  };
4283
4389
  Cron.prototype._checkTrigger = function(target) {
4284
- const now = /* @__PURE__ */ new Date(), shouldRun = !this.options.paused && now.getTime() >= target, isBlocked = this.blocking && this.options.protect;
4390
+ const now = /* @__PURE__ */ new Date(), shouldRun = !this._states.paused && now.getTime() >= target, isBlocked = this._states.blocking && this.options.protect;
4285
4391
  if (shouldRun && !isBlocked) {
4286
- this.options.maxRuns--;
4392
+ this._states.maxRuns--;
4287
4393
  this._trigger();
4288
- this.previousrun = new CronDate(void 0, this.options.timezone || this.options.utcOffset);
4289
- this.schedule();
4290
4394
  } else {
4291
- if (shouldRun && isBlocked && isFn(this.options.protect)) {
4292
- (async (inst) => inst.options.protect(inst))(this);
4395
+ if (shouldRun && isBlocked && isFunction2(this.options.protect)) {
4396
+ setTimeout(() => this.options.protect(this), 0);
4293
4397
  }
4294
- this.schedule(void 0, now);
4295
4398
  }
4399
+ this.schedule();
4296
4400
  };
4297
4401
  Cron.prototype._next = function(prev) {
4298
- const hasPreviousRun = prev || this.previousrun ? true : false;
4402
+ const hasPreviousRun = prev || this._states.currentRun ? true : false;
4299
4403
  prev = new CronDate(prev, this.options.timezone || this.options.utcOffset);
4300
4404
  if (this.options.startAt && prev && prev.getTime() < this.options.startAt.getTime()) {
4301
4405
  prev = this.options.startAt;
4302
4406
  }
4303
- const nextRun = this.once || new CronDate(prev, this.options.timezone || this.options.utcOffset).increment(this.pattern, this.options, hasPreviousRun);
4304
- if (this.once && this.once.getTime() <= prev.getTime()) {
4407
+ const nextRun = this._states.once || new CronDate(prev, this.options.timezone || this.options.utcOffset).increment(this._states.pattern, this.options, hasPreviousRun);
4408
+ if (this._states.once && this._states.once.getTime() <= prev.getTime()) {
4305
4409
  return null;
4306
- } else if (nextRun === null || this.options.maxRuns <= 0 || this.options.kill || this.options.stopAt && nextRun.getTime() >= this.options.stopAt.getTime()) {
4410
+ } else if (nextRun === null || this._states.maxRuns <= 0 || this._states.kill || this.options.stopAt && nextRun.getTime() >= this.options.stopAt.getTime()) {
4307
4411
  return null;
4308
4412
  } else {
4309
4413
  return nextRun;
@@ -4312,7 +4416,7 @@ Cron.prototype._next = function(prev) {
4312
4416
  Cron.Cron = Cron;
4313
4417
  Cron.scheduledJobs = scheduledJobs;
4314
4418
 
4315
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.plugins.js
4419
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.plugins.js
4316
4420
  var import_dayjs = __toESM(require_dayjs_min(), 1);
4317
4421
  var import_isToday = __toESM(require_isToday(), 1);
4318
4422
 
@@ -4418,10 +4522,10 @@ function prettyMilliseconds(milliseconds, options = {}) {
4418
4522
  return options.colonNotation ? result.join("") : result.join(" ");
4419
4523
  }
4420
4524
 
4421
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.plugins.js
4525
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.plugins.js
4422
4526
  import_dayjs.default.extend(import_isToday.default);
4423
4527
 
4424
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.cronjob.js
4528
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.cronjob.js
4425
4529
  var CronJob = class {
4426
4530
  constructor(cronManager, cronExpressionArg, jobFunction) {
4427
4531
  this.status = "initial";
@@ -4463,7 +4567,7 @@ var CronJob = class {
4463
4567
  }
4464
4568
  };
4465
4569
 
4466
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.units.js
4570
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.units.js
4467
4571
  var units = {
4468
4572
  years: (timesArg = 1) => {
4469
4573
  return timesArg * 3154e7;
@@ -4519,7 +4623,7 @@ var getMilliSecondsAsHumanReadableString = (milliSecondsArg) => {
4519
4623
  return prettyMilliseconds(milliSecondsArg);
4520
4624
  };
4521
4625
 
4522
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.cronmanager.js
4626
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.cronmanager.js
4523
4627
  var CronManager = class {
4524
4628
  constructor() {
4525
4629
  this.status = "stopped";
@@ -4546,29 +4650,29 @@ var CronManager = class {
4546
4650
  for (const cronJob of this.cronjobs.getArray()) {
4547
4651
  cronJob.start();
4548
4652
  }
4549
- const runCronCycle = async () => {
4550
- this.executionTimeout = new dist_ts_exports2.Timeout(0);
4551
- do {
4552
- let nextRunningCronjob;
4553
- for (const cronJob of this.cronjobs.getArray()) {
4554
- cronJob.checkExecution();
4555
- if (!nextRunningCronjob || cronJob.getTimeToNextExecution() < nextRunningCronjob.getTimeToNextExecution()) {
4556
- nextRunningCronjob = cronJob;
4557
- }
4558
- }
4559
- if (nextRunningCronjob) {
4560
- this.executionTimeout = new dist_ts_exports2.Timeout(nextRunningCronjob.getTimeToNextExecution());
4561
- console.log(`Next CronJob scheduled in ${getMilliSecondsAsHumanReadableString(this.executionTimeout.getTimeLeft())}`);
4562
- } else {
4563
- this.executionTimeout = new dist_ts_exports2.Timeout(1e3);
4564
- console.log("no cronjobs specified! Checking again in 1 second");
4565
- }
4566
- await this.executionTimeout.promise;
4567
- } while (this.status === "started");
4568
- };
4569
- runCronCycle();
4653
+ this.runCronCycle();
4570
4654
  }
4571
4655
  }
4656
+ async runCronCycle() {
4657
+ this.executionTimeout = new dist_ts_exports2.Timeout(0);
4658
+ do {
4659
+ let nextRunningCronjob;
4660
+ for (const cronJob of this.cronjobs.getArray()) {
4661
+ cronJob.checkExecution();
4662
+ if (!nextRunningCronjob || cronJob.getTimeToNextExecution() < nextRunningCronjob.getTimeToNextExecution()) {
4663
+ nextRunningCronjob = cronJob;
4664
+ }
4665
+ }
4666
+ if (nextRunningCronjob) {
4667
+ this.executionTimeout = new dist_ts_exports2.Timeout(nextRunningCronjob.getTimeToNextExecution());
4668
+ console.log(`Next CronJob scheduled in ${getMilliSecondsAsHumanReadableString(this.executionTimeout.getTimeLeft())}`);
4669
+ } else {
4670
+ this.executionTimeout = new dist_ts_exports2.Timeout(1e3);
4671
+ console.log("no cronjobs specified! Checking again in 1 second");
4672
+ }
4673
+ await this.executionTimeout.promise;
4674
+ } while (this.status === "started");
4675
+ }
4572
4676
  /**
4573
4677
  * stops all cronjobs
4574
4678
  */
@@ -4585,7 +4689,7 @@ var CronManager = class {
4585
4689
  }
4586
4690
  };
4587
4691
 
4588
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.extendeddate.js
4692
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.extendeddate.js
4589
4693
  var ExtendedDate = class _ExtendedDate extends Date {
4590
4694
  // STATIC factories
4591
4695
  static fromMillis(milliSeconds) {
@@ -4698,7 +4802,7 @@ var ExtendedDate = class _ExtendedDate extends Date {
4698
4802
  }
4699
4803
  };
4700
4804
 
4701
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.hrtmeasurement.js
4805
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.hrtmeasurement.js
4702
4806
  var HrtMeasurement = class {
4703
4807
  constructor() {
4704
4808
  this.nanoSeconds = null;
@@ -4739,7 +4843,7 @@ var HrtMeasurement = class {
4739
4843
  }
4740
4844
  };
4741
4845
 
4742
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.interval.js
4846
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.interval.js
4743
4847
  var Interval = class {
4744
4848
  constructor(intervalMillisencondsArg) {
4745
4849
  this.status = "initial";
@@ -4773,7 +4877,7 @@ var Interval = class {
4773
4877
  }
4774
4878
  };
4775
4879
 
4776
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.timestamp.js
4880
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.timestamp.js
4777
4881
  var TimeStamp = class _TimeStamp {
4778
4882
  /**
4779
4883
  * returns new TimeStamp from milliseconds
@@ -4843,7 +4947,7 @@ var TimeStamp = class _TimeStamp {
4843
4947
  }
4844
4948
  };
4845
4949
 
4846
- // node_modules/.pnpm/@push.rocks+smarttime@4.0.5/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.timer.js
4950
+ // node_modules/.pnpm/@push.rocks+smarttime@4.0.6/node_modules/@push.rocks/smarttime/dist_ts/smarttime.classes.timer.js
4847
4951
  var Timer = class {
4848
4952
  get timeLeft() {
4849
4953
  return this.timeInMilliseconds - this.pausedAt.change;
@@ -4890,10 +4994,10 @@ var Timer = class {
4890
4994
  }
4891
4995
  };
4892
4996
 
4893
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.plugins.js
4997
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.plugins.js
4894
4998
  var import_symbol_tree = __toESM(require_SymbolTree(), 1);
4895
4999
 
4896
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.asyncexecutionstack.js
5000
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.asyncexecutionstack.js
4897
5001
  var AsyncExecutionStack = class {
4898
5002
  constructor() {
4899
5003
  this.executionSlots = [];
@@ -4984,7 +5088,60 @@ var AsyncExecutionStack = class {
4984
5088
  }
4985
5089
  };
4986
5090
 
4987
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.fastmap.js
5091
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.backpressuredarray.js
5092
+ var BackpressuredArray = class {
5093
+ constructor(highWaterMark = 16) {
5094
+ this.hasSpace = new dist_ts_exports4.rxjs.Subject();
5095
+ this.itemsAvailable = new dist_ts_exports4.rxjs.Subject();
5096
+ this.data = [];
5097
+ this.highWaterMark = highWaterMark;
5098
+ }
5099
+ push(item) {
5100
+ this.data.push(item);
5101
+ this.itemsAvailable.next("itemsAvailable");
5102
+ const spaceAvailable = this.checkSpaceAvailable();
5103
+ if (spaceAvailable) {
5104
+ this.hasSpace.next("hasSpace");
5105
+ }
5106
+ return spaceAvailable;
5107
+ }
5108
+ shift() {
5109
+ const item = this.data.shift();
5110
+ if (this.checkSpaceAvailable()) {
5111
+ this.hasSpace.next("hasSpace");
5112
+ }
5113
+ return item;
5114
+ }
5115
+ checkSpaceAvailable() {
5116
+ return this.data.length < this.highWaterMark;
5117
+ }
5118
+ waitForSpace() {
5119
+ return new Promise((resolve) => {
5120
+ if (this.checkSpaceAvailable()) {
5121
+ resolve();
5122
+ } else {
5123
+ const subscription = this.hasSpace.subscribe(() => {
5124
+ subscription.unsubscribe();
5125
+ resolve();
5126
+ });
5127
+ }
5128
+ });
5129
+ }
5130
+ waitForItems() {
5131
+ return new Promise((resolve) => {
5132
+ if (this.data.length > 0) {
5133
+ resolve();
5134
+ } else {
5135
+ const subscription = this.itemsAvailable.subscribe(() => {
5136
+ subscription.unsubscribe();
5137
+ resolve();
5138
+ });
5139
+ }
5140
+ });
5141
+ }
5142
+ };
5143
+
5144
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.fastmap.js
4988
5145
  var FastMap = class _FastMap {
4989
5146
  constructor() {
4990
5147
  this.mapObject = {};
@@ -5058,7 +5215,7 @@ var FastMap = class _FastMap {
5058
5215
  }
5059
5216
  };
5060
5217
 
5061
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.objectmap.js
5218
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.objectmap.js
5062
5219
  var uni = (prefix = "uni") => {
5063
5220
  return `${prefix}xxxxxxxxxxx`.replace(/[xy]/g, (c) => {
5064
5221
  const r = Math.random() * 16 | 0;
@@ -5257,7 +5414,7 @@ var ObjectMap = class _ObjectMap {
5257
5414
  }
5258
5415
  };
5259
5416
 
5260
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.interestmap.interest.js
5417
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.interestmap.interest.js
5261
5418
  var Interest = class {
5262
5419
  /**
5263
5420
  * quick access to a string that makes the interest comparable for checking for similar interests
@@ -5319,7 +5476,7 @@ var Interest = class {
5319
5476
  }
5320
5477
  };
5321
5478
 
5322
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.interestmap.js
5479
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.interestmap.js
5323
5480
  var InterestMap = class {
5324
5481
  constructor(comparisonFuncArg, optionsArg = {}) {
5325
5482
  this.interestObjectMap = new ObjectMap();
@@ -5406,7 +5563,7 @@ var InterestMap = class {
5406
5563
  }
5407
5564
  };
5408
5565
 
5409
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.limitedarray.js
5566
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.limitedarray.js
5410
5567
  var LimitedArray = class {
5411
5568
  constructor(limitArg) {
5412
5569
  this.array = [];
@@ -5443,7 +5600,7 @@ var LimitedArray = class {
5443
5600
  }
5444
5601
  };
5445
5602
 
5446
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.looptracker.js
5603
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.looptracker.js
5447
5604
  var LoopTracker = class {
5448
5605
  constructor() {
5449
5606
  this.referenceObjectMap = new ObjectMap();
@@ -5462,7 +5619,7 @@ var LoopTracker = class {
5462
5619
  }
5463
5620
  };
5464
5621
 
5465
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.stringmap.js
5622
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.stringmap.js
5466
5623
  var Stringmap = class {
5467
5624
  constructor() {
5468
5625
  this._stringArray = [];
@@ -5566,7 +5723,7 @@ var Stringmap = class {
5566
5723
  }
5567
5724
  };
5568
5725
 
5569
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.timedaggregator.js
5726
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.timedaggregator.js
5570
5727
  var TimedAggregtor = class {
5571
5728
  constructor(optionsArg) {
5572
5729
  this.storageArray = [];
@@ -5597,7 +5754,7 @@ var TimedAggregtor = class {
5597
5754
  }
5598
5755
  };
5599
5756
 
5600
- // node_modules/.pnpm/@push.rocks+lik@6.0.5/node_modules/@push.rocks/lik/dist_ts/lik.tree.js
5757
+ // node_modules/.pnpm/@push.rocks+lik@6.0.15/node_modules/@push.rocks/lik/dist_ts/classes.tree.js
5601
5758
  var Tree = class {
5602
5759
  constructor() {
5603
5760
  this.symbolTree = new import_symbol_tree.default();
@@ -5708,832 +5865,126 @@ var Tree = class {
5708
5865
  }
5709
5866
  };
5710
5867
 
5711
- // node_modules/.pnpm/croner@7.0.3/node_modules/croner/dist/croner.min.js
5712
- function minitz2(y, m, d, h, i, s, tz, throwOnInvalid) {
5713
- return minitz2.fromTZ(minitz2.tp(y, m, d, h, i, s, tz), throwOnInvalid);
5714
- }
5715
- minitz2.fromTZISO = (localTimeStr, tz, throwOnInvalid) => {
5716
- return minitz2.fromTZ(parseISOLocal2(localTimeStr, tz), throwOnInvalid);
5717
- };
5718
- minitz2.fromTZ = function(tp, throwOnInvalid) {
5719
- const inDate = new Date(Date.UTC(tp.y, tp.m - 1, tp.d, tp.h, tp.i, tp.s)), offset = getTimezoneOffset2(tp.tz, inDate), dateGuess = new Date(inDate.getTime() - offset), dateOffsGuess = getTimezoneOffset2(tp.tz, dateGuess);
5720
- if (dateOffsGuess - offset === 0) {
5721
- return dateGuess;
5722
- } else {
5723
- const dateGuess2 = new Date(inDate.getTime() - dateOffsGuess), dateOffsGuess2 = getTimezoneOffset2(tp.tz, dateGuess2);
5724
- if (dateOffsGuess2 - dateOffsGuess === 0) {
5725
- return dateGuess2;
5726
- } else if (!throwOnInvalid && dateOffsGuess2 - dateOffsGuess > 0) {
5727
- return dateGuess2;
5728
- } else if (!throwOnInvalid) {
5729
- return dateGuess;
5730
- } else {
5731
- throw new Error("Invalid date passed to fromTZ()");
5732
- }
5868
+ // ts/smarttime.plugins.ts
5869
+ var import_dayjs2 = __toESM(require_dayjs_min(), 1);
5870
+ var import_isToday2 = __toESM(require_isToday(), 1);
5871
+ import_dayjs2.default.extend(import_isToday2.default);
5872
+
5873
+ // ts/smarttime.classes.cronjob.ts
5874
+ var CronJob2 = class {
5875
+ constructor(cronManager, cronExpressionArg, jobFunction) {
5876
+ this.status = "initial";
5877
+ this.nextExecutionUnix = 0;
5878
+ this.cronExpression = cronExpressionArg;
5879
+ this.jobFunction = jobFunction;
5880
+ this.cronParser = Cron(cronExpressionArg);
5733
5881
  }
5734
- };
5735
- minitz2.toTZ = function(d, tzStr) {
5736
- const localDateString = d.toLocaleString("en-US", { timeZone: tzStr }).replace(/[\u202f]/, " ");
5737
- const td = new Date(localDateString);
5738
- return { y: td.getFullYear(), m: td.getMonth() + 1, d: td.getDate(), h: td.getHours(), i: td.getMinutes(), s: td.getSeconds(), tz: tzStr };
5739
- };
5740
- minitz2.tp = (y, m, d, h, i, s, tz) => {
5741
- return { y, m, d, h, i, s, tz };
5742
- };
5743
- function getTimezoneOffset2(timeZone, date = /* @__PURE__ */ new Date()) {
5744
- const tz = date.toLocaleString("en-US", { timeZone, timeZoneName: "short" }).split(" ").slice(-1)[0];
5745
- const dateString = date.toLocaleString("en-US").replace(/[\u202f]/, " ");
5746
- return Date.parse(`${dateString} GMT`) - Date.parse(`${dateString} ${tz}`);
5747
- }
5748
- function parseISOLocal2(dtStr, tz) {
5749
- const pd = new Date(Date.parse(dtStr));
5750
- if (isNaN(pd)) {
5751
- throw new Error("minitz: Invalid ISO8601 passed to parser.");
5882
+ /**
5883
+ * checks wether the cronjob needs to be executed
5884
+ */
5885
+ checkExecution() {
5886
+ if (this.nextExecutionUnix === 0) {
5887
+ this.getNextExecutionTime();
5888
+ }
5889
+ if (Date.now() > this.nextExecutionUnix) {
5890
+ const maybePromise = this.jobFunction(this.nextExecutionUnix);
5891
+ if (maybePromise instanceof Promise) {
5892
+ maybePromise.catch((e) => console.log(e));
5893
+ }
5894
+ this.nextExecutionUnix = this.getNextExecutionTime();
5895
+ }
5896
+ return this.nextExecutionUnix;
5752
5897
  }
5753
- const stringEnd = dtStr.substring(9);
5754
- if (dtStr.includes("Z") || stringEnd.includes("-") || stringEnd.includes("+")) {
5755
- return minitz2.tp(pd.getUTCFullYear(), pd.getUTCMonth() + 1, pd.getUTCDate(), pd.getUTCHours(), pd.getUTCMinutes(), pd.getUTCSeconds(), "Etc/UTC");
5756
- } else {
5757
- return minitz2.tp(pd.getFullYear(), pd.getMonth() + 1, pd.getDate(), pd.getHours(), pd.getMinutes(), pd.getSeconds(), tz);
5898
+ getNextExecutionTime() {
5899
+ return this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution();
5758
5900
  }
5759
- }
5760
- minitz2.minitz = minitz2;
5761
- function CronOptions2(options) {
5762
- if (options === void 0) {
5763
- options = {};
5901
+ /**
5902
+ * gets the time to next execution
5903
+ */
5904
+ getTimeToNextExecution() {
5905
+ return this.cronParser.msToNext();
5764
5906
  }
5765
- delete options.name;
5766
- options.legacyMode = options.legacyMode === void 0 ? true : options.legacyMode;
5767
- options.paused = options.paused === void 0 ? false : options.paused;
5768
- options.maxRuns = options.maxRuns === void 0 ? Infinity : options.maxRuns;
5769
- options.catch = options.catch === void 0 ? false : options.catch;
5770
- options.interval = options.interval === void 0 ? 0 : parseInt(options.interval, 10);
5771
- options.utcOffset = options.utcOffset === void 0 ? void 0 : parseInt(options.utcOffset, 10);
5772
- options.unref = options.unref === void 0 ? false : options.unref;
5773
- if (options.startAt) {
5774
- options.startAt = new CronDate2(options.startAt, options.timezone);
5907
+ start() {
5908
+ this.status = "started";
5775
5909
  }
5776
- if (options.stopAt) {
5777
- options.stopAt = new CronDate2(options.stopAt, options.timezone);
5910
+ stop() {
5911
+ this.status = "stopped";
5778
5912
  }
5779
- if (options.interval !== null) {
5780
- if (isNaN(options.interval)) {
5781
- throw new Error("CronOptions: Supplied value for interval is not a number");
5782
- } else if (options.interval < 0) {
5783
- throw new Error("CronOptions: Supplied value for interval can not be negative");
5784
- }
5913
+ };
5914
+
5915
+ // ts/smarttime.units.ts
5916
+ var units2 = {
5917
+ years: (timesArg = 1) => {
5918
+ return timesArg * 3154e7;
5919
+ },
5920
+ months: (timesArg = 1) => {
5921
+ return timesArg * 2628e6;
5922
+ },
5923
+ weeks: (timesArg = 1) => {
5924
+ return timesArg * 6048e5;
5925
+ },
5926
+ days: (timesArg = 1) => {
5927
+ return timesArg * 864e5;
5928
+ },
5929
+ hours: (timesArg = 1) => {
5930
+ return timesArg * 36e5;
5931
+ },
5932
+ minutes: (timesArg = 1) => {
5933
+ return timesArg * 6e4;
5934
+ },
5935
+ seconds: (timesArg = 1) => {
5936
+ return timesArg * 1e3;
5785
5937
  }
5786
- if (options.utcOffset !== void 0) {
5787
- if (isNaN(options.utcOffset)) {
5788
- throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");
5789
- } else if (options.utcOffset < -870 || options.utcOffset > 870) {
5790
- throw new Error("CronOptions: utcOffset out of bounds.");
5791
- }
5792
- if (options.utcOffset !== void 0 && options.timezone) {
5793
- throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.");
5794
- }
5938
+ };
5939
+ var getMilliSecondsFromUnits2 = (combinationArg) => {
5940
+ let timeInMilliseconds = 0;
5941
+ let addMilliSeconds = (milliSecondsArg) => {
5942
+ timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
5943
+ };
5944
+ if (combinationArg.years) {
5945
+ addMilliSeconds(units2.years(combinationArg.years));
5795
5946
  }
5796
- if (options.unref !== true && options.unref !== false) {
5797
- throw new Error("CronOptions: Unref should be either true, false or undefined(false).");
5947
+ if (combinationArg.months) {
5948
+ addMilliSeconds(units2.months(combinationArg.months));
5798
5949
  }
5799
- return options;
5800
- }
5801
- var LAST_OCCURRENCE = 32;
5802
- var ANY_OCCURRENCE = 1 | 2 | 4 | 8 | 16 | LAST_OCCURRENCE;
5803
- var OCCURRENCE_BITMASKS = [1, 2, 4, 16, 16];
5804
- function CronPattern2(pattern, timezone) {
5805
- this.pattern = pattern;
5806
- this.timezone = timezone;
5807
- this.second = Array(60).fill(0);
5808
- this.minute = Array(60).fill(0);
5809
- this.hour = Array(24).fill(0);
5810
- this.day = Array(31).fill(0);
5811
- this.month = Array(12).fill(0);
5812
- this.dayOfWeek = Array(7).fill(0);
5813
- this.lastDayOfMonth = false;
5814
- this.starDOM = false;
5815
- this.starDOW = false;
5816
- this.parse();
5817
- }
5818
- CronPattern2.prototype.parse = function() {
5819
- if (!(typeof this.pattern === "string" || this.pattern.constructor === String)) {
5820
- throw new TypeError("CronPattern: Pattern has to be of type string.");
5950
+ if (combinationArg.weeks) {
5951
+ addMilliSeconds(units2.weeks(combinationArg.weeks));
5821
5952
  }
5822
- if (this.pattern.indexOf("@") >= 0)
5823
- this.pattern = this.handleNicknames(this.pattern).trim();
5824
- const parts = this.pattern.replace(/\s+/g, " ").split(" ");
5825
- if (parts.length < 5 || parts.length > 6) {
5826
- throw new TypeError("CronPattern: invalid configuration format ('" + this.pattern + "'), exacly five or six space separated parts required.");
5953
+ if (combinationArg.days) {
5954
+ addMilliSeconds(units2.days(combinationArg.days));
5827
5955
  }
5828
- if (parts.length === 5) {
5829
- parts.unshift("0");
5956
+ if (combinationArg.hours) {
5957
+ addMilliSeconds(units2.hours(combinationArg.hours));
5830
5958
  }
5831
- if (parts[3].indexOf("L") >= 0) {
5832
- parts[3] = parts[3].replace("L", "");
5833
- this.lastDayOfMonth = true;
5959
+ if (combinationArg.minutes) {
5960
+ addMilliSeconds(units2.minutes(combinationArg.minutes));
5834
5961
  }
5835
- if (parts[3] == "*") {
5836
- this.starDOM = true;
5962
+ if (combinationArg.seconds) {
5963
+ addMilliSeconds(units2.seconds(combinationArg.seconds));
5837
5964
  }
5838
- if (parts[4].length >= 3)
5839
- parts[4] = this.replaceAlphaMonths(parts[4]);
5840
- if (parts[5].length >= 3)
5841
- parts[5] = this.replaceAlphaDays(parts[5]);
5842
- if (parts[5] == "*") {
5843
- this.starDOW = true;
5965
+ return timeInMilliseconds;
5966
+ };
5967
+ var getMilliSecondsAsHumanReadableString2 = (milliSecondsArg) => {
5968
+ return prettyMilliseconds(milliSecondsArg);
5969
+ };
5970
+
5971
+ // ts/smarttime.classes.cronmanager.ts
5972
+ var CronManager3 = class {
5973
+ constructor() {
5974
+ this.status = "stopped";
5975
+ this.cronjobs = new dist_ts_exports5.ObjectMap();
5844
5976
  }
5845
- if (this.pattern.indexOf("?") >= 0) {
5846
- const initDate = new CronDate2(/* @__PURE__ */ new Date(), this.timezone).getDate(true);
5847
- parts[0] = parts[0].replace("?", initDate.getSeconds());
5848
- parts[1] = parts[1].replace("?", initDate.getMinutes());
5849
- parts[2] = parts[2].replace("?", initDate.getHours());
5850
- if (!this.starDOM)
5851
- parts[3] = parts[3].replace("?", initDate.getDate());
5852
- parts[4] = parts[4].replace("?", initDate.getMonth() + 1);
5853
- if (!this.starDOW)
5854
- parts[5] = parts[5].replace("?", initDate.getDay());
5977
+ addCronjob(cronIdentifierArg, cronFunctionArg) {
5978
+ const newCronJob = new CronJob2(this, cronIdentifierArg, cronFunctionArg);
5979
+ this.cronjobs.add(newCronJob);
5980
+ if (this.status === "started") {
5981
+ newCronJob.start();
5982
+ }
5983
+ return newCronJob;
5855
5984
  }
5856
- this.throwAtIllegalCharacters(parts);
5857
- this.partToArray("second", parts[0], 0, 1);
5858
- this.partToArray("minute", parts[1], 0, 1);
5859
- this.partToArray("hour", parts[2], 0, 1);
5860
- this.partToArray("day", parts[3], -1, 1);
5861
- this.partToArray("month", parts[4], -1, 1);
5862
- this.partToArray("dayOfWeek", parts[5], 0, ANY_OCCURRENCE);
5863
- if (this.dayOfWeek[7]) {
5864
- this.dayOfWeek[0] = this.dayOfWeek[7];
5865
- }
5866
- };
5867
- CronPattern2.prototype.partToArray = function(type, conf, valueIndexOffset, defaultValue) {
5868
- const arr = this[type];
5869
- const lastDayOfMonth = type === "day" && this.lastDayOfMonth;
5870
- if (conf === "" && !lastDayOfMonth)
5871
- throw new TypeError("CronPattern: configuration entry " + type + " (" + conf + ") is empty, check for trailing spaces.");
5872
- if (conf === "*")
5873
- return arr.fill(defaultValue);
5874
- const split = conf.split(",");
5875
- if (split.length > 1) {
5876
- for (let i = 0; i < split.length; i++) {
5877
- this.partToArray(type, split[i], valueIndexOffset, defaultValue);
5878
- }
5879
- } else if (conf.indexOf("-") !== -1 && conf.indexOf("/") !== -1) {
5880
- this.handleRangeWithStepping(conf, type, valueIndexOffset, defaultValue);
5881
- } else if (conf.indexOf("-") !== -1) {
5882
- this.handleRange(conf, type, valueIndexOffset, defaultValue);
5883
- } else if (conf.indexOf("/") !== -1) {
5884
- this.handleStepping(conf, type, valueIndexOffset, defaultValue);
5885
- } else if (conf !== "") {
5886
- this.handleNumber(conf, type, valueIndexOffset, defaultValue);
5887
- }
5888
- };
5889
- CronPattern2.prototype.throwAtIllegalCharacters = function(parts) {
5890
- for (let i = 0; i < parts.length; i++) {
5891
- const reValidCron = i === 5 ? /[^/*0-9,\-#L]+/ : /[^/*0-9,-]+/;
5892
- if (reValidCron.test(parts[i])) {
5893
- throw new TypeError("CronPattern: configuration entry " + i + " (" + parts[i] + ") contains illegal characters.");
5894
- }
5895
- }
5896
- };
5897
- CronPattern2.prototype.handleNumber = function(conf, type, valueIndexOffset, defaultValue) {
5898
- const result = this.extractNth(conf, type);
5899
- const i = parseInt(result[0], 10) + valueIndexOffset;
5900
- if (isNaN(i)) {
5901
- throw new TypeError("CronPattern: " + type + " is not a number: '" + conf + "'");
5902
- }
5903
- this.setPart(type, i, result[1] || defaultValue);
5904
- };
5905
- CronPattern2.prototype.setPart = function(part, index, value) {
5906
- if (!Object.prototype.hasOwnProperty.call(this, part)) {
5907
- throw new TypeError("CronPattern: Invalid part specified: " + part);
5908
- }
5909
- if (part === "dayOfWeek") {
5910
- if (index === 7)
5911
- index = 0;
5912
- if ((index < 0 || index > 6) && index !== "L") {
5913
- throw new RangeError("CronPattern: Invalid value for dayOfWeek: " + index);
5914
- }
5915
- this.setNthWeekdayOfMonth(index, value);
5916
- return;
5917
- }
5918
- if (part === "second" || part === "minute") {
5919
- if (index < 0 || index >= 60) {
5920
- throw new RangeError("CronPattern: Invalid value for " + part + ": " + index);
5921
- }
5922
- } else if (part === "hour") {
5923
- if (index < 0 || index >= 24) {
5924
- throw new RangeError("CronPattern: Invalid value for " + part + ": " + index);
5925
- }
5926
- } else if (part === "day") {
5927
- if (index < 0 || index >= 31) {
5928
- throw new RangeError("CronPattern: Invalid value for " + part + ": " + index);
5929
- }
5930
- } else if (part === "month") {
5931
- if (index < 0 || index >= 12) {
5932
- throw new RangeError("CronPattern: Invalid value for " + part + ": " + index);
5933
- }
5934
- }
5935
- this[part][index] = value;
5936
- };
5937
- CronPattern2.prototype.handleRangeWithStepping = function(conf, type, valueIndexOffset, defaultValue) {
5938
- const result = this.extractNth(conf, type);
5939
- const matches = result[0].match(/^(\d+)-(\d+)\/(\d+)$/);
5940
- if (matches === null)
5941
- throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '" + conf + "'");
5942
- let [, lower, upper, steps] = matches;
5943
- lower = parseInt(lower, 10) + valueIndexOffset;
5944
- upper = parseInt(upper, 10) + valueIndexOffset;
5945
- steps = parseInt(steps, 10);
5946
- if (isNaN(lower))
5947
- throw new TypeError("CronPattern: Syntax error, illegal lower range (NaN)");
5948
- if (isNaN(upper))
5949
- throw new TypeError("CronPattern: Syntax error, illegal upper range (NaN)");
5950
- if (isNaN(steps))
5951
- throw new TypeError("CronPattern: Syntax error, illegal stepping: (NaN)");
5952
- if (steps === 0)
5953
- throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");
5954
- if (steps > this[type].length)
5955
- throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part (" + this[type].length + ")");
5956
- if (lower > upper)
5957
- throw new TypeError("CronPattern: From value is larger than to value: '" + conf + "'");
5958
- for (let i = lower; i <= upper; i += steps) {
5959
- this.setPart(type, i, result[1] || defaultValue);
5960
- }
5961
- };
5962
- CronPattern2.prototype.extractNth = function(conf, type) {
5963
- let rest = conf;
5964
- let nth;
5965
- if (rest.includes("#")) {
5966
- if (type !== "dayOfWeek") {
5967
- throw new Error("CronPattern: nth (#) only allowed in day-of-week field");
5968
- }
5969
- nth = rest.split("#")[1];
5970
- rest = rest.split("#")[0];
5971
- }
5972
- return [rest, nth];
5973
- };
5974
- CronPattern2.prototype.handleRange = function(conf, type, valueIndexOffset, defaultValue) {
5975
- const result = this.extractNth(conf, type);
5976
- const split = result[0].split("-");
5977
- if (split.length !== 2) {
5978
- throw new TypeError("CronPattern: Syntax error, illegal range: '" + conf + "'");
5979
- }
5980
- const lower = parseInt(split[0], 10) + valueIndexOffset, upper = parseInt(split[1], 10) + valueIndexOffset;
5981
- if (isNaN(lower)) {
5982
- throw new TypeError("CronPattern: Syntax error, illegal lower range (NaN)");
5983
- } else if (isNaN(upper)) {
5984
- throw new TypeError("CronPattern: Syntax error, illegal upper range (NaN)");
5985
- }
5986
- if (lower > upper) {
5987
- throw new TypeError("CronPattern: From value is larger than to value: '" + conf + "'");
5988
- }
5989
- for (let i = lower; i <= upper; i++) {
5990
- this.setPart(type, i, result[1] || defaultValue);
5991
- }
5992
- };
5993
- CronPattern2.prototype.handleStepping = function(conf, type, _valueIndexOffset, defaultValue) {
5994
- const result = this.extractNth(conf, type);
5995
- const split = result[0].split("/");
5996
- if (split.length !== 2) {
5997
- throw new TypeError("CronPattern: Syntax error, illegal stepping: '" + conf + "'");
5998
- }
5999
- let start = 0;
6000
- if (split[0] !== "*") {
6001
- start = parseInt(split[0], 10);
6002
- }
6003
- const steps = parseInt(split[1], 10);
6004
- if (isNaN(steps))
6005
- throw new TypeError("CronPattern: Syntax error, illegal stepping: (NaN)");
6006
- if (steps === 0)
6007
- throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");
6008
- if (steps > this[type].length)
6009
- throw new TypeError("CronPattern: Syntax error, max steps for part is (" + this[type].length + ")");
6010
- for (let i = start; i < this[type].length; i += steps) {
6011
- this.setPart(type, i, result[1] || defaultValue);
6012
- }
6013
- };
6014
- CronPattern2.prototype.replaceAlphaDays = function(conf) {
6015
- return conf.replace(/-sun/gi, "-7").replace(/sun/gi, "0").replace(/mon/gi, "1").replace(/tue/gi, "2").replace(/wed/gi, "3").replace(/thu/gi, "4").replace(/fri/gi, "5").replace(/sat/gi, "6");
6016
- };
6017
- CronPattern2.prototype.replaceAlphaMonths = function(conf) {
6018
- return conf.replace(/jan/gi, "1").replace(/feb/gi, "2").replace(/mar/gi, "3").replace(/apr/gi, "4").replace(/may/gi, "5").replace(/jun/gi, "6").replace(/jul/gi, "7").replace(/aug/gi, "8").replace(/sep/gi, "9").replace(/oct/gi, "10").replace(/nov/gi, "11").replace(/dec/gi, "12");
6019
- };
6020
- CronPattern2.prototype.handleNicknames = function(pattern) {
6021
- const cleanPattern = pattern.trim().toLowerCase();
6022
- if (cleanPattern === "@yearly" || cleanPattern === "@annually") {
6023
- return "0 0 1 1 *";
6024
- } else if (cleanPattern === "@monthly") {
6025
- return "0 0 1 * *";
6026
- } else if (cleanPattern === "@weekly") {
6027
- return "0 0 * * 0";
6028
- } else if (cleanPattern === "@daily") {
6029
- return "0 0 * * *";
6030
- } else if (cleanPattern === "@hourly") {
6031
- return "0 * * * *";
6032
- } else {
6033
- return pattern;
6034
- }
6035
- };
6036
- CronPattern2.prototype.setNthWeekdayOfMonth = function(index, nthWeekday) {
6037
- if (nthWeekday === "L") {
6038
- this["dayOfWeek"][index] = this["dayOfWeek"][index] | LAST_OCCURRENCE;
6039
- } else if (nthWeekday < 6 && nthWeekday > 0) {
6040
- this["dayOfWeek"][index] = this["dayOfWeek"][index] | OCCURRENCE_BITMASKS[nthWeekday - 1];
6041
- } else if (nthWeekday === ANY_OCCURRENCE) {
6042
- this["dayOfWeek"][index] = ANY_OCCURRENCE;
6043
- } else {
6044
- throw new TypeError(`CronPattern: nth weekday of of range, should be 1-5 or L. Value: ${nthWeekday}`);
6045
- }
6046
- };
6047
- var DaysOfMonth2 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
6048
- var RecursionSteps2 = [["month", "year", 0], ["day", "month", -1], ["hour", "day", 0], ["minute", "hour", 0], ["second", "minute", 0]];
6049
- function CronDate2(d, tz) {
6050
- this.tz = tz;
6051
- if (d && d instanceof Date) {
6052
- if (!isNaN(d)) {
6053
- this.fromDate(d);
6054
- } else {
6055
- throw new TypeError("CronDate: Invalid date passed to CronDate constructor");
6056
- }
6057
- } else if (d === void 0) {
6058
- this.fromDate(/* @__PURE__ */ new Date());
6059
- } else if (d && typeof d === "string") {
6060
- this.fromString(d);
6061
- } else if (d instanceof CronDate2) {
6062
- this.fromCronDate(d);
6063
- } else {
6064
- throw new TypeError("CronDate: Invalid type (" + typeof d + ") passed to CronDate constructor");
6065
- }
6066
- }
6067
- CronDate2.prototype.isNthWeekdayOfMonth = function(year, month, day, nth) {
6068
- const date = new Date(Date.UTC(year, month, day));
6069
- const weekday = date.getUTCDay();
6070
- let count = 0;
6071
- for (let d = 1; d <= day; d++) {
6072
- if (new Date(Date.UTC(year, month, d)).getUTCDay() === weekday) {
6073
- count++;
6074
- }
6075
- }
6076
- if (nth & ANY_OCCURRENCE && OCCURRENCE_BITMASKS[count - 1] & nth) {
6077
- return true;
6078
- }
6079
- if (nth & LAST_OCCURRENCE) {
6080
- const daysInMonth = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
6081
- for (let d = day + 1; d <= daysInMonth; d++) {
6082
- if (new Date(Date.UTC(year, month, d)).getUTCDay() === weekday) {
6083
- return false;
6084
- }
6085
- }
6086
- return true;
6087
- }
6088
- return false;
6089
- };
6090
- CronDate2.prototype.fromDate = function(inDate) {
6091
- if (this.tz !== void 0) {
6092
- if (typeof this.tz === "number") {
6093
- this.ms = inDate.getUTCMilliseconds();
6094
- this.second = inDate.getUTCSeconds();
6095
- this.minute = inDate.getUTCMinutes() + this.tz;
6096
- this.hour = inDate.getUTCHours();
6097
- this.day = inDate.getUTCDate();
6098
- this.month = inDate.getUTCMonth();
6099
- this.year = inDate.getUTCFullYear();
6100
- this.apply();
6101
- } else {
6102
- const d = minitz2.toTZ(inDate, this.tz);
6103
- this.ms = inDate.getMilliseconds();
6104
- this.second = d.s;
6105
- this.minute = d.i;
6106
- this.hour = d.h;
6107
- this.day = d.d;
6108
- this.month = d.m - 1;
6109
- this.year = d.y;
6110
- }
6111
- } else {
6112
- this.ms = inDate.getMilliseconds();
6113
- this.second = inDate.getSeconds();
6114
- this.minute = inDate.getMinutes();
6115
- this.hour = inDate.getHours();
6116
- this.day = inDate.getDate();
6117
- this.month = inDate.getMonth();
6118
- this.year = inDate.getFullYear();
6119
- }
6120
- };
6121
- CronDate2.prototype.fromCronDate = function(d) {
6122
- this.tz = d.tz;
6123
- this.year = d.year;
6124
- this.month = d.month;
6125
- this.day = d.day;
6126
- this.hour = d.hour;
6127
- this.minute = d.minute;
6128
- this.second = d.second;
6129
- this.ms = d.ms;
6130
- };
6131
- CronDate2.prototype.apply = function() {
6132
- if (this.month > 11 || this.day > DaysOfMonth2[this.month] || this.hour > 59 || this.minute > 59 || this.second > 59 || this.hour < 0 || this.minute < 0 || this.second < 0) {
6133
- const d = new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms));
6134
- this.ms = d.getUTCMilliseconds();
6135
- this.second = d.getUTCSeconds();
6136
- this.minute = d.getUTCMinutes();
6137
- this.hour = d.getUTCHours();
6138
- this.day = d.getUTCDate();
6139
- this.month = d.getUTCMonth();
6140
- this.year = d.getUTCFullYear();
6141
- return true;
6142
- } else {
6143
- return false;
6144
- }
6145
- };
6146
- CronDate2.prototype.fromString = function(str) {
6147
- return this.fromDate(minitz2.fromTZISO(str, this.tz));
6148
- };
6149
- CronDate2.prototype.findNext = function(options, target, pattern, offset) {
6150
- const originalTarget = this[target];
6151
- let lastDayOfMonth;
6152
- if (pattern.lastDayOfMonth) {
6153
- if (this.month !== 1) {
6154
- lastDayOfMonth = DaysOfMonth2[this.month];
6155
- } else {
6156
- lastDayOfMonth = new Date(Date.UTC(this.year, this.month + 1, 0, 0, 0, 0, 0)).getUTCDate();
6157
- }
6158
- }
6159
- const fDomWeekDay = !pattern.starDOW && target == "day" ? new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay() : void 0;
6160
- for (let i = this[target] + offset; i < pattern[target].length; i++) {
6161
- let match = pattern[target][i];
6162
- if (target === "day" && pattern.lastDayOfMonth && i - offset == lastDayOfMonth) {
6163
- match = true;
6164
- }
6165
- if (target === "day" && !pattern.starDOW) {
6166
- let dowMatch = pattern.dayOfWeek[(fDomWeekDay + (i - offset - 1)) % 7];
6167
- if (dowMatch && dowMatch & ANY_OCCURRENCE) {
6168
- dowMatch = this.isNthWeekdayOfMonth(this.year, this.month, i - offset, dowMatch);
6169
- } else if (dowMatch) {
6170
- throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${dowMatch}`);
6171
- }
6172
- if (options.legacyMode && !pattern.starDOM) {
6173
- match = match || dowMatch;
6174
- } else {
6175
- match = match && dowMatch;
6176
- }
6177
- }
6178
- if (match) {
6179
- this[target] = i - offset;
6180
- return originalTarget !== this[target] ? 2 : 1;
6181
- }
6182
- }
6183
- return 3;
6184
- };
6185
- CronDate2.prototype.recurse = function(pattern, options, doing) {
6186
- const res = this.findNext(options, RecursionSteps2[doing][0], pattern, RecursionSteps2[doing][2]);
6187
- if (res > 1) {
6188
- let resetLevel = doing + 1;
6189
- while (resetLevel < RecursionSteps2.length) {
6190
- this[RecursionSteps2[resetLevel][0]] = -RecursionSteps2[resetLevel][2];
6191
- resetLevel++;
6192
- }
6193
- if (res === 3) {
6194
- this[RecursionSteps2[doing][1]]++;
6195
- this[RecursionSteps2[doing][0]] = -RecursionSteps2[doing][2];
6196
- this.apply();
6197
- return this.recurse(pattern, options, 0);
6198
- } else if (this.apply()) {
6199
- return this.recurse(pattern, options, doing - 1);
6200
- }
6201
- }
6202
- doing += 1;
6203
- if (doing >= RecursionSteps2.length) {
6204
- return this;
6205
- } else if (this.year >= 3e3) {
6206
- return null;
6207
- } else {
6208
- return this.recurse(pattern, options, doing);
6209
- }
6210
- };
6211
- CronDate2.prototype.increment = function(pattern, options, hasPreviousRun) {
6212
- this.second += options.interval > 1 && hasPreviousRun ? options.interval : 1;
6213
- this.ms = 0;
6214
- this.apply();
6215
- return this.recurse(pattern, options, 0);
6216
- };
6217
- CronDate2.prototype.getDate = function(internal) {
6218
- if (internal || this.tz === void 0) {
6219
- return new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms);
6220
- } else {
6221
- if (typeof this.tz === "number") {
6222
- return new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute - this.tz, this.second, this.ms));
6223
- } else {
6224
- return minitz2(this.year, this.month + 1, this.day, this.hour, this.minute, this.second, this.tz);
6225
- }
6226
- }
6227
- };
6228
- CronDate2.prototype.getTime = function() {
6229
- return this.getDate().getTime();
6230
- };
6231
- function isFunction2(v) {
6232
- return Object.prototype.toString.call(v) === "[object Function]" || "function" === typeof v || v instanceof Function;
6233
- }
6234
- function unrefTimer(timer2) {
6235
- if (typeof Deno !== "undefined" && typeof Deno.unrefTimer !== "undefined") {
6236
- Deno.unrefTimer(timer2);
6237
- } else if (timer2 && typeof timer2.unref !== "undefined") {
6238
- timer2.unref();
6239
- }
6240
- }
6241
- var maxDelay2 = 30 * 1e3;
6242
- var scheduledJobs2 = [];
6243
- function Cron2(pattern, fnOrOptions1, fnOrOptions2) {
6244
- if (!(this instanceof Cron2)) {
6245
- return new Cron2(pattern, fnOrOptions1, fnOrOptions2);
6246
- }
6247
- let options, func;
6248
- if (isFunction2(fnOrOptions1)) {
6249
- func = fnOrOptions1;
6250
- } else if (typeof fnOrOptions1 === "object") {
6251
- options = fnOrOptions1;
6252
- } else if (fnOrOptions1 !== void 0) {
6253
- throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");
6254
- }
6255
- if (isFunction2(fnOrOptions2)) {
6256
- func = fnOrOptions2;
6257
- } else if (typeof fnOrOptions2 === "object") {
6258
- options = fnOrOptions2;
6259
- } else if (fnOrOptions2 !== void 0) {
6260
- throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");
6261
- }
6262
- this.name = options ? options.name : void 0;
6263
- this.options = CronOptions2(options);
6264
- this._states = { kill: false, blocking: false, previousRun: void 0, currentRun: void 0, once: void 0, currentTimeout: void 0, maxRuns: options ? options.maxRuns : void 0, paused: options ? options.paused : false, pattern: void 0 };
6265
- if (pattern && (pattern instanceof Date || typeof pattern === "string" && pattern.indexOf(":") > 0)) {
6266
- this._states.once = new CronDate2(pattern, this.options.timezone || this.options.utcOffset);
6267
- } else {
6268
- this._states.pattern = new CronPattern2(pattern, this.options.timezone);
6269
- }
6270
- if (this.name) {
6271
- const existing = scheduledJobs2.find((j) => j.name === this.name);
6272
- if (existing) {
6273
- throw new Error("Cron: Tried to initialize new named job '" + this.name + "', but name already taken.");
6274
- } else {
6275
- scheduledJobs2.push(this);
6276
- }
6277
- }
6278
- if (func !== void 0) {
6279
- this.fn = func;
6280
- this.schedule();
6281
- }
6282
- return this;
6283
- }
6284
- Cron2.prototype.nextRun = function(prev) {
6285
- const next = this._next(prev);
6286
- return next ? next.getDate() : null;
6287
- };
6288
- Cron2.prototype.nextRuns = function(n, previous) {
6289
- if (n > this._states.maxRuns) {
6290
- n = this._states.maxRuns;
6291
- }
6292
- const enumeration = [];
6293
- let prev = previous || this._states.currentRun;
6294
- while (n-- && (prev = this.nextRun(prev))) {
6295
- enumeration.push(prev);
6296
- }
6297
- return enumeration;
6298
- };
6299
- Cron2.prototype.getPattern = function() {
6300
- return this._states.pattern ? this._states.pattern.pattern : void 0;
6301
- };
6302
- Cron2.prototype.isRunning = function() {
6303
- const msLeft = this.msToNext(this._states.currentRun);
6304
- const isRunning = !this._states.paused;
6305
- const isScheduled = this.fn !== void 0;
6306
- const notIsKilled = !this._states.kill;
6307
- return isRunning && isScheduled && notIsKilled && msLeft !== null;
6308
- };
6309
- Cron2.prototype.isStopped = function() {
6310
- return this._states.kill;
6311
- };
6312
- Cron2.prototype.isBusy = function() {
6313
- return this._states.blocking;
6314
- };
6315
- Cron2.prototype.currentRun = function() {
6316
- return this._states.currentRun ? this._states.currentRun.getDate() : null;
6317
- };
6318
- Cron2.prototype.previousRun = function() {
6319
- return this._states.previousRun ? this._states.previousRun.getDate() : null;
6320
- };
6321
- Cron2.prototype.msToNext = function(prev) {
6322
- const next = this._next(prev);
6323
- prev = new CronDate2(prev, this.options.timezone || this.options.utcOffset);
6324
- if (next) {
6325
- return next.getTime(true) - prev.getTime(true);
6326
- } else {
6327
- return null;
6328
- }
6329
- };
6330
- Cron2.prototype.stop = function() {
6331
- this._states.kill = true;
6332
- if (this._states.currentTimeout) {
6333
- clearTimeout(this._states.currentTimeout);
6334
- }
6335
- const jobIndex = scheduledJobs2.indexOf(this);
6336
- if (jobIndex >= 0) {
6337
- scheduledJobs2.splice(jobIndex, 1);
6338
- }
6339
- };
6340
- Cron2.prototype.pause = function() {
6341
- this._states.paused = true;
6342
- return !this._states.kill;
6343
- };
6344
- Cron2.prototype.resume = function() {
6345
- this._states.paused = false;
6346
- return !this._states.kill;
6347
- };
6348
- Cron2.prototype.schedule = function(func) {
6349
- if (func && this.fn) {
6350
- throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");
6351
- } else if (func) {
6352
- this.fn = func;
6353
- }
6354
- let waitMs = this.msToNext(this._states.currentRun);
6355
- const target = this.nextRun(this._states.currentRun);
6356
- if (waitMs === null || target === null)
6357
- return this;
6358
- if (waitMs > maxDelay2) {
6359
- waitMs = maxDelay2;
6360
- }
6361
- this._states.currentTimeout = setTimeout(() => this._checkTrigger(target), waitMs);
6362
- if (this._states.currentTimeout && this.options.unref) {
6363
- unrefTimer(this._states.currentTimeout);
6364
- }
6365
- return this;
6366
- };
6367
- Cron2.prototype._trigger = async function(initiationDate) {
6368
- this._states.blocking = true;
6369
- this._states.currentRun = new CronDate2(void 0, this.options.timezone || this.options.utcOffset);
6370
- if (this.options.catch) {
6371
- try {
6372
- await this.fn(this, this.options.context);
6373
- } catch (_e) {
6374
- if (isFunction2(this.options.catch)) {
6375
- this.options.catch(_e, this);
6376
- }
6377
- }
6378
- } else {
6379
- await this.fn(this, this.options.context);
6380
- }
6381
- this._states.previousRun = new CronDate2(initiationDate, this.options.timezone || this.options.utcOffset);
6382
- this._states.blocking = false;
6383
- };
6384
- Cron2.prototype.trigger = async function() {
6385
- await this._trigger();
6386
- };
6387
- Cron2.prototype._checkTrigger = function(target) {
6388
- const now = /* @__PURE__ */ new Date(), shouldRun = !this._states.paused && now.getTime() >= target, isBlocked = this._states.blocking && this.options.protect;
6389
- if (shouldRun && !isBlocked) {
6390
- this._states.maxRuns--;
6391
- this._trigger();
6392
- } else {
6393
- if (shouldRun && isBlocked && isFunction2(this.options.protect)) {
6394
- setTimeout(() => this.options.protect(this), 0);
6395
- }
6396
- }
6397
- this.schedule();
6398
- };
6399
- Cron2.prototype._next = function(prev) {
6400
- const hasPreviousRun = prev || this._states.currentRun ? true : false;
6401
- prev = new CronDate2(prev, this.options.timezone || this.options.utcOffset);
6402
- if (this.options.startAt && prev && prev.getTime() < this.options.startAt.getTime()) {
6403
- prev = this.options.startAt;
6404
- }
6405
- const nextRun = this._states.once || new CronDate2(prev, this.options.timezone || this.options.utcOffset).increment(this._states.pattern, this.options, hasPreviousRun);
6406
- if (this._states.once && this._states.once.getTime() <= prev.getTime()) {
6407
- return null;
6408
- } else if (nextRun === null || this._states.maxRuns <= 0 || this._states.kill || this.options.stopAt && nextRun.getTime() >= this.options.stopAt.getTime()) {
6409
- return null;
6410
- } else {
6411
- return nextRun;
6412
- }
6413
- };
6414
- Cron2.Cron = Cron2;
6415
- Cron2.scheduledJobs = scheduledJobs2;
6416
-
6417
- // ts/smarttime.plugins.ts
6418
- var import_dayjs2 = __toESM(require_dayjs_min(), 1);
6419
- var import_isToday2 = __toESM(require_isToday(), 1);
6420
- import_dayjs2.default.extend(import_isToday2.default);
6421
-
6422
- // ts/smarttime.classes.cronjob.ts
6423
- var CronJob2 = class {
6424
- constructor(cronManager, cronExpressionArg, jobFunction) {
6425
- this.status = "initial";
6426
- this.nextExecutionUnix = 0;
6427
- this.cronExpression = cronExpressionArg;
6428
- this.jobFunction = jobFunction;
6429
- this.cronParser = Cron2(cronExpressionArg);
6430
- }
6431
- /**
6432
- * checks wether the cronjob needs to be executed
6433
- */
6434
- checkExecution() {
6435
- if (this.nextExecutionUnix === 0) {
6436
- this.getNextExecutionTime();
6437
- }
6438
- if (Date.now() > this.nextExecutionUnix) {
6439
- const maybePromise = this.jobFunction(this.nextExecutionUnix);
6440
- if (maybePromise instanceof Promise) {
6441
- maybePromise.catch((e) => console.log(e));
6442
- }
6443
- this.nextExecutionUnix = this.getNextExecutionTime();
6444
- }
6445
- return this.nextExecutionUnix;
6446
- }
6447
- getNextExecutionTime() {
6448
- return this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution();
6449
- }
6450
- /**
6451
- * gets the time to next execution
6452
- */
6453
- getTimeToNextExecution() {
6454
- return this.cronParser.msToNext();
6455
- }
6456
- start() {
6457
- this.status = "started";
6458
- }
6459
- stop() {
6460
- this.status = "stopped";
6461
- }
6462
- };
6463
-
6464
- // ts/smarttime.units.ts
6465
- var units2 = {
6466
- years: (timesArg = 1) => {
6467
- return timesArg * 3154e7;
6468
- },
6469
- months: (timesArg = 1) => {
6470
- return timesArg * 2628e6;
6471
- },
6472
- weeks: (timesArg = 1) => {
6473
- return timesArg * 6048e5;
6474
- },
6475
- days: (timesArg = 1) => {
6476
- return timesArg * 864e5;
6477
- },
6478
- hours: (timesArg = 1) => {
6479
- return timesArg * 36e5;
6480
- },
6481
- minutes: (timesArg = 1) => {
6482
- return timesArg * 6e4;
6483
- },
6484
- seconds: (timesArg = 1) => {
6485
- return timesArg * 1e3;
6486
- }
6487
- };
6488
- var getMilliSecondsFromUnits2 = (combinationArg) => {
6489
- let timeInMilliseconds = 0;
6490
- let addMilliSeconds = (milliSecondsArg) => {
6491
- timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
6492
- };
6493
- if (combinationArg.years) {
6494
- addMilliSeconds(units2.years(combinationArg.years));
6495
- }
6496
- if (combinationArg.months) {
6497
- addMilliSeconds(units2.months(combinationArg.months));
6498
- }
6499
- if (combinationArg.weeks) {
6500
- addMilliSeconds(units2.weeks(combinationArg.weeks));
6501
- }
6502
- if (combinationArg.days) {
6503
- addMilliSeconds(units2.days(combinationArg.days));
6504
- }
6505
- if (combinationArg.hours) {
6506
- addMilliSeconds(units2.hours(combinationArg.hours));
6507
- }
6508
- if (combinationArg.minutes) {
6509
- addMilliSeconds(units2.minutes(combinationArg.minutes));
6510
- }
6511
- if (combinationArg.seconds) {
6512
- addMilliSeconds(units2.seconds(combinationArg.seconds));
6513
- }
6514
- return timeInMilliseconds;
6515
- };
6516
- var getMilliSecondsAsHumanReadableString2 = (milliSecondsArg) => {
6517
- return prettyMilliseconds(milliSecondsArg);
6518
- };
6519
-
6520
- // ts/smarttime.classes.cronmanager.ts
6521
- var CronManager3 = class {
6522
- constructor() {
6523
- this.status = "stopped";
6524
- this.cronjobs = new dist_ts_exports5.ObjectMap();
6525
- }
6526
- addCronjob(cronIdentifierArg, cronFunctionArg) {
6527
- const newCronJob = new CronJob2(this, cronIdentifierArg, cronFunctionArg);
6528
- this.cronjobs.add(newCronJob);
6529
- if (this.status === "started") {
6530
- newCronJob.start();
6531
- }
6532
- return newCronJob;
6533
- }
6534
- removeCronjob(cronjobArg) {
6535
- cronjobArg.stop();
6536
- this.cronjobs.remove(cronjobArg);
5985
+ removeCronjob(cronjobArg) {
5986
+ cronjobArg.stop();
5987
+ this.cronjobs.remove(cronjobArg);
6537
5988
  }
6538
5989
  /**
6539
5990
  * starts the cronjob
@@ -6591,9 +6042,6 @@ var CronManager3 = class {
6591
6042
 
6592
6043
  // ts/smarttime.classes.extendeddate.ts
6593
6044
  var ExtendedDate2 = class _ExtendedDate extends Date {
6594
- constructor(unixMilli = Date.now()) {
6595
- super(unixMilli);
6596
- }
6597
6045
  // STATIC factories
6598
6046
  static fromMillis(milliSeconds) {
6599
6047
  return new _ExtendedDate(milliSeconds);
@@ -6637,6 +6085,9 @@ var ExtendedDate2 = class _ExtendedDate extends Date {
6637
6085
  const unixMilli = date.toDate().getTime();
6638
6086
  return new _ExtendedDate(unixMilli);
6639
6087
  }
6088
+ constructor(unixMilli = Date.now()) {
6089
+ super(unixMilli);
6090
+ }
6640
6091
  //
6641
6092
  exportToEuropeanDate() {
6642
6093
  const units3 = this.exportToUnits();