chronal 0.0.21 → 0.0.23
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/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/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
package/esm/lib/set-unit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtract-time.d.ts","sourceRoot":"","sources":["../../src/lib/subtract-time.ts"],"names":[],"mappings":"AAEA,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,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"subtract-time.d.ts","sourceRoot":"","sources":["../../src/lib/subtract-time.ts"],"names":[],"mappings":"AAEA,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,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAW9D"}
|
package/esm/lib/subtract-time.js
CHANGED
|
@@ -11,22 +11,14 @@ import { addTime } from "./add-time.js";
|
|
|
11
11
|
* console.log(newDate.toISOString()); // '2023-02-28T12:00:00.000Z'
|
|
12
12
|
*/
|
|
13
13
|
export function subtractTime(date, opt) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
out.hours = -opt.hours;
|
|
25
|
-
if (opt.minutes)
|
|
26
|
-
out.minutes = -opt.minutes;
|
|
27
|
-
if (opt.seconds)
|
|
28
|
-
out.seconds = -opt.seconds;
|
|
29
|
-
if (opt.milliseconds)
|
|
30
|
-
out.milliseconds = -opt.milliseconds;
|
|
31
|
-
return addTime(date, out);
|
|
14
|
+
return addTime(date, {
|
|
15
|
+
years: opt.years ? -opt.years : undefined,
|
|
16
|
+
months: opt.months ? -opt.months : undefined,
|
|
17
|
+
weeks: opt.weeks ? -opt.weeks : undefined,
|
|
18
|
+
days: opt.days ? -opt.days : undefined,
|
|
19
|
+
hours: opt.hours ? -opt.hours : undefined,
|
|
20
|
+
minutes: opt.minutes ? -opt.minutes : undefined,
|
|
21
|
+
seconds: opt.seconds ? -opt.seconds : undefined,
|
|
22
|
+
milliseconds: opt.milliseconds ? -opt.milliseconds : undefined,
|
|
23
|
+
});
|
|
32
24
|
}
|
package/esm/lib/to-now.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-now.d.ts","sourceRoot":"","sources":["../../src/lib/to-now.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,MAAsB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"to-now.d.ts","sourceRoot":"","sources":["../../src/lib/to-now.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,MAAsB,GAAG,MAAM,CAwCxE"}
|
package/esm/lib/to-now.js
CHANGED
|
@@ -20,35 +20,35 @@ import { config } from "./config.js";
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
export function toNow(date, locale = config.locale) {
|
|
23
|
-
const
|
|
24
|
-
const diff = date.getTime() - now;
|
|
23
|
+
const diff = date.getTime() - Date.now();
|
|
25
24
|
const absDiff = Math.abs(diff);
|
|
26
25
|
const seconds = Math.floor(absDiff / 1000);
|
|
27
|
-
const minutes = Math.floor(seconds / 60);
|
|
28
|
-
const hours = Math.floor(minutes / 60);
|
|
29
|
-
const days = Math.floor(hours / 24);
|
|
30
|
-
const weeks = Math.floor(days / 7);
|
|
31
|
-
const months = Math.floor(days / 30);
|
|
32
|
-
const years = Math.floor(days / 365);
|
|
33
26
|
// Use auto for "now", always for everything else
|
|
34
27
|
if (seconds < 60) {
|
|
35
28
|
return getRTF(locale, "auto").format(0, "second");
|
|
36
29
|
}
|
|
37
30
|
const rtf = getRTF(locale, "always");
|
|
31
|
+
const sign = diff > 0 ? 1 : -1;
|
|
32
|
+
const minutes = Math.floor(seconds / 60);
|
|
38
33
|
if (minutes < 60) {
|
|
39
|
-
return rtf.format(
|
|
34
|
+
return rtf.format(sign * minutes, "minute");
|
|
40
35
|
}
|
|
36
|
+
const hours = Math.floor(minutes / 60);
|
|
41
37
|
if (hours < 24) {
|
|
42
|
-
return rtf.format(
|
|
38
|
+
return rtf.format(sign * hours, "hour");
|
|
43
39
|
}
|
|
40
|
+
const days = Math.floor(hours / 24);
|
|
44
41
|
if (days < 7) {
|
|
45
|
-
return rtf.format(
|
|
42
|
+
return rtf.format(sign * days, "day");
|
|
46
43
|
}
|
|
44
|
+
const weeks = Math.floor(days / 7);
|
|
47
45
|
if (days < 30) {
|
|
48
|
-
return rtf.format(
|
|
46
|
+
return rtf.format(sign * weeks, "week");
|
|
49
47
|
}
|
|
48
|
+
const months = Math.floor(days / 30);
|
|
50
49
|
if (months < 12) {
|
|
51
|
-
return rtf.format(
|
|
50
|
+
return rtf.format(sign * months, "month");
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
const years = Math.floor(days / 365);
|
|
53
|
+
return rtf.format(sign * years, "year");
|
|
54
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"week-of-year.d.ts","sourceRoot":"","sources":["../../src/lib/week-of-year.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"week-of-year.d.ts","sourceRoot":"","sources":["../../src/lib/week-of-year.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAK7C"}
|
package/esm/lib/week-of-year.js
CHANGED
|
@@ -13,15 +13,8 @@
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export function weekOfYear(date) {
|
|
16
|
-
// Get the start of the year
|
|
17
16
|
const year = date.getUTCFullYear();
|
|
18
17
|
const startOfYear = new Date(Date.UTC(year, 0, 1));
|
|
19
|
-
// Get day of week for start of year (0 = Sunday)
|
|
20
|
-
const startDay = startOfYear.getUTCDay();
|
|
21
|
-
// Get the date's day of year
|
|
22
18
|
const dayOfYear = Math.floor((date.getTime() - startOfYear.getTime()) / 86400000) + 1;
|
|
23
|
-
|
|
24
|
-
// Add startDay to align with week boundaries (Sunday = start of week)
|
|
25
|
-
const weekNum = Math.ceil((dayOfYear + startDay) / 7);
|
|
26
|
-
return weekNum;
|
|
19
|
+
return Math.ceil((dayOfYear + startOfYear.getUTCDay()) / 7);
|
|
27
20
|
}
|
package/esm/lib/weekdays.js
CHANGED
|
@@ -13,7 +13,7 @@ const daysCache = new Map();
|
|
|
13
13
|
*/
|
|
14
14
|
export function weekdays(format = "long", opt = {}) {
|
|
15
15
|
const locale = opt.locale ?? config.locale;
|
|
16
|
-
const key =
|
|
16
|
+
const key = locale + "|" + format;
|
|
17
17
|
const cached = daysCache.get(key);
|
|
18
18
|
if (cached)
|
|
19
19
|
return cached;
|
package/package.json
CHANGED
|
@@ -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,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yCAAyC;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"}
|
|
@@ -41,90 +41,36 @@ const chronal = (date, options) => {
|
|
|
41
41
|
else {
|
|
42
42
|
d = new Date(date);
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
const instance = {
|
|
45
45
|
date: d,
|
|
46
46
|
timezone,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
toNow: function (locale) {
|
|
74
|
-
return to_now_js_1.toNow.call(this, locale);
|
|
75
|
-
},
|
|
76
|
-
// Query
|
|
77
|
-
diff: function (date, unit) {
|
|
78
|
-
return diff_js_1.diff.call(this, date, unit);
|
|
79
|
-
},
|
|
80
|
-
isAfter: function (date) {
|
|
81
|
-
return is_after_js_1.isAfter.call(this, date);
|
|
82
|
-
},
|
|
83
|
-
isBefore: function (date) {
|
|
84
|
-
return is_before_js_1.isBefore.call(this, date);
|
|
85
|
-
},
|
|
86
|
-
isBetween: function (start, end, inclusivity) {
|
|
87
|
-
return is_between_js_1.isBetween.call(this, start, end, inclusivity);
|
|
88
|
-
},
|
|
89
|
-
isEqual: function (date) {
|
|
90
|
-
return is_equal_js_1.isEqual.call(this, date);
|
|
91
|
-
},
|
|
92
|
-
isSame: function (date, unit) {
|
|
93
|
-
return is_same_js_1.isSame.call(this, date, unit);
|
|
94
|
-
},
|
|
95
|
-
isToday: function () {
|
|
96
|
-
return is_today_js_1.isToday.call(this);
|
|
97
|
-
},
|
|
98
|
-
isTomorrow: function () {
|
|
99
|
-
return is_tomorrow_js_1.isTomorrow.call(this);
|
|
100
|
-
},
|
|
101
|
-
isYesterday: function () {
|
|
102
|
-
return is_yesterday_js_1.isYesterday.call(this);
|
|
103
|
-
},
|
|
104
|
-
isLeapYear: function () {
|
|
105
|
-
return is_leap_year_js_1.isLeapYear.call(this);
|
|
106
|
-
},
|
|
107
|
-
isValid: function () {
|
|
108
|
-
return is_valid_js_1.isValid.call(this);
|
|
109
|
-
},
|
|
110
|
-
// Get
|
|
111
|
-
get: function (unit) {
|
|
112
|
-
return get_unit_js_1.getUnit.call(this, unit);
|
|
113
|
-
},
|
|
114
|
-
quarter: function () {
|
|
115
|
-
return get_quarter_js_1.getQuarter.call(this);
|
|
116
|
-
},
|
|
117
|
-
daysInMonth: function () {
|
|
118
|
-
return days_in_month_js_1.daysInMonth.call(this);
|
|
119
|
-
},
|
|
120
|
-
week: function () {
|
|
121
|
-
return week_of_year_js_1.weekOfYear.call(this);
|
|
122
|
-
},
|
|
123
|
-
// Utilities
|
|
124
|
-
until: function (end, step) {
|
|
125
|
-
return dates_until_js_1.until.call(this, end, step);
|
|
126
|
-
},
|
|
47
|
+
add: add_js_1.add,
|
|
48
|
+
subtract: subtract_js_1.subtract,
|
|
49
|
+
startOf: start_of_js_1.startOf,
|
|
50
|
+
endOf: end_of_js_1.endOf,
|
|
51
|
+
set: set_unit_js_1.setUnit,
|
|
52
|
+
clamp: clamp_js_1.clamp,
|
|
53
|
+
format: format_js_1.format,
|
|
54
|
+
fromNow: from_now_js_1.fromNow,
|
|
55
|
+
toNow: to_now_js_1.toNow,
|
|
56
|
+
diff: diff_js_1.diff,
|
|
57
|
+
isAfter: is_after_js_1.isAfter,
|
|
58
|
+
isBefore: is_before_js_1.isBefore,
|
|
59
|
+
isBetween: is_between_js_1.isBetween,
|
|
60
|
+
isEqual: is_equal_js_1.isEqual,
|
|
61
|
+
isSame: is_same_js_1.isSame,
|
|
62
|
+
isToday: is_today_js_1.isToday,
|
|
63
|
+
isTomorrow: is_tomorrow_js_1.isTomorrow,
|
|
64
|
+
isYesterday: is_yesterday_js_1.isYesterday,
|
|
65
|
+
isLeapYear: is_leap_year_js_1.isLeapYear,
|
|
66
|
+
isValid: is_valid_js_1.isValid,
|
|
67
|
+
get: get_unit_js_1.getUnit,
|
|
68
|
+
quarter: get_quarter_js_1.getQuarter,
|
|
69
|
+
daysInMonth: days_in_month_js_1.daysInMonth,
|
|
70
|
+
week: week_of_year_js_1.weekOfYear,
|
|
71
|
+
until: dates_until_js_1.until,
|
|
127
72
|
};
|
|
73
|
+
return instance;
|
|
128
74
|
};
|
|
129
75
|
exports.chronal = chronal;
|
|
130
76
|
exports.chronal.config = config_js_1.setChronalConfig;
|
package/script/core/dtf.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getDTF = getDTF;
|
|
4
4
|
const dtfCache = new Map();
|
|
5
5
|
function getDTF(locale, tz) {
|
|
6
|
-
const key =
|
|
6
|
+
const key = locale + "|" + tz;
|
|
7
7
|
let dtf = dtfCache.get(key);
|
|
8
8
|
if (!dtf) {
|
|
9
9
|
dtf = new Intl.DateTimeFormat(locale, {
|
package/script/core/rtf.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getRTF = getRTF;
|
|
4
4
|
const rtfCache = new Map();
|
|
5
5
|
function getRTF(locale, numeric) {
|
|
6
|
-
const key =
|
|
6
|
+
const key = locale + "|" + numeric;
|
|
7
7
|
let rtf = rtfCache.get(key);
|
|
8
8
|
if (!rtf) {
|
|
9
9
|
rtf = new Intl.RelativeTimeFormat(locale, { numeric });
|
|
@@ -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/script/lib/add-time.js
CHANGED
|
@@ -19,15 +19,14 @@ function addTime(date, opt) {
|
|
|
19
19
|
const years = opt.years ?? 0;
|
|
20
20
|
const months = opt.months ?? 0;
|
|
21
21
|
const year = d.getUTCFullYear();
|
|
22
|
-
const month = d.getUTCMonth();
|
|
22
|
+
const month = d.getUTCMonth();
|
|
23
23
|
const day = d.getUTCDate();
|
|
24
24
|
// target year/month (allow overflow, normalize manually)
|
|
25
25
|
let targetMonth = month + months;
|
|
26
26
|
const targetYear = year + years + Math.floor(targetMonth / 12);
|
|
27
27
|
targetMonth = ((targetMonth % 12) + 12) % 12;
|
|
28
28
|
// last valid day of target month
|
|
29
|
-
const
|
|
30
|
-
const safeDay = Math.min(day, lastDayOfTargetMonth);
|
|
29
|
+
const safeDay = Math.min(day, new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate());
|
|
31
30
|
d = new Date(Date.UTC(targetYear, targetMonth, safeDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()));
|
|
32
31
|
}
|
|
33
32
|
// ===== 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"}
|
|
@@ -16,14 +16,8 @@ exports.daysInMonth = daysInMonth;
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
function daysInMonth(date) {
|
|
19
|
-
//
|
|
20
|
-
// This gives us the last day of the current month
|
|
19
|
+
// Create date for day 0 of next month, which gives last day of current month
|
|
21
20
|
const year = date.getUTCFullYear();
|
|
22
21
|
const month = date.getUTCMonth();
|
|
23
|
-
|
|
24
|
-
const nextMonth = new Date(Date.UTC(year, month + 1, 1));
|
|
25
|
-
// Go back one millisecond to get end of current month
|
|
26
|
-
nextMonth.setUTCMilliseconds(-1);
|
|
27
|
-
// Return the date which is the day of month
|
|
28
|
-
return nextMonth.getUTCDate();
|
|
22
|
+
return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
|
29
23
|
}
|
|
@@ -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"}
|
|
@@ -5,24 +5,24 @@ const dtf_js_1 = require("../core/dtf.js");
|
|
|
5
5
|
const months_js_1 = require("./months.js");
|
|
6
6
|
const weekdays_js_1 = require("./weekdays.js");
|
|
7
7
|
const config_js_1 = require("./config.js");
|
|
8
|
-
//
|
|
9
|
-
const pad2 = (n) => n < 10 ? "0" + n :
|
|
8
|
+
// Inline pad function - smaller minified output
|
|
9
|
+
const pad2 = (n) => (n < 10 ? "0" + n : "" + n);
|
|
10
10
|
const tokenMap = {
|
|
11
|
-
YYYY: (p) =>
|
|
12
|
-
YY: (p) =>
|
|
13
|
-
M: (p) =>
|
|
11
|
+
YYYY: (p) => "" + p.year,
|
|
12
|
+
YY: (p) => ("" + p.year).slice(-2),
|
|
13
|
+
M: (p) => "" + p.month,
|
|
14
14
|
MM: (p) => pad2(p.month),
|
|
15
15
|
MMM: (p, l) => (0, months_js_1.months)("short", { locale: l })[p.month - 1],
|
|
16
16
|
MMMM: (p, l) => (0, months_js_1.months)("long", { locale: l })[p.month - 1],
|
|
17
|
-
D: (p) =>
|
|
17
|
+
D: (p) => "" + p.day,
|
|
18
18
|
DD: (p) => pad2(p.day),
|
|
19
19
|
ddd: (p, l) => (0, weekdays_js_1.weekdays)("short", { locale: l })[p.dayOfWeek],
|
|
20
20
|
dddd: (p, l) => (0, weekdays_js_1.weekdays)("long", { locale: l })[p.dayOfWeek],
|
|
21
|
-
H: (p) =>
|
|
21
|
+
H: (p) => "" + p.hour,
|
|
22
22
|
HH: (p) => pad2(p.hour),
|
|
23
|
-
m: (p) =>
|
|
23
|
+
m: (p) => "" + p.minute,
|
|
24
24
|
mm: (p) => pad2(p.minute),
|
|
25
|
-
s: (p) =>
|
|
25
|
+
s: (p) => "" + p.second,
|
|
26
26
|
ss: (p) => pad2(p.second),
|
|
27
27
|
};
|
|
28
28
|
const tokenRegex = /YYYY|MMMM|MMM|YY|MM|M|dddd|ddd|DD|D|HH|H|mm|m|ss|s/g;
|
|
@@ -31,96 +31,43 @@ function compileFormat(fmt) {
|
|
|
31
31
|
const cached = formatCache.get(fmt);
|
|
32
32
|
if (cached)
|
|
33
33
|
return cached;
|
|
34
|
-
const hasLiterals = fmt.includes("[");
|
|
35
34
|
const parts = [];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
parts.push({ type: "token", value: match[0] });
|
|
49
|
-
lastIndex = match.index + match[0].length;
|
|
50
|
-
}
|
|
51
|
-
if (lastIndex < fmt.length) {
|
|
52
|
-
parts.push({ type: "literal", value: fmt.slice(lastIndex) });
|
|
53
|
-
}
|
|
35
|
+
// Handle escaped literals by replacing them first
|
|
36
|
+
let processed = fmt;
|
|
37
|
+
const literals = [];
|
|
38
|
+
// Extract literals [text] and replace with placeholders
|
|
39
|
+
if (fmt.includes("[")) {
|
|
40
|
+
processed = fmt.replace(/\[([^\]]+)\]/g, (_, text) => {
|
|
41
|
+
const idx = literals.length;
|
|
42
|
+
literals.push(text);
|
|
43
|
+
return `\x00${idx}\x00`; // Use null bytes as placeholder
|
|
44
|
+
});
|
|
54
45
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
let lastIndex = 0;
|
|
65
|
-
tokenRegex.lastIndex = 0;
|
|
66
|
-
let match;
|
|
67
|
-
while ((match = tokenRegex.exec(currentLiteral)) !== null) {
|
|
68
|
-
if (match.index > lastIndex) {
|
|
69
|
-
parts.push({
|
|
70
|
-
type: "literal",
|
|
71
|
-
value: currentLiteral.slice(lastIndex, match.index),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
parts.push({ type: "token", value: match[0] });
|
|
75
|
-
lastIndex = match.index + match[0].length;
|
|
76
|
-
}
|
|
77
|
-
if (lastIndex < currentLiteral.length) {
|
|
78
|
-
parts.push({
|
|
79
|
-
type: "literal",
|
|
80
|
-
value: currentLiteral.slice(lastIndex),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
currentLiteral = "";
|
|
84
|
-
}
|
|
85
|
-
inBracket = true;
|
|
86
|
-
i++;
|
|
87
|
-
}
|
|
88
|
-
else if (fmt[i] === "]" && inBracket) {
|
|
89
|
-
// Escaped literal content - add as-is
|
|
90
|
-
if (currentLiteral) {
|
|
91
|
-
parts.push({ type: "literal", value: currentLiteral });
|
|
92
|
-
currentLiteral = "";
|
|
93
|
-
}
|
|
94
|
-
inBracket = false;
|
|
95
|
-
i++;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
currentLiteral += fmt[i];
|
|
99
|
-
i++;
|
|
46
|
+
let lastIndex = 0;
|
|
47
|
+
tokenRegex.lastIndex = 0;
|
|
48
|
+
let match;
|
|
49
|
+
while ((match = tokenRegex.exec(processed)) !== null) {
|
|
50
|
+
if (match.index > lastIndex) {
|
|
51
|
+
// Add literal segment (restoring escaped literals)
|
|
52
|
+
let literal = processed.slice(lastIndex, match.index);
|
|
53
|
+
if (literals.length) {
|
|
54
|
+
literal = literal.replace(/\x00(\d+)\x00/g, (_, idx) => literals[+idx]);
|
|
100
55
|
}
|
|
56
|
+
parts.push(literal);
|
|
101
57
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
value: currentLiteral.slice(lastIndex, match.index),
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
parts.push({ type: "token", value: match[0] });
|
|
114
|
-
lastIndex = match.index + match[0].length;
|
|
115
|
-
}
|
|
116
|
-
if (lastIndex < currentLiteral.length) {
|
|
117
|
-
parts.push({ type: "literal", value: currentLiteral.slice(lastIndex) });
|
|
118
|
-
}
|
|
58
|
+
// Add token resolver function
|
|
59
|
+
parts.push(tokenMap[match[0]]);
|
|
60
|
+
lastIndex = match.index + match[0].length;
|
|
61
|
+
}
|
|
62
|
+
if (lastIndex < processed.length) {
|
|
63
|
+
let literal = processed.slice(lastIndex);
|
|
64
|
+
if (literals.length) {
|
|
65
|
+
literal = literal.replace(/\x00(\d+)\x00/g, (_, idx) => literals[+idx]);
|
|
119
66
|
}
|
|
67
|
+
parts.push(literal);
|
|
120
68
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return compiled;
|
|
69
|
+
formatCache.set(fmt, parts);
|
|
70
|
+
return parts;
|
|
124
71
|
}
|
|
125
72
|
// Fast UTC date parts extraction
|
|
126
73
|
function getUTCParts(date) {
|
|
@@ -141,30 +88,31 @@ function getPartsWithTZ(date, locale, tz) {
|
|
|
141
88
|
year: 0,
|
|
142
89
|
month: 0,
|
|
143
90
|
day: 0,
|
|
144
|
-
dayOfWeek:
|
|
91
|
+
dayOfWeek: date.getDay(),
|
|
145
92
|
hour: 0,
|
|
146
93
|
minute: 0,
|
|
147
94
|
second: 0,
|
|
148
95
|
};
|
|
149
96
|
for (const part of partsRaw) {
|
|
97
|
+
const val = +part.value;
|
|
150
98
|
switch (part.type) {
|
|
151
99
|
case "year":
|
|
152
|
-
p.year =
|
|
100
|
+
p.year = val;
|
|
153
101
|
break;
|
|
154
102
|
case "month":
|
|
155
|
-
p.month =
|
|
103
|
+
p.month = val;
|
|
156
104
|
break;
|
|
157
105
|
case "day":
|
|
158
|
-
p.day =
|
|
106
|
+
p.day = val;
|
|
159
107
|
break;
|
|
160
108
|
case "hour":
|
|
161
|
-
p.hour =
|
|
109
|
+
p.hour = val;
|
|
162
110
|
break;
|
|
163
111
|
case "minute":
|
|
164
|
-
p.minute =
|
|
112
|
+
p.minute = val;
|
|
165
113
|
break;
|
|
166
114
|
case "second":
|
|
167
|
-
p.second =
|
|
115
|
+
p.second = val;
|
|
168
116
|
break;
|
|
169
117
|
}
|
|
170
118
|
}
|
|
@@ -187,19 +135,11 @@ function getPartsWithTZ(date, locale, tz) {
|
|
|
187
135
|
function formatDate(date, fmt, options = {}) {
|
|
188
136
|
const locale = options.locale ?? config_js_1.config.locale;
|
|
189
137
|
const tz = options.tz ?? config_js_1.config.timezone;
|
|
190
|
-
// Get compiled format (cached)
|
|
191
138
|
const compiled = compileFormat(fmt);
|
|
192
|
-
// Fast path for UTC
|
|
193
139
|
const p = tz === "UTC" ? getUTCParts(date) : getPartsWithTZ(date, locale, tz);
|
|
194
|
-
// Build result string from compiled parts
|
|
195
140
|
let result = "";
|
|
196
|
-
for (const part of compiled
|
|
197
|
-
|
|
198
|
-
result += part.value;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
result += tokenMap[part.value](p, locale);
|
|
202
|
-
}
|
|
141
|
+
for (const part of compiled) {
|
|
142
|
+
result += typeof part === "string" ? part : part(p, locale);
|
|
203
143
|
}
|
|
204
144
|
return result;
|
|
205
145
|
}
|
package/script/lib/from-now.js
CHANGED
|
@@ -22,35 +22,35 @@ const config_js_1 = require("./config.js");
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
function fromNow(date, locale = config_js_1.config.locale) {
|
|
25
|
-
const
|
|
26
|
-
const diff = now - date.getTime();
|
|
25
|
+
const diff = Date.now() - date.getTime();
|
|
27
26
|
const absDiff = Math.abs(diff);
|
|
28
27
|
const seconds = Math.floor(absDiff / 1000);
|
|
29
|
-
const minutes = Math.floor(seconds / 60);
|
|
30
|
-
const hours = Math.floor(minutes / 60);
|
|
31
|
-
const days = Math.floor(hours / 24);
|
|
32
|
-
const weeks = Math.floor(days / 7);
|
|
33
|
-
const months = Math.floor(days / 30);
|
|
34
|
-
const years = Math.floor(days / 365);
|
|
35
28
|
// Use auto for "now", always for everything else
|
|
36
29
|
if (seconds < 60) {
|
|
37
30
|
return (0, rtf_js_1.getRTF)(locale, "auto").format(0, "second");
|
|
38
31
|
}
|
|
39
32
|
const rtf = (0, rtf_js_1.getRTF)(locale, "always");
|
|
33
|
+
const sign = diff < 0 ? 1 : -1;
|
|
34
|
+
const minutes = Math.floor(seconds / 60);
|
|
40
35
|
if (minutes < 60) {
|
|
41
|
-
return rtf.format(
|
|
36
|
+
return rtf.format(sign * minutes, "minute");
|
|
42
37
|
}
|
|
38
|
+
const hours = Math.floor(minutes / 60);
|
|
43
39
|
if (hours < 24) {
|
|
44
|
-
return rtf.format(
|
|
40
|
+
return rtf.format(sign * hours, "hour");
|
|
45
41
|
}
|
|
42
|
+
const days = Math.floor(hours / 24);
|
|
46
43
|
if (days < 7) {
|
|
47
|
-
return rtf.format(
|
|
44
|
+
return rtf.format(sign * days, "day");
|
|
48
45
|
}
|
|
46
|
+
const weeks = Math.floor(days / 7);
|
|
49
47
|
if (days < 30) {
|
|
50
|
-
return rtf.format(
|
|
48
|
+
return rtf.format(sign * weeks, "week");
|
|
51
49
|
}
|
|
50
|
+
const months = Math.floor(days / 30);
|
|
52
51
|
if (months < 12) {
|
|
53
|
-
return rtf.format(
|
|
52
|
+
return rtf.format(sign * months, "month");
|
|
54
53
|
}
|
|
55
|
-
|
|
54
|
+
const years = Math.floor(days / 365);
|
|
55
|
+
return rtf.format(sign * years, "year");
|
|
56
56
|
}
|
|
@@ -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"}
|