@zelgadis87/utils-core 5.2.9 → 5.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esbuild/index.cjs CHANGED
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
6
  var __export = (target, all) => {
12
7
  for (var name in all)
13
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -20,154 +15,8 @@ var __copyProps = (to, from, except, desc) => {
20
15
  }
21
16
  return to;
22
17
  };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
19
 
33
- // ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js
34
- var require_format = __commonJS({
35
- "../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(exports2) {
36
- "use strict";
37
- Object.defineProperty(exports2, "__esModule", {
38
- value: true
39
- });
40
- exports2["default"] = format2;
41
- function ownKeys(object, enumerableOnly) {
42
- var keys = Object.keys(object);
43
- if (Object.getOwnPropertySymbols) {
44
- var symbols = Object.getOwnPropertySymbols(object);
45
- if (enumerableOnly) {
46
- symbols = symbols.filter(function(sym) {
47
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
48
- });
49
- }
50
- keys.push.apply(keys, symbols);
51
- }
52
- return keys;
53
- }
54
- function _objectSpread(target) {
55
- for (var i = 1; i < arguments.length; i++) {
56
- var source = arguments[i] != null ? arguments[i] : {};
57
- if (i % 2) {
58
- ownKeys(Object(source), true).forEach(function(key) {
59
- _defineProperty(target, key, source[key]);
60
- });
61
- } else if (Object.getOwnPropertyDescriptors) {
62
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
63
- } else {
64
- ownKeys(Object(source)).forEach(function(key) {
65
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
66
- });
67
- }
68
- }
69
- return target;
70
- }
71
- function _defineProperty(obj, key, value) {
72
- if (key in obj) {
73
- Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
74
- } else {
75
- obj[key] = value;
76
- }
77
- return obj;
78
- }
79
- var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
80
- var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"|(\+)/g;
81
- var optionNames = {
82
- y: "year",
83
- M: "month",
84
- d: "day",
85
- D: "weekday",
86
- S: "fractionalSecondDigits",
87
- G: "era",
88
- Z: "timeZoneName",
89
- P: "dayPeriod",
90
- a: "hour12",
91
- h: "hour",
92
- H: "hour",
93
- m: "minute",
94
- s: "second"
95
- };
96
- var values = {
97
- y: ["numeric", "2-digit", void 0, "numeric"],
98
- M: ["narrow", "2-digit", "short", "long"],
99
- d: ["numeric", "2-digit"],
100
- D: ["narrow", "short", "long"],
101
- S: [1, 2, 3],
102
- G: ["narrow", "short", "long"],
103
- Z: ["short", "long"],
104
- P: ["narrow", "short", "long"],
105
- a: [true],
106
- h: ["numeric", "2-digit"],
107
- H: ["numeric", "2-digit"],
108
- m: ["numeric", "2-digit"],
109
- s: ["numeric", "2-digit"]
110
- };
111
- function padIf(condition, value, length) {
112
- return condition && length === 2 && value / 10 < 1 ? "0" + value : value;
113
- }
114
- function formatType(date, type, length) {
115
- var _options;
116
- var _ref = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}, locale = _ref.locale, timeZone = _ref.timeZone;
117
- var option = optionNames[type];
118
- var value = values[type][length - 1];
119
- if (!value) {
120
- return;
121
- }
122
- var options = (_options = {}, _defineProperty(_options, option, value), _defineProperty(_options, "timeZone", timeZone), _options);
123
- if (type === "a") {
124
- return Intl.DateTimeFormat(locale, _objectSpread(_objectSpread({}, options), {}, {
125
- hour: "numeric"
126
- })).formatToParts(date).pop().value;
127
- }
128
- if (type === "G" || type === "Z") {
129
- return Intl.DateTimeFormat(locale, options).formatToParts(date).pop().value;
130
- }
131
- if (type === "H" || type === "h") {
132
- return Intl.DateTimeFormat("en-GB", _objectSpread(_objectSpread({}, options), {}, {
133
- hourCycle: type === "H" ? "h23" : "h11"
134
- })).format(date).toLocaleLowerCase().replace(" am", "").replace(" pm", "");
135
- }
136
- return padIf(["m", "s"].includes(type) && value === "2-digit", Intl.DateTimeFormat(locale, options).format(date), 2);
137
- }
138
- function format2(date, pattern, config) {
139
- return pattern.split(ESCAPE_REGEX).filter(function(sub) {
140
- return sub !== void 0;
141
- }).map(function(sub, index) {
142
- if (index % 2 !== 0) {
143
- return sub;
144
- }
145
- return sub.replace(PATTERN_REGEX, function(match) {
146
- var type = match.charAt(0);
147
- return formatType(date, type, match.length, config) || match;
148
- });
149
- }).join("");
150
- }
151
- }
152
- });
153
-
154
- // ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js
155
- var require_lib = __commonJS({
156
- "../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(exports2) {
157
- "use strict";
158
- Object.defineProperty(exports2, "__esModule", {
159
- value: true
160
- });
161
- exports2.format = void 0;
162
- var _format = require_format();
163
- var _format2 = _interopRequireDefault(_format);
164
- function _interopRequireDefault(obj) {
165
- return obj && obj.__esModule ? obj : { "default": obj };
166
- }
167
- exports2.format = _format2["default"];
168
- }
169
- });
170
-
171
20
  // src/index.ts
