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.
Files changed (102) hide show
  1. package/dist/basic-DIp_pxR2.cjs +450 -0
  2. package/dist/basic-Dputob9z.mjs +366 -0
  3. package/dist/constants.cjs +27 -1
  4. package/dist/constants.mjs +5 -1
  5. package/dist/convert-CNVL-mop.mjs +22 -0
  6. package/dist/convert-dQuGWhVm.cjs +33 -0
  7. package/dist/greet-B8ZtypgG.cjs +40 -0
  8. package/dist/greet-B9j4afzD.mjs +35 -0
  9. package/dist/guards.cjs +119 -1
  10. package/dist/guards.mjs +110 -1
  11. package/dist/helpers-CrMc9iJZ.mjs +185 -0
  12. package/dist/helpers-M_SfAbAv.cjs +262 -0
  13. package/dist/index.cjs +1461 -1
  14. package/dist/index.mjs +1458 -1
  15. package/dist/non-primitives-CT4vszrX.cjs +52 -0
  16. package/dist/non-primitives-DrQfPj1r.mjs +22 -0
  17. package/dist/plugins/banglaPlugin.cjs +121 -1
  18. package/dist/plugins/banglaPlugin.d.cts +1 -1
  19. package/dist/plugins/banglaPlugin.d.mts +1 -1
  20. package/dist/plugins/banglaPlugin.mjs +120 -1
  21. package/dist/plugins/businessPlugin.cjs +118 -1
  22. package/dist/plugins/businessPlugin.d.cts +1 -1
  23. package/dist/plugins/businessPlugin.d.mts +1 -1
  24. package/dist/plugins/businessPlugin.mjs +117 -1
  25. package/dist/plugins/dateRangePlugin.cjs +46 -1
  26. package/dist/plugins/dateRangePlugin.d.cts +1 -1
  27. package/dist/plugins/dateRangePlugin.d.mts +1 -1
  28. package/dist/plugins/dateRangePlugin.mjs +45 -1
  29. package/dist/plugins/dayPartPlugin.cjs +26 -1
  30. package/dist/plugins/dayPartPlugin.d.cts +1 -1
  31. package/dist/plugins/dayPartPlugin.d.mts +1 -1
  32. package/dist/plugins/dayPartPlugin.mjs +25 -1
  33. package/dist/plugins/durationPlugin.cjs +91 -1
  34. package/dist/plugins/durationPlugin.d.cts +1 -1
  35. package/dist/plugins/durationPlugin.d.mts +1 -1
  36. package/dist/plugins/durationPlugin.mjs +90 -1
  37. package/dist/plugins/fromNowPlugin.cjs +80 -1
  38. package/dist/plugins/fromNowPlugin.d.cts +1 -1
  39. package/dist/plugins/fromNowPlugin.d.mts +1 -1
  40. package/dist/plugins/fromNowPlugin.mjs +79 -1
  41. package/dist/plugins/greetingPlugin.cjs +19 -1
  42. package/dist/plugins/greetingPlugin.d.cts +1 -1
  43. package/dist/plugins/greetingPlugin.d.mts +1 -1
  44. package/dist/plugins/greetingPlugin.mjs +18 -1
  45. package/dist/plugins/palindromePlugin.cjs +22 -1
  46. package/dist/plugins/palindromePlugin.d.cts +1 -1
  47. package/dist/plugins/palindromePlugin.d.mts +1 -1
  48. package/dist/plugins/palindromePlugin.mjs +21 -1
  49. package/dist/plugins/relativeTimePlugin.cjs +74 -1
  50. package/dist/plugins/relativeTimePlugin.d.cts +1 -1
  51. package/dist/plugins/relativeTimePlugin.d.mts +1 -1
  52. package/dist/plugins/relativeTimePlugin.mjs +73 -1
  53. package/dist/plugins/roundPlugin.cjs +69 -1
  54. package/dist/plugins/roundPlugin.d.cts +1 -1
  55. package/dist/plugins/roundPlugin.d.mts +1 -1
  56. package/dist/plugins/roundPlugin.mjs +68 -1
  57. package/dist/plugins/seasonPlugin.cjs +31 -1
  58. package/dist/plugins/seasonPlugin.d.cts +1 -1
  59. package/dist/plugins/seasonPlugin.d.mts +1 -1
  60. package/dist/plugins/seasonPlugin.mjs +30 -1
  61. package/dist/plugins/timeZonePlugin.cjs +139 -1
  62. package/dist/plugins/timeZonePlugin.d.cts +1 -1
  63. package/dist/plugins/timeZonePlugin.d.mts +1 -1
  64. package/dist/plugins/timeZonePlugin.mjs +138 -1
  65. package/dist/plugins/zodiacPlugin.cjs +51 -1
  66. package/dist/plugins/zodiacPlugin.d.cts +1 -1
  67. package/dist/plugins/zodiacPlugin.d.mts +1 -1
  68. package/dist/plugins/zodiacPlugin.mjs +50 -1
  69. package/dist/primitives-BME3_QrA.cjs +49 -0
  70. package/dist/primitives-DEt6I7Sy.mjs +19 -0
  71. package/dist/seasons-CHnjrIKK.mjs +352 -0
  72. package/dist/seasons-CcZicoe1.cjs +418 -0
  73. package/dist/timezone-BfBXeMK_.mjs +5573 -0
  74. package/dist/timezone-DYVJJYKz.cjs +5609 -0
  75. package/dist/types.mjs +1 -1
  76. package/dist/utilities-BU4MSYS7.mjs +43 -0
  77. package/dist/utilities-CGL7F6R9.cjs +72 -0
  78. package/dist/utilities-CtOZhIYv.mjs +241 -0
  79. package/dist/utilities-bXwTPJaD.cjs +318 -0
  80. package/dist/utils.cjs +76 -1
  81. package/dist/utils.mjs +44 -1
  82. package/package.json +1 -1
  83. package/dist/basic-CKxaRSHQ.cjs +0 -1
  84. package/dist/basic-e46DaNAi.mjs +0 -1
  85. package/dist/convert-Bmp63ats.mjs +0 -1
  86. package/dist/convert-DrLrcgqz.cjs +0 -1
  87. package/dist/greet-BBsrvmkn.mjs +0 -1
  88. package/dist/greet-C-6mruI9.cjs +0 -1
  89. package/dist/helpers-DGzYnP81.cjs +0 -1
  90. package/dist/helpers-N1X_Rj_V.mjs +0 -1
  91. package/dist/non-primitives-B2EE6D6s.mjs +0 -1
  92. package/dist/non-primitives-Bu3a4WL4.cjs +0 -1
  93. package/dist/primitives-Cxss_JVF.mjs +0 -1
  94. package/dist/primitives-Db2FUp4e.cjs +0 -1
  95. package/dist/seasons-ChAIVphi.mjs +0 -1
  96. package/dist/seasons-oABOhHcX.cjs +0 -1
  97. package/dist/timezone-B10UItNO.mjs +0 -1
  98. package/dist/timezone-CWxbK_7I.cjs +0 -1
  99. package/dist/utilities-B8dOAQVD.cjs +0 -1
  100. package/dist/utilities-BJE06bms.mjs +0 -1
  101. package/dist/utilities-D2-p26DX.cjs +0 -1
  102. package/dist/utilities-DV_ohS37.mjs +0 -1
