chronos-date 1.0.1 → 1.1.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/basic-DIp_pxR2.cjs +450 -0
- package/dist/basic-Dputob9z.mjs +366 -0
- package/dist/constants.cjs +27 -1
- package/dist/constants.mjs +5 -1
- package/dist/convert-CNVL-mop.mjs +22 -0
- package/dist/convert-dQuGWhVm.cjs +33 -0
- package/dist/greet-B8ZtypgG.cjs +40 -0
- package/dist/greet-B9j4afzD.mjs +35 -0
- package/dist/guards.cjs +119 -1
- package/dist/guards.mjs +110 -1
- package/dist/helpers-CrMc9iJZ.mjs +185 -0
- package/dist/helpers-M_SfAbAv.cjs +262 -0
- package/dist/index.cjs +1461 -1
- package/dist/index.mjs +1458 -1
- package/dist/non-primitives-CT4vszrX.cjs +52 -0
- package/dist/non-primitives-DrQfPj1r.mjs +22 -0
- package/dist/plugins/banglaPlugin.cjs +121 -1
- package/dist/plugins/banglaPlugin.d.cts +1 -1
- package/dist/plugins/banglaPlugin.d.mts +1 -1
- package/dist/plugins/banglaPlugin.mjs +120 -1
- package/dist/plugins/businessPlugin.cjs +118 -1
- package/dist/plugins/businessPlugin.d.cts +1 -1
- package/dist/plugins/businessPlugin.d.mts +1 -1
- package/dist/plugins/businessPlugin.mjs +117 -1
- package/dist/plugins/dateRangePlugin.cjs +46 -1
- package/dist/plugins/dateRangePlugin.d.cts +1 -1
- package/dist/plugins/dateRangePlugin.d.mts +1 -1
- package/dist/plugins/dateRangePlugin.mjs +45 -1
- package/dist/plugins/dayPartPlugin.cjs +26 -1
- package/dist/plugins/dayPartPlugin.d.cts +1 -1
- package/dist/plugins/dayPartPlugin.d.mts +1 -1
- package/dist/plugins/dayPartPlugin.mjs +25 -1
- package/dist/plugins/durationPlugin.cjs +91 -1
- package/dist/plugins/durationPlugin.d.cts +1 -1
- package/dist/plugins/durationPlugin.d.mts +1 -1
- package/dist/plugins/durationPlugin.mjs +90 -1
- package/dist/plugins/fromNowPlugin.cjs +80 -1
- package/dist/plugins/fromNowPlugin.d.cts +1 -1
- package/dist/plugins/fromNowPlugin.d.mts +1 -1
- package/dist/plugins/fromNowPlugin.mjs +79 -1
- package/dist/plugins/greetingPlugin.cjs +19 -1
- package/dist/plugins/greetingPlugin.d.cts +1 -1
- package/dist/plugins/greetingPlugin.d.mts +1 -1
- package/dist/plugins/greetingPlugin.mjs +18 -1
- package/dist/plugins/palindromePlugin.cjs +22 -1
- package/dist/plugins/palindromePlugin.d.cts +1 -1
- package/dist/plugins/palindromePlugin.d.mts +1 -1
- package/dist/plugins/palindromePlugin.mjs +21 -1
- package/dist/plugins/relativeTimePlugin.cjs +74 -1
- package/dist/plugins/relativeTimePlugin.d.cts +1 -1
- package/dist/plugins/relativeTimePlugin.d.mts +1 -1
- package/dist/plugins/relativeTimePlugin.mjs +73 -1
- package/dist/plugins/roundPlugin.cjs +69 -1
- package/dist/plugins/roundPlugin.d.cts +1 -1
- package/dist/plugins/roundPlugin.d.mts +1 -1
- package/dist/plugins/roundPlugin.mjs +68 -1
- package/dist/plugins/seasonPlugin.cjs +31 -1
- package/dist/plugins/seasonPlugin.d.cts +1 -1
- package/dist/plugins/seasonPlugin.d.mts +1 -1
- package/dist/plugins/seasonPlugin.mjs +30 -1
- package/dist/plugins/timeZonePlugin.cjs +139 -1
- package/dist/plugins/timeZonePlugin.d.cts +1 -1
- package/dist/plugins/timeZonePlugin.d.mts +1 -1
- package/dist/plugins/timeZonePlugin.mjs +138 -1
- package/dist/plugins/zodiacPlugin.cjs +51 -1
- package/dist/plugins/zodiacPlugin.d.cts +1 -1
- package/dist/plugins/zodiacPlugin.d.mts +1 -1
- package/dist/plugins/zodiacPlugin.mjs +50 -1
- package/dist/primitives-BME3_QrA.cjs +49 -0
- package/dist/primitives-DEt6I7Sy.mjs +19 -0
- package/dist/seasons-CHnjrIKK.mjs +352 -0
- package/dist/seasons-CcZicoe1.cjs +418 -0
- package/dist/timezone-BfBXeMK_.mjs +5573 -0
- package/dist/timezone-DYVJJYKz.cjs +5609 -0
- package/dist/types.mjs +1 -1
- package/dist/utilities-BU4MSYS7.mjs +43 -0
- package/dist/utilities-CGL7F6R9.cjs +72 -0
- package/dist/utilities-CtOZhIYv.mjs +241 -0
- package/dist/utilities-bXwTPJaD.cjs +318 -0
- package/dist/utils.cjs +76 -1
- package/dist/utils.mjs +44 -1
- package/package.json +1 -1
- 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,46 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_basic = require('../basic-DIp_pxR2.cjs');
|
|
3
|
+
const require_primitives = require('../primitives-BME3_QrA.cjs');
|
|
4
|
+
const require_non_primitives = require('../non-primitives-CT4vszrX.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/dateRangePlugin.ts
|
|
7
|
+
/** * Plugin to inject `getDatesInRange` related method */
|
|
8
|
+
const dateRangePlugin = ($Chronos) => {
|
|
9
|
+
const { internalDate: $Date, cast, withOrigin, offset } = $Chronos[require_basic.INTERNALS];
|
|
10
|
+
$Chronos.prototype.getDatesInRange = function(options) {
|
|
11
|
+
let startDate = this.clone(), endDate = this.addWeeks(4);
|
|
12
|
+
const { format = "local", onlyDays, skipDays, roundDate = false } = options ?? {};
|
|
13
|
+
if (options) {
|
|
14
|
+
if ("from" in options || "to" in options) {
|
|
15
|
+
if (options?.from) startDate = cast(options.from);
|
|
16
|
+
if (options?.to) endDate = cast(options.to);
|
|
17
|
+
} else if ("span" in options || "unit" in options) {
|
|
18
|
+
const { span = 4, unit = "week" } = options;
|
|
19
|
+
endDate = startDate.add(span, unit);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (roundDate) {
|
|
23
|
+
startDate = startDate.startOf("day");
|
|
24
|
+
endDate = endDate.startOf("day");
|
|
25
|
+
}
|
|
26
|
+
const skippedDays = require_non_primitives.isValidArray(onlyDays) ? onlyDays : require_non_primitives.isValidArray(skipDays) ? skipDays : [];
|
|
27
|
+
const skipSet = new Set(skippedDays.map((day) => require_primitives.isNumber(day) ? day : require_basic.DAYS.indexOf(day)));
|
|
28
|
+
const dates = [];
|
|
29
|
+
const startTime = $Date(startDate).getTime();
|
|
30
|
+
const endTime = $Date(endDate).getTime();
|
|
31
|
+
const step = (startTime <= endTime ? 1 : -1) * require_basic.MS_PER_DAY;
|
|
32
|
+
const totalDays = Math.floor(Math.abs(endTime - startTime) / require_basic.MS_PER_DAY);
|
|
33
|
+
for (let i = 0; i <= totalDays; i++) {
|
|
34
|
+
const ts = startTime + i * step;
|
|
35
|
+
const wDay = new Date(ts).getDay();
|
|
36
|
+
if (require_non_primitives.isValidArray(onlyDays) ? skipSet.has(wDay) : !skipSet.has(wDay)) {
|
|
37
|
+
const chr = withOrigin(new $Chronos(ts), "clone", offset(this), startDate.timeZoneName, startDate.timeZoneId, startDate.$tzTracker);
|
|
38
|
+
dates.push(format === "local" ? chr.toLocalISOString() : chr.toISOString());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return dates;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.dateRangePlugin = dateRangePlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, I as RangeWithDates, L as RelativeDateRange, ht as ISOTimeString } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/dateRangePlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns an array of ISO date-time strings within a specific date range.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, I as RangeWithDates, L as RelativeDateRange, ht as ISOTimeString } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/dateRangePlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns an array of ISO date-time strings within a specific date range.
|
|
@@ -1 +1,45 @@
|
|
|
1
|
-
import{o as
|
|
1
|
+
import { o as DAYS, s as INTERNALS, u as MS_PER_DAY } from "../basic-Dputob9z.mjs";
|
|
2
|
+
import { r as isNumber } from "../primitives-DEt6I7Sy.mjs";
|
|
3
|
+
import { a as isValidArray } from "../non-primitives-DrQfPj1r.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/dateRangePlugin.ts
|
|
6
|
+
/** * Plugin to inject `getDatesInRange` related method */
|
|
7
|
+
const dateRangePlugin = ($Chronos) => {
|
|
8
|
+
const { internalDate: $Date, cast, withOrigin, offset } = $Chronos[INTERNALS];
|
|
9
|
+
$Chronos.prototype.getDatesInRange = function(options) {
|
|
10
|
+
let startDate = this.clone(), endDate = this.addWeeks(4);
|
|
11
|
+
const { format = "local", onlyDays, skipDays, roundDate = false } = options ?? {};
|
|
12
|
+
if (options) {
|
|
13
|
+
if ("from" in options || "to" in options) {
|
|
14
|
+
if (options?.from) startDate = cast(options.from);
|
|
15
|
+
if (options?.to) endDate = cast(options.to);
|
|
16
|
+
} else if ("span" in options || "unit" in options) {
|
|
17
|
+
const { span = 4, unit = "week" } = options;
|
|
18
|
+
endDate = startDate.add(span, unit);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (roundDate) {
|
|
22
|
+
startDate = startDate.startOf("day");
|
|
23
|
+
endDate = endDate.startOf("day");
|
|
24
|
+
}
|
|
25
|
+
const skippedDays = isValidArray(onlyDays) ? onlyDays : isValidArray(skipDays) ? skipDays : [];
|
|
26
|
+
const skipSet = new Set(skippedDays.map((day) => isNumber(day) ? day : DAYS.indexOf(day)));
|
|
27
|
+
const dates = [];
|
|
28
|
+
const startTime = $Date(startDate).getTime();
|
|
29
|
+
const endTime = $Date(endDate).getTime();
|
|
30
|
+
const step = (startTime <= endTime ? 1 : -1) * MS_PER_DAY;
|
|
31
|
+
const totalDays = Math.floor(Math.abs(endTime - startTime) / MS_PER_DAY);
|
|
32
|
+
for (let i = 0; i <= totalDays; i++) {
|
|
33
|
+
const ts = startTime + i * step;
|
|
34
|
+
const wDay = new Date(ts).getDay();
|
|
35
|
+
if (isValidArray(onlyDays) ? skipSet.has(wDay) : !skipSet.has(wDay)) {
|
|
36
|
+
const chr = withOrigin(new $Chronos(ts), "clone", offset(this), startDate.timeZoneName, startDate.timeZoneId, startDate.$tzTracker);
|
|
37
|
+
dates.push(format === "local" ? chr.toLocalISOString() : chr.toISOString());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return dates;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { dateRangePlugin };
|
|
@@ -1 +1,26 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_basic = require('../basic-DIp_pxR2.cjs');
|
|
3
|
+
const require_non_primitives = require('../non-primitives-CT4vszrX.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/dayPartPlugin.ts
|
|
6
|
+
/** * Plugin to inject `getPartOfDay` method */
|
|
7
|
+
const dayPartPlugin = ($Chronos) => {
|
|
8
|
+
$Chronos.prototype.getPartOfDay = function(config) {
|
|
9
|
+
const hour = this.hour;
|
|
10
|
+
const ranges = {
|
|
11
|
+
...require_basic.DATE_PART_RANGES,
|
|
12
|
+
...require_non_primitives.isNotEmptyObject(config) && config
|
|
13
|
+
};
|
|
14
|
+
for (const [part, [start, end]] of Object.entries(ranges)) {
|
|
15
|
+
const from = Number(start);
|
|
16
|
+
const to = Number(end);
|
|
17
|
+
if (from <= to) {
|
|
18
|
+
if (hour >= from && hour <= to) return part;
|
|
19
|
+
} else if (hour >= from || hour <= to) return part;
|
|
20
|
+
}
|
|
21
|
+
return "night";
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.dayPartPlugin = dayPartPlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, c as DayPart, l as DayPartConfig } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/dayPartPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns the part of day (`'midnight', 'lateNight', 'night', 'morning', 'afternoon', 'evening'`) based on the current hour.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, c as DayPart, l as DayPartConfig } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/dayPartPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns the part of day (`'midnight', 'lateNight', 'night', 'morning', 'afternoon', 'evening'`) based on the current hour.
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import { a as DATE_PART_RANGES } from "../basic-Dputob9z.mjs";
|
|
2
|
+
import { n as isNotEmptyObject } from "../non-primitives-DrQfPj1r.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/dayPartPlugin.ts
|
|
5
|
+
/** * Plugin to inject `getPartOfDay` method */
|
|
6
|
+
const dayPartPlugin = ($Chronos) => {
|
|
7
|
+
$Chronos.prototype.getPartOfDay = function(config) {
|
|
8
|
+
const hour = this.hour;
|
|
9
|
+
const ranges = {
|
|
10
|
+
...DATE_PART_RANGES,
|
|
11
|
+
...isNotEmptyObject(config) && config
|
|
12
|
+
};
|
|
13
|
+
for (const [part, [start, end]] of Object.entries(ranges)) {
|
|
14
|
+
const from = Number(start);
|
|
15
|
+
const to = Number(end);
|
|
16
|
+
if (from <= to) {
|
|
17
|
+
if (hour >= from && hour <= to) return part;
|
|
18
|
+
} else if (hour >= from || hour <= to) return part;
|
|
19
|
+
}
|
|
20
|
+
return "night";
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { dayPartPlugin };
|
|
@@ -1 +1,91 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_basic = require('../basic-DIp_pxR2.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/durationPlugin.ts
|
|
5
|
+
/** * Plugin to inject `duration` related methods */
|
|
6
|
+
const durationPlugin = ($Chronos) => {
|
|
7
|
+
const { toNewDate } = $Chronos[require_basic.INTERNALS];
|
|
8
|
+
/**
|
|
9
|
+
* @private Normalizes duration values based on sign and `absolute` flag.
|
|
10
|
+
* @param result The raw time breakdown to normalize.
|
|
11
|
+
* @param absolute If true, ensures all values are positive.
|
|
12
|
+
* @param isFuture Whether the duration was forward (true) or backward (false).
|
|
13
|
+
* @returns The normalized duration object.
|
|
14
|
+
*/
|
|
15
|
+
const _normalizeDuration = (result, absolute, isFuture) => {
|
|
16
|
+
const entries = Object.entries(result);
|
|
17
|
+
const updated = { ...result };
|
|
18
|
+
if (!absolute && !isFuture) {
|
|
19
|
+
for (const [key, value] of entries) if (value !== 0) updated[key] = value * -1;
|
|
20
|
+
} else if (absolute) for (const [key, value] of entries) updated[key] = Math.abs(value);
|
|
21
|
+
return updated;
|
|
22
|
+
};
|
|
23
|
+
$Chronos.prototype.duration = function(toTime, absolute = true) {
|
|
24
|
+
const now = this.toDate();
|
|
25
|
+
const target = toNewDate(this, toTime);
|
|
26
|
+
const isFuture = target > now;
|
|
27
|
+
const from = isFuture ? now : target;
|
|
28
|
+
const to = isFuture ? target : now;
|
|
29
|
+
/** Get difference between `to` and `from` for specific unit */
|
|
30
|
+
const _getDiff = (suffix) => {
|
|
31
|
+
return to[`get${suffix}`]() - from[`get${suffix}`]();
|
|
32
|
+
};
|
|
33
|
+
let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
|
|
34
|
+
if (ms < 0) {
|
|
35
|
+
ms += 1e3;
|
|
36
|
+
s--;
|
|
37
|
+
}
|
|
38
|
+
if (s < 0) {
|
|
39
|
+
s += 60;
|
|
40
|
+
m--;
|
|
41
|
+
}
|
|
42
|
+
if (m < 0) {
|
|
43
|
+
m += 60;
|
|
44
|
+
h--;
|
|
45
|
+
}
|
|
46
|
+
if (h < 0) {
|
|
47
|
+
h += 24;
|
|
48
|
+
d--;
|
|
49
|
+
}
|
|
50
|
+
if (d < 0) {
|
|
51
|
+
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
52
|
+
d += prevMonth.getDate();
|
|
53
|
+
mo--;
|
|
54
|
+
}
|
|
55
|
+
if (mo < 0) {
|
|
56
|
+
mo += 12;
|
|
57
|
+
y--;
|
|
58
|
+
}
|
|
59
|
+
return _normalizeDuration({
|
|
60
|
+
years: y,
|
|
61
|
+
months: mo,
|
|
62
|
+
days: d,
|
|
63
|
+
hours: h,
|
|
64
|
+
minutes: m,
|
|
65
|
+
seconds: s,
|
|
66
|
+
milliseconds: ms
|
|
67
|
+
}, absolute, isFuture);
|
|
68
|
+
};
|
|
69
|
+
$Chronos.prototype.durationString = function(options) {
|
|
70
|
+
const { toTime, absolute = true, maxUnits = 7, separator = ", ", style = "full", showZero = false } = options ?? {};
|
|
71
|
+
const duration = this.duration(toTime, absolute);
|
|
72
|
+
const units = {
|
|
73
|
+
years: "y",
|
|
74
|
+
months: "mo",
|
|
75
|
+
days: "d",
|
|
76
|
+
hours: "h",
|
|
77
|
+
minutes: "m",
|
|
78
|
+
seconds: "s",
|
|
79
|
+
milliseconds: "ms"
|
|
80
|
+
};
|
|
81
|
+
const _formatUnit = (unit, value) => {
|
|
82
|
+
if (style === "short") return `${value}${units[unit]}`;
|
|
83
|
+
return `${value} ${Math.abs(value) === 1 ? unit.slice(0, -1) : unit}`;
|
|
84
|
+
};
|
|
85
|
+
const parts = Object.entries(duration).filter(([_, value]) => showZero || Math.abs(value) > 0).slice(0, maxUnits).map(([unit, value]) => _formatUnit(unit, value));
|
|
86
|
+
return parts.length ? parts.join(separator) : style === "short" ? "0s" : "0 seconds";
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
exports.durationPlugin = durationPlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, D as ChronosInput, d as DurationOptions, g as TimeDuration } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/durationPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns the full time duration breakdown between current input (start) and another time (to) as {@link TimeDuration} object.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, D as ChronosInput, d as DurationOptions, g as TimeDuration } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/durationPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns the full time duration breakdown between current input (start) and another time (to) as {@link TimeDuration} object.
|
|
@@ -1 +1,90 @@
|
|
|
1
|
-
import{s as
|
|
1
|
+
import { s as INTERNALS } from "../basic-Dputob9z.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/durationPlugin.ts
|
|
4
|
+
/** * Plugin to inject `duration` related methods */
|
|
5
|
+
const durationPlugin = ($Chronos) => {
|
|
6
|
+
const { toNewDate } = $Chronos[INTERNALS];
|
|
7
|
+
/**
|
|
8
|
+
* @private Normalizes duration values based on sign and `absolute` flag.
|
|
9
|
+
* @param result The raw time breakdown to normalize.
|
|
10
|
+
* @param absolute If true, ensures all values are positive.
|
|
11
|
+
* @param isFuture Whether the duration was forward (true) or backward (false).
|
|
12
|
+
* @returns The normalized duration object.
|
|
13
|
+
*/
|
|
14
|
+
const _normalizeDuration = (result, absolute, isFuture) => {
|
|
15
|
+
const entries = Object.entries(result);
|
|
16
|
+
const updated = { ...result };
|
|
17
|
+
if (!absolute && !isFuture) {
|
|
18
|
+
for (const [key, value] of entries) if (value !== 0) updated[key] = value * -1;
|
|
19
|
+
} else if (absolute) for (const [key, value] of entries) updated[key] = Math.abs(value);
|
|
20
|
+
return updated;
|
|
21
|
+
};
|
|
22
|
+
$Chronos.prototype.duration = function(toTime, absolute = true) {
|
|
23
|
+
const now = this.toDate();
|
|
24
|
+
const target = toNewDate(this, toTime);
|
|
25
|
+
const isFuture = target > now;
|
|
26
|
+
const from = isFuture ? now : target;
|
|
27
|
+
const to = isFuture ? target : now;
|
|
28
|
+
/** Get difference between `to` and `from` for specific unit */
|
|
29
|
+
const _getDiff = (suffix) => {
|
|
30
|
+
return to[`get${suffix}`]() - from[`get${suffix}`]();
|
|
31
|
+
};
|
|
32
|
+
let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
|
|
33
|
+
if (ms < 0) {
|
|
34
|
+
ms += 1e3;
|
|
35
|
+
s--;
|
|
36
|
+
}
|
|
37
|
+
if (s < 0) {
|
|
38
|
+
s += 60;
|
|
39
|
+
m--;
|
|
40
|
+
}
|
|
41
|
+
if (m < 0) {
|
|
42
|
+
m += 60;
|
|
43
|
+
h--;
|
|
44
|
+
}
|
|
45
|
+
if (h < 0) {
|
|
46
|
+
h += 24;
|
|
47
|
+
d--;
|
|
48
|
+
}
|
|
49
|
+
if (d < 0) {
|
|
50
|
+
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
51
|
+
d += prevMonth.getDate();
|
|
52
|
+
mo--;
|
|
53
|
+
}
|
|
54
|
+
if (mo < 0) {
|
|
55
|
+
mo += 12;
|
|
56
|
+
y--;
|
|
57
|
+
}
|
|
58
|
+
return _normalizeDuration({
|
|
59
|
+
years: y,
|
|
60
|
+
months: mo,
|
|
61
|
+
days: d,
|
|
62
|
+
hours: h,
|
|
63
|
+
minutes: m,
|
|
64
|
+
seconds: s,
|
|
65
|
+
milliseconds: ms
|
|
66
|
+
}, absolute, isFuture);
|
|
67
|
+
};
|
|
68
|
+
$Chronos.prototype.durationString = function(options) {
|
|
69
|
+
const { toTime, absolute = true, maxUnits = 7, separator = ", ", style = "full", showZero = false } = options ?? {};
|
|
70
|
+
const duration = this.duration(toTime, absolute);
|
|
71
|
+
const units = {
|
|
72
|
+
years: "y",
|
|
73
|
+
months: "mo",
|
|
74
|
+
days: "d",
|
|
75
|
+
hours: "h",
|
|
76
|
+
minutes: "m",
|
|
77
|
+
seconds: "s",
|
|
78
|
+
milliseconds: "ms"
|
|
79
|
+
};
|
|
80
|
+
const _formatUnit = (unit, value) => {
|
|
81
|
+
if (style === "short") return `${value}${units[unit]}`;
|
|
82
|
+
return `${value} ${Math.abs(value) === 1 ? unit.slice(0, -1) : unit}`;
|
|
83
|
+
};
|
|
84
|
+
const parts = Object.entries(duration).filter(([_, value]) => showZero || Math.abs(value) > 0).slice(0, maxUnits).map(([unit, value]) => _formatUnit(unit, value));
|
|
85
|
+
return parts.length ? parts.join(separator) : style === "short" ? "0s" : "0 seconds";
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { durationPlugin };
|
|
@@ -1 +1,80 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_basic = require('../basic-DIp_pxR2.cjs');
|
|
3
|
+
const require_convert = require('../convert-dQuGWhVm.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/fromNowPlugin.ts
|
|
6
|
+
/** * Plugin to inject `fromNow` method */
|
|
7
|
+
const fromNowPlugin = ($Chronos) => {
|
|
8
|
+
const { toNewDate } = $Chronos[require_basic.INTERNALS];
|
|
9
|
+
$Chronos.prototype.fromNow = function(level = "second", wSP = true, time) {
|
|
10
|
+
const now = toNewDate(this, time);
|
|
11
|
+
const target = this.toDate();
|
|
12
|
+
const isFuture = target > now;
|
|
13
|
+
const from = isFuture ? now : target;
|
|
14
|
+
const to = isFuture ? target : now;
|
|
15
|
+
/** Get difference between `to` and `from` for specific unit */
|
|
16
|
+
const _getDiff = (suffix) => {
|
|
17
|
+
return to[`get${suffix}`]() - from[`get${suffix}`]();
|
|
18
|
+
};
|
|
19
|
+
let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
|
|
20
|
+
if (ms < 0) {
|
|
21
|
+
ms += 1e3;
|
|
22
|
+
s--;
|
|
23
|
+
}
|
|
24
|
+
if (s < 0) {
|
|
25
|
+
s += 60;
|
|
26
|
+
m--;
|
|
27
|
+
}
|
|
28
|
+
if (m < 0) {
|
|
29
|
+
m += 60;
|
|
30
|
+
h--;
|
|
31
|
+
}
|
|
32
|
+
if (h < 0) {
|
|
33
|
+
h += 24;
|
|
34
|
+
d--;
|
|
35
|
+
}
|
|
36
|
+
if (d < 0) {
|
|
37
|
+
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
38
|
+
d += prevMonth.getDate();
|
|
39
|
+
mo--;
|
|
40
|
+
}
|
|
41
|
+
if (mo < 0) {
|
|
42
|
+
mo += 12;
|
|
43
|
+
y--;
|
|
44
|
+
}
|
|
45
|
+
const unitOrder = [
|
|
46
|
+
"year",
|
|
47
|
+
"month",
|
|
48
|
+
"day",
|
|
49
|
+
"hour",
|
|
50
|
+
"minute",
|
|
51
|
+
"second",
|
|
52
|
+
"millisecond"
|
|
53
|
+
];
|
|
54
|
+
const lvlIdx = unitOrder.indexOf(level);
|
|
55
|
+
const parts = [];
|
|
56
|
+
/** Push value-unit string to `parts` array */
|
|
57
|
+
const _pushToParts = (value, unit) => {
|
|
58
|
+
parts.push(require_convert.formatUnitWithPlural(value, unit));
|
|
59
|
+
};
|
|
60
|
+
/** Check if a unit level is required */
|
|
61
|
+
const _isLevelRequired = (unit) => {
|
|
62
|
+
return lvlIdx >= unitOrder.indexOf(unit);
|
|
63
|
+
};
|
|
64
|
+
if (y > 0) _pushToParts(y, "year");
|
|
65
|
+
if (_isLevelRequired("month") && mo > 0) _pushToParts(mo, "month");
|
|
66
|
+
if (_isLevelRequired("day") && d > 0) _pushToParts(d, "day");
|
|
67
|
+
if (_isLevelRequired("hour") && h > 0) _pushToParts(h, "hour");
|
|
68
|
+
if (_isLevelRequired("minute") && m > 0) _pushToParts(m, "minute");
|
|
69
|
+
if (_isLevelRequired("second") && s > 0) _pushToParts(s, "second");
|
|
70
|
+
if (_isLevelRequired("millisecond") && (ms > 0 || parts?.length === 0)) _pushToParts(ms, "millisecond");
|
|
71
|
+
let prefix = "";
|
|
72
|
+
let suffix = "";
|
|
73
|
+
if (wSP) if (isFuture) prefix = "in ";
|
|
74
|
+
else suffix = " ago";
|
|
75
|
+
return `${prefix}${parts.length ? parts?.join(" ") : `0 ${level}s`}${suffix}`;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
exports.fromNowPlugin = fromNowPlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, D as ChronosInput, ut as FromNowUnit } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/fromNowPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns full time difference from now (or a specified time) down to a given level.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, D as ChronosInput, ut as FromNowUnit } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/fromNowPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns full time difference from now (or a specified time) down to a given level.
|
|
@@ -1 +1,79 @@
|
|
|
1
|
-
import{s as
|
|
1
|
+
import { s as INTERNALS } from "../basic-Dputob9z.mjs";
|
|
2
|
+
import { t as formatUnitWithPlural } from "../convert-CNVL-mop.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/fromNowPlugin.ts
|
|
5
|
+
/** * Plugin to inject `fromNow` method */
|
|
6
|
+
const fromNowPlugin = ($Chronos) => {
|
|
7
|
+
const { toNewDate } = $Chronos[INTERNALS];
|
|
8
|
+
$Chronos.prototype.fromNow = function(level = "second", wSP = true, time) {
|
|
9
|
+
const now = toNewDate(this, time);
|
|
10
|
+
const target = this.toDate();
|
|
11
|
+
const isFuture = target > now;
|
|
12
|
+
const from = isFuture ? now : target;
|
|
13
|
+
const to = isFuture ? target : now;
|
|
14
|
+
/** Get difference between `to` and `from` for specific unit */
|
|
15
|
+
const _getDiff = (suffix) => {
|
|
16
|
+
return to[`get${suffix}`]() - from[`get${suffix}`]();
|
|
17
|
+
};
|
|
18
|
+
let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
|
|
19
|
+
if (ms < 0) {
|
|
20
|
+
ms += 1e3;
|
|
21
|
+
s--;
|
|
22
|
+
}
|
|
23
|
+
if (s < 0) {
|
|
24
|
+
s += 60;
|
|
25
|
+
m--;
|
|
26
|
+
}
|
|
27
|
+
if (m < 0) {
|
|
28
|
+
m += 60;
|
|
29
|
+
h--;
|
|
30
|
+
}
|
|
31
|
+
if (h < 0) {
|
|
32
|
+
h += 24;
|
|
33
|
+
d--;
|
|
34
|
+
}
|
|
35
|
+
if (d < 0) {
|
|
36
|
+
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
37
|
+
d += prevMonth.getDate();
|
|
38
|
+
mo--;
|
|
39
|
+
}
|
|
40
|
+
if (mo < 0) {
|
|
41
|
+
mo += 12;
|
|
42
|
+
y--;
|
|
43
|
+
}
|
|
44
|
+
const unitOrder = [
|
|
45
|
+
"year",
|
|
46
|
+
"month",
|
|
47
|
+
"day",
|
|
48
|
+
"hour",
|
|
49
|
+
"minute",
|
|
50
|
+
"second",
|
|
51
|
+
"millisecond"
|
|
52
|
+
];
|
|
53
|
+
const lvlIdx = unitOrder.indexOf(level);
|
|
54
|
+
const parts = [];
|
|
55
|
+
/** Push value-unit string to `parts` array */
|
|
56
|
+
const _pushToParts = (value, unit) => {
|
|
57
|
+
parts.push(formatUnitWithPlural(value, unit));
|
|
58
|
+
};
|
|
59
|
+
/** Check if a unit level is required */
|
|
60
|
+
const _isLevelRequired = (unit) => {
|
|
61
|
+
return lvlIdx >= unitOrder.indexOf(unit);
|
|
62
|
+
};
|
|
63
|
+
if (y > 0) _pushToParts(y, "year");
|
|
64
|
+
if (_isLevelRequired("month") && mo > 0) _pushToParts(mo, "month");
|
|
65
|
+
if (_isLevelRequired("day") && d > 0) _pushToParts(d, "day");
|
|
66
|
+
if (_isLevelRequired("hour") && h > 0) _pushToParts(h, "hour");
|
|
67
|
+
if (_isLevelRequired("minute") && m > 0) _pushToParts(m, "minute");
|
|
68
|
+
if (_isLevelRequired("second") && s > 0) _pushToParts(s, "second");
|
|
69
|
+
if (_isLevelRequired("millisecond") && (ms > 0 || parts?.length === 0)) _pushToParts(ms, "millisecond");
|
|
70
|
+
let prefix = "";
|
|
71
|
+
let suffix = "";
|
|
72
|
+
if (wSP) if (isFuture) prefix = "in ";
|
|
73
|
+
else suffix = " ago";
|
|
74
|
+
return `${prefix}${parts.length ? parts?.join(" ") : `0 ${level}s`}${suffix}`;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { fromNowPlugin };
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_greet = require('../greet-B8ZtypgG.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/greetingPlugin.ts
|
|
5
|
+
/** * Plugin to inject `getGreeting`/`greet` method */
|
|
6
|
+
const greetingPlugin = ($Chronos) => {
|
|
7
|
+
$Chronos.prototype.getGreeting = function(configs) {
|
|
8
|
+
return require_greet.getGreeting({
|
|
9
|
+
currentTime: this.formatStrict("HH:mm"),
|
|
10
|
+
...configs
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
$Chronos.prototype.greet = function(configs) {
|
|
14
|
+
return this.getGreeting(configs);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.greetingPlugin = greetingPlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, dt as GreetingConfigs } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/greetingPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns a greeting message based on current instance of `Chronos` time or provided time in the `configs`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, dt as GreetingConfigs } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/greetingPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns a greeting message based on current instance of `Chronos` time or provided time in the `configs`.
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import{t as
|
|
1
|
+
import { t as getGreeting } from "../greet-B9j4afzD.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/greetingPlugin.ts
|
|
4
|
+
/** * Plugin to inject `getGreeting`/`greet` method */
|
|
5
|
+
const greetingPlugin = ($Chronos) => {
|
|
6
|
+
$Chronos.prototype.getGreeting = function(configs) {
|
|
7
|
+
return getGreeting({
|
|
8
|
+
currentTime: this.formatStrict("HH:mm"),
|
|
9
|
+
...configs
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
$Chronos.prototype.greet = function(configs) {
|
|
13
|
+
return this.getGreeting(configs);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { greetingPlugin };
|