chronos-date 1.0.2 → 1.1.1
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/basic-DqKyujoj.mjs +382 -0
- package/dist/basic-DsQqC5nZ.cjs +466 -0
- package/dist/constants.cjs +43 -1
- package/dist/constants.d.cts +17 -1
- package/dist/constants.d.mts +17 -1
- package/dist/constants.mjs +21 -1
- package/dist/convert-DbgntRVW.cjs +49 -0
- package/dist/convert-mMaI4YP0.mjs +38 -0
- package/dist/greet-D07t2_e6.mjs +51 -0
- package/dist/greet-hjVsd2dt.cjs +56 -0
- package/dist/guards.cjs +140 -1
- package/dist/guards.d.cts +18 -2
- package/dist/guards.d.mts +18 -2
- package/dist/guards.mjs +131 -1
- package/dist/helpers-CQzi908i.cjs +278 -0
- package/dist/helpers-DEf4sevD.mjs +201 -0
- package/dist/index.cjs +1477 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +1474 -1
- package/dist/non-primitives-D9zxCwX8.cjs +68 -0
- package/dist/non-primitives-DBtomDty.mjs +38 -0
- package/dist/plugins/banglaPlugin.cjs +137 -1
- package/dist/plugins/banglaPlugin.d.cts +19 -3
- package/dist/plugins/banglaPlugin.d.mts +19 -3
- package/dist/plugins/banglaPlugin.mjs +136 -1
- package/dist/plugins/businessPlugin.cjs +134 -1
- package/dist/plugins/businessPlugin.d.cts +17 -1
- package/dist/plugins/businessPlugin.d.mts +17 -1
- package/dist/plugins/businessPlugin.mjs +133 -1
- package/dist/plugins/dateRangePlugin.cjs +62 -1
- package/dist/plugins/dateRangePlugin.d.cts +19 -3
- package/dist/plugins/dateRangePlugin.d.mts +19 -3
- package/dist/plugins/dateRangePlugin.mjs +61 -1
- package/dist/plugins/dayPartPlugin.cjs +42 -1
- package/dist/plugins/dayPartPlugin.d.cts +17 -1
- package/dist/plugins/dayPartPlugin.d.mts +17 -1
- package/dist/plugins/dayPartPlugin.mjs +41 -1
- package/dist/plugins/durationPlugin.cjs +107 -1
- package/dist/plugins/durationPlugin.d.cts +17 -1
- package/dist/plugins/durationPlugin.d.mts +17 -1
- package/dist/plugins/durationPlugin.mjs +106 -1
- package/dist/plugins/fromNowPlugin.cjs +96 -1
- package/dist/plugins/fromNowPlugin.d.cts +17 -1
- package/dist/plugins/fromNowPlugin.d.mts +17 -1
- package/dist/plugins/fromNowPlugin.mjs +95 -1
- package/dist/plugins/greetingPlugin.cjs +35 -1
- package/dist/plugins/greetingPlugin.d.cts +17 -1
- package/dist/plugins/greetingPlugin.d.mts +17 -1
- package/dist/plugins/greetingPlugin.mjs +34 -1
- package/dist/plugins/palindromePlugin.cjs +38 -1
- package/dist/plugins/palindromePlugin.d.cts +17 -1
- package/dist/plugins/palindromePlugin.d.mts +17 -1
- package/dist/plugins/palindromePlugin.mjs +37 -1
- package/dist/plugins/relativeTimePlugin.cjs +90 -1
- package/dist/plugins/relativeTimePlugin.d.cts +17 -1
- package/dist/plugins/relativeTimePlugin.d.mts +17 -1
- package/dist/plugins/relativeTimePlugin.mjs +89 -1
- package/dist/plugins/roundPlugin.cjs +85 -1
- package/dist/plugins/roundPlugin.d.cts +17 -1
- package/dist/plugins/roundPlugin.d.mts +17 -1
- package/dist/plugins/roundPlugin.mjs +84 -1
- package/dist/plugins/seasonPlugin.cjs +47 -1
- package/dist/plugins/seasonPlugin.d.cts +17 -1
- package/dist/plugins/seasonPlugin.d.mts +17 -1
- package/dist/plugins/seasonPlugin.mjs +46 -1
- package/dist/plugins/timeZonePlugin.cjs +155 -1
- package/dist/plugins/timeZonePlugin.d.cts +17 -1
- package/dist/plugins/timeZonePlugin.d.mts +17 -1
- package/dist/plugins/timeZonePlugin.mjs +154 -1
- package/dist/plugins/zodiacPlugin.cjs +67 -1
- package/dist/plugins/zodiacPlugin.d.cts +17 -1
- package/dist/plugins/zodiacPlugin.d.mts +17 -1
- package/dist/plugins/zodiacPlugin.mjs +66 -1
- package/dist/primitives-CtuSNmV7.cjs +65 -0
- package/dist/primitives-dXzXlzJw.mjs +35 -0
- package/dist/seasons-B7kK88zq.cjs +434 -0
- package/dist/{seasons-CioTH5Dm.d.mts → seasons-B_kjFWIX.d.mts} +16 -0
- package/dist/{seasons-CsVeJ27s.d.cts → seasons-CpUn45n6.d.cts} +16 -0
- package/dist/seasons-Cq3ah3pV.mjs +368 -0
- package/dist/timezone-BNnHFgki.cjs +5625 -0
- package/dist/timezone-Db2CeL32.mjs +5589 -0
- package/dist/{types-B2fgrJ86.d.mts → types-Cb4gxrgJ.d.mts} +29 -15
- package/dist/{types-DPTQ_yLx.d.cts → types-CdmsXbU_.d.cts} +29 -15
- package/dist/types.cjs +16 -0
- package/dist/types.d.cts +18 -2
- package/dist/types.d.mts +18 -2
- package/dist/types.mjs +17 -1
- package/dist/utilities-BGX8dviZ.mjs +257 -0
- package/dist/utilities-BKtVo78T.mjs +59 -0
- package/dist/utilities-CpF3uys3.cjs +88 -0
- package/dist/utilities-D47SN9EZ.cjs +334 -0
- package/dist/utils.cjs +92 -1
- package/dist/utils.d.cts +20 -4
- package/dist/utils.d.mts +20 -4
- package/dist/utils.mjs +60 -1
- package/package.json +10 -4
- package/dist/basic-CKxaRSHQ.cjs +0 -1
- package/dist/basic-e46DaNAi.mjs +0 -1
- package/dist/convert-Bmp63ats.mjs +0 -1
- package/dist/convert-DrLrcgqz.cjs +0 -1
- package/dist/greet-BBsrvmkn.mjs +0 -1
- package/dist/greet-C-6mruI9.cjs +0 -1
- package/dist/helpers-DGzYnP81.cjs +0 -1
- package/dist/helpers-N1X_Rj_V.mjs +0 -1
- package/dist/non-primitives-B2EE6D6s.mjs +0 -1
- package/dist/non-primitives-Bu3a4WL4.cjs +0 -1
- package/dist/primitives-Cxss_JVF.mjs +0 -1
- package/dist/primitives-Db2FUp4e.cjs +0 -1
- package/dist/seasons-ChAIVphi.mjs +0 -1
- package/dist/seasons-oABOhHcX.cjs +0 -1
- package/dist/timezone-B10UItNO.mjs +0 -1
- package/dist/timezone-CWxbK_7I.cjs +0 -1
- package/dist/utilities-B8dOAQVD.cjs +0 -1
- package/dist/utilities-BJE06bms.mjs +0 -1
- package/dist/utilities-D2-p26DX.cjs +0 -1
- package/dist/utilities-DV_ohS37.mjs +0 -1
|
@@ -1 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { s as INTERNALS } from "../basic-DqKyujoj.mjs";
|
|
18
|
+
|
|
19
|
+
//#region src/plugins/durationPlugin.ts
|
|
20
|
+
/** * Plugin to inject `duration` related methods */
|
|
21
|
+
const durationPlugin = ($Chronos) => {
|
|
22
|
+
const { toNewDate } = $Chronos[INTERNALS];
|
|
23
|
+
/**
|
|
24
|
+
* @private Normalizes duration values based on sign and `absolute` flag.
|
|
25
|
+
* @param result The raw time breakdown to normalize.
|
|
26
|
+
* @param absolute If true, ensures all values are positive.
|
|
27
|
+
* @param isFuture Whether the duration was forward (true) or backward (false).
|
|
28
|
+
* @returns The normalized duration object.
|
|
29
|
+
*/
|
|
30
|
+
const _normalizeDuration = (result, absolute, isFuture) => {
|
|
31
|
+
const entries = Object.entries(result);
|
|
32
|
+
const updated = { ...result };
|
|
33
|
+
if (!absolute && !isFuture) {
|
|
34
|
+
for (const [key, value] of entries) if (value !== 0) updated[key] = value * -1;
|
|
35
|
+
} else if (absolute) for (const [key, value] of entries) updated[key] = Math.abs(value);
|
|
36
|
+
return updated;
|
|
37
|
+
};
|
|
38
|
+
$Chronos.prototype.duration = function(toTime, absolute = true) {
|
|
39
|
+
const now = this.toDate();
|
|
40
|
+
const target = toNewDate(this, toTime);
|
|
41
|
+
const isFuture = target > now;
|
|
42
|
+
const from = isFuture ? now : target;
|
|
43
|
+
const to = isFuture ? target : now;
|
|
44
|
+
/** Get difference between `to` and `from` for specific unit */
|
|
45
|
+
const _getDiff = (suffix) => {
|
|
46
|
+
return to[`get${suffix}`]() - from[`get${suffix}`]();
|
|
47
|
+
};
|
|
48
|
+
let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
|
|
49
|
+
if (ms < 0) {
|
|
50
|
+
ms += 1e3;
|
|
51
|
+
s--;
|
|
52
|
+
}
|
|
53
|
+
if (s < 0) {
|
|
54
|
+
s += 60;
|
|
55
|
+
m--;
|
|
56
|
+
}
|
|
57
|
+
if (m < 0) {
|
|
58
|
+
m += 60;
|
|
59
|
+
h--;
|
|
60
|
+
}
|
|
61
|
+
if (h < 0) {
|
|
62
|
+
h += 24;
|
|
63
|
+
d--;
|
|
64
|
+
}
|
|
65
|
+
if (d < 0) {
|
|
66
|
+
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
67
|
+
d += prevMonth.getDate();
|
|
68
|
+
mo--;
|
|
69
|
+
}
|
|
70
|
+
if (mo < 0) {
|
|
71
|
+
mo += 12;
|
|
72
|
+
y--;
|
|
73
|
+
}
|
|
74
|
+
return _normalizeDuration({
|
|
75
|
+
years: y,
|
|
76
|
+
months: mo,
|
|
77
|
+
days: d,
|
|
78
|
+
hours: h,
|
|
79
|
+
minutes: m,
|
|
80
|
+
seconds: s,
|
|
81
|
+
milliseconds: ms
|
|
82
|
+
}, absolute, isFuture);
|
|
83
|
+
};
|
|
84
|
+
$Chronos.prototype.durationString = function(options) {
|
|
85
|
+
const { toTime, absolute = true, maxUnits = 7, separator = ", ", style = "full", showZero = false } = options ?? {};
|
|
86
|
+
const duration = this.duration(toTime, absolute);
|
|
87
|
+
const units = {
|
|
88
|
+
years: "y",
|
|
89
|
+
months: "mo",
|
|
90
|
+
days: "d",
|
|
91
|
+
hours: "h",
|
|
92
|
+
minutes: "m",
|
|
93
|
+
seconds: "s",
|
|
94
|
+
milliseconds: "ms"
|
|
95
|
+
};
|
|
96
|
+
const _formatUnit = (unit, value) => {
|
|
97
|
+
if (style === "short") return `${value}${units[unit]}`;
|
|
98
|
+
return `${value} ${Math.abs(value) === 1 ? unit.slice(0, -1) : unit}`;
|
|
99
|
+
};
|
|
100
|
+
const parts = Object.entries(duration).filter(([_, value]) => showZero || Math.abs(value) > 0).slice(0, maxUnits).map(([unit, value]) => _formatUnit(unit, value));
|
|
101
|
+
return parts.length ? parts.join(separator) : style === "short" ? "0s" : "0 seconds";
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { durationPlugin };
|
|
@@ -1 +1,96 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
+
const require_basic = require('../basic-DsQqC5nZ.cjs');
|
|
19
|
+
const require_convert = require('../convert-DbgntRVW.cjs');
|
|
20
|
+
|
|
21
|
+
//#region src/plugins/fromNowPlugin.ts
|
|
22
|
+
/** * Plugin to inject `fromNow` method */
|
|
23
|
+
const fromNowPlugin = ($Chronos) => {
|
|
24
|
+
const { toNewDate } = $Chronos[require_basic.INTERNALS];
|
|
25
|
+
$Chronos.prototype.fromNow = function(level = "second", wSP = true, time) {
|
|
26
|
+
const now = toNewDate(this, time);
|
|
27
|
+
const target = this.toDate();
|
|
28
|
+
const isFuture = target > now;
|
|
29
|
+
const from = isFuture ? now : target;
|
|
30
|
+
const to = isFuture ? target : now;
|
|
31
|
+
/** Get difference between `to` and `from` for specific unit */
|
|
32
|
+
const _getDiff = (suffix) => {
|
|
33
|
+
return to[`get${suffix}`]() - from[`get${suffix}`]();
|
|
34
|
+
};
|
|
35
|
+
let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
|
|
36
|
+
if (ms < 0) {
|
|
37
|
+
ms += 1e3;
|
|
38
|
+
s--;
|
|
39
|
+
}
|
|
40
|
+
if (s < 0) {
|
|
41
|
+
s += 60;
|
|
42
|
+
m--;
|
|
43
|
+
}
|
|
44
|
+
if (m < 0) {
|
|
45
|
+
m += 60;
|
|
46
|
+
h--;
|
|
47
|
+
}
|
|
48
|
+
if (h < 0) {
|
|
49
|
+
h += 24;
|
|
50
|
+
d--;
|
|
51
|
+
}
|
|
52
|
+
if (d < 0) {
|
|
53
|
+
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
54
|
+
d += prevMonth.getDate();
|
|
55
|
+
mo--;
|
|
56
|
+
}
|
|
57
|
+
if (mo < 0) {
|
|
58
|
+
mo += 12;
|
|
59
|
+
y--;
|
|
60
|
+
}
|
|
61
|
+
const unitOrder = [
|
|
62
|
+
"year",
|
|
63
|
+
"month",
|
|
64
|
+
"day",
|
|
65
|
+
"hour",
|
|
66
|
+
"minute",
|
|
67
|
+
"second",
|
|
68
|
+
"millisecond"
|
|
69
|
+
];
|
|
70
|
+
const lvlIdx = unitOrder.indexOf(level);
|
|
71
|
+
const parts = [];
|
|
72
|
+
/** Push value-unit string to `parts` array */
|
|
73
|
+
const _pushToParts = (value, unit) => {
|
|
74
|
+
parts.push(require_convert.formatUnitWithPlural(value, unit));
|
|
75
|
+
};
|
|
76
|
+
/** Check if a unit level is required */
|
|
77
|
+
const _isLevelRequired = (unit) => {
|
|
78
|
+
return lvlIdx >= unitOrder.indexOf(unit);
|
|
79
|
+
};
|
|
80
|
+
if (y > 0) _pushToParts(y, "year");
|
|
81
|
+
if (_isLevelRequired("month") && mo > 0) _pushToParts(mo, "month");
|
|
82
|
+
if (_isLevelRequired("day") && d > 0) _pushToParts(d, "day");
|
|
83
|
+
if (_isLevelRequired("hour") && h > 0) _pushToParts(h, "hour");
|
|
84
|
+
if (_isLevelRequired("minute") && m > 0) _pushToParts(m, "minute");
|
|
85
|
+
if (_isLevelRequired("second") && s > 0) _pushToParts(s, "second");
|
|
86
|
+
if (_isLevelRequired("millisecond") && (ms > 0 || parts?.length === 0)) _pushToParts(ms, "millisecond");
|
|
87
|
+
let prefix = "";
|
|
88
|
+
let suffix = "";
|
|
89
|
+
if (wSP) if (isFuture) prefix = "in ";
|
|
90
|
+
else suffix = " ago";
|
|
91
|
+
return `${prefix}${parts.length ? parts?.join(" ") : `0 ${level}s`}${suffix}`;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
exports.fromNowPlugin = fromNowPlugin;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, D as ChronosInput, ut as FromNowUnit } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/fromNowPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, D as ChronosInput, ut as FromNowUnit } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/fromNowPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1 +1,95 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { s as INTERNALS } from "../basic-DqKyujoj.mjs";
|
|
18
|
+
import { t as formatUnitWithPlural } from "../convert-mMaI4YP0.mjs";
|
|
19
|
+
|
|
20
|
+
//#region src/plugins/fromNowPlugin.ts
|
|
21
|
+
/** * Plugin to inject `fromNow` method */
|
|
22
|
+
const fromNowPlugin = ($Chronos) => {
|
|
23
|
+
const { toNewDate } = $Chronos[INTERNALS];
|
|
24
|
+
$Chronos.prototype.fromNow = function(level = "second", wSP = true, time) {
|
|
25
|
+
const now = toNewDate(this, time);
|
|
26
|
+
const target = this.toDate();
|
|
27
|
+
const isFuture = target > now;
|
|
28
|
+
const from = isFuture ? now : target;
|
|
29
|
+
const to = isFuture ? target : now;
|
|
30
|
+
/** Get difference between `to` and `from` for specific unit */
|
|
31
|
+
const _getDiff = (suffix) => {
|
|
32
|
+
return to[`get${suffix}`]() - from[`get${suffix}`]();
|
|
33
|
+
};
|
|
34
|
+
let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
|
|
35
|
+
if (ms < 0) {
|
|
36
|
+
ms += 1e3;
|
|
37
|
+
s--;
|
|
38
|
+
}
|
|
39
|
+
if (s < 0) {
|
|
40
|
+
s += 60;
|
|
41
|
+
m--;
|
|
42
|
+
}
|
|
43
|
+
if (m < 0) {
|
|
44
|
+
m += 60;
|
|
45
|
+
h--;
|
|
46
|
+
}
|
|
47
|
+
if (h < 0) {
|
|
48
|
+
h += 24;
|
|
49
|
+
d--;
|
|
50
|
+
}
|
|
51
|
+
if (d < 0) {
|
|
52
|
+
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
53
|
+
d += prevMonth.getDate();
|
|
54
|
+
mo--;
|
|
55
|
+
}
|
|
56
|
+
if (mo < 0) {
|
|
57
|
+
mo += 12;
|
|
58
|
+
y--;
|
|
59
|
+
}
|
|
60
|
+
const unitOrder = [
|
|
61
|
+
"year",
|
|
62
|
+
"month",
|
|
63
|
+
"day",
|
|
64
|
+
"hour",
|
|
65
|
+
"minute",
|
|
66
|
+
"second",
|
|
67
|
+
"millisecond"
|
|
68
|
+
];
|
|
69
|
+
const lvlIdx = unitOrder.indexOf(level);
|
|
70
|
+
const parts = [];
|
|
71
|
+
/** Push value-unit string to `parts` array */
|
|
72
|
+
const _pushToParts = (value, unit) => {
|
|
73
|
+
parts.push(formatUnitWithPlural(value, unit));
|
|
74
|
+
};
|
|
75
|
+
/** Check if a unit level is required */
|
|
76
|
+
const _isLevelRequired = (unit) => {
|
|
77
|
+
return lvlIdx >= unitOrder.indexOf(unit);
|
|
78
|
+
};
|
|
79
|
+
if (y > 0) _pushToParts(y, "year");
|
|
80
|
+
if (_isLevelRequired("month") && mo > 0) _pushToParts(mo, "month");
|
|
81
|
+
if (_isLevelRequired("day") && d > 0) _pushToParts(d, "day");
|
|
82
|
+
if (_isLevelRequired("hour") && h > 0) _pushToParts(h, "hour");
|
|
83
|
+
if (_isLevelRequired("minute") && m > 0) _pushToParts(m, "minute");
|
|
84
|
+
if (_isLevelRequired("second") && s > 0) _pushToParts(s, "second");
|
|
85
|
+
if (_isLevelRequired("millisecond") && (ms > 0 || parts?.length === 0)) _pushToParts(ms, "millisecond");
|
|
86
|
+
let prefix = "";
|
|
87
|
+
let suffix = "";
|
|
88
|
+
if (wSP) if (isFuture) prefix = "in ";
|
|
89
|
+
else suffix = " ago";
|
|
90
|
+
return `${prefix}${parts.length ? parts?.join(" ") : `0 ${level}s`}${suffix}`;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { fromNowPlugin };
|
|
@@ -1 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
+
const require_greet = require('../greet-hjVsd2dt.cjs');
|
|
19
|
+
|
|
20
|
+
//#region src/plugins/greetingPlugin.ts
|
|
21
|
+
/** * Plugin to inject `getGreeting`/`greet` method */
|
|
22
|
+
const greetingPlugin = ($Chronos) => {
|
|
23
|
+
$Chronos.prototype.getGreeting = function(configs) {
|
|
24
|
+
return require_greet.getGreeting({
|
|
25
|
+
currentTime: this.formatStrict("HH:mm"),
|
|
26
|
+
...configs
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
$Chronos.prototype.greet = function(configs) {
|
|
30
|
+
return this.getGreeting(configs);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.greetingPlugin = greetingPlugin;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, dt as GreetingConfigs } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/greetingPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, dt as GreetingConfigs } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/greetingPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { t as getGreeting } from "../greet-D07t2_e6.mjs";
|
|
18
|
+
|
|
19
|
+
//#region src/plugins/greetingPlugin.ts
|
|
20
|
+
/** * Plugin to inject `getGreeting`/`greet` method */
|
|
21
|
+
const greetingPlugin = ($Chronos) => {
|
|
22
|
+
$Chronos.prototype.getGreeting = function(configs) {
|
|
23
|
+
return getGreeting({
|
|
24
|
+
currentTime: this.formatStrict("HH:mm"),
|
|
25
|
+
...configs
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
$Chronos.prototype.greet = function(configs) {
|
|
29
|
+
return this.getGreeting(configs);
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { greetingPlugin };
|
|
@@ -1 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
+
const require_convert = require('../convert-DbgntRVW.cjs');
|
|
19
|
+
|
|
20
|
+
//#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/string/guards.js
|
|
21
|
+
const isPalindrome = (input) => {
|
|
22
|
+
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
23
|
+
return normalized === require_convert.reverseString(normalized);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/plugins/palindromePlugin.ts
|
|
28
|
+
/** * Plugin to inject `isPalindromeDate` method */
|
|
29
|
+
const palindromePlugin = ($Chronos) => {
|
|
30
|
+
$Chronos.prototype.isPalindromeDate = function(shortYear = false) {
|
|
31
|
+
const padded = this.formatStrict(shortYear ? "YY-MM-DD" : "YYYY-MM-DD");
|
|
32
|
+
const normal = this.formatStrict(shortYear ? "YY-M-D" : "YYYY-M-D");
|
|
33
|
+
return isPalindrome(padded) || isPalindrome(normal);
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.palindromePlugin = palindromePlugin;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/palindromePlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/palindromePlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { n as reverseString } from "../convert-mMaI4YP0.mjs";
|
|
18
|
+
|
|
19
|
+
//#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/string/guards.js
|
|
20
|
+
const isPalindrome = (input) => {
|
|
21
|
+
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
22
|
+
return normalized === reverseString(normalized);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/plugins/palindromePlugin.ts
|
|
27
|
+
/** * Plugin to inject `isPalindromeDate` method */
|
|
28
|
+
const palindromePlugin = ($Chronos) => {
|
|
29
|
+
$Chronos.prototype.isPalindromeDate = function(shortYear = false) {
|
|
30
|
+
const padded = this.formatStrict(shortYear ? "YY-MM-DD" : "YYYY-MM-DD");
|
|
31
|
+
const normal = this.formatStrict(shortYear ? "YY-M-D" : "YYYY-M-D");
|
|
32
|
+
return isPalindrome(padded) || isPalindrome(normal);
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { palindromePlugin };
|