@zelgadis87/utils-core 5.2.8 → 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/CHANGELOG.md +11 -2
- package/dist/Optional.d.ts +4 -2
- package/dist/time/TimeInstant.d.ts +31 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/empties.d.ts +1 -0
- package/esbuild/index.cjs +363 -171
- package/esbuild/index.cjs.map +4 -4
- package/esbuild/index.mjs +363 -184
- package/esbuild/index.mjs.map +4 -4
- package/package.json +1 -4
- package/src/Optional.ts +3 -1
- package/src/time/TimeInstant.ts +421 -15
- package/src/time/TimeInstantBuilder.ts +2 -2
- package/src/utils/empties.ts +2 -0
package/esbuild/index.mjs
CHANGED
|
@@ -1,167 +1,3 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
// ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js
|
|
28
|
-
var require_format = __commonJS({
|
|
29
|
-
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(exports) {
|
|
30
|
-
"use strict";
|
|
31
|
-
Object.defineProperty(exports, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
});
|
|
34
|
-
exports["default"] = format2;
|
|
35
|
-
function ownKeys(object, enumerableOnly) {
|
|
36
|
-
var keys = Object.keys(object);
|
|
37
|
-
if (Object.getOwnPropertySymbols) {
|
|
38
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
39
|
-
if (enumerableOnly) {
|
|
40
|
-
symbols = symbols.filter(function(sym) {
|
|
41
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
keys.push.apply(keys, symbols);
|
|
45
|
-
}
|
|
46
|
-
return keys;
|
|
47
|
-
}
|
|
48
|
-
function _objectSpread(target) {
|
|
49
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
50
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
51
|
-
if (i % 2) {
|
|
52
|
-
ownKeys(Object(source), true).forEach(function(key) {
|
|
53
|
-
_defineProperty(target, key, source[key]);
|
|
54
|
-
});
|
|
55
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
56
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
57
|
-
} else {
|
|
58
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
59
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return target;
|
|
64
|
-
}
|
|
65
|
-
function _defineProperty(obj, key, value) {
|
|
66
|
-
if (key in obj) {
|
|
67
|
-
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
68
|
-
} else {
|
|
69
|
-
obj[key] = value;
|
|
70
|
-
}
|
|
71
|
-
return obj;
|
|
72
|
-
}
|
|
73
|
-
var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
|
|
74
|
-
var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"|(\+)/g;
|
|
75
|
-
var optionNames = {
|
|
76
|
-
y: "year",
|
|
77
|
-
M: "month",
|
|
78
|
-
d: "day",
|
|
79
|
-
D: "weekday",
|
|
80
|
-
S: "fractionalSecondDigits",
|
|
81
|
-
G: "era",
|
|
82
|
-
Z: "timeZoneName",
|
|
83
|
-
P: "dayPeriod",
|
|
84
|
-
a: "hour12",
|
|
85
|
-
h: "hour",
|
|
86
|
-
H: "hour",
|
|
87
|
-
m: "minute",
|
|
88
|
-
s: "second"
|
|
89
|
-
};
|
|
90
|
-
var values = {
|
|
91
|
-
y: ["numeric", "2-digit", void 0, "numeric"],
|
|
92
|
-
M: ["narrow", "2-digit", "short", "long"],
|
|
93
|
-
d: ["numeric", "2-digit"],
|
|
94
|
-
D: ["narrow", "short", "long"],
|
|
95
|
-
S: [1, 2, 3],
|
|
96
|
-
G: ["narrow", "short", "long"],
|
|
97
|
-
Z: ["short", "long"],
|
|
98
|
-
P: ["narrow", "short", "long"],
|
|
99
|
-
a: [true],
|
|
100
|
-
h: ["numeric", "2-digit"],
|
|
101
|
-
H: ["numeric", "2-digit"],
|
|
102
|
-
m: ["numeric", "2-digit"],
|
|
103
|
-
s: ["numeric", "2-digit"]
|
|
104
|
-
};
|
|
105
|
-
function padIf(condition, value, length) {
|
|
106
|
-
return condition && length === 2 && value / 10 < 1 ? "0" + value : value;
|
|
107
|
-
}
|
|
108
|
-
function formatType(date, type, length) {
|
|
109
|
-
var _options;
|
|
110
|
-
var _ref = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}, locale = _ref.locale, timeZone = _ref.timeZone;
|
|
111
|
-
var option = optionNames[type];
|
|
112
|
-
var value = values[type][length - 1];
|
|
113
|
-
if (!value) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
var options = (_options = {}, _defineProperty(_options, option, value), _defineProperty(_options, "timeZone", timeZone), _options);
|
|
117
|
-
if (type === "a") {
|
|
118
|
-
return Intl.DateTimeFormat(locale, _objectSpread(_objectSpread({}, options), {}, {
|
|
119
|
-
hour: "numeric"
|
|
120
|
-
})).formatToParts(date).pop().value;
|
|
121
|
-
}
|
|
122
|
-
if (type === "G" || type === "Z") {
|
|
123
|
-
return Intl.DateTimeFormat(locale, options).formatToParts(date).pop().value;
|
|
124
|
-
}
|
|
125
|
-
if (type === "H" || type === "h") {
|
|
126
|
-
return Intl.DateTimeFormat("en-GB", _objectSpread(_objectSpread({}, options), {}, {
|
|
127
|
-
hourCycle: type === "H" ? "h23" : "h11"
|
|
128
|
-
})).format(date).toLocaleLowerCase().replace(" am", "").replace(" pm", "");
|
|
129
|
-
}
|
|
130
|
-
return padIf(["m", "s"].includes(type) && value === "2-digit", Intl.DateTimeFormat(locale, options).format(date), 2);
|
|
131
|
-
}
|
|
132
|
-
function format2(date, pattern, config) {
|
|
133
|
-
return pattern.split(ESCAPE_REGEX).filter(function(sub) {
|
|
134
|
-
return sub !== void 0;
|
|
135
|
-
}).map(function(sub, index) {
|
|
136
|
-
if (index % 2 !== 0) {
|
|
137
|
-
return sub;
|
|
138
|
-
}
|
|
139
|
-
return sub.replace(PATTERN_REGEX, function(match) {
|
|
140
|
-
var type = match.charAt(0);
|
|
141
|
-
return formatType(date, type, match.length, config) || match;
|
|
142
|
-
});
|
|
143
|
-
}).join("");
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js
|
|
149
|
-
var require_lib = __commonJS({
|
|
150
|
-
"../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(exports) {
|
|
151
|
-
"use strict";
|
|
152
|
-
Object.defineProperty(exports, "__esModule", {
|
|
153
|
-
value: true
|
|
154
|
-
});
|
|
155
|
-
exports.format = void 0;
|
|
156
|
-
var _format = require_format();
|
|
157
|
-
var _format2 = _interopRequireDefault(_format);
|
|
158
|
-
function _interopRequireDefault(obj) {
|
|
159
|
-
return obj && obj.__esModule ? obj : { "default": obj };
|
|
160
|
-
}
|
|
161
|
-
exports.format = _format2["default"];
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
1
|
// src/async/Deferred.ts
|
|
166
2
|
var DeferredCanceledError = class extends Error {
|
|
167
3
|
constructor() {
|
|
@@ -1531,9 +1367,6 @@ var LazyDictionary = class _LazyDictionary {
|
|
|
1531
1367
|
}
|
|
1532
1368
|
};
|
|
1533
1369
|
|
|
1534
|
-
// src/time/TimeInstant.ts
|
|
1535
|
-
var import_small_date = __toESM(require_lib());
|
|
1536
|
-
|
|
1537
1370
|
// src/time/TimeUnit.ts
|
|
1538
1371
|
var TimeUnit = class _TimeUnit {
|
|
1539
1372
|
constructor(multiplier) {
|
|
@@ -1700,13 +1533,13 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1700
1533
|
* @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
|
|
1701
1534
|
*/
|
|
1702
1535
|
get formatted() {
|
|
1703
|
-
const
|
|
1536
|
+
const format = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
|
|
1704
1537
|
const units = this.toUnits();
|
|
1705
|
-
if (units.days >= 1) return
|
|
1538
|
+
if (units.days >= 1) return format(units.days, "d", units.hours, "h");
|
|
1706
1539
|
else if (units.hours >= 1)
|
|
1707
|
-
return
|
|
1540
|
+
return format(units.hours, "h", units.minutes, "m");
|
|
1708
1541
|
else if (units.minutes >= 1)
|
|
1709
|
-
return
|
|
1542
|
+
return format(units.minutes, "m", units.seconds, "s");
|
|
1710
1543
|
else if (units.seconds >= 0)
|
|
1711
1544
|
return units.seconds.toString() + "s";
|
|
1712
1545
|
else if (units.seconds > -60)
|
|
@@ -1952,7 +1785,7 @@ var timeInstantResolveValue = (getFromDate2, referenceDate, x) => {
|
|
|
1952
1785
|
};
|
|
1953
1786
|
var getFromDate = {
|
|
1954
1787
|
year: (d) => d.getFullYear(),
|
|
1955
|
-
month: (d) => d.getMonth(),
|
|
1788
|
+
month: (d) => d.getMonth() + 1,
|
|
1956
1789
|
date: (d) => d.getDate(),
|
|
1957
1790
|
hours: (d) => d.getHours(),
|
|
1958
1791
|
minutes: (d) => d.getMinutes(),
|
|
@@ -1969,7 +1802,8 @@ function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInsta
|
|
|
1969
1802
|
const referenceDate = toReferenceDate(aReferenceDate);
|
|
1970
1803
|
const timestamp2 = Date.UTC(
|
|
1971
1804
|
timeInstantResolveValue(getFromDate.year, referenceDate, year),
|
|
1972
|
-
timeInstantResolveValue(getFromDate.month, referenceDate, month),
|
|
1805
|
+
timeInstantResolveValue(getFromDate.month, referenceDate, month) - 1,
|
|
1806
|
+
// Convert from 1-based to 0-based for Date.UTC()
|
|
1973
1807
|
timeInstantResolveValue(getFromDate.date, referenceDate, date),
|
|
1974
1808
|
timeInstantResolveValue(getFromDate.hours, referenceDate, hours),
|
|
1975
1809
|
timeInstantResolveValue(getFromDate.minutes, referenceDate, minutes),
|
|
@@ -2094,6 +1928,8 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2094
1928
|
/**
|
|
2095
1929
|
* Formats this instant using the given pattern. The pattern can contain the following tokens:
|
|
2096
1930
|
*
|
|
1931
|
+
* Note: Implementation inspired by the small-date library (https://github.com/robinweser/small-date).
|
|
1932
|
+
*
|
|
2097
1933
|
* | Token | Description | Example |
|
|
2098
1934
|
* |:------|:--------------------------------|:------------------------------|
|
|
2099
1935
|
* | D | Weekday, 1 letter | W |
|
|
@@ -2133,7 +1969,29 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2133
1969
|
* @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
|
|
2134
1970
|
*/
|
|
2135
1971
|
format(pattern, config = {}) {
|
|
2136
|
-
return (
|
|
1972
|
+
return formatTimeInstant(this, pattern, config);
|
|
1973
|
+
}
|
|
1974
|
+
/**
|
|
1975
|
+
* Parses a date string using the given pattern and creates a TimeInstant.
|
|
1976
|
+
* This method is the inverse of format() - parsing a formatted string should recreate the original instant.
|
|
1977
|
+
*
|
|
1978
|
+
* For partial patterns (e.g., time-only or date-only), the missing components are taken from the base instant.
|
|
1979
|
+
* For example, parsing "14:30" with base set to yesterday at midnight will result in yesterday at 14:30.
|
|
1980
|
+
*
|
|
1981
|
+
* Note: Currently performs basic validation (e.g., month 1-12, day 1-31) but does not validate
|
|
1982
|
+
* calendar-specific constraints (e.g., February 30th, April 31st). Invalid dates may be
|
|
1983
|
+
* normalized by the underlying Date constructor.
|
|
1984
|
+
*
|
|
1985
|
+
* @param dateString The date string to parse
|
|
1986
|
+
* @param pattern The pattern used to parse the string (same tokens as format())
|
|
1987
|
+
* @param base The base TimeInstant to use for partial patterns (defaults to now)
|
|
1988
|
+
* @param config An optional locale and timeZone definition to use during parsing
|
|
1989
|
+
* @returns A TimeInstant parsed from the string
|
|
1990
|
+
* @throws Error if the string doesn't match the pattern or contains invalid basic values
|
|
1991
|
+
* @todo Add calendar-aware validation to reject dates like February 30th, April 31st
|
|
1992
|
+
*/
|
|
1993
|
+
static parse(dateString, pattern, base = _TimeInstant.now(), config = {}) {
|
|
1994
|
+
return parseTimeInstant(dateString, pattern, base, config);
|
|
2137
1995
|
}
|
|
2138
1996
|
/**
|
|
2139
1997
|
* @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
|
|
@@ -2217,13 +2075,47 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2217
2075
|
return timeInstantBuilder();
|
|
2218
2076
|
}
|
|
2219
2077
|
static fromIso8601(str) {
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2078
|
+
const iso8601Regex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})(Z|[+-]\d{2}:\d{2})?$/;
|
|
2079
|
+
const match = str.match(iso8601Regex);
|
|
2080
|
+
if (!match) {
|
|
2081
|
+
throw new Error("Invalid ISO 8601 date format: " + str);
|
|
2082
|
+
}
|
|
2083
|
+
const [, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr, millisecondStr] = match;
|
|
2084
|
+
const year = parseInt(yearStr, 10);
|
|
2085
|
+
const month = parseInt(monthStr, 10);
|
|
2086
|
+
const date = parseInt(dayStr, 10);
|
|
2087
|
+
const hours = parseInt(hourStr, 10);
|
|
2088
|
+
const minutes = parseInt(minuteStr, 10);
|
|
2089
|
+
const seconds = parseInt(secondStr, 10);
|
|
2090
|
+
const milliseconds = parseInt(millisecondStr, 10);
|
|
2091
|
+
if (!isValidYear(year))
|
|
2092
|
+
throw new Error("Invalid year in: " + str);
|
|
2093
|
+
if (!isValidMonth(month))
|
|
2094
|
+
throw new Error("Invalid month in: " + str);
|
|
2095
|
+
if (!isValidDayOfMonth(date))
|
|
2096
|
+
throw new Error("Invalid day in: " + str);
|
|
2097
|
+
if (!isValidHour(hours))
|
|
2098
|
+
throw new Error("Invalid hour in: " + str);
|
|
2099
|
+
if (!isValidMinute(minutes))
|
|
2100
|
+
throw new Error("Invalid minute in: " + str);
|
|
2101
|
+
if (!isValidSecond(seconds))
|
|
2102
|
+
throw new Error("Invalid second in: " + str);
|
|
2103
|
+
if (!isValidMillisecond(milliseconds))
|
|
2104
|
+
throw new Error("Invalid millisecond in: " + str);
|
|
2105
|
+
return _TimeInstant.fromParameters({
|
|
2106
|
+
year,
|
|
2107
|
+
month,
|
|
2108
|
+
date,
|
|
2109
|
+
hours,
|
|
2110
|
+
minutes,
|
|
2111
|
+
seconds,
|
|
2112
|
+
milliseconds
|
|
2113
|
+
});
|
|
2226
2114
|
}
|
|
2115
|
+
/**
|
|
2116
|
+
* @deprecated [2025.10.19]: Use fromIso8601 instead.
|
|
2117
|
+
*/
|
|
2118
|
+
static tryFromIso8601 = this.fromIso8601;
|
|
2227
2119
|
static now() {
|
|
2228
2120
|
return _TimeInstant.fromUnixTimestamp(Date.now());
|
|
2229
2121
|
}
|
|
@@ -2252,16 +2144,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
|
|
|
2252
2144
|
return _TimeInstant.fromUnixTimestamp(timestamp2);
|
|
2253
2145
|
}
|
|
2254
2146
|
get dayOfMonth() {
|
|
2255
|
-
return this.toDate().
|
|
2147
|
+
return this.toDate().getUTCDate();
|
|
2256
2148
|
}
|
|
2257
2149
|
get dayOfWeek() {
|
|
2258
|
-
return this.toDate().
|
|
2150
|
+
return this.toDate().getUTCDay() + 1;
|
|
2259
2151
|
}
|
|
2260
2152
|
get month() {
|
|
2261
|
-
return this.toDate().
|
|
2153
|
+
return this.toDate().getUTCMonth() + 1;
|
|
2262
2154
|
}
|
|
2263
2155
|
get year() {
|
|
2264
|
-
return this.toDate().
|
|
2156
|
+
return this.toDate().getUTCFullYear();
|
|
2265
2157
|
}
|
|
2266
2158
|
/**
|
|
2267
2159
|
* Returns the week number represented by this instant, according to the ISO 8601 standard.
|
|
@@ -2294,6 +2186,293 @@ function isTimeInstant(x) {
|
|
|
2294
2186
|
return x !== null && x !== void 0 && x instanceof TimeInstant;
|
|
2295
2187
|
}
|
|
2296
2188
|
var TimeInstant_default = TimeInstant;
|
|
2189
|
+
function isValidYear(num) {
|
|
2190
|
+
return num >= 0 && num <= 9999;
|
|
2191
|
+
}
|
|
2192
|
+
function isValidMonth(num) {
|
|
2193
|
+
return num >= 1 && num <= 12;
|
|
2194
|
+
}
|
|
2195
|
+
function isValidDayOfMonth(num) {
|
|
2196
|
+
return num >= 1 && num <= 31;
|
|
2197
|
+
}
|
|
2198
|
+
function isValidHour(num) {
|
|
2199
|
+
return num >= 0 && num <= 23;
|
|
2200
|
+
}
|
|
2201
|
+
function isValidMinute(num) {
|
|
2202
|
+
return num >= 0 && num <= 59;
|
|
2203
|
+
}
|
|
2204
|
+
function isValidSecond(num) {
|
|
2205
|
+
return num >= 0 && num <= 59;
|
|
2206
|
+
}
|
|
2207
|
+
function isValidMillisecond(num) {
|
|
2208
|
+
return num >= 0 && num <= 999;
|
|
2209
|
+
}
|
|
2210
|
+
var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
|
|
2211
|
+
var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"/g;
|
|
2212
|
+
var optionNames = {
|
|
2213
|
+
y: "year",
|
|
2214
|
+
M: "month",
|
|
2215
|
+
d: "day",
|
|
2216
|
+
D: "weekday",
|
|
2217
|
+
S: "fractionalSecondDigits",
|
|
2218
|
+
G: "era",
|
|
2219
|
+
Z: "timeZoneName",
|
|
2220
|
+
P: "dayPeriod",
|
|
2221
|
+
a: "hour12",
|
|
2222
|
+
h: "hour",
|
|
2223
|
+
H: "hour",
|
|
2224
|
+
m: "minute",
|
|
2225
|
+
s: "second"
|
|
2226
|
+
};
|
|
2227
|
+
var values = {
|
|
2228
|
+
y: ["numeric", "2-digit", void 0, "numeric"],
|
|
2229
|
+
M: ["narrow", "2-digit", "short", "long"],
|
|
2230
|
+
d: ["numeric", "2-digit"],
|
|
2231
|
+
D: ["narrow", "short", "long"],
|
|
2232
|
+
S: [1, 2, 3],
|
|
2233
|
+
G: ["narrow", "short", "long"],
|
|
2234
|
+
Z: ["short", "long"],
|
|
2235
|
+
P: ["narrow", "short", "long"],
|
|
2236
|
+
a: [true],
|
|
2237
|
+
h: ["numeric", "2-digit"],
|
|
2238
|
+
H: ["numeric", "2-digit"],
|
|
2239
|
+
m: ["numeric", "2-digit"],
|
|
2240
|
+
s: ["numeric", "2-digit"]
|
|
2241
|
+
};
|
|
2242
|
+
function formatType(instant, type, length, { locale, timeZone } = {}) {
|
|
2243
|
+
if (type === "y") {
|
|
2244
|
+
const year = instant.year;
|
|
2245
|
+
if (length === 2) {
|
|
2246
|
+
return String(year).slice(-2);
|
|
2247
|
+
}
|
|
2248
|
+
return String(year);
|
|
2249
|
+
}
|
|
2250
|
+
if (type === "M" && (length === 1 || length === 2)) {
|
|
2251
|
+
const month = instant.month;
|
|
2252
|
+
return length === 2 && month < 10 ? "0" + month : String(month);
|
|
2253
|
+
}
|
|
2254
|
+
if (type === "d" && (length === 1 || length === 2)) {
|
|
2255
|
+
const day = instant.dayOfMonth;
|
|
2256
|
+
return length === 2 && day < 10 ? "0" + day : String(day);
|
|
2257
|
+
}
|
|
2258
|
+
if (type === "H" && (length === 1 || length === 2)) {
|
|
2259
|
+
const hours = instant.toDate().getUTCHours();
|
|
2260
|
+
return length === 2 && hours < 10 ? "0" + hours : String(hours);
|
|
2261
|
+
}
|
|
2262
|
+
if (type === "h" && (length === 1 || length === 2)) {
|
|
2263
|
+
let hours = instant.toDate().getUTCHours();
|
|
2264
|
+
hours = hours === 0 ? 12 : hours > 12 ? hours - 12 : hours;
|
|
2265
|
+
return length === 2 && hours < 10 ? "0" + hours : String(hours);
|
|
2266
|
+
}
|
|
2267
|
+
if (type === "m" && (length === 1 || length === 2)) {
|
|
2268
|
+
const minutes = instant.toDate().getUTCMinutes();
|
|
2269
|
+
return length === 2 && minutes < 10 ? "0" + minutes : String(minutes);
|
|
2270
|
+
}
|
|
2271
|
+
if (type === "s" && (length === 1 || length === 2)) {
|
|
2272
|
+
const seconds = instant.toDate().getUTCSeconds();
|
|
2273
|
+
return length === 2 && seconds < 10 ? "0" + seconds : String(seconds);
|
|
2274
|
+
}
|
|
2275
|
+
if (type === "S") {
|
|
2276
|
+
const ms = instant.toDate().getUTCMilliseconds();
|
|
2277
|
+
if (length === 1) return String(Math.floor(ms / 100));
|
|
2278
|
+
if (length === 2) return String(Math.floor(ms / 10)).padStart(2, "0");
|
|
2279
|
+
if (length === 3) return String(ms).padStart(3, "0");
|
|
2280
|
+
return String(ms);
|
|
2281
|
+
}
|
|
2282
|
+
const date = instant.toDate();
|
|
2283
|
+
const option = optionNames[type];
|
|
2284
|
+
const value = values[type][length - 1];
|
|
2285
|
+
if (!value) {
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
const options = {
|
|
2289
|
+
[option]: value,
|
|
2290
|
+
timeZone
|
|
2291
|
+
};
|
|
2292
|
+
if (type === "a") {
|
|
2293
|
+
return Intl.DateTimeFormat(locale, {
|
|
2294
|
+
...options,
|
|
2295
|
+
hour: "numeric"
|
|
2296
|
+
}).formatToParts(date).pop()?.value;
|
|
2297
|
+
}
|
|
2298
|
+
if (type === "G" || type === "Z") {
|
|
2299
|
+
return Intl.DateTimeFormat(locale, options).formatToParts(date).pop()?.value;
|
|
2300
|
+
}
|
|
2301
|
+
return Intl.DateTimeFormat(locale, options).format(date);
|
|
2302
|
+
}
|
|
2303
|
+
function formatTimeInstant(instant, pattern, config = {}) {
|
|
2304
|
+
return pattern.split(ESCAPE_REGEX).filter((sub) => sub !== void 0).map((sub, index) => {
|
|
2305
|
+
if (index % 2 !== 0) {
|
|
2306
|
+
return sub;
|
|
2307
|
+
}
|
|
2308
|
+
return sub.replace(PATTERN_REGEX, (match) => {
|
|
2309
|
+
const type = match.charAt(0);
|
|
2310
|
+
return formatType(instant, type, match.length, config) || match;
|
|
2311
|
+
});
|
|
2312
|
+
}).join("");
|
|
2313
|
+
}
|
|
2314
|
+
function parseTimeInstant(dateString, pattern, base, config = {}) {
|
|
2315
|
+
let regexPattern = pattern;
|
|
2316
|
+
const tokens = [];
|
|
2317
|
+
let position = 0;
|
|
2318
|
+
const parts = pattern.split(ESCAPE_REGEX).filter((sub) => sub !== void 0);
|
|
2319
|
+
regexPattern = parts.map((sub, index) => {
|
|
2320
|
+
if (index % 2 !== 0) {
|
|
2321
|
+
return sub.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2322
|
+
}
|
|
2323
|
+
return sub.replace(PATTERN_REGEX, (match) => {
|
|
2324
|
+
const type = match.charAt(0);
|
|
2325
|
+
tokens.push({ type, length: match.length, position: position++ });
|
|
2326
|
+
switch (type) {
|
|
2327
|
+
case "y":
|
|
2328
|
+
return match.length === 2 ? "(\\d{2})" : "(\\d{4})";
|
|
2329
|
+
case "M":
|
|
2330
|
+
if (match.length === 1) return "(\\d{1,2})";
|
|
2331
|
+
if (match.length === 2) return "(\\d{2})";
|
|
2332
|
+
if (match.length === 3) return "([A-Za-z]{3})";
|
|
2333
|
+
return "([A-Za-z]+)";
|
|
2334
|
+
case "d":
|
|
2335
|
+
return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
|
|
2336
|
+
case "H":
|
|
2337
|
+
case "h":
|
|
2338
|
+
return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
|
|
2339
|
+
case "m":
|
|
2340
|
+
case "s":
|
|
2341
|
+
return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
|
|
2342
|
+
case "S":
|
|
2343
|
+
return `(\\d{${match.length}})`;
|
|
2344
|
+
case "a":
|
|
2345
|
+
return "([aApP][mM])";
|
|
2346
|
+
case "D":
|
|
2347
|
+
if (match.length === 1) return "([A-Za-z])";
|
|
2348
|
+
if (match.length === 2) return "([A-Za-z]{3})";
|
|
2349
|
+
return "([A-Za-z]+)";
|
|
2350
|
+
case "G":
|
|
2351
|
+
if (match.length === 1) return "([A-Za-z])";
|
|
2352
|
+
if (match.length === 2) return "([A-Za-z]{2})";
|
|
2353
|
+
return "([A-Za-z\\s]+)";
|
|
2354
|
+
case "Z":
|
|
2355
|
+
return match.length === 1 ? "([A-Za-z0-9+\\-:]+)" : "([A-Za-z\\s]+)";
|
|
2356
|
+
case "P":
|
|
2357
|
+
return "([A-Za-z\\s]+)";
|
|
2358
|
+
default:
|
|
2359
|
+
return match;
|
|
2360
|
+
}
|
|
2361
|
+
});
|
|
2362
|
+
}).join("");
|
|
2363
|
+
const regex = new RegExp("^" + regexPattern + "$");
|
|
2364
|
+
const matches = dateString.match(regex);
|
|
2365
|
+
if (!matches) {
|
|
2366
|
+
throw new Error(`Date string "${dateString}" does not match pattern "${pattern}"`);
|
|
2367
|
+
}
|
|
2368
|
+
let year = base.year;
|
|
2369
|
+
let month = base.month;
|
|
2370
|
+
let day = base.dayOfMonth;
|
|
2371
|
+
let hour = base.toDate().getUTCHours();
|
|
2372
|
+
let minute = base.toDate().getUTCMinutes();
|
|
2373
|
+
let second = base.toDate().getUTCSeconds();
|
|
2374
|
+
let millisecond = base.toDate().getUTCMilliseconds();
|
|
2375
|
+
let isPM = false;
|
|
2376
|
+
let is12Hour = false;
|
|
2377
|
+
tokens.forEach((token, index) => {
|
|
2378
|
+
const value = matches[index + 1];
|
|
2379
|
+
switch (token.type) {
|
|
2380
|
+
case "y":
|
|
2381
|
+
if (token.length === 2) {
|
|
2382
|
+
const shortYear = parseInt(value, 10);
|
|
2383
|
+
year = shortYear < 50 ? 2e3 + shortYear : 1900 + shortYear;
|
|
2384
|
+
} else {
|
|
2385
|
+
year = parseInt(value, 10);
|
|
2386
|
+
}
|
|
2387
|
+
break;
|
|
2388
|
+
case "M":
|
|
2389
|
+
if (token.length <= 2) {
|
|
2390
|
+
month = parseInt(value, 10);
|
|
2391
|
+
} else {
|
|
2392
|
+
const monthNames2 = [
|
|
2393
|
+
"Jan",
|
|
2394
|
+
"Feb",
|
|
2395
|
+
"Mar",
|
|
2396
|
+
"Apr",
|
|
2397
|
+
"May",
|
|
2398
|
+
"Jun",
|
|
2399
|
+
"Jul",
|
|
2400
|
+
"Aug",
|
|
2401
|
+
"Sep",
|
|
2402
|
+
"Oct",
|
|
2403
|
+
"Nov",
|
|
2404
|
+
"Dec"
|
|
2405
|
+
];
|
|
2406
|
+
const longMonthNames = [
|
|
2407
|
+
"January",
|
|
2408
|
+
"February",
|
|
2409
|
+
"March",
|
|
2410
|
+
"April",
|
|
2411
|
+
"May",
|
|
2412
|
+
"June",
|
|
2413
|
+
"July",
|
|
2414
|
+
"August",
|
|
2415
|
+
"September",
|
|
2416
|
+
"October",
|
|
2417
|
+
"November",
|
|
2418
|
+
"December"
|
|
2419
|
+
];
|
|
2420
|
+
let monthIndex = monthNames2.findIndex((name) => name.toLowerCase() === value.toLowerCase());
|
|
2421
|
+
if (monthIndex === -1) {
|
|
2422
|
+
monthIndex = longMonthNames.findIndex((name) => name.toLowerCase() === value.toLowerCase());
|
|
2423
|
+
}
|
|
2424
|
+
month = monthIndex !== -1 ? monthIndex + 1 : 1;
|
|
2425
|
+
}
|
|
2426
|
+
break;
|
|
2427
|
+
case "d":
|
|
2428
|
+
day = parseInt(value, 10);
|
|
2429
|
+
break;
|
|
2430
|
+
case "H":
|
|
2431
|
+
hour = parseInt(value, 10);
|
|
2432
|
+
break;
|
|
2433
|
+
case "h":
|
|
2434
|
+
hour = parseInt(value, 10);
|
|
2435
|
+
is12Hour = true;
|
|
2436
|
+
break;
|
|
2437
|
+
case "m":
|
|
2438
|
+
minute = parseInt(value, 10);
|
|
2439
|
+
break;
|
|
2440
|
+
case "s":
|
|
2441
|
+
second = parseInt(value, 10);
|
|
2442
|
+
break;
|
|
2443
|
+
case "S":
|
|
2444
|
+
let ms = parseInt(value, 10);
|
|
2445
|
+
if (token.length === 1) ms *= 100;
|
|
2446
|
+
else if (token.length === 2) ms *= 10;
|
|
2447
|
+
millisecond = ms;
|
|
2448
|
+
break;
|
|
2449
|
+
case "a":
|
|
2450
|
+
isPM = value.toLowerCase().includes("p");
|
|
2451
|
+
break;
|
|
2452
|
+
}
|
|
2453
|
+
});
|
|
2454
|
+
if (is12Hour && isPM && hour < 12) {
|
|
2455
|
+
hour += 12;
|
|
2456
|
+
} else if (is12Hour && !isPM && hour === 12) {
|
|
2457
|
+
hour = 0;
|
|
2458
|
+
}
|
|
2459
|
+
if (!isValidYear(year)) throw new Error(`Invalid year in date string: ${dateString}`);
|
|
2460
|
+
if (!isValidMonth(month)) throw new Error(`Invalid month in date string: ${dateString}`);
|
|
2461
|
+
if (!isValidDayOfMonth(day)) throw new Error(`Invalid day in date string: ${dateString}`);
|
|
2462
|
+
if (!isValidHour(hour)) throw new Error(`Invalid hour in date string: ${dateString}`);
|
|
2463
|
+
if (!isValidMinute(minute)) throw new Error(`Invalid minute in date string: ${dateString}`);
|
|
2464
|
+
if (!isValidSecond(second)) throw new Error(`Invalid second in date string: ${dateString}`);
|
|
2465
|
+
if (!isValidMillisecond(millisecond)) throw new Error(`Invalid millisecond in date string: ${dateString}`);
|
|
2466
|
+
return TimeInstant.fromParameters({
|
|
2467
|
+
year,
|
|
2468
|
+
month,
|
|
2469
|
+
date: day,
|
|
2470
|
+
hours: hour,
|
|
2471
|
+
minutes: minute,
|
|
2472
|
+
seconds: second,
|
|
2473
|
+
milliseconds: millisecond
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
2297
2476
|
|
|
2298
2477
|
// src/Logger.ts
|
|
2299
2478
|
var LEVELS = ["trace", "log", "debug", "info", "warn", "error"];
|