package/dist/types.mjs CHANGED
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -0,0 +1,43 @@
1
+ import { i as isString, r as isNumber } from "./primitives-DEt6I7Sy.mjs";
2
+
3
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/guards/specials.js
4
+ function isNumericString(value) {
5
+ return isString(value) && value?.trim() !== "" && Number.isFinite(Number(value));
6
+ }
7
+
8
+ //#endregion
9
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/number/constants.js
10
+ const BN_DIGITS = /* @__PURE__ */ Object.freeze({
11
+ "০": 0,
12
+ "১": 1,
13
+ "২": 2,
14
+ "৩": 3,
15
+ "৪": 4,
16
+ "৫": 5,
17
+ "৬": 6,
18
+ "৭": 7,
19
+ "৮": 8,
20
+ "৯": 9
21
+ });
22
+
23
+ //#endregion
24
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/number/utilities.js
25
+ const roundToNearest = (value, interval = 5) => {
26
+ return Math.round(Number(value) / interval) * interval;
27
+ };
28
+ const getOrdinal = (num, withNumber = true) => {
29
+ const remainder10 = Number(num) % 10;
30
+ const remainder100 = Number(num) % 100;
31
+ let suffix;
32
+ if (remainder10 === 1 && remainder100 !== 11) suffix = "st";
33
+ else if (remainder10 === 2 && remainder100 !== 12) suffix = "nd";
34
+ else if (remainder10 === 3 && remainder100 !== 13) suffix = "rd";
35
+ else suffix = "th";
36
+ return withNumber ? String(num).concat(suffix) : suffix;
37
+ };
38
+ function normalizeNumber(num) {
39
+ return isNumber(num) ? num : isNumericString(num) ? Number(num) : void 0;
40
+ }
41
+
42
+ //#endregion
43
+ export { isNumericString as a, BN_DIGITS as i, normalizeNumber as n, roundToNearest as r, getOrdinal as t };
@@ -0,0 +1,72 @@
1
+ const require_primitives = require('./primitives-BME3_QrA.cjs');
2
+
3
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/guards/specials.js
4
+ function isNumericString(value) {
5
+ return require_primitives.isString(value) && value?.trim() !== "" && Number.isFinite(Number(value));
6
+ }
7
+
8
+ //#endregion
9
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/number/constants.js
10
+ const BN_DIGITS = /* @__PURE__ */ Object.freeze({
11
+ "০": 0,
12
+ "১": 1,
13
+ "২": 2,
14
+ "৩": 3,
15
+ "৪": 4,
16
+ "৫": 5,
17
+ "৬": 6,
18
+ "৭": 7,
19
+ "৮": 8,
20
+ "৯": 9
21
+ });
22
+
23
+ //#endregion
24
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/number/utilities.js
25
+ const roundToNearest = (value, interval = 5) => {
26
+ return Math.round(Number(value) / interval) * interval;
27
+ };
28
+ const getOrdinal = (num, withNumber = true) => {
29
+ const remainder10 = Number(num) % 10;
30
+ const remainder100 = Number(num) % 100;
31
+ let suffix;
32
+ if (remainder10 === 1 && remainder100 !== 11) suffix = "st";
33
+ else if (remainder10 === 2 && remainder100 !== 12) suffix = "nd";
34
+ else if (remainder10 === 3 && remainder100 !== 13) suffix = "rd";
35
+ else suffix = "th";
36
+ return withNumber ? String(num).concat(suffix) : suffix;
37
+ };
38
+ function normalizeNumber(num) {
39
+ return require_primitives.isNumber(num) ? num : isNumericString(num) ? Number(num) : void 0;
40
+ }
41
+
42
+ //#endregion
43
+ Object.defineProperty(exports, 'BN_DIGITS', {
44
+ enumerable: true,
45
+ get: function () {
46
+ return BN_DIGITS;
47
+ }
48
+ });
49
+ Object.defineProperty(exports, 'getOrdinal', {
50
+ enumerable: true,
51
+ get: function () {
52
+ return getOrdinal;
53
+ }
54
+ });
55
+ Object.defineProperty(exports, 'isNumericString', {
56
+ enumerable: true,
57
+ get: function () {
58
+ return isNumericString;
59
+ }
60
+ });
61
+ Object.defineProperty(exports, 'normalizeNumber', {
62
+ enumerable: true,
63
+ get: function () {
64
+ return normalizeNumber;
65
+ }
66
+ });
67
+ Object.defineProperty(exports, 'roundToNearest', {
68
+ enumerable: true,
69
+ get: function () {
70
+ return roundToNearest;
71
+ }
72
+ });
@@ -0,0 +1,241 @@
1
+ import { n as NATIVE_TZ_IDS } from "./timezone-BfBXeMK_.mjs";
2
+ import { a as isUndefined } from "./primitives-DEt6I7Sy.mjs";
3
+ import { r as isObject } from "./non-primitives-DrQfPj1r.mjs";
4
+ import { n as normalizeNumber } from "./utilities-BU4MSYS7.mjs";
5
+ import { isValidUTCOffset } from "./guards.mjs";
6
+ import { n as _dateArgsToDate, p as _resolveNativeTzName, r as _formatDate, s as _gmtToUtcOffset, u as _normalizeOffset } from "./helpers-CrMc9iJZ.mjs";
7
+
8
+ //#region src/utils/utilities.ts
9
+ /**
10
+ * * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format.
11
+ *
12
+ * @param time - The time string to extract from.
13
+ * @return The extracted hour and minute as number tuple.
14
+ */
15
+ function extractHourMinute(time) {
16
+ const [hour, minute] = time.split(":").map(Number);
17
+ return [hour, minute];
18
+ }
19
+ /**
20
+ * * Converts a time string `HH:MM` or `-HH:MM` into total minutes from `00:00`.
21
+ *
22
+ * @param time - The time in `HH:MM` or `-HH:MM` format.
23
+ * @returns The total minutes elapsed since `00:00`.
24
+ */
25
+ function getTotalMinutes(time) {
26
+ const isNegative = time.startsWith("-");
27
+ const [h, m] = extractHourMinute(isNegative ? time.slice(1) : time);
28
+ const total = h * 60 + m;
29
+ return isNegative ? -total : total;
30
+ }
31
+ /**
32
+ * * Extract Time in `HH:MM` format from given UTC value.
33
+ *
34
+ * @param utc UTC value in `UTC-01:30` or `UTC+01:30` format.
35
+ * @returns The UTC value in `HH:MM` format.
36
+ */
37
+ function extractTimeFromUTC(utc) {
38
+ return utc.replace(/^UTC[+]?/g, "");
39
+ }
40
+ /**
41
+ * * Converts a UTC value in `UTC-01:30` or `UTC+01:30` format into total minutes in number.
42
+ *
43
+ * @param time - UTC value in `UTC-01:30` or `UTC+01:30` format.
44
+ * @returns The total minutes elapsed since `00:00`.
45
+ */
46
+ function extractMinutesFromUTC(utc) {
47
+ return getTotalMinutes(extractTimeFromUTC(utc));
48
+ }
49
+ /**
50
+ * * Converts a number of minutes into a time string in "HH:MM" format.
51
+ *
52
+ * @param minutes - The number of minutes to convert. Can be a number or a numeric string.
53
+ * @returns A string representing the time in "HH:MM" format.
54
+ *
55
+ * @remarks Always returns the absolute value of the minutes, ignoring the sign if they are negative.
56
+ *
57
+ * @example
58
+ * convertMinutesToTime(75); // "1:15"
59
+ * convertMinutesToTime(-45); // "0:45"
60
+ */
61
+ function convertMinutesToTime(minutes) {
62
+ const parsed = normalizeNumber(minutes);
63
+ if (isUndefined(parsed)) throw new TypeError(`Invalid numeric input!`, { cause: `${minutes} cannot be converted to a number.` });
64
+ const numMIn = Math.abs(parsed);
65
+ return `${String(Math.floor(numMIn / 60))}:${String(numMIn % 60).padStart(2, "0")}`;
66
+ }
67
+ /**
68
+ * * Converts a minute-based offset to a UTC offset string in the format `UTC±HH:MM`.
69
+ *
70
+ * @param minutes - The offset in minutes (positive or negative).
71
+ * @returns A formatted UTC offset string like `UTC+05:30` or `UTC-04:00`.
72
+ */
73
+ function formatUTCOffset(minutes) {
74
+ const parsed = normalizeNumber(minutes);
75
+ if (isUndefined(parsed)) throw new TypeError(`Invalid numeric input!`, { cause: `${minutes} cannot be converted to a number.` });
76
+ const sign = parsed < 0 ? "-" : "+";
77
+ const abs = Math.abs(parsed);
78
+ return `UTC${sign}${String(Math.floor(abs / 60)).padStart(2, "0")}:${String(abs % 60).padStart(2, "0")}`;
79
+ }
80
+ /** Get the current system's time zone identifier using {@link Intl.DateTimeFormat} API. */
81
+ function getNativeTimeZoneId() {
82
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
83
+ }
84
+ /**
85
+ * * Retrieves comprehensive time zone details using the {@link Intl.DateTimeFormat} API.
86
+ * @param tzId Optional timezone identifier. Defaults to the system timezone.
87
+ * @param date Optional date for which to resolve the information.
88
+ * @returns Object containing time zone identifier, names, and offset.
89
+ */
90
+ function getTimeZoneDetails(tzId, date) {
91
+ const TZ_NAME_TYPES = [
92
+ "long",
93
+ "longGeneric",
94
+ "longOffset"
95
+ ];
96
+ const $tzId = tzId || getNativeTimeZoneId();
97
+ const obj = { tzIdentifier: $tzId };
98
+ for (const type of TZ_NAME_TYPES) {
99
+ const key = `tzName${type[0].toUpperCase()}${type.slice(1)}`;
100
+ obj[key] = _resolveNativeTzName($tzId, type, date);
101
+ }
102
+ return obj;
103
+ }
104
+ /** Cache for offset to time zone */
105
+ const TZ_MAP = /* @__PURE__ */ new Map();
106
+ /**
107
+ * * Resolves all IANA time-zone identifiers that match a given UTC offset.
108
+ *
109
+ * @remarks
110
+ * - Uses an internal in-memory cache that persists for the lifetime of the running application.
111
+ * - The cache is lazily populated so the `offset`-to-`time-zone` mapping is computed only once per offset.
112
+ * - Offset and time-zone identifier detection uses the {@link Intl.DateTimeFormat} API.
113
+ *
114
+ * @param offset The UTC offset in `"UTC±HH:MM"` format.
115
+ * @returns An array of matching IANA time-zone identifiers, or an empty array if the offset is invalid.
116
+ */
117
+ function getTimeZoneIds(offset) {
118
+ if (!isValidUTCOffset(offset)) return [];
119
+ if (TZ_MAP.has(offset)) return TZ_MAP.get(offset) ?? [];
120
+ for (const zone of NATIVE_TZ_IDS) {
121
+ const off = _gmtToUtcOffset(_resolveNativeTzName(zone, "longOffset"));
122
+ if (off) TZ_MAP.set(off, [...TZ_MAP.get(off) ?? [], zone]);
123
+ }
124
+ return TZ_MAP.get(offset) ?? [];
125
+ }
126
+ /**
127
+ * * Formats a date into a specified string format.
128
+ *
129
+ * @param options Options to control date and time formatting.
130
+ *
131
+ * @remarks
132
+ * - If no date is provided, the current date and time will be used.
133
+ * - If the provided date is invalid, the function will return `'Invalid Date!'`.
134
+ * - The default format is `'dd, mmm DD, YYYY HH:mm:ss'` (e.g., `'Sun, Apr 06, 2025 16:11:55'`).
135
+ * - By default, local time is used; set `useUTC` to `true` to format in UTC.
136
+ * - The format string supports various tokens for date and time components, as well as literal text enclosed in square brackets.
137
+ * - See {@link https://toolbox.nazmul-nhb.dev/docs/utilities/date/formatDate#format-tokens format tokens} for details on supported tokens.
138
+ * - For more complex date/time manipulations, consider using the {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos Chronos} class.
139
+ *
140
+ * @returns Date/time string in specified format.
141
+ */
142
+ function formatDate(options) {
143
+ const { date = /* @__PURE__ */ new Date(), format = "dd, mmm DD, YYYY HH:mm:ss", useUTC = false } = options ?? {};
144
+ const $date = _dateArgsToDate(date);
145
+ if (isNaN($date.getTime())) return "Invalid Date!";
146
+ /** Get unit value for {@link $date} for specific unit in local or UTC time */
147
+ const _getUnitValue = (suffix) => {
148
+ return useUTC ? $date[`getUTC${suffix}`]() : $date[`get${suffix}`]();
149
+ };
150
+ return _formatDate(format, _getUnitValue("FullYear"), _getUnitValue("Month"), _getUnitValue("Day"), _getUnitValue("Date"), _getUnitValue("Hours"), _getUnitValue("Minutes"), _getUnitValue("Seconds"), _getUnitValue("Milliseconds"), useUTC ? "Z" : formatUTCOffset(-$date.getTimezoneOffset()).slice(3));
151
+ }
152
+ /**
153
+ * * Formats a time-only string into a formatted time string.
154
+ *
155
+ * @param time - Time string to be formatted. Supported formats include:
156
+ * - `HH:mm` → e.g., `'14:50'`
157
+ * - `HH:mm:ss` → e.g., `'14:50:00'`
158
+ * - `HH:mm:ss.mss` → e.g., `'14:50:00.800'`
159
+ * - `HH:mm+TimeZoneOffset(HH)` → e.g., `'14:50+06'`
160
+ * - `HH:mm+TimeZoneOffset(HH:mm)` → e.g., `'14:50+06:00'`
161
+ * - `HH:mm:ss+TimeZoneOffset(HH)` → e.g., `'14:50:00+06'`
162
+ * - `HH:mm:ss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00+05:30'`
163
+ * - `HH:mm:ss.mss+TimeZoneOffset(HH)` → e.g., `'14:50:00.800+06'`
164
+ * - `HH:mm:ss.mss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00.800+06:30'`
165
+ *
166
+ * - *Input will default to today's date and assume local timezone if no offset is provided.*
167
+ *
168
+ * @param format - Format tokens accepted by {@link formatDate} method ({@link TimeOnlyFormat}) for time part only.
169
+ * Default: `hh:mm:ss a` → 02:33:36 pm.
170
+ * @returns Formatted time string in local (System) time.
171
+ */
172
+ function formatTimePart(time, format) {
173
+ return formatDate({
174
+ date: `${formatDate({ format: "YYYY-MM-DD" })}T${_normalizeOffset(time)}`,
175
+ format: format || "hh:mm:ss a"
176
+ });
177
+ }
178
+ /**
179
+ * * Formats a date as a relative time string (e.g., "5m ago", "2h from now").
180
+ *
181
+ * @param date - The date to format, which can be a `Date` object, a date string, or a timestamp number.
182
+ * @param format - Optional format string for dates older than 7 days. Defaults to `'mmm D, yyyy hh:mm a'`.
183
+ * @returns A relative time string if the date is within the last 7 days, otherwise a formatted date string.
184
+ *
185
+ * @remarks
186
+ * - If date is provided but `undefined`, current date and time will be used.
187
+ * - If the provided date is invalid, the function will return `'Invalid Date!'`.
188
+ * - For dates within the last 7 days, the output will be in the format of "Xm ago" or "Xh from now".
189
+ * - For dates older than 7 days, the output will be formatted using the provided `format` string or the default format if none is provided.
190
+ *
191
+ * @example
192
+ * formatDateRelative(Date.now() - 5 * 60000); // "5m ago"
193
+ * formatDateRelative(Date.now() + 2 * 3600000); // "2h from now"
194
+ * formatDateRelative(Date.now() - 10 * 86400000); // "Apr 6, 2026 04:11 PM" (formatted date string)
195
+ */
196
+ function formatDateRelative(date, format) {
197
+ const $date = _dateArgsToDate(date);
198
+ if (isNaN($date.getTime())) return "Invalid Date!";
199
+ const now = Date.now();
200
+ const then = $date.getTime();
201
+ const diff = Math.abs(now - then);
202
+ const minutes = Math.floor(diff / 6e4);
203
+ const hours = Math.floor(diff / 36e5);
204
+ const days = Math.floor(diff / 864e5);
205
+ const suffix = then < now ? "ago" : "from now";
206
+ if (minutes < 1) return "Just now";
207
+ if (minutes < 60) return `${minutes}m ${suffix}`;
208
+ if (hours < 24) return `${hours}h ${suffix}`;
209
+ if (days < 7) return `${days}d ${suffix}`;
210
+ return formatDate({
211
+ date,
212
+ format: format || "mmm D, yyyy hh:mm a"
213
+ });
214
+ }
215
+ /** Get timestamp in ISO 8601 format. */
216
+ function getTimestamp(args, format) {
217
+ let $value;
218
+ let $format;
219
+ const _isTsOptions = (opt) => {
220
+ return isObject(opt) && ("value" in opt || "format" in opt);
221
+ };
222
+ if (_isTsOptions(args)) {
223
+ $value = args.value || /* @__PURE__ */ new Date();
224
+ $format = args.format || "utc";
225
+ } else {
226
+ $value = args || /* @__PURE__ */ new Date();
227
+ $format = format || "utc";
228
+ }
229
+ let date = _dateArgsToDate($value);
230
+ if (isNaN(date.getTime())) date = /* @__PURE__ */ new Date();
231
+ if ($format === "local") {
232
+ const offsetMins = date.getTimezoneOffset();
233
+ const localDate = /* @__PURE__ */ new Date(date.getTime() - offsetMins * 6e4);
234
+ const offset = formatUTCOffset(-offsetMins).slice(3);
235
+ return localDate.toISOString().replace("Z", offset);
236
+ }
237
+ return date.toISOString();
238
+ }
239
+
240
+ //#endregion
241
+ export { formatDate as a, formatUTCOffset as c, getTimeZoneIds as d, getTimestamp as f, extractTimeFromUTC as i, getNativeTimeZoneId as l, extractHourMinute as n, formatDateRelative as o, getTotalMinutes as p, extractMinutesFromUTC as r, formatTimePart as s, convertMinutesToTime as t, getTimeZoneDetails as u };
@@ -0,0 +1,318 @@
1
+ const require_timezone = require('./timezone-DYVJJYKz.cjs');
2
+ const require_primitives = require('./primitives-BME3_QrA.cjs');
3
+ const require_non_primitives = require('./non-primitives-CT4vszrX.cjs');
4
+ const require_utilities = require('./utilities-CGL7F6R9.cjs');
5
+ const require_guards = require('./guards.cjs');
6
+ const require_helpers = require('./helpers-M_SfAbAv.cjs');
7
+
8
+ //#region src/utils/utilities.ts
9
+ /**
10
+ * * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format.
11
+ *
12
+ * @param time - The time string to extract from.
13
+ * @return The extracted hour and minute as number tuple.
14
+ */
15
+ function extractHourMinute(time) {
16
+ const [hour, minute] = time.split(":").map(Number);
17
+ return [hour, minute];
18
+ }
19
+ /**
20
+ * * Converts a time string `HH:MM` or `-HH:MM` into total minutes from `00:00`.
21
+ *
22
+ * @param time - The time in `HH:MM` or `-HH:MM` format.
23
+ * @returns The total minutes elapsed since `00:00`.
24
+ */
25
+ function getTotalMinutes(time) {
26
+ const isNegative = time.startsWith("-");
27
+ const [h, m] = extractHourMinute(isNegative ? time.slice(1) : time);
28
+ const total = h * 60 + m;
29
+ return isNegative ? -total : total;
30
+ }
31
+ /**
32
+ * * Extract Time in `HH:MM` format from given UTC value.
33
+ *
34
+ * @param utc UTC value in `UTC-01:30` or `UTC+01:30` format.
35
+ * @returns The UTC value in `HH:MM` format.
36
+ */
37
+ function extractTimeFromUTC(utc) {
38
+ return utc.replace(/^UTC[+]?/g, "");
39
+ }
40
+ /**
41
+ * * Converts a UTC value in `UTC-01:30` or `UTC+01:30` format into total minutes in number.
42
+ *
43
+ * @param time - UTC value in `UTC-01:30` or `UTC+01:30` format.
44
+ * @returns The total minutes elapsed since `00:00`.
45
+ */
46
+ function extractMinutesFromUTC(utc) {
47
+ return getTotalMinutes(extractTimeFromUTC(utc));
48
+ }
49
+ /**
50
+ * * Converts a number of minutes into a time string in "HH:MM" format.
51
+ *
52
+ * @param minutes - The number of minutes to convert. Can be a number or a numeric string.
53
+ * @returns A string representing the time in "HH:MM" format.
54
+ *
55
+ * @remarks Always returns the absolute value of the minutes, ignoring the sign if they are negative.
56
+ *
57
+ * @example
58
+ * convertMinutesToTime(75); // "1:15"
59
+ * convertMinutesToTime(-45); // "0:45"
60
+ */
61
+ function convertMinutesToTime(minutes) {
62
+ const parsed = require_utilities.normalizeNumber(minutes);
63
+ if (require_primitives.isUndefined(parsed)) throw new TypeError(`Invalid numeric input!`, { cause: `${minutes} cannot be converted to a number.` });
64
+ const numMIn = Math.abs(parsed);
65
+ return `${String(Math.floor(numMIn / 60))}:${String(numMIn % 60).padStart(2, "0")}`;
66
+ }
67
+ /**
68
+ * * Converts a minute-based offset to a UTC offset string in the format `UTC±HH:MM`.
69
+ *
70
+ * @param minutes - The offset in minutes (positive or negative).
71
+ * @returns A formatted UTC offset string like `UTC+05:30` or `UTC-04:00`.
72
+ */
73
+ function formatUTCOffset(minutes) {
74
+ const parsed = require_utilities.normalizeNumber(minutes);
75
+ if (require_primitives.isUndefined(parsed)) throw new TypeError(`Invalid numeric input!`, { cause: `${minutes} cannot be converted to a number.` });
76
+ const sign = parsed < 0 ? "-" : "+";
77
+ const abs = Math.abs(parsed);
78
+ return `UTC${sign}${String(Math.floor(abs / 60)).padStart(2, "0")}:${String(abs % 60).padStart(2, "0")}`;
79
+ }
80
+ /** Get the current system's time zone identifier using {@link Intl.DateTimeFormat} API. */
81
+ function getNativeTimeZoneId() {
82
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
83
+ }
84
+ /**
85
+ * * Retrieves comprehensive time zone details using the {@link Intl.DateTimeFormat} API.
86
+ * @param tzId Optional timezone identifier. Defaults to the system timezone.
87
+ * @param date Optional date for which to resolve the information.
88
+ * @returns Object containing time zone identifier, names, and offset.
89
+ */
90
+ function getTimeZoneDetails(tzId, date) {
91
+ const TZ_NAME_TYPES = [
92
+ "long",
93
+ "longGeneric",
94
+ "longOffset"
95
+ ];
96
+ const $tzId = tzId || getNativeTimeZoneId();
97
+ const obj = { tzIdentifier: $tzId };
98
+ for (const type of TZ_NAME_TYPES) {
99
+ const key = `tzName${type[0].toUpperCase()}${type.slice(1)}`;
100
+ obj[key] = require_helpers._resolveNativeTzName($tzId, type, date);
101
+ }
102
+ return obj;
103
+ }
104
+ /** Cache for offset to time zone */
105
+ const TZ_MAP = /* @__PURE__ */ new Map();
106
+ /**
107
+ * * Resolves all IANA time-zone identifiers that match a given UTC offset.
108
+ *
109
+ * @remarks
110
+ * - Uses an internal in-memory cache that persists for the lifetime of the running application.
111
+ * - The cache is lazily populated so the `offset`-to-`time-zone` mapping is computed only once per offset.
112
+ * - Offset and time-zone identifier detection uses the {@link Intl.DateTimeFormat} API.
113
+ *
114
+ * @param offset The UTC offset in `"UTC±HH:MM"` format.
115
+ * @returns An array of matching IANA time-zone identifiers, or an empty array if the offset is invalid.
116
+ */
117
+ function getTimeZoneIds(offset) {
118
+ if (!require_guards.isValidUTCOffset(offset)) return [];
119
+ if (TZ_MAP.has(offset)) return TZ_MAP.get(offset) ?? [];
120
+ for (const zone of require_timezone.NATIVE_TZ_IDS) {
121
+ const off = require_helpers._gmtToUtcOffset(require_helpers._resolveNativeTzName(zone, "longOffset"));
122
+ if (off) TZ_MAP.set(off, [...TZ_MAP.get(off) ?? [], zone]);
123
+ }
124
+ return TZ_MAP.get(offset) ?? [];
125
+ }
126
+ /**
127
+ * * Formats a date into a specified string format.
128
+ *
129
+ * @param options Options to control date and time formatting.
130
+ *
131
+ * @remarks
132
+ * - If no date is provided, the current date and time will be used.
133
+ * - If the provided date is invalid, the function will return `'Invalid Date!'`.
134
+ * - The default format is `'dd, mmm DD, YYYY HH:mm:ss'` (e.g., `'Sun, Apr 06, 2025 16:11:55'`).
135
+ * - By default, local time is used; set `useUTC` to `true` to format in UTC.
136
+ * - The format string supports various tokens for date and time components, as well as literal text enclosed in square brackets.
137
+ * - See {@link https://toolbox.nazmul-nhb.dev/docs/utilities/date/formatDate#format-tokens format tokens} for details on supported tokens.
138
+ * - For more complex date/time manipulations, consider using the {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos Chronos} class.
139
+ *
140
+ * @returns Date/time string in specified format.
141
+ */
142
+ function formatDate(options) {
143
+ const { date = /* @__PURE__ */ new Date(), format = "dd, mmm DD, YYYY HH:mm:ss", useUTC = false } = options ?? {};
144
+ const $date = require_helpers._dateArgsToDate(date);
145
+ if (isNaN($date.getTime())) return "Invalid Date!";
146
+ /** Get unit value for {@link $date} for specific unit in local or UTC time */
147
+ const _getUnitValue = (suffix) => {
148
+ return useUTC ? $date[`getUTC${suffix}`]() : $date[`get${suffix}`]();
149
+ };
150
+ return require_helpers._formatDate(format, _getUnitValue("FullYear"), _getUnitValue("Month"), _getUnitValue("Day"), _getUnitValue("Date"), _getUnitValue("Hours"), _getUnitValue("Minutes"), _getUnitValue("Seconds"), _getUnitValue("Milliseconds"), useUTC ? "Z" : formatUTCOffset(-$date.getTimezoneOffset()).slice(3));
151
+ }
152
+ /**
153
+ * * Formats a time-only string into a formatted time string.
154
+ *
155
+ * @param time - Time string to be formatted. Supported formats include:
156
+ * - `HH:mm` → e.g., `'14:50'`
157
+ * - `HH:mm:ss` → e.g., `'14:50:00'`
158
+ * - `HH:mm:ss.mss` → e.g., `'14:50:00.800'`
159
+ * - `HH:mm+TimeZoneOffset(HH)` → e.g., `'14:50+06'`
160
+ * - `HH:mm+TimeZoneOffset(HH:mm)` → e.g., `'14:50+06:00'`
161
+ * - `HH:mm:ss+TimeZoneOffset(HH)` → e.g., `'14:50:00+06'`
162
+ * - `HH:mm:ss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00+05:30'`
163
+ * - `HH:mm:ss.mss+TimeZoneOffset(HH)` → e.g., `'14:50:00.800+06'`
164
+ * - `HH:mm:ss.mss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00.800+06:30'`
165
+ *
166
+ * - *Input will default to today's date and assume local timezone if no offset is provided.*
167
+ *
168
+ * @param format - Format tokens accepted by {@link formatDate} method ({@link TimeOnlyFormat}) for time part only.
169
+ * Default: `hh:mm:ss a` → 02:33:36 pm.
170
+ * @returns Formatted time string in local (System) time.
171
+ */
172
+ function formatTimePart(time, format) {
173
+ return formatDate({
174
+ date: `${formatDate({ format: "YYYY-MM-DD" })}T${require_helpers._normalizeOffset(time)}`,
175
+ format: format || "hh:mm:ss a"
176
+ });
177
+ }
178
+ /**
179
+ * * Formats a date as a relative time string (e.g., "5m ago", "2h from now").
180
+ *
181
+ * @param date - The date to format, which can be a `Date` object, a date string, or a timestamp number.
182
+ * @param format - Optional format string for dates older than 7 days. Defaults to `'mmm D, yyyy hh:mm a'`.
183
+ * @returns A relative time string if the date is within the last 7 days, otherwise a formatted date string.
184
+ *
185
+ * @remarks
186
+ * - If date is provided but `undefined`, current date and time will be used.
187
+ * - If the provided date is invalid, the function will return `'Invalid Date!'`.
188
+ * - For dates within the last 7 days, the output will be in the format of "Xm ago" or "Xh from now".
189
+ * - For dates older than 7 days, the output will be formatted using the provided `format` string or the default format if none is provided.
190
+ *
191
+ * @example
192
+ * formatDateRelative(Date.now() - 5 * 60000); // "5m ago"
193
+ * formatDateRelative(Date.now() + 2 * 3600000); // "2h from now"
194
+ * formatDateRelative(Date.now() - 10 * 86400000); // "Apr 6, 2026 04:11 PM" (formatted date string)
195
+ */
196
+ function formatDateRelative(date, format) {
197
+ const $date = require_helpers._dateArgsToDate(date);
198
+ if (isNaN($date.getTime())) return "Invalid Date!";
199
+ const now = Date.now();
200
+ const then = $date.getTime();
201
+ const diff = Math.abs(now - then);
202
+ const minutes = Math.floor(diff / 6e4);
203
+ const hours = Math.floor(diff / 36e5);
204
+ const days = Math.floor(diff / 864e5);
205
+ const suffix = then < now ? "ago" : "from now";
206
+ if (minutes < 1) return "Just now";
207
+ if (minutes < 60) return `${minutes}m ${suffix}`;
208
+ if (hours < 24) return `${hours}h ${suffix}`;
209
+ if (days < 7) return `${days}d ${suffix}`;
210
+ return formatDate({
211
+ date,
212
+ format: format || "mmm D, yyyy hh:mm a"
213
+ });
214
+ }
215
+ /** Get timestamp in ISO 8601 format. */
216
+ function getTimestamp(args, format) {
217
+ let $value;
218
+ let $format;
219
+ const _isTsOptions = (opt) => {
220
+ return require_non_primitives.isObject(opt) && ("value" in opt || "format" in opt);
221
+ };
222
+ if (_isTsOptions(args)) {
223
+ $value = args.value || /* @__PURE__ */ new Date();
224
+ $format = args.format || "utc";
225
+ } else {
226
+ $value = args || /* @__PURE__ */ new Date();
227
+ $format = format || "utc";
228
+ }
229
+ let date = require_helpers._dateArgsToDate($value);
230
+ if (isNaN(date.getTime())) date = /* @__PURE__ */ new Date();
231
+ if ($format === "local") {
232
+ const offsetMins = date.getTimezoneOffset();
233
+ const localDate = /* @__PURE__ */ new Date(date.getTime() - offsetMins * 6e4);
234
+ const offset = formatUTCOffset(-offsetMins).slice(3);
235
+ return localDate.toISOString().replace("Z", offset);
236
+ }
237
+ return date.toISOString();
238
+ }
239
+
240
+ //#endregion
241
+ Object.defineProperty(exports, 'convertMinutesToTime', {
242
+ enumerable: true,
243
+ get: function () {
244
+ return convertMinutesToTime;
245
+ }
246
+ });
247
+ Object.defineProperty(exports, 'extractHourMinute', {
248
+ enumerable: true,
249
+ get: function () {
250
+ return extractHourMinute;
251
+ }
252
+ });
253
+ Object.defineProperty(exports, 'extractMinutesFromUTC', {
254
+ enumerable: true,
255
+ get: function () {
256
+ return extractMinutesFromUTC;
257
+ }
258
+ });
259
+ Object.defineProperty(exports, 'extractTimeFromUTC', {
260
+ enumerable: true,
261
+ get: function () {
262
+ return extractTimeFromUTC;
263
+ }
264
+ });
265
+ Object.defineProperty(exports, 'formatDate', {
266
+ enumerable: true,
267
+ get: function () {
268
+ return formatDate;
269
+ }
270
+ });
271
+ Object.defineProperty(exports, 'formatDateRelative', {
272
+ enumerable: true,
273
+ get: function () {
274
+ return formatDateRelative;
275
+ }
276
+ });
277
+ Object.defineProperty(exports, 'formatTimePart', {
278
+ enumerable: true,
279
+ get: function () {
280
+ return formatTimePart;
281
+ }
282
+ });
283
+ Object.defineProperty(exports, 'formatUTCOffset', {
284
+ enumerable: true,
285
+ get: function () {
286
+ return formatUTCOffset;
287
+ }
288
+ });
289
+ Object.defineProperty(exports, 'getNativeTimeZoneId', {
290
+ enumerable: true,
291
+ get: function () {
292
+ return getNativeTimeZoneId;
293
+ }
294
+ });
295
+ Object.defineProperty(exports, 'getTimeZoneDetails', {
296
+ enumerable: true,
297
+ get: function () {
298
+ return getTimeZoneDetails;
299
+ }
300
+ });
301
+ Object.defineProperty(exports, 'getTimeZoneIds', {
302
+ enumerable: true,
303
+ get: function () {
304
+ return getTimeZoneIds;
305
+ }
306
+ });
307
+ Object.defineProperty(exports, 'getTimestamp', {
308
+ enumerable: true,
309
+ get: function () {
310
+ return getTimestamp;
311
+ }
312
+ });
313
+ Object.defineProperty(exports, 'getTotalMinutes', {
314
+ enumerable: true,
315
+ get: function () {
316
+ return getTotalMinutes;
317
+ }
318
+ });