@stacksjs/datetime 0.59.11 → 0.61.0
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/dist/index.js +197 -132
- package/package.json +2 -2
- package/dist/index.d.ts +0 -5
package/dist/index.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// src/index.ts
|
|
3
3
|
import {useDateFormat, useNow} from "@stacksjs/utils";
|
|
4
4
|
|
|
5
|
-
// ../../../../node_modules/@formkit/tempo/dist/
|
|
6
|
-
var iso8601 = function(
|
|
7
|
-
const matches =
|
|
5
|
+
// ../../../../node_modules/@formkit/tempo/dist/iso8601.mjs
|
|
6
|
+
var iso8601 = function(date) {
|
|
7
|
+
const matches = date.match(iso8601Match);
|
|
8
8
|
if (matches) {
|
|
9
9
|
const month = Number(matches[2]);
|
|
10
10
|
if (month < 1 || month > 12)
|
|
11
11
|
return false;
|
|
12
12
|
if (typeof matches[3] !== undefined) {
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
13
|
+
const date2 = Number(matches[3]);
|
|
14
|
+
if (date2 < 1 || date2 > 31)
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
17
|
if (typeof matches[4] !== undefined) {
|
|
@@ -23,6 +23,9 @@ var iso8601 = function(date2) {
|
|
|
23
23
|
}
|
|
24
24
|
return false;
|
|
25
25
|
};
|
|
26
|
+
var iso8601Match = /^([0-9]{4})-([0-1][0-9])(?:-([0-3][0-9]))?(?:[T ]?([0-2][0-9])(?::([0-5][0-9]))?(?::([0-5][0-9]))?)?(?:\.[0-9]+)?(Z|(?:\+|\-)[0-9]{2}:?[0-9]{2})?$/;
|
|
27
|
+
|
|
28
|
+
// ../../../../node_modules/@formkit/tempo/dist/date.mjs
|
|
26
29
|
var normalize = function(date2) {
|
|
27
30
|
const matches = date2.match(iso8601Match);
|
|
28
31
|
if (matches && typeof matches[4] === "undefined") {
|
|
@@ -45,6 +48,8 @@ var date = function(date2) {
|
|
|
45
48
|
}
|
|
46
49
|
throw new Error(`Non ISO 8601 compliant date (${date2}).`);
|
|
47
50
|
};
|
|
51
|
+
|
|
52
|
+
// ../../../../node_modules/@formkit/tempo/dist/monthEnd.mjs
|
|
48
53
|
var monthEnd = function(inputDate) {
|
|
49
54
|
const d = date(inputDate);
|
|
50
55
|
d.setDate(1);
|
|
@@ -52,49 +57,62 @@ var monthEnd = function(inputDate) {
|
|
|
52
57
|
d.setDate(0);
|
|
53
58
|
return d;
|
|
54
59
|
};
|
|
60
|
+
|
|
61
|
+
// ../../../../node_modules/@formkit/tempo/dist/monthDays.mjs
|
|
55
62
|
var monthDays = function(inputDate) {
|
|
56
63
|
const d = monthEnd(inputDate);
|
|
57
64
|
return d.getDate();
|
|
58
65
|
};
|
|
66
|
+
|
|
67
|
+
// ../../../../node_modules/@formkit/tempo/dist/common.mjs
|
|
68
|
+
var fixedLengthByOffset = function(offsetString) {
|
|
69
|
+
if (/^[+-]\d{2}:\d{2}/.test(offsetString)) {
|
|
70
|
+
return 6;
|
|
71
|
+
}
|
|
72
|
+
if (/^[+-]\d{4}/.test(offsetString)) {
|
|
73
|
+
return 5;
|
|
74
|
+
}
|
|
75
|
+
throw new Error("Invalid offset format");
|
|
76
|
+
};
|
|
59
77
|
var normStr = function(part) {
|
|
60
78
|
if (part.type === "literal") {
|
|
61
79
|
part.value = part.value.normalize("NFKC");
|
|
62
80
|
}
|
|
63
81
|
return part;
|
|
64
82
|
};
|
|
65
|
-
var fill = function(inputDate,
|
|
66
|
-
const partMap = createPartMap(inputDate,
|
|
83
|
+
var fill = function(inputDate, parts, locale, genitive = false, offset = null) {
|
|
84
|
+
const partMap = createPartMap(inputDate, parts, locale, genitive);
|
|
67
85
|
const d = date(inputDate);
|
|
68
86
|
function value({ partName, partValue, token }) {
|
|
69
87
|
if (partName === "literal")
|
|
70
88
|
return partValue;
|
|
71
89
|
const value2 = partMap[partName];
|
|
72
90
|
if (partName === "hour" && token === "H") {
|
|
73
|
-
return value2.replace(/^0/, "");
|
|
91
|
+
return value2.replace(/^0/, "") || "0";
|
|
74
92
|
}
|
|
75
|
-
if (
|
|
93
|
+
if (["mm", "ss", "MM"].includes(token) && value2.length === 1) {
|
|
76
94
|
return `0${value2}`;
|
|
77
95
|
}
|
|
78
96
|
if (partName === "dayPeriod") {
|
|
79
|
-
const p =
|
|
97
|
+
const p = ap2(d.getUTCHours() < 12 ? "am" : "pm", locale);
|
|
80
98
|
return token === "A" ? p.toUpperCase() : p.toLowerCase();
|
|
81
99
|
}
|
|
82
100
|
if (partName === "timeZoneName") {
|
|
83
|
-
return
|
|
101
|
+
return offset != null ? offset : minsToOffset(-1 * d.getTimezoneOffset(), token);
|
|
84
102
|
}
|
|
85
103
|
return value2;
|
|
86
104
|
}
|
|
87
|
-
return
|
|
105
|
+
return parts.map((part) => {
|
|
88
106
|
return {
|
|
89
107
|
...part,
|
|
90
108
|
value: value(part)
|
|
91
109
|
};
|
|
92
110
|
});
|
|
93
111
|
};
|
|
94
|
-
var createPartMap = function(inputDate,
|
|
112
|
+
var createPartMap = function(inputDate, parts, locale, genitive = false) {
|
|
95
113
|
const d = date(inputDate);
|
|
96
|
-
const hour12 =
|
|
97
|
-
const hour24 =
|
|
114
|
+
const hour12 = parts.filter((part) => part.hour12);
|
|
115
|
+
const hour24 = parts.filter((part) => !part.hour12);
|
|
98
116
|
const valueParts = [];
|
|
99
117
|
const genitiveParts = [];
|
|
100
118
|
function addValues(requestedParts, hour122 = false) {
|
|
@@ -141,23 +159,33 @@ var createPartMap = function(inputDate, parts2, locale, genitive = false) {
|
|
|
141
159
|
return map;
|
|
142
160
|
}, {});
|
|
143
161
|
};
|
|
144
|
-
var minsToOffset = function(timeDiffInMins) {
|
|
162
|
+
var minsToOffset = function(timeDiffInMins, token = "Z") {
|
|
145
163
|
const hours = String(Math.floor(Math.abs(timeDiffInMins / 60))).padStart(2, "0");
|
|
146
164
|
const mins = String(Math.abs(timeDiffInMins % 60)).padStart(2, "0");
|
|
147
165
|
const sign = timeDiffInMins < 0 ? "-" : "+";
|
|
148
|
-
|
|
166
|
+
if (token === "ZZ") {
|
|
167
|
+
return `${sign}${hours}${mins}`;
|
|
168
|
+
}
|
|
169
|
+
return `${sign}${hours}:${mins}`;
|
|
149
170
|
};
|
|
150
|
-
var offsetToMins = function(
|
|
151
|
-
validOffset(
|
|
152
|
-
const [_, sign, hours, mins] =
|
|
171
|
+
var offsetToMins = function(offset, token) {
|
|
172
|
+
validOffset(offset, token);
|
|
173
|
+
const [_, sign, hours, mins] = offset.match(/([+-])([0-3][0-9]):?([0-6][0-9])/);
|
|
153
174
|
const offsetInMins = Number(hours) * 60 + Number(mins);
|
|
154
175
|
return sign === "+" ? offsetInMins : -offsetInMins;
|
|
155
176
|
};
|
|
156
|
-
var validOffset = function(
|
|
157
|
-
const valid =
|
|
177
|
+
var validOffset = function(offset, token = "Z") {
|
|
178
|
+
const valid = ((token2) => {
|
|
179
|
+
switch (token2) {
|
|
180
|
+
case "Z":
|
|
181
|
+
return /^([+-])[0-3][0-9]:[0-6][0-9]$/.test(offset);
|
|
182
|
+
case "ZZ":
|
|
183
|
+
return /^([+-])[0-3][0-9][0-6][0-9]$/.test(offset);
|
|
184
|
+
}
|
|
185
|
+
})(token);
|
|
158
186
|
if (!valid)
|
|
159
|
-
throw new Error(`Invalid offset: ${
|
|
160
|
-
return
|
|
187
|
+
throw new Error(`Invalid offset: ${offset}`);
|
|
188
|
+
return offset;
|
|
161
189
|
};
|
|
162
190
|
var escapeTokens = function(str) {
|
|
163
191
|
return clockAgnostic.concat(clock24).concat(clock12).sort((a, b) => a[0].length > b[0].length ? 1 : -1).reduce((target, part) => {
|
|
@@ -167,9 +195,9 @@ var escapeTokens = function(str) {
|
|
|
167
195
|
var isNumeric = function(part) {
|
|
168
196
|
return ["numeric", "2-digit"].includes(part.partValue);
|
|
169
197
|
};
|
|
170
|
-
var validate = function(
|
|
198
|
+
var validate = function(parts) {
|
|
171
199
|
let lastPart = undefined;
|
|
172
|
-
for (const part of
|
|
200
|
+
for (const part of parts) {
|
|
173
201
|
if (part.partName === "literal" && !isNaN(parseFloat(part.partValue))) {
|
|
174
202
|
throw new Error(`Numbers in format (${part.partValue}).`);
|
|
175
203
|
}
|
|
@@ -180,9 +208,71 @@ var validate = function(parts2) {
|
|
|
180
208
|
}
|
|
181
209
|
lastPart = part;
|
|
182
210
|
}
|
|
183
|
-
return
|
|
211
|
+
return parts;
|
|
212
|
+
};
|
|
213
|
+
var getOffsetFormat = function(format) {
|
|
214
|
+
if (typeof format === "string") {
|
|
215
|
+
return format.includes("ZZ") ? "ZZ" : "Z";
|
|
216
|
+
}
|
|
217
|
+
return "time" in format && format.time === "full" ? "Z" : "ZZ";
|
|
218
|
+
};
|
|
219
|
+
var specDate = "1999-03-04T02:05:01.000Z";
|
|
220
|
+
var memoParts = new Map;
|
|
221
|
+
var clockAgnostic = [
|
|
222
|
+
["YYYY", { year: "numeric" }],
|
|
223
|
+
["YY", { year: "2-digit" }],
|
|
224
|
+
["MMMM", { month: "long" }],
|
|
225
|
+
["MMM", { month: "short" }],
|
|
226
|
+
["MM", { month: "2-digit" }],
|
|
227
|
+
["M", { month: "numeric" }],
|
|
228
|
+
["DD", { day: "2-digit" }],
|
|
229
|
+
["D", { day: "numeric" }],
|
|
230
|
+
["dddd", { weekday: "long" }],
|
|
231
|
+
["ddd", { weekday: "short" }],
|
|
232
|
+
["d", { weekday: "narrow" }],
|
|
233
|
+
["mm", { minute: "2-digit" }],
|
|
234
|
+
["m", { minute: "numeric" }],
|
|
235
|
+
["ss", { second: "2-digit" }],
|
|
236
|
+
["s", { second: "numeric" }],
|
|
237
|
+
["ZZ", { timeZoneName: "long" }],
|
|
238
|
+
["Z", { timeZoneName: "short" }]
|
|
239
|
+
];
|
|
240
|
+
var clock24 = [
|
|
241
|
+
["HH", { hour: "2-digit" }],
|
|
242
|
+
["H", { hour: "numeric" }]
|
|
243
|
+
];
|
|
244
|
+
var clock12 = [
|
|
245
|
+
["hh", { hour: "2-digit" }],
|
|
246
|
+
["h", { hour: "numeric" }],
|
|
247
|
+
["a", { dayPeriod: "narrow" }],
|
|
248
|
+
["A", { dayPeriod: "narrow" }]
|
|
249
|
+
];
|
|
250
|
+
var fixedLength = {
|
|
251
|
+
DD: 2,
|
|
252
|
+
HH: 2,
|
|
253
|
+
MM: 2,
|
|
254
|
+
YY: 2,
|
|
255
|
+
YYYY: 4,
|
|
256
|
+
hh: 2,
|
|
257
|
+
mm: 2,
|
|
258
|
+
ss: 2
|
|
184
259
|
};
|
|
185
|
-
var
|
|
260
|
+
var genitiveTokens = ["MMMM", "MMM", "dddd", "ddd"];
|
|
261
|
+
var tokens = new Map([...clockAgnostic, ...clock24, ...clock12].map((format) => {
|
|
262
|
+
return [format[0], format];
|
|
263
|
+
}));
|
|
264
|
+
var dayPeriodMap = new Map;
|
|
265
|
+
var styles = [
|
|
266
|
+
"full",
|
|
267
|
+
"long",
|
|
268
|
+
"medium",
|
|
269
|
+
"short"
|
|
270
|
+
];
|
|
271
|
+
var two = (n) => String(n).padStart(2, "0");
|
|
272
|
+
var four = (n) => String(n).padStart(2, "0");
|
|
273
|
+
|
|
274
|
+
// ../../../../node_modules/@formkit/tempo/dist/ap.mjs
|
|
275
|
+
var ap2 = function(ampm, locale) {
|
|
186
276
|
const l = dayPeriodMap.get(locale);
|
|
187
277
|
if (l && l[ampm])
|
|
188
278
|
return l[ampm];
|
|
@@ -201,14 +291,28 @@ var ap = function(ampm, locale) {
|
|
|
201
291
|
}
|
|
202
292
|
return ampm;
|
|
203
293
|
};
|
|
204
|
-
|
|
294
|
+
|
|
295
|
+
// ../../../../node_modules/@formkit/tempo/dist/applyOffset.mjs
|
|
296
|
+
var applyOffset = function(dateInput, offset = "+00:00") {
|
|
205
297
|
const d = date(dateInput);
|
|
206
|
-
const
|
|
298
|
+
const token = (() => {
|
|
299
|
+
switch (fixedLengthByOffset(offset)) {
|
|
300
|
+
case 5:
|
|
301
|
+
return "ZZ";
|
|
302
|
+
case 6:
|
|
303
|
+
return "Z";
|
|
304
|
+
}
|
|
305
|
+
})();
|
|
306
|
+
const timeDiffInMins = offsetToMins(offset, token);
|
|
207
307
|
return new Date(d.getTime() + timeDiffInMins * 1000 * 60);
|
|
208
308
|
};
|
|
309
|
+
|
|
310
|
+
// ../../../../node_modules/@formkit/tempo/dist/deviceTZ.mjs
|
|
209
311
|
var deviceTZ = function() {
|
|
210
312
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
211
313
|
};
|
|
314
|
+
|
|
315
|
+
// ../../../../node_modules/@formkit/tempo/dist/offset.mjs
|
|
212
316
|
var relativeTime = function(d, timeZone) {
|
|
213
317
|
const utcParts = new Intl.DateTimeFormat("en-US", {
|
|
214
318
|
year: "numeric",
|
|
@@ -220,26 +324,28 @@ var relativeTime = function(d, timeZone) {
|
|
|
220
324
|
timeZone,
|
|
221
325
|
hourCycle: "h23"
|
|
222
326
|
}).formatToParts(d).map(normStr);
|
|
223
|
-
const
|
|
327
|
+
const parts = {};
|
|
224
328
|
utcParts.forEach((part) => {
|
|
225
|
-
|
|
329
|
+
parts[part.type] = part.value;
|
|
226
330
|
});
|
|
227
|
-
return new Date(`${
|
|
331
|
+
return new Date(`${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}Z`);
|
|
228
332
|
};
|
|
229
|
-
var offset = function(utcTime, tzA = "UTC", tzB = "device") {
|
|
333
|
+
var offset = function(utcTime, tzA = "UTC", tzB = "device", timeZoneToken = "Z") {
|
|
230
334
|
var _a;
|
|
231
335
|
tzB = tzB === "device" ? (_a = deviceTZ()) != null ? _a : "utc" : tzB;
|
|
232
336
|
const d = date(utcTime);
|
|
233
337
|
const timeA = relativeTime(d, tzA);
|
|
234
338
|
const timeB = relativeTime(d, tzB);
|
|
235
339
|
const timeDiffInMins = (timeB.getTime() - timeA.getTime()) / 1000 / 60;
|
|
236
|
-
return minsToOffset(timeDiffInMins);
|
|
340
|
+
return minsToOffset(timeDiffInMins, timeZoneToken);
|
|
237
341
|
};
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
342
|
+
|
|
343
|
+
// ../../../../node_modules/@formkit/tempo/dist/parts.mjs
|
|
344
|
+
var parts = function(format, locale) {
|
|
345
|
+
if (styles.includes(format) || typeof format === "object") {
|
|
346
|
+
return styleParts(format, locale);
|
|
241
347
|
}
|
|
242
|
-
let f =
|
|
348
|
+
let f = format;
|
|
243
349
|
let match = 0;
|
|
244
350
|
const testPattern = (pattern) => {
|
|
245
351
|
if (!pattern[2])
|
|
@@ -293,17 +399,17 @@ var parts = function(format2, locale) {
|
|
|
293
399
|
};
|
|
294
400
|
}).filter((part) => !(part.partName === "literal" && part.partValue === ""));
|
|
295
401
|
};
|
|
296
|
-
var styleParts = function(
|
|
402
|
+
var styleParts = function(format, locale) {
|
|
297
403
|
const options = {
|
|
298
404
|
timeZone: "UTC"
|
|
299
405
|
};
|
|
300
|
-
if (typeof
|
|
301
|
-
options.dateStyle =
|
|
406
|
+
if (typeof format === "string") {
|
|
407
|
+
options.dateStyle = format;
|
|
302
408
|
} else {
|
|
303
|
-
if ("date" in
|
|
304
|
-
options.dateStyle =
|
|
305
|
-
if ("time" in
|
|
306
|
-
options.timeStyle =
|
|
409
|
+
if ("date" in format)
|
|
410
|
+
options.dateStyle = format.date;
|
|
411
|
+
if ("time" in format)
|
|
412
|
+
options.timeStyle = format.time;
|
|
307
413
|
}
|
|
308
414
|
const formatter = new Intl.DateTimeFormat(locale, options);
|
|
309
415
|
const segments = formatter.formatToParts(new Date(specDate)).map(normStr);
|
|
@@ -312,7 +418,7 @@ var styleParts = function(format2, locale) {
|
|
|
312
418
|
const hourType = hourPart && hourPart.value === "23" ? 24 : 12;
|
|
313
419
|
return segments.map((part) => {
|
|
314
420
|
const partName = part.type;
|
|
315
|
-
const formatPattern = guessPattern(part.type, part.value, locale, part.type === "hour" ? hourType : undefined);
|
|
421
|
+
const formatPattern = guessPattern(part.type, part.value, locale, part.type === "hour" ? hourType : undefined, options);
|
|
316
422
|
if (formatPattern === undefined)
|
|
317
423
|
return;
|
|
318
424
|
const partValue = formatPattern[1][partName];
|
|
@@ -330,7 +436,7 @@ var styleParts = function(format2, locale) {
|
|
|
330
436
|
};
|
|
331
437
|
}).filter((part) => !!part);
|
|
332
438
|
};
|
|
333
|
-
var guessPattern = function(partName, partValue, locale, hour) {
|
|
439
|
+
var guessPattern = function(partName, partValue, locale, hour, options) {
|
|
334
440
|
const l = partValue.length;
|
|
335
441
|
const n = !isNaN(Number(partValue));
|
|
336
442
|
let style;
|
|
@@ -372,31 +478,30 @@ var guessPattern = function(partName, partValue, locale, hour) {
|
|
|
372
478
|
case "literal":
|
|
373
479
|
return [partValue, { literal: partValue }, new RegExp("")];
|
|
374
480
|
case "timeZoneName":
|
|
375
|
-
|
|
376
|
-
return offset2.length === 2 && offset2[1].length === 4 ? tokens.get("ZZ") : tokens.get("Z");
|
|
481
|
+
return options.timeStyle === "full" ? tokens.get("Z") : tokens.get("ZZ");
|
|
377
482
|
default:
|
|
378
483
|
return;
|
|
379
484
|
}
|
|
380
485
|
};
|
|
381
486
|
var partStyle = function(locale, part, value) {
|
|
382
487
|
if (!memoParts.has(locale)) {
|
|
383
|
-
const
|
|
488
|
+
const date16 = new Date(specDate);
|
|
384
489
|
const weekdays = [3, 8, 9, 7, 6, 4, 3];
|
|
385
490
|
const parts2 = ["weekday", "month", "dayPeriod"];
|
|
386
491
|
const partStyles = ["long", "short", "narrow"];
|
|
387
492
|
const formats2 = {};
|
|
388
493
|
for (let i = 0;i < 12; i++) {
|
|
389
|
-
|
|
494
|
+
date16.setMonth(0 + i);
|
|
390
495
|
if (i in weekdays)
|
|
391
|
-
|
|
392
|
-
|
|
496
|
+
date16.setDate(weekdays[i]);
|
|
497
|
+
date16.setUTCHours(8 + i);
|
|
393
498
|
for (const style of partStyles) {
|
|
394
|
-
const segments = new Intl.DateTimeFormat(locale, parts2.reduce((options, part2) => Object.assign(options, { [part2]: style }), { hour12: true, timeZone: "UTC" })).formatToParts(
|
|
499
|
+
const segments = new Intl.DateTimeFormat(locale, parts2.reduce((options, part2) => Object.assign(options, { [part2]: style }), { hour12: true, timeZone: "UTC" })).formatToParts(date16).map(normStr);
|
|
395
500
|
if (style === "long" || style === "short") {
|
|
396
501
|
const genitiveFormattedParts = new Intl.DateTimeFormat(locale, {
|
|
397
502
|
dateStyle: style === "short" ? "medium" : "long",
|
|
398
503
|
timeZone: "UTC"
|
|
399
|
-
}).formatToParts(
|
|
504
|
+
}).formatToParts(date16).map(normStr);
|
|
400
505
|
const genitiveMonth = genitiveFormattedParts.find((part2) => part2.type === "month");
|
|
401
506
|
const index = segments.findIndex((part2) => part2.type === "month");
|
|
402
507
|
if (index > -1 && genitiveMonth)
|
|
@@ -417,13 +522,19 @@ var partStyle = function(locale, part, value) {
|
|
|
417
522
|
const formats = memoParts.get(locale);
|
|
418
523
|
return formats ? formats[part][value] : undefined;
|
|
419
524
|
};
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
525
|
+
|
|
526
|
+
// ../../../../node_modules/@formkit/tempo/dist/removeOffset.mjs
|
|
527
|
+
var removeOffset = function(dateInput, offset3 = "+00:00") {
|
|
528
|
+
const positive = offset3.slice(0, 1) === "+";
|
|
529
|
+
return applyOffset(dateInput, offset3.replace(positive ? "+" : "-", positive ? "-" : "+"));
|
|
423
530
|
};
|
|
531
|
+
|
|
532
|
+
// ../../../../node_modules/@formkit/tempo/dist/deviceLocale.mjs
|
|
424
533
|
var deviceLocale = function() {
|
|
425
534
|
return Intl.DateTimeFormat().resolvedOptions().locale;
|
|
426
535
|
};
|
|
536
|
+
|
|
537
|
+
// ../../../../node_modules/@formkit/tempo/dist/format.mjs
|
|
427
538
|
var format = function(inputDateOrOptions, format2 = "long", locale = "device", genitive = false, partFilter) {
|
|
428
539
|
let tz, forceOffset;
|
|
429
540
|
if (typeof inputDateOrOptions === "object" && !(inputDateOrOptions instanceof Date)) {
|
|
@@ -439,7 +550,7 @@ var format = function(inputDateOrOptions, format2 = "long", locale = "device", g
|
|
|
439
550
|
if (format2 === "ISO8601")
|
|
440
551
|
return date(inputDateOrOptions).toISOString();
|
|
441
552
|
if (tz) {
|
|
442
|
-
forceOffset = offset(inputDateOrOptions, "utc", tz);
|
|
553
|
+
forceOffset = offset(inputDateOrOptions, "utc", tz, getOffsetFormat(format2));
|
|
443
554
|
}
|
|
444
555
|
tz != null || (tz = deviceTZ());
|
|
445
556
|
if ((tz == null ? undefined : tz.toLowerCase()) !== "utc") {
|
|
@@ -450,9 +561,13 @@ var format = function(inputDateOrOptions, format2 = "long", locale = "device", g
|
|
|
450
561
|
}
|
|
451
562
|
return fill(inputDateOrOptions, parts(format2, locale).filter(partFilter != null ? partFilter : () => true), locale, genitive, forceOffset).map((p) => p.value).join("");
|
|
452
563
|
};
|
|
564
|
+
|
|
565
|
+
// ../../../../node_modules/@formkit/tempo/dist/formatStr.mjs
|
|
453
566
|
var formatStr = function(format2, locale = "en", escapeLiterals = false, filterParts = () => true) {
|
|
454
567
|
return parts(format2, locale).filter(filterParts).reduce((f, p) => f += escapeLiterals && p.partName === "literal" ? escapeTokens(p.token) : p.token, "").normalize("NFKC");
|
|
455
568
|
};
|
|
569
|
+
|
|
570
|
+
// ../../../../node_modules/@formkit/tempo/dist/fourDigitYear.mjs
|
|
456
571
|
var fourDigitYear = function(value) {
|
|
457
572
|
const y = (new Date()).getFullYear();
|
|
458
573
|
const currentYear = y % 100;
|
|
@@ -460,6 +575,8 @@ var fourDigitYear = function(value) {
|
|
|
460
575
|
const parsedYear = Number(value);
|
|
461
576
|
return (century + (parsedYear > currentYear + 20 ? -1 : 0)) * 100 + parsedYear;
|
|
462
577
|
};
|
|
578
|
+
|
|
579
|
+
// ../../../../node_modules/@formkit/tempo/dist/range.mjs
|
|
463
580
|
var range = function(token, locale = "en", genitive = false) {
|
|
464
581
|
const r = (n, c) => Array(n).fill("").map((_, i) => `${c(i)}`);
|
|
465
582
|
if (token === "M")
|
|
@@ -474,9 +591,9 @@ var range = function(token, locale = "en", genitive = false) {
|
|
|
474
591
|
if (token.startsWith("d"))
|
|
475
592
|
return r(7, (i) => `0${i + 2}`).map((d) => format(`2022-10-${d}`, token, locale));
|
|
476
593
|
if (token === "a")
|
|
477
|
-
return [
|
|
594
|
+
return [ap2("am", locale).toLowerCase(), ap2("pm", locale).toLowerCase()];
|
|
478
595
|
if (token === "A")
|
|
479
|
-
return [
|
|
596
|
+
return [ap2("am", locale).toUpperCase(), ap2("pm", locale).toUpperCase()];
|
|
480
597
|
if (token.startsWith("Y")) {
|
|
481
598
|
const year = (new Date()).getFullYear();
|
|
482
599
|
return r(120, (i) => i + 1).reduce((ranges, i) => {
|
|
@@ -496,14 +613,16 @@ var range = function(token, locale = "en", genitive = false) {
|
|
|
496
613
|
return r(60, (i) => `${token.length > 1 && i < 10 ? "0" : ""}${i}`);
|
|
497
614
|
return [];
|
|
498
615
|
};
|
|
499
|
-
|
|
616
|
+
|
|
617
|
+
// ../../../../node_modules/@formkit/tempo/dist/parse.mjs
|
|
618
|
+
var parse = function(dateStrOrOptions, format3 = "ISO8601", locale = "device") {
|
|
500
619
|
let partFilter = () => true;
|
|
501
620
|
let dateStr;
|
|
502
621
|
let dateOverflow = "backward";
|
|
503
622
|
if (typeof dateStrOrOptions === "object") {
|
|
504
623
|
({
|
|
505
624
|
date: dateStr,
|
|
506
|
-
format:
|
|
625
|
+
format: format3 = "ISO8601",
|
|
507
626
|
locale = "device",
|
|
508
627
|
dateOverflow = "backward",
|
|
509
628
|
partFilter = () => true
|
|
@@ -514,12 +633,12 @@ var parse = function(dateStrOrOptions, format2 = "ISO8601", locale = "device") {
|
|
|
514
633
|
if (!dateStr)
|
|
515
634
|
throw new Error("parse() requires a date string.");
|
|
516
635
|
const invalid = () => {
|
|
517
|
-
throw new Error(`Date (${dateStr}) does not match format (${formatStr(
|
|
636
|
+
throw new Error(`Date (${dateStr}) does not match format (${formatStr(format3, locale)})`);
|
|
518
637
|
};
|
|
519
|
-
if (
|
|
638
|
+
if (format3 === "ISO8601")
|
|
520
639
|
return date(dateStr);
|
|
521
|
-
const genitive = styles.includes(
|
|
522
|
-
const formatParts = validate(parts(
|
|
640
|
+
const genitive = styles.includes(format3) || typeof format3 === "object";
|
|
641
|
+
const formatParts = validate(parts(format3, locale).filter(partFilter));
|
|
523
642
|
if (!formatParts.length)
|
|
524
643
|
throw new Error("parse() requires a pattern.");
|
|
525
644
|
let parsedParts;
|
|
@@ -538,7 +657,7 @@ var parse = function(dateStrOrOptions, format2 = "ISO8601", locale = "device") {
|
|
|
538
657
|
["ss", 0]
|
|
539
658
|
]);
|
|
540
659
|
let a = null;
|
|
541
|
-
let
|
|
660
|
+
let offset4 = "";
|
|
542
661
|
parsedParts.forEach((part) => {
|
|
543
662
|
if (part.partName === "literal")
|
|
544
663
|
return;
|
|
@@ -560,9 +679,9 @@ var parse = function(dateStrOrOptions, format2 = "ISO8601", locale = "device") {
|
|
|
560
679
|
} else if (t === "M") {
|
|
561
680
|
parsed.set("MM", v);
|
|
562
681
|
} else if (t === "a" || t === "A") {
|
|
563
|
-
a = part.value.toLowerCase() ===
|
|
564
|
-
} else if (t === "Z") {
|
|
565
|
-
|
|
682
|
+
a = part.value.toLowerCase() === ap2("am", locale).toLowerCase();
|
|
683
|
+
} else if (t === "Z" || t === "ZZ") {
|
|
684
|
+
offset4 = validOffset(part.value, t);
|
|
566
685
|
} else {
|
|
567
686
|
const values = range(t, locale, genitive);
|
|
568
687
|
const index = values.indexOf(part.value);
|
|
@@ -590,7 +709,7 @@ var parse = function(dateStrOrOptions, format2 = "ISO8601", locale = "device") {
|
|
|
590
709
|
if (maxDaysInMonth < D && dateOverflow === "throw")
|
|
591
710
|
throw new Error(`Invalid date ${four(Y)}-${two(M + 1)}-${two(D)}`);
|
|
592
711
|
D = dateOverflow === "backward" ? Math.min(D, maxDaysInMonth) : D;
|
|
593
|
-
const isoString = `${four(Y)}-${two(M + 1)}-${two(D)}T${two(h)}:${two(m)}:${two(s)}${
|
|
712
|
+
const isoString = `${four(Y)}-${two(M + 1)}-${two(D)}T${two(h)}:${two(m)}:${two(s)}${offset4}`;
|
|
594
713
|
const d = new Date(isoString);
|
|
595
714
|
if (isFinite(+d))
|
|
596
715
|
return d;
|
|
@@ -598,9 +717,9 @@ var parse = function(dateStrOrOptions, format2 = "ISO8601", locale = "device") {
|
|
|
598
717
|
};
|
|
599
718
|
var parseParts = function(dateStr, formatParts) {
|
|
600
719
|
let i = 0;
|
|
601
|
-
const advance = (
|
|
602
|
-
|
|
603
|
-
|
|
720
|
+
const advance = (parts22) => [
|
|
721
|
+
parts22[i++],
|
|
722
|
+
parts22[i]
|
|
604
723
|
];
|
|
605
724
|
let pos = 0;
|
|
606
725
|
const parsed = [];
|
|
@@ -611,6 +730,8 @@ var parseParts = function(dateStr, formatParts) {
|
|
|
611
730
|
let len = 1;
|
|
612
731
|
if (current.partName === "literal") {
|
|
613
732
|
len = current.partValue.length;
|
|
733
|
+
} else if (current.partName === "timeZoneName") {
|
|
734
|
+
len = fixedLengthByOffset(dateStr.substring(pos));
|
|
614
735
|
} else if (current.token in fixedLength) {
|
|
615
736
|
len = fixedLength[current.token];
|
|
616
737
|
} else if (next) {
|
|
@@ -638,62 +759,6 @@ var parseParts = function(dateStr, formatParts) {
|
|
|
638
759
|
} while (n);
|
|
639
760
|
return parsed;
|
|
640
761
|
};
|
|
641
|
-
var iso8601Match = /^([0-9]{4})-([0-1][0-9])(?:-([0-3][0-9]))?(?:[T ]?([0-2][0-9])(?::([0-5][0-9]))?(?::([0-5][0-9]))?)?(?:\.[0-9]+)?(Z|(?:\+|\-)[0-9]{4})?$/;
|
|
642
|
-
var specDate = "1999-03-04T02:05:01.000Z";
|
|
643
|
-
var memoParts = new Map;
|
|
644
|
-
var clockAgnostic = [
|
|
645
|
-
["YYYY", { year: "numeric" }],
|
|
646
|
-
["YY", { year: "2-digit" }],
|
|
647
|
-
["MMMM", { month: "long" }],
|
|
648
|
-
["MMM", { month: "short" }],
|
|
649
|
-
["MM", { month: "2-digit" }],
|
|
650
|
-
["M", { month: "numeric" }],
|
|
651
|
-
["DD", { day: "2-digit" }],
|
|
652
|
-
["D", { day: "numeric" }],
|
|
653
|
-
["dddd", { weekday: "long" }],
|
|
654
|
-
["ddd", { weekday: "short" }],
|
|
655
|
-
["d", { weekday: "narrow" }],
|
|
656
|
-
["mm", { minute: "2-digit" }],
|
|
657
|
-
["m", { minute: "numeric" }],
|
|
658
|
-
["ss", { second: "2-digit" }],
|
|
659
|
-
["s", { second: "numeric" }],
|
|
660
|
-
["Z", { timeZoneName: "short" }]
|
|
661
|
-
];
|
|
662
|
-
var clock24 = [
|
|
663
|
-
["HH", { hour: "2-digit" }],
|
|
664
|
-
["H", { hour: "numeric" }]
|
|
665
|
-
];
|
|
666
|
-
var clock12 = [
|
|
667
|
-
["hh", { hour: "2-digit" }],
|
|
668
|
-
["h", { hour: "numeric" }],
|
|
669
|
-
["a", { dayPeriod: "narrow" }],
|
|
670
|
-
["A", { dayPeriod: "narrow" }]
|
|
671
|
-
];
|
|
672
|
-
var fixedLength = {
|
|
673
|
-
DD: 2,
|
|
674
|
-
HH: 2,
|
|
675
|
-
MM: 2,
|
|
676
|
-
YY: 2,
|
|
677
|
-
YYYY: 4,
|
|
678
|
-
hh: 2,
|
|
679
|
-
mm: 2,
|
|
680
|
-
ss: 2,
|
|
681
|
-
Z: 5
|
|
682
|
-
};
|
|
683
|
-
var genitiveTokens = ["MMMM", "MMM", "dddd", "ddd"];
|
|
684
|
-
var tokens = new Map([...clockAgnostic, ...clock24, ...clock12].map((format2) => {
|
|
685
|
-
return [format2[0], format2];
|
|
686
|
-
}));
|
|
687
|
-
var dayPeriodMap = new Map;
|
|
688
|
-
var styles = [
|
|
689
|
-
"full",
|
|
690
|
-
"long",
|
|
691
|
-
"medium",
|
|
692
|
-
"short"
|
|
693
|
-
];
|
|
694
|
-
var two = (n) => String(n).padStart(2, "0");
|
|
695
|
-
var four = (n) => String(n).padStart(2, "0");
|
|
696
|
-
|
|
697
762
|
// src/index.ts
|
|
698
763
|
var now = useNow;
|
|
699
764
|
var dateFormat = useDateFormat;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/datetime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.61.0",
|
|
5
5
|
"description": "The Stacks datetime helpers.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"prepublishOnly": "bun run build"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@formkit/tempo": "^0.
|
|
52
|
+
"@formkit/tempo": "^0.1.1",
|
|
53
53
|
"@stacksjs/utils": "latest"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|