172
21
  var index_exports = {};
173
22
  __export(index_exports, {
@@ -1720,9 +1569,6 @@ var LazyDictionary = class _LazyDictionary {
1720
1569
  }
1721
1570
  };
1722
1571
 
1723
- // src/time/TimeInstant.ts
1724
- var import_small_date = __toESM(require_lib());
1725
-
1726
1572
  // src/time/TimeUnit.ts
1727
1573
  var TimeUnit = class _TimeUnit {
1728
1574
  constructor(multiplier) {
@@ -1889,13 +1735,13 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1889
1735
  * @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
1890
1736
  */
1891
1737
  get formatted() {
1892
- const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1738
+ const format = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1893
1739
  const units = this.toUnits();
1894
- if (units.days >= 1) return format2(units.days, "d", units.hours, "h");
1740
+ if (units.days >= 1) return format(units.days, "d", units.hours, "h");
1895
1741
  else if (units.hours >= 1)
1896
- return format2(units.hours, "h", units.minutes, "m");
1742
+ return format(units.hours, "h", units.minutes, "m");
1897
1743
  else if (units.minutes >= 1)
1898
- return format2(units.minutes, "m", units.seconds, "s");
1744
+ return format(units.minutes, "m", units.seconds, "s");
1899
1745
  else if (units.seconds >= 0)
1900
1746
  return units.seconds.toString() + "s";
1901
1747
  else if (units.seconds > -60)
@@ -2141,7 +1987,7 @@ var timeInstantResolveValue = (getFromDate2, referenceDate, x) => {
2141
1987
  };
2142
1988
  var getFromDate = {
2143
1989
  year: (d) => d.getFullYear(),
2144
- month: (d) => d.getMonth(),
1990
+ month: (d) => d.getMonth() + 1,
2145
1991
  date: (d) => d.getDate(),
2146
1992
  hours: (d) => d.getHours(),
2147
1993
  minutes: (d) => d.getMinutes(),
@@ -2158,7 +2004,8 @@ function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInsta
2158
2004
  const referenceDate = toReferenceDate(aReferenceDate);
2159
2005
  const timestamp2 = Date.UTC(
2160
2006
  timeInstantResolveValue(getFromDate.year, referenceDate, year),
2161
- timeInstantResolveValue(getFromDate.month, referenceDate, month),
2007
+ timeInstantResolveValue(getFromDate.month, referenceDate, month) - 1,
2008
+ // Convert from 1-based to 0-based for Date.UTC()
2162
2009
  timeInstantResolveValue(getFromDate.date, referenceDate, date),
2163
2010
  timeInstantResolveValue(getFromDate.hours, referenceDate, hours),
2164
2011
  timeInstantResolveValue(getFromDate.minutes, referenceDate, minutes),
@@ -2283,6 +2130,8 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2283
2130
  /**
2284
2131
  * Formats this instant using the given pattern. The pattern can contain the following tokens:
2285
2132
  *
2133
+ * Note: Implementation inspired by the small-date library (https://github.com/robinweser/small-date).
2134
+ *
2286
2135
  * | Token | Description | Example |
2287
2136
  * |:------|:--------------------------------|:------------------------------|
2288
2137
  * | D | Weekday, 1 letter | W |
@@ -2322,7 +2171,29 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2322
2171
  * @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
2323
2172
  */
2324
2173
  format(pattern, config = {}) {
2325
- return (0, import_small_date.format)(this.toDate(), pattern, config);
2174
+ return formatTimeInstant(this, pattern, config);
2175
+ }
2176
+ /**
2177
+ * Parses a date string using the given pattern and creates a TimeInstant.
2178
+ * This method is the inverse of format() - parsing a formatted string should recreate the original instant.
2179
+ *
2180
+ * For partial patterns (e.g., time-only or date-only), the missing components are taken from the base instant.
2181
+ * For example, parsing "14:30" with base set to yesterday at midnight will result in yesterday at 14:30.
2182
+ *
2183
+ * Note: Currently performs basic validation (e.g., month 1-12, day 1-31) but does not validate
2184
+ * calendar-specific constraints (e.g., February 30th, April 31st). Invalid dates may be
2185
+ * normalized by the underlying Date constructor.
2186
+ *
2187
+ * @param dateString The date string to parse
2188
+ * @param pattern The pattern used to parse the string (same tokens as format())
2189
+ * @param base The base TimeInstant to use for partial patterns (defaults to now)
2190
+ * @param config An optional locale and timeZone definition to use during parsing
2191
+ * @returns A TimeInstant parsed from the string
2192
+ * @throws Error if the string doesn't match the pattern or contains invalid basic values
2193
+ * @todo Add calendar-aware validation to reject dates like February 30th, April 31st
2194
+ */
2195
+ static parse(dateString, pattern, base = _TimeInstant.now(), config = {}) {
2196
+ return parseTimeInstant(dateString, pattern, base, config);
2326
2197
  }
2327
2198
  /**
2328
2199
  * @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
@@ -2406,13 +2277,47 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2406
2277
  return timeInstantBuilder();
2407
2278
  }
2408
2279
  static fromIso8601(str) {
2409
- return _TimeInstant.fromUnixTimestamp(new Date(str).getTime());
2410
- }
2411
- static tryFromIso8601(str) {
2412
- if (!str.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:.\d{3}|)(?:Z|[+-]\d{2}:\d{2})?$/))
2413
- throw new Error("Invalid date given: " + str);
2414
- return _TimeInstant.fromUnixTimestamp(new Date(str).getTime());
2280
+ const iso8601Regex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})(Z|[+-]\d{2}:\d{2})?$/;
2281
+ const match = str.match(iso8601Regex);
2282
+ if (!match) {
2283
+ throw new Error("Invalid ISO 8601 date format: " + str);
2284
+ }
2285
+ const [, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr, millisecondStr] = match;
2286
+ const year = parseInt(yearStr, 10);
2287
+ const month = parseInt(monthStr, 10);
2288
+ const date = parseInt(dayStr, 10);
2289
+ const hours = parseInt(hourStr, 10);
2290
+ const minutes = parseInt(minuteStr, 10);
2291
+ const seconds = parseInt(secondStr, 10);
2292
+ const milliseconds = parseInt(millisecondStr, 10);
2293
+ if (!isValidYear(year))
2294
+ throw new Error("Invalid year in: " + str);
2295
+ if (!isValidMonth(month))
2296
+ throw new Error("Invalid month in: " + str);
2297
+ if (!isValidDayOfMonth(date))
2298
+ throw new Error("Invalid day in: " + str);
2299
+ if (!isValidHour(hours))
2300
+ throw new Error("Invalid hour in: " + str);
2301
+ if (!isValidMinute(minutes))
2302
+ throw new Error("Invalid minute in: " + str);
2303
+ if (!isValidSecond(seconds))
2304
+ throw new Error("Invalid second in: " + str);
2305
+ if (!isValidMillisecond(milliseconds))
2306
+ throw new Error("Invalid millisecond in: " + str);
2307
+ return _TimeInstant.fromParameters({
2308
+ year,
2309
+ month,
2310
+ date,
2311
+ hours,
2312
+ minutes,
2313
+ seconds,
2314
+ milliseconds
2315
+ });
2415
2316
  }
2317
+ /**
2318
+ * @deprecated [2025.10.19]: Use fromIso8601 instead.
2319
+ */
2320
+ static tryFromIso8601 = this.fromIso8601;
2416
2321
  static now() {
2417
2322
  return _TimeInstant.fromUnixTimestamp(Date.now());
2418
2323
  }
@@ -2441,16 +2346,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2441
2346
  return _TimeInstant.fromUnixTimestamp(timestamp2);
2442
2347
  }
2443
2348
  get dayOfMonth() {
2444
- return this.toDate().getDate();
2349
+ return this.toDate().getUTCDate();
2445
2350
  }
2446
2351
  get dayOfWeek() {
2447
- return this.toDate().getDay() + 1;
2352
+ return this.toDate().getUTCDay() + 1;
2448
2353
  }
2449
2354
  get month() {
2450
- return this.toDate().getMonth() + 1;
2355
+ return this.toDate().getUTCMonth() + 1;
2451
2356
  }
2452
2357
  get year() {
2453
- return this.toDate().getFullYear();
2358
+ return this.toDate().getUTCFullYear();
2454
2359
  }
2455
2360
  /**
2456
2361
  * Returns the week number represented by this instant, according to the ISO 8601 standard.
@@ -2483,6 +2388,293 @@ function isTimeInstant(x) {
2483
2388
  return x !== null && x !== void 0 && x instanceof TimeInstant;
2484
2389
  }
2485
2390
  var TimeInstant_default = TimeInstant;
2391
+ function isValidYear(num) {
2392
+ return num >= 0 && num <= 9999;
2393
+ }
2394
+ function isValidMonth(num) {
2395
+ return num >= 1 && num <= 12;
2396
+ }
2397
+ function isValidDayOfMonth(num) {
2398
+ return num >= 1 && num <= 31;
2399
+ }
2400
+ function isValidHour(num) {
2401
+ return num >= 0 && num <= 23;
2402
+ }
2403
+ function isValidMinute(num) {
2404
+ return num >= 0 && num <= 59;
2405
+ }
2406
+ function isValidSecond(num) {
2407
+ return num >= 0 && num <= 59;
2408
+ }
2409
+ function isValidMillisecond(num) {
2410
+ return num >= 0 && num <= 999;
2411
+ }
2412
+ var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
2413
+ var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"/g;
2414
+ var optionNames = {
2415
+ y: "year",
2416
+ M: "month",
2417
+ d: "day",
2418
+ D: "weekday",
2419
+ S: "fractionalSecondDigits",
2420
+ G: "era",
2421
+ Z: "timeZoneName",
2422
+ P: "dayPeriod",
2423
+ a: "hour12",
2424
+ h: "hour",
2425
+ H: "hour",
2426
+ m: "minute",
2427
+ s: "second"
2428
+ };
2429
+ var values = {
2430
+ y: ["numeric", "2-digit", void 0, "numeric"],
2431
+ M: ["narrow", "2-digit", "short", "long"],
2432
+ d: ["numeric", "2-digit"],
2433
+ D: ["narrow", "short", "long"],
2434
+ S: [1, 2, 3],
2435
+ G: ["narrow", "short", "long"],
2436
+ Z: ["short", "long"],
2437
+ P: ["narrow", "short", "long"],
2438
+ a: [true],
2439
+ h: ["numeric", "2-digit"],
2440
+ H: ["numeric", "2-digit"],
2441
+ m: ["numeric", "2-digit"],
2442
+ s: ["numeric", "2-digit"]
2443
+ };
2444
+ function formatType(instant, type, length, { locale, timeZone } = {}) {
2445
+ if (type === "y") {
2446
+ const year = instant.year;
2447
+ if (length === 2) {
2448
+ return String(year).slice(-2);
2449
+ }
2450
+ return String(year);
2451
+ }
2452
+ if (type === "M" && (length === 1 || length === 2)) {
2453
+ const month = instant.month;
2454
+ return length === 2 && month < 10 ? "0" + month : String(month);
2455
+ }
2456
+ if (type === "d" && (length === 1 || length === 2)) {
2457
+ const day = instant.dayOfMonth;
2458
+ return length === 2 && day < 10 ? "0" + day : String(day);
2459
+ }
2460
+ if (type === "H" && (length === 1 || length === 2)) {
2461
+ const hours = instant.toDate().getUTCHours();
2462
+ return length === 2 && hours < 10 ? "0" + hours : String(hours);
2463
+ }
2464
+ if (type === "h" && (length === 1 || length === 2)) {
2465
+ let hours = instant.toDate().getUTCHours();
2466
+ hours = hours === 0 ? 12 : hours > 12 ? hours - 12 : hours;
2467
+ return length === 2 && hours < 10 ? "0" + hours : String(hours);
2468
+ }
2469
+ if (type === "m" && (length === 1 || length === 2)) {
2470
+ const minutes = instant.toDate().getUTCMinutes();
2471
+ return length === 2 && minutes < 10 ? "0" + minutes : String(minutes);
2472
+ }
2473
+ if (type === "s" && (length === 1 || length === 2)) {
2474
+ const seconds = instant.toDate().getUTCSeconds();
2475
+ return length === 2 && seconds < 10 ? "0" + seconds : String(seconds);
2476
+ }
2477
+ if (type === "S") {
2478
+ const ms = instant.toDate().getUTCMilliseconds();
2479
+ if (length === 1) return String(Math.floor(ms / 100));
2480
+ if (length === 2) return String(Math.floor(ms / 10)).padStart(2, "0");
2481
+ if (length === 3) return String(ms).padStart(3, "0");
2482
+ return String(ms);
2483
+ }
2484
+ const date = instant.toDate();
2485
+ const option = optionNames[type];
2486
+ const value = values[type][length - 1];
2487
+ if (!value) {
2488
+ return;
2489
+ }
2490
+ const options = {
2491
+ [option]: value,
2492
+ timeZone
2493
+ };
2494
+ if (type === "a") {
2495
+ return Intl.DateTimeFormat(locale, {
2496
+ ...options,
2497
+ hour: "numeric"
2498
+ }).formatToParts(date).pop()?.value;
2499
+ }
2500
+ if (type === "G" || type === "Z") {
2501
+ return Intl.DateTimeFormat(locale, options).formatToParts(date).pop()?.value;
2502
+ }
2503
+ return Intl.DateTimeFormat(locale, options).format(date);
2504
+ }
2505
+ function formatTimeInstant(instant, pattern, config = {}) {
2506
+ return pattern.split(ESCAPE_REGEX).filter((sub) => sub !== void 0).map((sub, index) => {
2507
+ if (index % 2 !== 0) {
2508
+ return sub;
2509
+ }
2510
+ return sub.replace(PATTERN_REGEX, (match) => {
2511
+ const type = match.charAt(0);
2512
+ return formatType(instant, type, match.length, config) || match;
2513
+ });
2514
+ }).join("");
2515
+ }
2516
+ function parseTimeInstant(dateString, pattern, base, config = {}) {
2517
+ let regexPattern = pattern;
2518
+ const tokens = [];
2519
+ let position = 0;
2520
+ const parts = pattern.split(ESCAPE_REGEX).filter((sub) => sub !== void 0);
2521
+ regexPattern = parts.map((sub, index) => {
2522
+ if (index % 2 !== 0) {
2523
+ return sub.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2524
+ }
2525
+ return sub.replace(PATTERN_REGEX, (match) => {
2526
+ const type = match.charAt(0);
2527
+ tokens.push({ type, length: match.length, position: position++ });
2528
+ switch (type) {
2529
+ case "y":
2530
+ return match.length === 2 ? "(\\d{2})" : "(\\d{4})";
2531
+ case "M":
2532
+ if (match.length === 1) return "(\\d{1,2})";
2533
+ if (match.length === 2) return "(\\d{2})";
2534
+ if (match.length === 3) return "([A-Za-z]{3})";
2535
+ return "([A-Za-z]+)";
2536
+ case "d":
2537
+ return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
2538
+ case "H":
2539
+ case "h":
2540
+ return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
2541
+ case "m":
2542
+ case "s":
2543
+ return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
2544
+ case "S":
2545
+ return `(\\d{${match.length}})`;
2546
+ case "a":
2547
+ return "([aApP][mM])";
2548
+ case "D":
2549
+ if (match.length === 1) return "([A-Za-z])";
2550
+ if (match.length === 2) return "([A-Za-z]{3})";
2551
+ return "([A-Za-z]+)";
2552
+ case "G":
2553
+ if (match.length === 1) return "([A-Za-z])";
2554
+ if (match.length === 2) return "([A-Za-z]{2})";
2555
+ return "([A-Za-z\\s]+)";
2556
+ case "Z":
2557
+ return match.length === 1 ? "([A-Za-z0-9+\\-:]+)" : "([A-Za-z\\s]+)";
2558
+ case "P":
2559
+ return "([A-Za-z\\s]+)";
2560
+ default:
2561
+ return match;
2562
+ }
2563
+ });
2564
+ }).join("");
2565
+ const regex = new RegExp("^" + regexPattern + "$");
2566
+ const matches = dateString.match(regex);
2567
+ if (!matches) {
2568
+ throw new Error(`Date string "${dateString}" does not match pattern "${pattern}"`);
2569
+ }
2570
+ let year = base.year;
2571
+ let month = base.month;
2572
+ let day = base.dayOfMonth;
2573
+ let hour = base.toDate().getUTCHours();
2574
+ let minute = base.toDate().getUTCMinutes();
2575
+ let second = base.toDate().getUTCSeconds();
2576
+ let millisecond = base.toDate().getUTCMilliseconds();
2577
+ let isPM = false;
2578
+ let is12Hour = false;
2579
+ tokens.forEach((token, index) => {
2580
+ const value = matches[index + 1];
2581
+ switch (token.type) {
2582
+ case "y":
2583
+ if (token.length === 2) {
2584
+ const shortYear = parseInt(value, 10);
2585
+ year = shortYear < 50 ? 2e3 + shortYear : 1900 + shortYear;
2586
+ } else {
2587
+ year = parseInt(value, 10);
2588
+ }
2589
+ break;
2590
+ case "M":
2591
+ if (token.length <= 2) {
2592
+ month = parseInt(value, 10);
2593
+ } else {
2594
+ const monthNames2 = [
2595
+ "Jan",
2596
+ "Feb",
2597
+ "Mar",
2598
+ "Apr",
2599
+ "May",
2600
+ "Jun",
2601
+ "Jul",
2602
+ "Aug",
2603
+ "Sep",
2604
+ "Oct",
2605
+ "Nov",
2606
+ "Dec"
2607
+ ];
2608
+ const longMonthNames = [
2609
+ "January",
2610
+ "February",
2611
+ "March",
2612
+ "April",
2613
+ "May",
2614
+ "June",
2615
+ "July",
2616
+ "August",
2617
+ "September",
2618
+ "October",
2619
+ "November",
2620
+ "December"
2621
+ ];
2622
+ let monthIndex = monthNames2.findIndex((name) => name.toLowerCase() === value.toLowerCase());
2623
+ if (monthIndex === -1) {
2624
+ monthIndex = longMonthNames.findIndex((name) => name.toLowerCase() === value.toLowerCase());
2625
+ }
2626
+ month = monthIndex !== -1 ? monthIndex + 1 : 1;
2627
+ }
2628
+ break;
2629
+ case "d":
2630
+ day = parseInt(value, 10);
2631
+ break;
2632
+ case "H":
2633
+ hour = parseInt(value, 10);
2634
+ break;
2635
+ case "h":
2636
+ hour = parseInt(value, 10);
2637
+ is12Hour = true;
2638
+ break;
2639
+ case "m":
2640
+ minute = parseInt(value, 10);
2641
+ break;
2642
+ case "s":
2643
+ second = parseInt(value, 10);
2644
+ break;
2645
+ case "S":
2646
+ let ms = parseInt(value, 10);
2647
+ if (token.length === 1) ms *= 100;
2648
+ else if (token.length === 2) ms *= 10;
2649
+ millisecond = ms;
2650
+ break;
2651
+ case "a":
2652
+ isPM = value.toLowerCase().includes("p");
2653
+ break;
2654
+ }
2655
+ });
2656
+ if (is12Hour && isPM && hour < 12) {
2657
+ hour += 12;
2658
+ } else if (is12Hour && !isPM && hour === 12) {
2659
+ hour = 0;
2660
+ }
2661
+ if (!isValidYear(year)) throw new Error(`Invalid year in date string: ${dateString}`);
2662
+ if (!isValidMonth(month)) throw new Error(`Invalid month in date string: ${dateString}`);
2663
+ if (!isValidDayOfMonth(day)) throw new Error(`Invalid day in date string: ${dateString}`);
2664
+ if (!isValidHour(hour)) throw new Error(`Invalid hour in date string: ${dateString}`);
2665
+ if (!isValidMinute(minute)) throw new Error(`Invalid minute in date string: ${dateString}`);
2666
+ if (!isValidSecond(second)) throw new Error(`Invalid second in date string: ${dateString}`);
2667
+ if (!isValidMillisecond(millisecond)) throw new Error(`Invalid millisecond in date string: ${dateString}`);
2668
+ return TimeInstant.fromParameters({
2669
+ year,
2670
+ month,
2671
+ date: day,
2672
+ hours: hour,
2673
+ minutes: minute,
2674
+ seconds: second,
2675
+ milliseconds: millisecond
2676
+ });
2677
+ }
2486
2678
 
2487
2679
  // src/Logger.ts
2488
2680
  var LEVELS = ["trace", "log", "debug", "info", "warn", "error"];