@bereasoftware/time-guard 2.6.1 → 2.7.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/README.en.md +232 -0
- package/README.md +259 -4
- package/dist/angular/index.cjs +148 -0
- package/dist/angular/index.d.ts +2 -0
- package/dist/angular/index.es.js +143 -0
- package/dist/angular.d.ts +59 -0
- package/dist/calendars/index.cjs +357 -2
- package/dist/calendars/index.es.js +99 -68
- package/dist/chunk-BbtWAPZS.cjs +36 -0
- package/dist/core-BFdo248T.cjs +1892 -0
- package/dist/core-CyBR5PPd.js +1809 -0
- package/dist/core.d.ts +224 -0
- package/dist/index.d.ts +9 -0
- package/dist/locales/african.locale.d.ts +7 -0
- package/dist/locales/index.cjs +7 -1
- package/dist/{types/locales → locales}/index.d.ts +2 -2
- package/dist/locales/index.es.js +3 -3
- package/dist/locales/south-american.locale.d.ts +7 -0
- package/dist/locales-B1mDDyn_.cjs +3537 -0
- package/dist/{locales-DSBvgSaw.js → locales-By7IK3Ep.js} +749 -33
- package/dist/native/index.cjs +48 -0
- package/dist/native/index.d.ts +2 -0
- package/dist/native/index.es.js +18 -0
- package/dist/native.d.ts +9 -0
- package/dist/plugins/advanced-format.cjs +105 -2
- package/dist/plugins/advanced-format.es.js +63 -45
- package/dist/plugins/duration.cjs +258 -2
- package/dist/plugins/duration.es.js +165 -61
- package/dist/plugins/relative-time.cjs +166 -2
- package/dist/plugins/relative-time.es.js +74 -37
- package/dist/qwik/index.cjs +104 -0
- package/dist/qwik/index.d.ts +2 -0
- package/dist/qwik/index.es.js +100 -0
- package/dist/qwik.d.ts +32 -0
- package/dist/react/index.cjs +112 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.es.js +103 -0
- package/dist/react.d.ts +46 -0
- package/dist/solid/index.cjs +127 -0
- package/dist/solid/index.d.ts +2 -0
- package/dist/solid/index.es.js +122 -0
- package/dist/solid.d.ts +53 -0
- package/dist/svelte/index.cjs +398 -0
- package/dist/svelte/index.d.ts +2 -0
- package/dist/svelte/index.es.js +393 -0
- package/dist/svelte.d.ts +88 -0
- package/dist/time-guard.cjs +7359 -4
- package/dist/time-guard.es.js +3625 -8085
- package/dist/time-guard.iife.js +13549 -4
- package/dist/time-guard.umd.js +13550 -4
- package/dist/types/index.d.ts +651 -127
- package/dist/vue/index.cjs +143 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.es.js +137 -0
- package/dist/vue.d.ts +35 -0
- package/package.json +107 -27
- package/dist/calendars/index.cjs.map +0 -1
- package/dist/calendars/index.es.js.map +0 -1
- package/dist/locales-DSBvgSaw.js.map +0 -1
- package/dist/locales-ybx7jS8G.cjs +0 -2
- package/dist/locales-ybx7jS8G.cjs.map +0 -1
- package/dist/plugins/advanced-format.cjs.map +0 -1
- package/dist/plugins/advanced-format.es.js.map +0 -1
- package/dist/plugins/duration.cjs.map +0 -1
- package/dist/plugins/duration.es.js.map +0 -1
- package/dist/plugins/relative-time.cjs.map +0 -1
- package/dist/plugins/relative-time.es.js.map +0 -1
- package/dist/time-guard.cjs.map +0 -1
- package/dist/time-guard.es.js.map +0 -1
- package/dist/time-guard.iife.js.map +0 -1
- package/dist/time-guard.umd.js.map +0 -1
- package/dist/types/types/index.d.ts +0 -641
- /package/dist/{types/adapters → adapters}/temporal.adapter.d.ts +0 -0
- /package/dist/{types/calendars → calendars}/calendar.manager.d.ts +0 -0
- /package/dist/{types/calendars → calendars}/index.d.ts +0 -0
- /package/dist/{types/formatters → formatters}/date.formatter.d.ts +0 -0
- /package/dist/{types/locales → locales}/additional.locale.d.ts +0 -0
- /package/dist/{types/locales → locales}/asian.locale.d.ts +0 -0
- /package/dist/{types/locales → locales}/english.locale.d.ts +0 -0
- /package/dist/{types/locales → locales}/european.locale.d.ts +0 -0
- /package/dist/{types/locales → locales}/locale.manager.d.ts +0 -0
- /package/dist/{types/locales → locales}/middle-eastern.locale.d.ts +0 -0
- /package/dist/{types/locales → locales}/nordic.locale.d.ts +0 -0
- /package/dist/{types/locales → locales}/romance.locale.d.ts +0 -0
- /package/dist/{types/locales → locales}/slavic.locale.d.ts +0 -0
- /package/dist/{types/locales → locales}/spanish.locale.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/advanced-format/index.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/advanced-format.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/duration/index.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/duration/types.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/duration.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/index.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/manager.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/relative-time/index.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/relative-time/types.d.ts +0 -0
- /package/dist/{types/plugins → plugins}/relative-time.d.ts +0 -0
- /package/dist/{types/time-guard.d.ts → time-guard.d.ts} +0 -0
- /package/dist/{types/utils → utils}/duration-locale.d.ts +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*! time-guard v2.7.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const require_core = require("../core-BFdo248T.cjs");
|
|
4
|
+
const require_locales = require("../locales-B1mDDyn_.cjs");
|
|
5
|
+
const require_calendars_index = require("../calendars/index.cjs");
|
|
6
|
+
const require_plugins_relative_time = require("../plugins/relative-time.cjs");
|
|
7
|
+
const require_plugins_duration = require("../plugins/duration.cjs");
|
|
8
|
+
const require_plugins_advanced_format = require("../plugins/advanced-format.cjs");
|
|
9
|
+
//#region src/native.ts
|
|
10
|
+
/**
|
|
11
|
+
* TimeGuard - Modern date/time library using Temporal API
|
|
12
|
+
* Native Mode (zero-polyfill build)
|
|
13
|
+
* Assumes globalThis.Temporal is already available in the environment.
|
|
14
|
+
*
|
|
15
|
+
* @author Berea-Soft
|
|
16
|
+
* @license MIT
|
|
17
|
+
*/
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.ALL_LOCALES = require_locales.ALL_LOCALES;
|
|
20
|
+
exports.AdvancedFormatPlugin = require_plugins_advanced_format.AdvancedFormatPlugin;
|
|
21
|
+
exports.BuddhistCalendar = require_calendars_index.BuddhistCalendar;
|
|
22
|
+
exports.CalendarManager = require_core.CalendarManager;
|
|
23
|
+
exports.ChineseCalendar = require_calendars_index.ChineseCalendar;
|
|
24
|
+
exports.DateFormatter = require_core.DateFormatter;
|
|
25
|
+
exports.Duration = require_plugins_duration.Duration;
|
|
26
|
+
exports.DurationPlugin = require_plugins_duration.DurationPlugin;
|
|
27
|
+
exports.DurationResult = require_core.DurationResult;
|
|
28
|
+
exports.EN_LOCALE = require_core.EN_LOCALE;
|
|
29
|
+
exports.ES_LOCALE = require_core.ES_LOCALE;
|
|
30
|
+
exports.GregorianCalendar = require_core.GregorianCalendar;
|
|
31
|
+
exports.HebrewCalendar = require_calendars_index.HebrewCalendar;
|
|
32
|
+
exports.IslamicCalendar = require_calendars_index.IslamicCalendar;
|
|
33
|
+
exports.JapaneseCalendar = require_calendars_index.JapaneseCalendar;
|
|
34
|
+
exports.LOCALES_COUNT = require_locales.LOCALES_COUNT;
|
|
35
|
+
exports.LocaleManager = require_core.LocaleManager;
|
|
36
|
+
exports.PluginManager = require_core.PluginManager;
|
|
37
|
+
exports.RelativeTimePlugin = require_plugins_relative_time.RelativeTimePlugin;
|
|
38
|
+
exports.TemporalAdapter = require_core.TemporalAdapter;
|
|
39
|
+
exports.TimeGuard = require_core.TimeGuard;
|
|
40
|
+
exports.TimeRange = require_core.TimeRange;
|
|
41
|
+
exports.advancedFormatPlugin = require_plugins_advanced_format.default;
|
|
42
|
+
exports.calendarManager = require_core.calendarManager;
|
|
43
|
+
exports.durationPlugin = require_plugins_duration.default;
|
|
44
|
+
exports.getAvailableLocales = require_locales.getAvailableLocales;
|
|
45
|
+
exports.registerAllLocales = require_locales.registerAllLocales;
|
|
46
|
+
exports.relativeTimePlugin = require_plugins_relative_time.default;
|
|
47
|
+
exports.timeGuard = require_core.timeGuard;
|
|
48
|
+
exports.version = require_core.version;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! time-guard v2.7.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
|
|
2
|
+
import { a as version, c as GregorianCalendar, d as TemporalAdapter, f as EN_LOCALE, i as timeGuard, l as calendarManager, m as LocaleManager, n as TimeGuard, o as PluginManager, p as ES_LOCALE, r as TimeRange, s as CalendarManager, t as DurationResult, u as DateFormatter } from "../core-CyBR5PPd.js";
|
|
3
|
+
import { i as registerAllLocales, n as LOCALES_COUNT, r as getAvailableLocales, t as ALL_LOCALES } from "../locales-By7IK3Ep.js";
|
|
4
|
+
import { BuddhistCalendar, ChineseCalendar, HebrewCalendar, IslamicCalendar, JapaneseCalendar } from "../calendars/index.es.js";
|
|
5
|
+
import relative_time_default, { RelativeTimePlugin } from "../plugins/relative-time.es.js";
|
|
6
|
+
import durationPlugin, { Duration, DurationPlugin } from "../plugins/duration.es.js";
|
|
7
|
+
import advanced_format_default, { AdvancedFormatPlugin } from "../plugins/advanced-format.es.js";
|
|
8
|
+
//#region src/native.ts
|
|
9
|
+
/**
|
|
10
|
+
* TimeGuard - Modern date/time library using Temporal API
|
|
11
|
+
* Native Mode (zero-polyfill build)
|
|
12
|
+
* Assumes globalThis.Temporal is already available in the environment.
|
|
13
|
+
*
|
|
14
|
+
* @author Berea-Soft
|
|
15
|
+
* @license MIT
|
|
16
|
+
*/
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ALL_LOCALES, AdvancedFormatPlugin, BuddhistCalendar, CalendarManager, ChineseCalendar, DateFormatter, Duration, DurationPlugin, DurationResult, EN_LOCALE, ES_LOCALE, GregorianCalendar, HebrewCalendar, IslamicCalendar, JapaneseCalendar, LOCALES_COUNT, LocaleManager, PluginManager, RelativeTimePlugin, TemporalAdapter, TimeGuard, TimeRange, advanced_format_default as advancedFormatPlugin, calendarManager, durationPlugin, getAvailableLocales, registerAllLocales, relative_time_default as relativeTimePlugin, timeGuard, version };
|
package/dist/native.d.ts
ADDED
|
@@ -1,2 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*! time-guard v2.7.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
//#region src/plugins/advanced-format/index.ts
|
|
7
|
+
var AdvancedFormatPlugin = class {
|
|
8
|
+
name = "advanced-format";
|
|
9
|
+
version = "1.0.0";
|
|
10
|
+
/**
|
|
11
|
+
* Install plugin into TimeGuard
|
|
12
|
+
*/
|
|
13
|
+
install(TimeGuardClass) {
|
|
14
|
+
const originalFormat = TimeGuardClass.prototype.format;
|
|
15
|
+
TimeGuardClass.prototype.format = function(pattern) {
|
|
16
|
+
if (!pattern || typeof pattern !== "string") return originalFormat.call(this, pattern);
|
|
17
|
+
if (!/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/.test(pattern)) return originalFormat.call(this, pattern);
|
|
18
|
+
const temporal = this.toTemporal();
|
|
19
|
+
const temporal_dt = "toPlainDateTime" in temporal ? temporal.toPlainDateTime() : temporal;
|
|
20
|
+
const ordinalFn = (n) => {
|
|
21
|
+
const suffixes = [
|
|
22
|
+
"th",
|
|
23
|
+
"st",
|
|
24
|
+
"nd",
|
|
25
|
+
"rd"
|
|
26
|
+
];
|
|
27
|
+
const v = n % 100;
|
|
28
|
+
return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
|
|
29
|
+
};
|
|
30
|
+
const padFn = (n, length) => String(n).padStart(length, "0");
|
|
31
|
+
const getISOWeek = (temporal) => {
|
|
32
|
+
const jan4 = new Date(temporal.year, 0, 4);
|
|
33
|
+
const week1Start = new Date(jan4);
|
|
34
|
+
week1Start.setDate(jan4.getDate() - jan4.getDay() + (jan4.getDay() === 0 ? -6 : 1));
|
|
35
|
+
const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);
|
|
36
|
+
const weekNum = Math.floor((currentDate.getTime() - week1Start.getTime()) / (10080 * 60 * 1e3)) + 1;
|
|
37
|
+
return Math.max(1, weekNum);
|
|
38
|
+
};
|
|
39
|
+
const getWeekOfYear = (temporal) => {
|
|
40
|
+
const weekNum = Math.ceil((temporal.day + new Date(temporal.year, temporal.month - 1, 1).getDay()) / 7);
|
|
41
|
+
return Math.max(1, weekNum);
|
|
42
|
+
};
|
|
43
|
+
const getISOWeekYear = (temporal) => {
|
|
44
|
+
const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);
|
|
45
|
+
const yearAdjust = currentDate.getTime() < new Date(temporal.year, 0, 1).getTime() ? -1 : currentDate.getTime() >= new Date(temporal.year + 1, 0, 1).getTime() ? 1 : 0;
|
|
46
|
+
return temporal.year + yearAdjust;
|
|
47
|
+
};
|
|
48
|
+
const getWeekYear = (temporal) => {
|
|
49
|
+
const yearAdjust = temporal.month === 1 && temporal.day < 4 ? -1 : temporal.month === 12 && temporal.day > 28 ? 1 : 0;
|
|
50
|
+
return temporal.year + yearAdjust;
|
|
51
|
+
};
|
|
52
|
+
const result = pattern.replace(/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/g, (match) => {
|
|
53
|
+
let replacement = "";
|
|
54
|
+
switch (match) {
|
|
55
|
+
case "Q":
|
|
56
|
+
replacement = String(Math.ceil(temporal_dt.month / 3));
|
|
57
|
+
break;
|
|
58
|
+
case "Do":
|
|
59
|
+
replacement = ordinalFn(temporal_dt.day);
|
|
60
|
+
break;
|
|
61
|
+
case "W":
|
|
62
|
+
case "WW":
|
|
63
|
+
replacement = padFn(getISOWeek(temporal_dt), match === "W" ? 1 : 2);
|
|
64
|
+
break;
|
|
65
|
+
case "w":
|
|
66
|
+
case "ww":
|
|
67
|
+
replacement = padFn(getWeekOfYear(temporal_dt), match === "w" ? 1 : 2);
|
|
68
|
+
break;
|
|
69
|
+
case "GGGG":
|
|
70
|
+
replacement = String(getISOWeekYear(temporal_dt));
|
|
71
|
+
break;
|
|
72
|
+
case "gggg":
|
|
73
|
+
replacement = String(getWeekYear(temporal_dt));
|
|
74
|
+
break;
|
|
75
|
+
case "k":
|
|
76
|
+
case "kk":
|
|
77
|
+
replacement = padFn(temporal_dt.hour === 0 ? 24 : temporal_dt.hour, match === "k" ? 1 : 2);
|
|
78
|
+
break;
|
|
79
|
+
case "X":
|
|
80
|
+
replacement = String(Math.floor(this.valueOf() / 1e3));
|
|
81
|
+
break;
|
|
82
|
+
case "x":
|
|
83
|
+
replacement = String(this.valueOf());
|
|
84
|
+
break;
|
|
85
|
+
case "z":
|
|
86
|
+
replacement = `${this.getTimezoneOffset()}`;
|
|
87
|
+
break;
|
|
88
|
+
case "zzz":
|
|
89
|
+
replacement = `${this.getTimezoneOffsetLong()}`;
|
|
90
|
+
break;
|
|
91
|
+
default: return match;
|
|
92
|
+
}
|
|
93
|
+
return `[${replacement}]`;
|
|
94
|
+
});
|
|
95
|
+
return originalFormat.call(this, result);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Create and export default instance
|
|
101
|
+
*/
|
|
102
|
+
var advanced_format_default = new AdvancedFormatPlugin();
|
|
103
|
+
//#endregion
|
|
104
|
+
exports.AdvancedFormatPlugin = AdvancedFormatPlugin;
|
|
105
|
+
exports.default = advanced_format_default;
|
|
@@ -1,82 +1,100 @@
|
|
|
1
|
-
/*! time-guard v2.
|
|
1
|
+
/*! time-guard v2.7.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
|
|
2
2
|
//#region src/plugins/advanced-format/index.ts
|
|
3
|
-
var
|
|
3
|
+
var AdvancedFormatPlugin = class {
|
|
4
4
|
name = "advanced-format";
|
|
5
5
|
version = "1.0.0";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Install plugin into TimeGuard
|
|
8
|
+
*/
|
|
9
|
+
install(TimeGuardClass) {
|
|
10
|
+
const originalFormat = TimeGuardClass.prototype.format;
|
|
11
|
+
TimeGuardClass.prototype.format = function(pattern) {
|
|
12
|
+
if (!pattern || typeof pattern !== "string") return originalFormat.call(this, pattern);
|
|
13
|
+
if (!/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/.test(pattern)) return originalFormat.call(this, pattern);
|
|
14
|
+
const temporal = this.toTemporal();
|
|
15
|
+
const temporal_dt = "toPlainDateTime" in temporal ? temporal.toPlainDateTime() : temporal;
|
|
16
|
+
const ordinalFn = (n) => {
|
|
17
|
+
const suffixes = [
|
|
12
18
|
"th",
|
|
13
19
|
"st",
|
|
14
20
|
"nd",
|
|
15
21
|
"rd"
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
];
|
|
23
|
+
const v = n % 100;
|
|
24
|
+
return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
|
|
25
|
+
};
|
|
26
|
+
const padFn = (n, length) => String(n).padStart(length, "0");
|
|
27
|
+
const getISOWeek = (temporal) => {
|
|
28
|
+
const jan4 = new Date(temporal.year, 0, 4);
|
|
29
|
+
const week1Start = new Date(jan4);
|
|
30
|
+
week1Start.setDate(jan4.getDate() - jan4.getDay() + (jan4.getDay() === 0 ? -6 : 1));
|
|
31
|
+
const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);
|
|
32
|
+
const weekNum = Math.floor((currentDate.getTime() - week1Start.getTime()) / (10080 * 60 * 1e3)) + 1;
|
|
33
|
+
return Math.max(1, weekNum);
|
|
34
|
+
};
|
|
35
|
+
const getWeekOfYear = (temporal) => {
|
|
36
|
+
const weekNum = Math.ceil((temporal.day + new Date(temporal.year, temporal.month - 1, 1).getDay()) / 7);
|
|
37
|
+
return Math.max(1, weekNum);
|
|
38
|
+
};
|
|
39
|
+
const getISOWeekYear = (temporal) => {
|
|
40
|
+
const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);
|
|
41
|
+
const yearAdjust = currentDate.getTime() < new Date(temporal.year, 0, 1).getTime() ? -1 : currentDate.getTime() >= new Date(temporal.year + 1, 0, 1).getTime() ? 1 : 0;
|
|
42
|
+
return temporal.year + yearAdjust;
|
|
43
|
+
};
|
|
44
|
+
const getWeekYear = (temporal) => {
|
|
45
|
+
const yearAdjust = temporal.month === 1 && temporal.day < 4 ? -1 : temporal.month === 12 && temporal.day > 28 ? 1 : 0;
|
|
46
|
+
return temporal.year + yearAdjust;
|
|
47
|
+
};
|
|
48
|
+
const result = pattern.replace(/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/g, (match) => {
|
|
49
|
+
let replacement = "";
|
|
50
|
+
switch (match) {
|
|
35
51
|
case "Q":
|
|
36
|
-
|
|
52
|
+
replacement = String(Math.ceil(temporal_dt.month / 3));
|
|
37
53
|
break;
|
|
38
54
|
case "Do":
|
|
39
|
-
|
|
55
|
+
replacement = ordinalFn(temporal_dt.day);
|
|
40
56
|
break;
|
|
41
57
|
case "W":
|
|
42
58
|
case "WW":
|
|
43
|
-
|
|
59
|
+
replacement = padFn(getISOWeek(temporal_dt), match === "W" ? 1 : 2);
|
|
44
60
|
break;
|
|
45
61
|
case "w":
|
|
46
62
|
case "ww":
|
|
47
|
-
|
|
63
|
+
replacement = padFn(getWeekOfYear(temporal_dt), match === "w" ? 1 : 2);
|
|
48
64
|
break;
|
|
49
65
|
case "GGGG":
|
|
50
|
-
|
|
66
|
+
replacement = String(getISOWeekYear(temporal_dt));
|
|
51
67
|
break;
|
|
52
68
|
case "gggg":
|
|
53
|
-
|
|
69
|
+
replacement = String(getWeekYear(temporal_dt));
|
|
54
70
|
break;
|
|
55
71
|
case "k":
|
|
56
72
|
case "kk":
|
|
57
|
-
|
|
73
|
+
replacement = padFn(temporal_dt.hour === 0 ? 24 : temporal_dt.hour, match === "k" ? 1 : 2);
|
|
58
74
|
break;
|
|
59
75
|
case "X":
|
|
60
|
-
|
|
76
|
+
replacement = String(Math.floor(this.valueOf() / 1e3));
|
|
61
77
|
break;
|
|
62
78
|
case "x":
|
|
63
|
-
|
|
79
|
+
replacement = String(this.valueOf());
|
|
64
80
|
break;
|
|
65
81
|
case "z":
|
|
66
|
-
|
|
82
|
+
replacement = `${this.getTimezoneOffset()}`;
|
|
67
83
|
break;
|
|
68
84
|
case "zzz":
|
|
69
|
-
|
|
85
|
+
replacement = `${this.getTimezoneOffsetLong()}`;
|
|
70
86
|
break;
|
|
71
|
-
default: return
|
|
87
|
+
default: return match;
|
|
72
88
|
}
|
|
73
|
-
return `[${
|
|
89
|
+
return `[${replacement}]`;
|
|
74
90
|
});
|
|
75
|
-
return
|
|
91
|
+
return originalFormat.call(this, result);
|
|
76
92
|
};
|
|
77
93
|
}
|
|
78
|
-
}
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Create and export default instance
|
|
97
|
+
*/
|
|
98
|
+
var advanced_format_default = new AdvancedFormatPlugin();
|
|
79
99
|
//#endregion
|
|
80
|
-
export {
|
|
81
|
-
|
|
82
|
-
//# sourceMappingURL=advanced-format.es.js.map
|
|
100
|
+
export { AdvancedFormatPlugin, advanced_format_default as default };
|
|
@@ -1,2 +1,258 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*! time-guard v2.7.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
//#region src/plugins/duration/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Duration class - represents time span following ISO 8601 standard
|
|
9
|
+
*/
|
|
10
|
+
var Duration = class Duration {
|
|
11
|
+
years = 0;
|
|
12
|
+
months = 0;
|
|
13
|
+
weeks = 0;
|
|
14
|
+
days = 0;
|
|
15
|
+
hours = 0;
|
|
16
|
+
minutes = 0;
|
|
17
|
+
seconds = 0;
|
|
18
|
+
milliseconds = 0;
|
|
19
|
+
constructor(input) {
|
|
20
|
+
this.years = input.years || 0;
|
|
21
|
+
this.months = input.months || 0;
|
|
22
|
+
this.weeks = input.weeks || 0;
|
|
23
|
+
this.days = input.days || 0;
|
|
24
|
+
this.hours = input.hours || 0;
|
|
25
|
+
this.minutes = input.minutes || 0;
|
|
26
|
+
this.seconds = input.seconds || 0;
|
|
27
|
+
this.milliseconds = input.milliseconds || 0;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create Duration from ISO 8601 string
|
|
31
|
+
* @example Duration.fromISO("P3Y6M4DT12H30M5S")
|
|
32
|
+
*/
|
|
33
|
+
static fromISO(iso) {
|
|
34
|
+
const match = iso.match(/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:([\d.]+)S)?)?$/);
|
|
35
|
+
if (!match) throw new Error(`Invalid ISO 8601 duration: ${iso}`);
|
|
36
|
+
const [, negative, years, months, , days, hours, minutes, seconds] = match;
|
|
37
|
+
const multiplier = negative ? -1 : 1;
|
|
38
|
+
return new Duration({
|
|
39
|
+
years: parseInt(years || "0", 10) * multiplier,
|
|
40
|
+
months: parseInt(months || "0", 10) * multiplier,
|
|
41
|
+
days: parseInt(days || "0", 10) * multiplier,
|
|
42
|
+
hours: parseInt(hours || "0", 10) * multiplier,
|
|
43
|
+
minutes: parseInt(minutes || "0", 10) * multiplier,
|
|
44
|
+
seconds: parseFloat(seconds || "0") * multiplier
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a Duration between this date and another
|
|
49
|
+
*/
|
|
50
|
+
static between(from, to) {
|
|
51
|
+
const fromDT = from.toTemporal();
|
|
52
|
+
const duration = to.toTemporal().since(fromDT);
|
|
53
|
+
return new Duration({
|
|
54
|
+
years: duration.years || 0,
|
|
55
|
+
months: duration.months || 0,
|
|
56
|
+
weeks: 0,
|
|
57
|
+
days: duration.days || 0,
|
|
58
|
+
hours: duration.hours || 0,
|
|
59
|
+
minutes: duration.minutes || 0,
|
|
60
|
+
seconds: duration.seconds || 0,
|
|
61
|
+
milliseconds: duration.milliseconds || 0
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create Duration from milliseconds
|
|
66
|
+
*/
|
|
67
|
+
static fromMilliseconds(ms) {
|
|
68
|
+
const isNegative = ms < 0;
|
|
69
|
+
const absMilhs = Math.abs(ms);
|
|
70
|
+
const years = Math.floor(absMilhs / (1e3 * 60 * 60 * 24 * 365));
|
|
71
|
+
const months = Math.floor(absMilhs % (1e3 * 60 * 60 * 24 * 365) / (1e3 * 60 * 60 * 24 * 30));
|
|
72
|
+
const days = Math.floor(absMilhs % (1e3 * 60 * 60 * 24 * 30) / (1e3 * 60 * 60 * 24));
|
|
73
|
+
const hours = Math.floor(absMilhs % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60));
|
|
74
|
+
const minutes = Math.floor(absMilhs % (1e3 * 60 * 60) / (1e3 * 60));
|
|
75
|
+
const seconds = Math.floor(absMilhs % (1e3 * 60) / 1e3);
|
|
76
|
+
const milliseconds = Math.floor(absMilhs % 1e3);
|
|
77
|
+
const multiplier = isNegative ? -1 : 1;
|
|
78
|
+
return new Duration({
|
|
79
|
+
years: years * multiplier,
|
|
80
|
+
months: months * multiplier,
|
|
81
|
+
days: days * multiplier,
|
|
82
|
+
hours: hours * multiplier,
|
|
83
|
+
minutes: minutes * multiplier,
|
|
84
|
+
seconds: seconds * multiplier,
|
|
85
|
+
milliseconds: milliseconds * multiplier
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get duration in specific unit
|
|
90
|
+
*/
|
|
91
|
+
as(unit) {
|
|
92
|
+
return this.asMilliseconds() / {
|
|
93
|
+
milliseconds: 1,
|
|
94
|
+
seconds: 1e3,
|
|
95
|
+
minutes: 1e3 * 60,
|
|
96
|
+
hours: 1e3 * 60 * 60,
|
|
97
|
+
days: 1e3 * 60 * 60 * 24,
|
|
98
|
+
weeks: 1e3 * 60 * 60 * 24 * 7,
|
|
99
|
+
months: 1e3 * 60 * 60 * 24 * 30,
|
|
100
|
+
years: 1e3 * 60 * 60 * 24 * 365
|
|
101
|
+
}[unit];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get duration as milliseconds
|
|
105
|
+
*/
|
|
106
|
+
asMilliseconds() {
|
|
107
|
+
return this.years * 1e3 * 60 * 60 * 24 * 365 + this.months * 1e3 * 60 * 60 * 24 * 30 + this.weeks * 1e3 * 60 * 60 * 24 * 7 + this.days * 1e3 * 60 * 60 * 24 + this.hours * 1e3 * 60 * 60 + this.minutes * 1e3 * 60 + this.seconds * 1e3 + this.milliseconds;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get duration as seconds
|
|
111
|
+
*/
|
|
112
|
+
asSeconds() {
|
|
113
|
+
return this.asMilliseconds() / 1e3;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get duration as minutes
|
|
117
|
+
*/
|
|
118
|
+
asMinutes() {
|
|
119
|
+
return this.asSeconds() / 60;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get duration as hours
|
|
123
|
+
*/
|
|
124
|
+
asHours() {
|
|
125
|
+
return this.asMinutes() / 60;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get duration as days
|
|
129
|
+
*/
|
|
130
|
+
asDays() {
|
|
131
|
+
return this.asHours() / 24;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get duration as weeks
|
|
135
|
+
*/
|
|
136
|
+
asWeeks() {
|
|
137
|
+
return this.asDays() / 7;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get duration as months
|
|
141
|
+
*/
|
|
142
|
+
asMonths() {
|
|
143
|
+
return this.asDays() / 30;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get duration as years
|
|
147
|
+
*/
|
|
148
|
+
asYears() {
|
|
149
|
+
return this.asDays() / 365;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get all components
|
|
153
|
+
*/
|
|
154
|
+
toObject() {
|
|
155
|
+
return {
|
|
156
|
+
years: this.years,
|
|
157
|
+
months: this.months,
|
|
158
|
+
weeks: this.weeks,
|
|
159
|
+
days: this.days,
|
|
160
|
+
hours: this.hours,
|
|
161
|
+
minutes: this.minutes,
|
|
162
|
+
seconds: this.seconds,
|
|
163
|
+
milliseconds: this.milliseconds
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get ISO 8601 string representation
|
|
168
|
+
* @example "P3Y6M4DT12H30M5S"
|
|
169
|
+
*/
|
|
170
|
+
toISO() {
|
|
171
|
+
let datePart = "";
|
|
172
|
+
if (this.years) datePart += `${this.years}Y`;
|
|
173
|
+
if (this.months) datePart += `${this.months}M`;
|
|
174
|
+
if (this.weeks || this.days) datePart += `${this.weeks * 7 + this.days}D`;
|
|
175
|
+
let timePart = "";
|
|
176
|
+
if (this.hours) timePart += `${this.hours}H`;
|
|
177
|
+
if (this.minutes) timePart += `${this.minutes}M`;
|
|
178
|
+
if (this.seconds || this.milliseconds) timePart += `${this.seconds + this.milliseconds / 1e3}S`;
|
|
179
|
+
return `${this.isNegative() ? "-" : ""}P${datePart}${timePart ? `T${timePart}` : ""}`;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get human-readable string
|
|
183
|
+
*/
|
|
184
|
+
humanize() {
|
|
185
|
+
const parts = [];
|
|
186
|
+
if (this.years) parts.push(`${Math.abs(this.years)} year${Math.abs(this.years) !== 1 ? "s" : ""}`);
|
|
187
|
+
if (this.months) parts.push(`${Math.abs(this.months)} month${Math.abs(this.months) !== 1 ? "s" : ""}`);
|
|
188
|
+
if (this.weeks) parts.push(`${Math.abs(this.weeks)} week${Math.abs(this.weeks) !== 1 ? "s" : ""}`);
|
|
189
|
+
if (this.days) parts.push(`${Math.abs(this.days)} day${Math.abs(this.days) !== 1 ? "s" : ""}`);
|
|
190
|
+
if (this.hours) parts.push(`${Math.abs(this.hours)} hour${Math.abs(this.hours) !== 1 ? "s" : ""}`);
|
|
191
|
+
if (this.minutes) parts.push(`${Math.abs(this.minutes)} minute${Math.abs(this.minutes) !== 1 ? "s" : ""}`);
|
|
192
|
+
if (this.seconds) parts.push(`${Math.abs(this.seconds)} second${Math.abs(this.seconds) !== 1 ? "s" : ""}`);
|
|
193
|
+
if (this.milliseconds) parts.push(`${Math.abs(this.milliseconds)} ms`);
|
|
194
|
+
if (parts.length === 0) return "0 seconds";
|
|
195
|
+
const text = parts.join(", ");
|
|
196
|
+
return this.isNegative() ? `-${text}` : text;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Check if duration is negative
|
|
200
|
+
*/
|
|
201
|
+
isNegative() {
|
|
202
|
+
return this.years < 0 || this.months < 0 || this.weeks < 0 || this.days < 0 || this.hours < 0 || this.minutes < 0 || this.seconds < 0 || this.milliseconds < 0;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get absolute duration
|
|
206
|
+
*/
|
|
207
|
+
abs() {
|
|
208
|
+
return new Duration({
|
|
209
|
+
years: Math.abs(this.years),
|
|
210
|
+
months: Math.abs(this.months),
|
|
211
|
+
weeks: Math.abs(this.weeks),
|
|
212
|
+
days: Math.abs(this.days),
|
|
213
|
+
hours: Math.abs(this.hours),
|
|
214
|
+
minutes: Math.abs(this.minutes),
|
|
215
|
+
seconds: Math.abs(this.seconds),
|
|
216
|
+
milliseconds: Math.abs(this.milliseconds)
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* String representation
|
|
221
|
+
*/
|
|
222
|
+
toString() {
|
|
223
|
+
return this.toISO();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Duration Plugin
|
|
228
|
+
*/
|
|
229
|
+
var DurationPlugin = class {
|
|
230
|
+
name = "duration";
|
|
231
|
+
version = "1.0.0";
|
|
232
|
+
/**
|
|
233
|
+
* Install plugin into TimeGuard
|
|
234
|
+
*/
|
|
235
|
+
install(TimeGuardClass) {
|
|
236
|
+
/**
|
|
237
|
+
* Create a Duration between this date and another
|
|
238
|
+
*/
|
|
239
|
+
TimeGuardClass.prototype.duration = function(other) {
|
|
240
|
+
return Duration.between(this, other);
|
|
241
|
+
};
|
|
242
|
+
TimeGuardClass.Duration = Duration;
|
|
243
|
+
TimeGuardClass.duration = {
|
|
244
|
+
fromISO: (iso) => Duration.fromISO(iso),
|
|
245
|
+
between: (from, to) => Duration.between(from, to),
|
|
246
|
+
fromMilliseconds: (ms) => Duration.fromMilliseconds(ms)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Create and export default instance
|
|
252
|
+
*/
|
|
253
|
+
var durationPlugin = new DurationPlugin();
|
|
254
|
+
//#endregion
|
|
255
|
+
exports.Duration = Duration;
|
|
256
|
+
exports.DurationPlugin = DurationPlugin;
|
|
257
|
+
exports.default = durationPlugin;
|
|
258
|
+
exports.durationPlugin = durationPlugin;
|