chronal 0.0.20 → 0.0.22
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/esm/chainable/chronal.d.ts.map +1 -1
- package/esm/chainable/chronal.js +27 -81
- package/esm/core/dtf.js +1 -1
- package/esm/core/rtf.js +1 -1
- package/esm/lib/add-time.d.ts.map +1 -1
- package/esm/lib/add-time.js +2 -3
- package/esm/lib/days-in-month.d.ts.map +1 -1
- package/esm/lib/days-in-month.js +2 -8
- package/esm/lib/format-date.d.ts.map +1 -1
- package/esm/lib/format-date.js +50 -110
- package/esm/lib/from-now.js +14 -14
- package/esm/lib/is-between.d.ts.map +1 -1
- package/esm/lib/is-between.js +1 -2
- package/esm/lib/is-same.d.ts.map +1 -1
- package/esm/lib/is-same.js +18 -55
- package/esm/lib/is-today.js +1 -1
- package/esm/lib/months.js +1 -1
- package/esm/lib/parse-date.d.ts.map +1 -1
- package/esm/lib/parse-date.js +6 -5
- package/esm/lib/set-unit.d.ts.map +1 -1
- package/esm/lib/set-unit.js +2 -0
- package/esm/lib/subtract-time.d.ts.map +1 -1
- package/esm/lib/subtract-time.js +10 -18
- package/esm/lib/to-now.d.ts.map +1 -1
- package/esm/lib/to-now.js +14 -14
- package/esm/lib/week-of-year.d.ts.map +1 -1
- package/esm/lib/week-of-year.js +1 -8
- package/esm/lib/weekdays.js +1 -1
- package/package.json +1 -1
- package/script/chainable/chronal.d.ts.map +1 -1
- package/script/chainable/chronal.js +27 -81
- package/script/core/dtf.js +1 -1
- package/script/core/rtf.js +1 -1
- package/script/lib/add-time.d.ts.map +1 -1
- package/script/lib/add-time.js +2 -3
- package/script/lib/days-in-month.d.ts.map +1 -1
- package/script/lib/days-in-month.js +2 -8
- package/script/lib/format-date.d.ts.map +1 -1
- package/script/lib/format-date.js +50 -110
- package/script/lib/from-now.js +14 -14
- package/script/lib/is-between.d.ts.map +1 -1
- package/script/lib/is-between.js +1 -2
- package/script/lib/is-same.d.ts.map +1 -1
- package/script/lib/is-same.js +18 -55
- package/script/lib/is-today.js +1 -1
- package/script/lib/months.js +1 -1
- package/script/lib/parse-date.d.ts.map +1 -1
- package/script/lib/parse-date.js +6 -5
- package/script/lib/set-unit.d.ts.map +1 -1
- package/script/lib/set-unit.js +2 -0
- package/script/lib/subtract-time.d.ts.map +1 -1
- package/script/lib/subtract-time.js +10 -18
- package/script/lib/to-now.d.ts.map +1 -1
- package/script/lib/to-now.js +14 -14
- package/script/lib/week-of-year.d.ts.map +1 -1
- package/script/lib/week-of-year.js +1 -8
- package/script/lib/weekdays.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chronal.d.ts","sourceRoot":"","sources":["../../src/chainable/chronal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAA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AyC;IACzC,OAAO,EAAE,OAAO,UAAU,CAAC;IAC3B,2CAA2C;IAC3C,WAAW,EAAE,OAAO,WAAW,CAAC;IAChC,uCAAuC;IACvC,IAAI,EAAE,OAAO,UAAU,CAAC;IAGxB,iEAAiE;IACjE,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,KAAK,cAAc,GAAG;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC;IAC1E,MAAM,EAAE,OAAO,gBAAgB,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,cA+CrB,CAAC"}
|
package/esm/chainable/chronal.js
CHANGED
|
@@ -38,89 +38,35 @@ export const chronal = (date, options) => {
|
|
|
38
38
|
else {
|
|
39
39
|
d = new Date(date);
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
const instance = {
|
|
42
42
|
date: d,
|
|
43
43
|
timezone,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
toNow: function (locale) {
|
|
71
|
-
return toNow.call(this, locale);
|
|
72
|
-
},
|
|
73
|
-
// Query
|
|
74
|
-
diff: function (date, unit) {
|
|
75
|
-
return diff.call(this, date, unit);
|
|
76
|
-
},
|
|
77
|
-
isAfter: function (date) {
|
|
78
|
-
return isAfter.call(this, date);
|
|
79
|
-
},
|
|
80
|
-
isBefore: function (date) {
|
|
81
|
-
return isBefore.call(this, date);
|
|
82
|
-
},
|
|
83
|
-
isBetween: function (start, end, inclusivity) {
|
|
84
|
-
return isBetween.call(this, start, end, inclusivity);
|
|
85
|
-
},
|
|
86
|
-
isEqual: function (date) {
|
|
87
|
-
return isEqual.call(this, date);
|
|
88
|
-
},
|
|
89
|
-
isSame: function (date, unit) {
|
|
90
|
-
return isSame.call(this, date, unit);
|
|
91
|
-
},
|
|
92
|
-
isToday: function () {
|
|
93
|
-
return isToday.call(this);
|
|
94
|
-
},
|
|
95
|
-
isTomorrow: function () {
|
|
96
|
-
return isTomorrow.call(this);
|
|
97
|
-
},
|
|
98
|
-
isYesterday: function () {
|
|
99
|
-
return isYesterday.call(this);
|
|
100
|
-
},
|
|
101
|
-
isLeapYear: function () {
|
|
102
|
-
return isLeapYear.call(this);
|
|
103
|
-
},
|
|
104
|
-
isValid: function () {
|
|
105
|
-
return isValid.call(this);
|
|
106
|
-
},
|
|
107
|
-
// Get
|
|
108
|
-
get: function (unit) {
|
|
109
|
-
return getUnit.call(this, unit);
|
|
110
|
-
},
|
|
111
|
-
quarter: function () {
|
|
112
|
-
return getQuarter.call(this);
|
|
113
|
-
},
|
|
114
|
-
daysInMonth: function () {
|
|
115
|
-
return daysInMonth.call(this);
|
|
116
|
-
},
|
|
117
|
-
week: function () {
|
|
118
|
-
return weekOfYear.call(this);
|
|
119
|
-
},
|
|
120
|
-
// Utilities
|
|
121
|
-
until: function (end, step) {
|
|
122
|
-
return until.call(this, end, step);
|
|
123
|
-
},
|
|
44
|
+
add,
|
|
45
|
+
subtract,
|
|
46
|
+
startOf,
|
|
47
|
+
endOf,
|
|
48
|
+
set: setUnit,
|
|
49
|
+
clamp,
|
|
50
|
+
format,
|
|
51
|
+
fromNow,
|
|
52
|
+
toNow,
|
|
53
|
+
diff,
|
|
54
|
+
isAfter,
|
|
55
|
+
isBefore,
|
|
56
|
+
isBetween,
|
|
57
|
+
isEqual,
|
|
58
|
+
isSame,
|
|
59
|
+
isToday,
|
|
60
|
+
isTomorrow,
|
|
61
|
+
isYesterday,
|
|
62
|
+
isLeapYear,
|
|
63
|
+
isValid,
|
|
64
|
+
get: getUnit,
|
|
65
|
+
quarter: getQuarter,
|
|
66
|
+
daysInMonth,
|
|
67
|
+
week: weekOfYear,
|
|
68
|
+
until,
|
|
124
69
|
};
|
|
70
|
+
return instance;
|
|
125
71
|
};
|
|
126
72
|
chronal.config = setChronalConfig;
|
package/esm/core/dtf.js
CHANGED
package/esm/core/rtf.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-time.d.ts","sourceRoot":"","sources":["../../src/lib/add-time.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;GAUG;AAEH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"add-time.d.ts","sourceRoot":"","sources":["../../src/lib/add-time.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;GAUG;AAEH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CA0CzD"}
|
package/esm/lib/add-time.js
CHANGED
|
@@ -16,15 +16,14 @@ export function addTime(date, opt) {
|
|
|
16
16
|
const years = opt.years ?? 0;
|
|
17
17
|
const months = opt.months ?? 0;
|
|
18
18
|
const year = d.getUTCFullYear();
|
|
19
|
-
const month = d.getUTCMonth();
|
|
19
|
+
const month = d.getUTCMonth();
|
|
20
20
|
const day = d.getUTCDate();
|
|
21
21
|
// target year/month (allow overflow, normalize manually)
|
|
22
22
|
let targetMonth = month + months;
|
|
23
23
|
const targetYear = year + years + Math.floor(targetMonth / 12);
|
|
24
24
|
targetMonth = ((targetMonth % 12) + 12) % 12;
|
|
25
25
|
// last valid day of target month
|
|
26
|
-
const
|
|
27
|
-
const safeDay = Math.min(day, lastDayOfTargetMonth);
|
|
26
|
+
const safeDay = Math.min(day, new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate());
|
|
28
27
|
d = new Date(Date.UTC(targetYear, targetMonth, safeDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()));
|
|
29
28
|
}
|
|
30
29
|
// ===== time-based =====
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"days-in-month.d.ts","sourceRoot":"","sources":["../../src/lib/days-in-month.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"days-in-month.d.ts","sourceRoot":"","sources":["../../src/lib/days-in-month.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAK9C"}
|
package/esm/lib/days-in-month.js
CHANGED
|
@@ -13,14 +13,8 @@
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export function daysInMonth(date) {
|
|
16
|
-
//
|
|
17
|
-
// This gives us the last day of the current month
|
|
16
|
+
// Create date for day 0 of next month, which gives last day of current month
|
|
18
17
|
const year = date.getUTCFullYear();
|
|
19
18
|
const month = date.getUTCMonth();
|
|
20
|
-
|
|
21
|
-
const nextMonth = new Date(Date.UTC(year, month + 1, 1));
|
|
22
|
-
// Go back one millisecond to get end of current month
|
|
23
|
-
nextMonth.setUTCMilliseconds(-1);
|
|
24
|
-
// Return the date which is the day of month
|
|
25
|
-
return nextMonth.getUTCDate();
|
|
19
|
+
return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
|
26
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-date.d.ts","sourceRoot":"","sources":["../../src/lib/format-date.ts"],"names":[],"mappings":"AAKA,KAAK,aAAa,GAAG;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"format-date.d.ts","sourceRoot":"","sources":["../../src/lib/format-date.ts"],"names":[],"mappings":"AAKA,KAAK,aAAa,GAAG;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAqIF;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,UAAU,CACxB,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAaR"}
|
package/esm/lib/format-date.js
CHANGED
|
@@ -2,24 +2,24 @@ import { getDTF } from "../core/dtf.js";
|
|
|
2
2
|
import { months } from "./months.js";
|
|
3
3
|
import { weekdays } from "./weekdays.js";
|
|
4
4
|
import { config } from "./config.js";
|
|
5
|
-
//
|
|
6
|
-
const pad2 = (n) => n < 10 ? "0" + n :
|
|
5
|
+
// Inline pad function - smaller minified output
|
|
6
|
+
const pad2 = (n) => (n < 10 ? "0" + n : "" + n);
|
|
7
7
|
const tokenMap = {
|
|
8
|
-
YYYY: (p) =>
|
|
9
|
-
YY: (p) =>
|
|
10
|
-
M: (p) =>
|
|
8
|
+
YYYY: (p) => "" + p.year,
|
|
9
|
+
YY: (p) => ("" + p.year).slice(-2),
|
|
10
|
+
M: (p) => "" + p.month,
|
|
11
11
|
MM: (p) => pad2(p.month),
|
|
12
12
|
MMM: (p, l) => months("short", { locale: l })[p.month - 1],
|
|
13
13
|
MMMM: (p, l) => months("long", { locale: l })[p.month - 1],
|
|
14
|
-
D: (p) =>
|
|
14
|
+
D: (p) => "" + p.day,
|
|
15
15
|
DD: (p) => pad2(p.day),
|
|
16
16
|
ddd: (p, l) => weekdays("short", { locale: l })[p.dayOfWeek],
|
|
17
17
|
dddd: (p, l) => weekdays("long", { locale: l })[p.dayOfWeek],
|
|
18
|
-
H: (p) =>
|
|
18
|
+
H: (p) => "" + p.hour,
|
|
19
19
|
HH: (p) => pad2(p.hour),
|
|
20
|
-
m: (p) =>
|
|
20
|
+
m: (p) => "" + p.minute,
|
|
21
21
|
mm: (p) => pad2(p.minute),
|
|
22
|
-
s: (p) =>
|
|
22
|
+
s: (p) => "" + p.second,
|
|
23
23
|
ss: (p) => pad2(p.second),
|
|
24
24
|
};
|
|
25
25
|
const tokenRegex = /YYYY|MMMM|MMM|YY|MM|M|dddd|ddd|DD|D|HH|H|mm|m|ss|s/g;
|
|
@@ -28,96 +28,43 @@ function compileFormat(fmt) {
|
|
|
28
28
|
const cached = formatCache.get(fmt);
|
|
29
29
|
if (cached)
|
|
30
30
|
return cached;
|
|
31
|
-
const hasLiterals = fmt.includes("[");
|
|
32
31
|
const parts = [];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
parts.push({ type: "token", value: match[0] });
|
|
46
|
-
lastIndex = match.index + match[0].length;
|
|
47
|
-
}
|
|
48
|
-
if (lastIndex < fmt.length) {
|
|
49
|
-
parts.push({ type: "literal", value: fmt.slice(lastIndex) });
|
|
50
|
-
}
|
|
32
|
+
// Handle escaped literals by replacing them first
|
|
33
|
+
let processed = fmt;
|
|
34
|
+
const literals = [];
|
|
35
|
+
// Extract literals [text] and replace with placeholders
|
|
36
|
+
if (fmt.includes("[")) {
|
|
37
|
+
processed = fmt.replace(/\[([^\]]+)\]/g, (_, text) => {
|
|
38
|
+
const idx = literals.length;
|
|
39
|
+
literals.push(text);
|
|
40
|
+
return `\x00${idx}\x00`; // Use null bytes as placeholder
|
|
41
|
+
});
|
|
51
42
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
let lastIndex = 0;
|
|
62
|
-
tokenRegex.lastIndex = 0;
|
|
63
|
-
let match;
|
|
64
|
-
while ((match = tokenRegex.exec(currentLiteral)) !== null) {
|
|
65
|
-
if (match.index > lastIndex) {
|
|
66
|
-
parts.push({
|
|
67
|
-
type: "literal",
|
|
68
|
-
value: currentLiteral.slice(lastIndex, match.index),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
parts.push({ type: "token", value: match[0] });
|
|
72
|
-
lastIndex = match.index + match[0].length;
|
|
73
|
-
}
|
|
74
|
-
if (lastIndex < currentLiteral.length) {
|
|
75
|
-
parts.push({
|
|
76
|
-
type: "literal",
|
|
77
|
-
value: currentLiteral.slice(lastIndex),
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
currentLiteral = "";
|
|
81
|
-
}
|
|
82
|
-
inBracket = true;
|
|
83
|
-
i++;
|
|
84
|
-
}
|
|
85
|
-
else if (fmt[i] === "]" && inBracket) {
|
|
86
|
-
// Escaped literal content - add as-is
|
|
87
|
-
if (currentLiteral) {
|
|
88
|
-
parts.push({ type: "literal", value: currentLiteral });
|
|
89
|
-
currentLiteral = "";
|
|
90
|
-
}
|
|
91
|
-
inBracket = false;
|
|
92
|
-
i++;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
currentLiteral += fmt[i];
|
|
96
|
-
i++;
|
|
43
|
+
let lastIndex = 0;
|
|
44
|
+
tokenRegex.lastIndex = 0;
|
|
45
|
+
let match;
|
|
46
|
+
while ((match = tokenRegex.exec(processed)) !== null) {
|
|
47
|
+
if (match.index > lastIndex) {
|
|
48
|
+
// Add literal segment (restoring escaped literals)
|
|
49
|
+
let literal = processed.slice(lastIndex, match.index);
|
|
50
|
+
if (literals.length) {
|
|
51
|
+
literal = literal.replace(/\x00(\d+)\x00/g, (_, idx) => literals[+idx]);
|
|
97
52
|
}
|
|
53
|
+
parts.push(literal);
|
|
98
54
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
value: currentLiteral.slice(lastIndex, match.index),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
parts.push({ type: "token", value: match[0] });
|
|
111
|
-
lastIndex = match.index + match[0].length;
|
|
112
|
-
}
|
|
113
|
-
if (lastIndex < currentLiteral.length) {
|
|
114
|
-
parts.push({ type: "literal", value: currentLiteral.slice(lastIndex) });
|
|
115
|
-
}
|
|
55
|
+
// Add token resolver function
|
|
56
|
+
parts.push(tokenMap[match[0]]);
|
|
57
|
+
lastIndex = match.index + match[0].length;
|
|
58
|
+
}
|
|
59
|
+
if (lastIndex < processed.length) {
|
|
60
|
+
let literal = processed.slice(lastIndex);
|
|
61
|
+
if (literals.length) {
|
|
62
|
+
literal = literal.replace(/\x00(\d+)\x00/g, (_, idx) => literals[+idx]);
|
|
116
63
|
}
|
|
64
|
+
parts.push(literal);
|
|
117
65
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return compiled;
|
|
66
|
+
formatCache.set(fmt, parts);
|
|
67
|
+
return parts;
|
|
121
68
|
}
|
|
122
69
|
// Fast UTC date parts extraction
|
|
123
70
|
function getUTCParts(date) {
|
|
@@ -138,30 +85,31 @@ function getPartsWithTZ(date, locale, tz) {
|
|
|
138
85
|
year: 0,
|
|
139
86
|
month: 0,
|
|
140
87
|
day: 0,
|
|
141
|
-
dayOfWeek:
|
|
88
|
+
dayOfWeek: date.getDay(),
|
|
142
89
|
hour: 0,
|
|
143
90
|
minute: 0,
|
|
144
91
|
second: 0,
|
|
145
92
|
};
|
|
146
93
|
for (const part of partsRaw) {
|
|
94
|
+
const val = +part.value;
|
|
147
95
|
switch (part.type) {
|
|
148
96
|
case "year":
|
|
149
|
-
p.year =
|
|
97
|
+
p.year = val;
|
|
150
98
|
break;
|
|
151
99
|
case "month":
|
|
152
|
-
p.month =
|
|
100
|
+
p.month = val;
|
|
153
101
|
break;
|
|
154
102
|
case "day":
|
|
155
|
-
p.day =
|
|
103
|
+
p.day = val;
|
|
156
104
|
break;
|
|
157
105
|
case "hour":
|
|
158
|
-
p.hour =
|
|
106
|
+
p.hour = val;
|
|
159
107
|
break;
|
|
160
108
|
case "minute":
|
|
161
|
-
p.minute =
|
|
109
|
+
p.minute = val;
|
|
162
110
|
break;
|
|
163
111
|
case "second":
|
|
164
|
-
p.second =
|
|
112
|
+
p.second = val;
|
|
165
113
|
break;
|
|
166
114
|
}
|
|
167
115
|
}
|
|
@@ -184,19 +132,11 @@ function getPartsWithTZ(date, locale, tz) {
|
|
|
184
132
|
export function formatDate(date, fmt, options = {}) {
|
|
185
133
|
const locale = options.locale ?? config.locale;
|
|
186
134
|
const tz = options.tz ?? config.timezone;
|
|
187
|
-
// Get compiled format (cached)
|
|
188
135
|
const compiled = compileFormat(fmt);
|
|
189
|
-
// Fast path for UTC
|
|
190
136
|
const p = tz === "UTC" ? getUTCParts(date) : getPartsWithTZ(date, locale, tz);
|
|
191
|
-
// Build result string from compiled parts
|
|
192
137
|
let result = "";
|
|
193
|
-
for (const part of compiled
|
|
194
|
-
|
|
195
|
-
result += part.value;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
result += tokenMap[part.value](p, locale);
|
|
199
|
-
}
|
|
138
|
+
for (const part of compiled) {
|
|
139
|
+
result += typeof part === "string" ? part : part(p, locale);
|
|
200
140
|
}
|
|
201
141
|
return result;
|
|
202
142
|
}
|
package/esm/lib/from-now.js
CHANGED
|
@@ -19,35 +19,35 @@ import { config } from "./config.js";
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
export function fromNow(date, locale = config.locale) {
|
|
22
|
-
const
|
|
23
|
-
const diff = now - date.getTime();
|
|
22
|
+
const diff = Date.now() - date.getTime();
|
|
24
23
|
const absDiff = Math.abs(diff);
|
|
25
24
|
const seconds = Math.floor(absDiff / 1000);
|
|
26
|
-
const minutes = Math.floor(seconds / 60);
|
|
27
|
-
const hours = Math.floor(minutes / 60);
|
|
28
|
-
const days = Math.floor(hours / 24);
|
|
29
|
-
const weeks = Math.floor(days / 7);
|
|
30
|
-
const months = Math.floor(days / 30);
|
|
31
|
-
const years = Math.floor(days / 365);
|
|
32
25
|
// Use auto for "now", always for everything else
|
|
33
26
|
if (seconds < 60) {
|
|
34
27
|
return getRTF(locale, "auto").format(0, "second");
|
|
35
28
|
}
|
|
36
29
|
const rtf = getRTF(locale, "always");
|
|
30
|
+
const sign = diff < 0 ? 1 : -1;
|
|
31
|
+
const minutes = Math.floor(seconds / 60);
|
|
37
32
|
if (minutes < 60) {
|
|
38
|
-
return rtf.format(
|
|
33
|
+
return rtf.format(sign * minutes, "minute");
|
|
39
34
|
}
|
|
35
|
+
const hours = Math.floor(minutes / 60);
|
|
40
36
|
if (hours < 24) {
|
|
41
|
-
return rtf.format(
|
|
37
|
+
return rtf.format(sign * hours, "hour");
|
|
42
38
|
}
|
|
39
|
+
const days = Math.floor(hours / 24);
|
|
43
40
|
if (days < 7) {
|
|
44
|
-
return rtf.format(
|
|
41
|
+
return rtf.format(sign * days, "day");
|
|
45
42
|
}
|
|
43
|
+
const weeks = Math.floor(days / 7);
|
|
46
44
|
if (days < 30) {
|
|
47
|
-
return rtf.format(
|
|
45
|
+
return rtf.format(sign * weeks, "week");
|
|
48
46
|
}
|
|
47
|
+
const months = Math.floor(days / 30);
|
|
49
48
|
if (months < 12) {
|
|
50
|
-
return rtf.format(
|
|
49
|
+
return rtf.format(sign * months, "month");
|
|
51
50
|
}
|
|
52
|
-
|
|
51
|
+
const years = Math.floor(days / 365);
|
|
52
|
+
return rtf.format(sign * years, "year");
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-between.d.ts","sourceRoot":"","sources":["../../src/lib/is-between.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,IAAI,EACX,GAAG,EAAE,IAAI,EACT,WAAW,GAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAW,GAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"is-between.d.ts","sourceRoot":"","sources":["../../src/lib/is-between.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,IAAI,EACX,GAAG,EAAE,IAAI,EACT,WAAW,GAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAW,GAC5C,OAAO,CAkBT"}
|
package/esm/lib/is-between.js
CHANGED
|
@@ -27,8 +27,7 @@ export function isBetween(date, start, end, inclusivity = "[]") {
|
|
|
27
27
|
const startTime = start.getTime();
|
|
28
28
|
const endTime = end.getTime();
|
|
29
29
|
// Handle reversed bounds
|
|
30
|
-
const min = startTime < endTime ? startTime : endTime;
|
|
31
|
-
const max = startTime < endTime ? endTime : startTime;
|
|
30
|
+
const [min, max] = startTime < endTime ? [startTime, endTime] : [endTime, startTime];
|
|
32
31
|
switch (inclusivity) {
|
|
33
32
|
case "[]":
|
|
34
33
|
return time >= min && time <= max;
|
package/esm/lib/is-same.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-same.d.ts","sourceRoot":"","sources":["../../src/lib/is-same.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;;;;;GAYG;AAEH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"is-same.d.ts","sourceRoot":"","sources":["../../src/lib/is-same.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;;;;;GAYG;AAEH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CA4D3E"}
|
package/esm/lib/is-same.js
CHANGED
|
@@ -16,9 +16,8 @@ export function isSame(dateLeft, dateRight, unit) {
|
|
|
16
16
|
case "year":
|
|
17
17
|
return dateLeft.getUTCFullYear() === dateRight.getUTCFullYear();
|
|
18
18
|
case "month": {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return yl === yr && dateLeft.getUTCMonth() === dateRight.getUTCMonth();
|
|
19
|
+
return dateLeft.getUTCFullYear() === dateRight.getUTCFullYear() &&
|
|
20
|
+
dateLeft.getUTCMonth() === dateRight.getUTCMonth();
|
|
22
21
|
}
|
|
23
22
|
case "week": {
|
|
24
23
|
// Calculate week start by getting days since Sunday
|
|
@@ -33,65 +32,29 @@ export function isSame(dateLeft, dateRight, unit) {
|
|
|
33
32
|
return weekStartLeft === weekStartRight;
|
|
34
33
|
}
|
|
35
34
|
case "day": {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return false;
|
|
40
|
-
const ml = dateLeft.getUTCMonth();
|
|
41
|
-
const mr = dateRight.getUTCMonth();
|
|
42
|
-
return ml === mr && dateLeft.getUTCDate() === dateRight.getUTCDate();
|
|
35
|
+
return dateLeft.getUTCFullYear() === dateRight.getUTCFullYear() &&
|
|
36
|
+
dateLeft.getUTCMonth() === dateRight.getUTCMonth() &&
|
|
37
|
+
dateLeft.getUTCDate() === dateRight.getUTCDate();
|
|
43
38
|
}
|
|
44
39
|
case "hour": {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const ml = dateLeft.getUTCMonth();
|
|
50
|
-
const mr = dateRight.getUTCMonth();
|
|
51
|
-
if (ml !== mr)
|
|
52
|
-
return false;
|
|
53
|
-
const dl = dateLeft.getUTCDate();
|
|
54
|
-
const dr = dateRight.getUTCDate();
|
|
55
|
-
return dl === dr && dateLeft.getUTCHours() === dateRight.getUTCHours();
|
|
40
|
+
return dateLeft.getUTCFullYear() === dateRight.getUTCFullYear() &&
|
|
41
|
+
dateLeft.getUTCMonth() === dateRight.getUTCMonth() &&
|
|
42
|
+
dateLeft.getUTCDate() === dateRight.getUTCDate() &&
|
|
43
|
+
dateLeft.getUTCHours() === dateRight.getUTCHours();
|
|
56
44
|
}
|
|
57
45
|
case "minute": {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const ml = dateLeft.getUTCMonth();
|
|
63
|
-
const mr = dateRight.getUTCMonth();
|
|
64
|
-
if (ml !== mr)
|
|
65
|
-
return false;
|
|
66
|
-
const dl = dateLeft.getUTCDate();
|
|
67
|
-
const dr = dateRight.getUTCDate();
|
|
68
|
-
if (dl !== dr)
|
|
69
|
-
return false;
|
|
70
|
-
const hl = dateLeft.getUTCHours();
|
|
71
|
-
const hr = dateRight.getUTCHours();
|
|
72
|
-
return hl === hr &&
|
|
46
|
+
return dateLeft.getUTCFullYear() === dateRight.getUTCFullYear() &&
|
|
47
|
+
dateLeft.getUTCMonth() === dateRight.getUTCMonth() &&
|
|
48
|
+
dateLeft.getUTCDate() === dateRight.getUTCDate() &&
|
|
49
|
+
dateLeft.getUTCHours() === dateRight.getUTCHours() &&
|
|
73
50
|
dateLeft.getUTCMinutes() === dateRight.getUTCMinutes();
|
|
74
51
|
}
|
|
75
52
|
case "second": {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const mr = dateRight.getUTCMonth();
|
|
82
|
-
if (ml !== mr)
|
|
83
|
-
return false;
|
|
84
|
-
const dl = dateLeft.getUTCDate();
|
|
85
|
-
const dr = dateRight.getUTCDate();
|
|
86
|
-
if (dl !== dr)
|
|
87
|
-
return false;
|
|
88
|
-
const hl = dateLeft.getUTCHours();
|
|
89
|
-
const hr = dateRight.getUTCHours();
|
|
90
|
-
if (hl !== hr)
|
|
91
|
-
return false;
|
|
92
|
-
const minl = dateLeft.getUTCMinutes();
|
|
93
|
-
const minr = dateRight.getUTCMinutes();
|
|
94
|
-
return minl === minr &&
|
|
53
|
+
return dateLeft.getUTCFullYear() === dateRight.getUTCFullYear() &&
|
|
54
|
+
dateLeft.getUTCMonth() === dateRight.getUTCMonth() &&
|
|
55
|
+
dateLeft.getUTCDate() === dateRight.getUTCDate() &&
|
|
56
|
+
dateLeft.getUTCHours() === dateRight.getUTCHours() &&
|
|
57
|
+
dateLeft.getUTCMinutes() === dateRight.getUTCMinutes() &&
|
|
95
58
|
dateLeft.getUTCSeconds() === dateRight.getUTCSeconds();
|
|
96
59
|
}
|
|
97
60
|
default:
|
package/esm/lib/is-today.js
CHANGED
|
@@ -19,7 +19,7 @@ import { config } from "./config.js";
|
|
|
19
19
|
*/
|
|
20
20
|
export function isToday(date, options = {}) {
|
|
21
21
|
const timezone = options.tz || config.timezone;
|
|
22
|
-
const now = new Date(
|
|
22
|
+
const now = new Date();
|
|
23
23
|
if (timezone === "UTC") {
|
|
24
24
|
return date.getUTCFullYear() === now.getUTCFullYear() &&
|
|
25
25
|
date.getUTCMonth() === now.getUTCMonth() &&
|
package/esm/lib/months.js
CHANGED
|
@@ -13,7 +13,7 @@ const monthsCache = new Map();
|
|
|
13
13
|
*/
|
|
14
14
|
export function months(format = "long", opt = {}) {
|
|
15
15
|
const locale = opt.locale ?? config.locale;
|
|
16
|
-
const key =
|
|
16
|
+
const key = locale + "|" + format;
|
|
17
17
|
const cached = monthsCache.get(key);
|
|
18
18
|
if (cached)
|
|
19
19
|
return cached;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-date.d.ts","sourceRoot":"","sources":["../../src/lib/parse-date.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAClC,IAAI,
|
|
1
|
+
{"version":3,"file":"parse-date.d.ts","sourceRoot":"","sources":["../../src/lib/parse-date.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAClC,IAAI,CA8FN"}
|
package/esm/lib/parse-date.js
CHANGED
|
@@ -87,13 +87,14 @@ export function parseDate(dateString, options) {
|
|
|
87
87
|
if (!match) {
|
|
88
88
|
throw new Error("Invalid date");
|
|
89
89
|
}
|
|
90
|
-
// Extract values in order
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
// Extract values in order - cache indices for efficiency
|
|
91
|
+
const getIdx = (t) => tokenOrder.indexOf(t);
|
|
92
|
+
const getVal = (t) => {
|
|
93
|
+
const i = getIdx(t);
|
|
94
|
+
return i !== -1 ? parseInt(match[i + 1], 10) : 0;
|
|
94
95
|
};
|
|
95
96
|
// Create date (months are 0-indexed)
|
|
96
|
-
const date = new Date(Date.UTC(
|
|
97
|
+
const date = new Date(Date.UTC(getVal("YYYY") || 1970, (getVal("MM") || 1) - 1, getVal("DD") || 1, getVal("HH"), getVal("mm"), getVal("ss")));
|
|
97
98
|
if (isNaN(date.getTime())) {
|
|
98
99
|
throw new Error("Invalid date");
|
|
99
100
|
}
|