chronos-date 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/basic-DqKyujoj.mjs +382 -0
  2. package/dist/basic-DsQqC5nZ.cjs +466 -0
  3. package/dist/constants.cjs +43 -1
  4. package/dist/constants.d.cts +17 -1
  5. package/dist/constants.d.mts +17 -1
  6. package/dist/constants.mjs +21 -1
  7. package/dist/convert-DbgntRVW.cjs +49 -0
  8. package/dist/convert-mMaI4YP0.mjs +38 -0
  9. package/dist/greet-D07t2_e6.mjs +51 -0
  10. package/dist/greet-hjVsd2dt.cjs +56 -0
  11. package/dist/guards.cjs +140 -1
  12. package/dist/guards.d.cts +18 -2
  13. package/dist/guards.d.mts +18 -2
  14. package/dist/guards.mjs +131 -1
  15. package/dist/helpers-CQzi908i.cjs +278 -0
  16. package/dist/helpers-DEf4sevD.mjs +201 -0
  17. package/dist/index.cjs +1477 -1
  18. package/dist/index.d.cts +18 -2
  19. package/dist/index.d.mts +18 -2
  20. package/dist/index.mjs +1474 -1
  21. package/dist/non-primitives-D9zxCwX8.cjs +68 -0
  22. package/dist/non-primitives-DBtomDty.mjs +38 -0
  23. package/dist/plugins/banglaPlugin.cjs +137 -1
  24. package/dist/plugins/banglaPlugin.d.cts +19 -3
  25. package/dist/plugins/banglaPlugin.d.mts +19 -3
  26. package/dist/plugins/banglaPlugin.mjs +136 -1
  27. package/dist/plugins/businessPlugin.cjs +134 -1
  28. package/dist/plugins/businessPlugin.d.cts +17 -1
  29. package/dist/plugins/businessPlugin.d.mts +17 -1
  30. package/dist/plugins/businessPlugin.mjs +133 -1
  31. package/dist/plugins/dateRangePlugin.cjs +62 -1
  32. package/dist/plugins/dateRangePlugin.d.cts +19 -3
  33. package/dist/plugins/dateRangePlugin.d.mts +19 -3
  34. package/dist/plugins/dateRangePlugin.mjs +61 -1
  35. package/dist/plugins/dayPartPlugin.cjs +42 -1
  36. package/dist/plugins/dayPartPlugin.d.cts +17 -1
  37. package/dist/plugins/dayPartPlugin.d.mts +17 -1
  38. package/dist/plugins/dayPartPlugin.mjs +41 -1
  39. package/dist/plugins/durationPlugin.cjs +107 -1
  40. package/dist/plugins/durationPlugin.d.cts +17 -1
  41. package/dist/plugins/durationPlugin.d.mts +17 -1
  42. package/dist/plugins/durationPlugin.mjs +106 -1
  43. package/dist/plugins/fromNowPlugin.cjs +96 -1
  44. package/dist/plugins/fromNowPlugin.d.cts +17 -1
  45. package/dist/plugins/fromNowPlugin.d.mts +17 -1
  46. package/dist/plugins/fromNowPlugin.mjs +95 -1
  47. package/dist/plugins/greetingPlugin.cjs +35 -1
  48. package/dist/plugins/greetingPlugin.d.cts +17 -1
  49. package/dist/plugins/greetingPlugin.d.mts +17 -1
  50. package/dist/plugins/greetingPlugin.mjs +34 -1
  51. package/dist/plugins/palindromePlugin.cjs +38 -1
  52. package/dist/plugins/palindromePlugin.d.cts +17 -1
  53. package/dist/plugins/palindromePlugin.d.mts +17 -1
  54. package/dist/plugins/palindromePlugin.mjs +37 -1
  55. package/dist/plugins/relativeTimePlugin.cjs +90 -1
  56. package/dist/plugins/relativeTimePlugin.d.cts +17 -1
  57. package/dist/plugins/relativeTimePlugin.d.mts +17 -1
  58. package/dist/plugins/relativeTimePlugin.mjs +89 -1
  59. package/dist/plugins/roundPlugin.cjs +85 -1
  60. package/dist/plugins/roundPlugin.d.cts +17 -1
  61. package/dist/plugins/roundPlugin.d.mts +17 -1
  62. package/dist/plugins/roundPlugin.mjs +84 -1
  63. package/dist/plugins/seasonPlugin.cjs +47 -1
  64. package/dist/plugins/seasonPlugin.d.cts +17 -1
  65. package/dist/plugins/seasonPlugin.d.mts +17 -1
  66. package/dist/plugins/seasonPlugin.mjs +46 -1
  67. package/dist/plugins/timeZonePlugin.cjs +155 -1
  68. package/dist/plugins/timeZonePlugin.d.cts +17 -1
  69. package/dist/plugins/timeZonePlugin.d.mts +17 -1
  70. package/dist/plugins/timeZonePlugin.mjs +154 -1
  71. package/dist/plugins/zodiacPlugin.cjs +67 -1
  72. package/dist/plugins/zodiacPlugin.d.cts +17 -1
  73. package/dist/plugins/zodiacPlugin.d.mts +17 -1
  74. package/dist/plugins/zodiacPlugin.mjs +66 -1
  75. package/dist/primitives-CtuSNmV7.cjs +65 -0
  76. package/dist/primitives-dXzXlzJw.mjs +35 -0
  77. package/dist/seasons-B7kK88zq.cjs +434 -0
  78. package/dist/{seasons-CioTH5Dm.d.mts → seasons-B_kjFWIX.d.mts} +16 -0
  79. package/dist/{seasons-CsVeJ27s.d.cts → seasons-CpUn45n6.d.cts} +16 -0
  80. package/dist/seasons-Cq3ah3pV.mjs +368 -0
  81. package/dist/timezone-BNnHFgki.cjs +5625 -0
  82. package/dist/timezone-Db2CeL32.mjs +5589 -0
  83. package/dist/{types-B2fgrJ86.d.mts → types-Cb4gxrgJ.d.mts} +29 -15
  84. package/dist/{types-DPTQ_yLx.d.cts → types-CdmsXbU_.d.cts} +29 -15
  85. package/dist/types.cjs +16 -0
  86. package/dist/types.d.cts +18 -2
  87. package/dist/types.d.mts +18 -2
  88. package/dist/types.mjs +17 -1
  89. package/dist/utilities-BGX8dviZ.mjs +257 -0
  90. package/dist/utilities-BKtVo78T.mjs +59 -0
  91. package/dist/utilities-CpF3uys3.cjs +88 -0
  92. package/dist/utilities-D47SN9EZ.cjs +334 -0
  93. package/dist/utils.cjs +92 -1
  94. package/dist/utils.d.cts +20 -4
  95. package/dist/utils.d.mts +20 -4
  96. package/dist/utils.mjs +60 -1
  97. package/package.json +10 -4
  98. package/dist/basic-CKxaRSHQ.cjs +0 -1
  99. package/dist/basic-e46DaNAi.mjs +0 -1
  100. package/dist/convert-Bmp63ats.mjs +0 -1
  101. package/dist/convert-DrLrcgqz.cjs +0 -1
  102. package/dist/greet-BBsrvmkn.mjs +0 -1
  103. package/dist/greet-C-6mruI9.cjs +0 -1
  104. package/dist/helpers-DGzYnP81.cjs +0 -1
  105. package/dist/helpers-N1X_Rj_V.mjs +0 -1
  106. package/dist/non-primitives-B2EE6D6s.mjs +0 -1
  107. package/dist/non-primitives-Bu3a4WL4.cjs +0 -1
  108. package/dist/primitives-Cxss_JVF.mjs +0 -1
  109. package/dist/primitives-Db2FUp4e.cjs +0 -1
  110. package/dist/seasons-ChAIVphi.mjs +0 -1
  111. package/dist/seasons-oABOhHcX.cjs +0 -1
  112. package/dist/timezone-B10UItNO.mjs +0 -1
  113. package/dist/timezone-CWxbK_7I.cjs +0 -1
  114. package/dist/utilities-B8dOAQVD.cjs +0 -1
  115. package/dist/utilities-BJE06bms.mjs +0 -1
  116. package/dist/utilities-D2-p26DX.cjs +0 -1
  117. package/dist/utilities-DV_ohS37.mjs +0 -1
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const require_primitives = require('./primitives-CtuSNmV7.cjs');
18
+
19
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/guards/specials.js
20
+ function isNumericString(value) {
21
+ return require_primitives.isString(value) && value?.trim() !== "" && Number.isFinite(Number(value));
22
+ }
23
+
24
+ //#endregion
25
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/number/constants.js
26
+ const BN_DIGITS = /* @__PURE__ */ Object.freeze({
27
+ "০": 0,
28
+ "১": 1,
29
+ "২": 2,
30
+ "৩": 3,
31
+ "৪": 4,
32
+ "৫": 5,
33
+ "৬": 6,
34
+ "৭": 7,
35
+ "৮": 8,
36
+ "৯": 9
37
+ });
38
+
39
+ //#endregion
40
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/number/utilities.js
41
+ const roundToNearest = (value, interval = 5) => {
42
+ return Math.round(Number(value) / interval) * interval;
43
+ };
44
+ const getOrdinal = (num, withNumber = true) => {
45
+ const remainder10 = Number(num) % 10;
46
+ const remainder100 = Number(num) % 100;
47
+ let suffix;
48
+ if (remainder10 === 1 && remainder100 !== 11) suffix = "st";
49
+ else if (remainder10 === 2 && remainder100 !== 12) suffix = "nd";
50
+ else if (remainder10 === 3 && remainder100 !== 13) suffix = "rd";
51
+ else suffix = "th";
52
+ return withNumber ? String(num).concat(suffix) : suffix;
53
+ };
54
+ function normalizeNumber(num) {
55
+ return require_primitives.isNumber(num) ? num : isNumericString(num) ? Number(num) : void 0;
56
+ }
57
+
58
+ //#endregion
59
+ Object.defineProperty(exports, 'BN_DIGITS', {
60
+ enumerable: true,
61
+ get: function () {
62
+ return BN_DIGITS;
63
+ }
64
+ });
65
+ Object.defineProperty(exports, 'getOrdinal', {
66
+ enumerable: true,
67
+ get: function () {
68
+ return getOrdinal;
69
+ }
70
+ });
71
+ Object.defineProperty(exports, 'isNumericString', {
72
+ enumerable: true,
73
+ get: function () {
74
+ return isNumericString;
75
+ }
76
+ });
77
+ Object.defineProperty(exports, 'normalizeNumber', {
78
+ enumerable: true,
79
+ get: function () {
80
+ return normalizeNumber;
81
+ }
82
+ });
83
+ Object.defineProperty(exports, 'roundToNearest', {
84
+ enumerable: true,
85
+ get: function () {
86
+ return roundToNearest;
87
+ }
88
+ });
@@ -0,0 +1,334 @@
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const require_timezone = require('./timezone-BNnHFgki.cjs');
18
+ const require_primitives = require('./primitives-CtuSNmV7.cjs');
19
+ const require_non_primitives = require('./non-primitives-D9zxCwX8.cjs');
20
+ const require_utilities = require('./utilities-CpF3uys3.cjs');
21
+ const require_guards = require('./guards.cjs');
22
+ const require_helpers = require('./helpers-CQzi908i.cjs');
23
+
24
+ //#region src/utils/utilities.ts
25
+ /**
26
+ * * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format.
27
+ *
28
+ * @param time - The time string to extract from.
29
+ * @return The extracted hour and minute as number tuple.
30
+ */
31
+ function extractHourMinute(time) {
32
+ const [hour, minute] = time.split(":").map(Number);
33
+ return [hour, minute];
34
+ }
35
+ /**
36
+ * * Converts a time string `HH:MM` or `-HH:MM` into total minutes from `00:00`.
37
+ *
38
+ * @param time - The time in `HH:MM` or `-HH:MM` format.
39
+ * @returns The total minutes elapsed since `00:00`.
40
+ */
41
+ function getTotalMinutes(time) {
42
+ const isNegative = time.startsWith("-");
43
+ const [h, m] = extractHourMinute(isNegative ? time.slice(1) : time);
44
+ const total = h * 60 + m;
45
+ return isNegative ? -total : total;
46
+ }
47
+ /**
48
+ * * Extract Time in `HH:MM` format from given UTC value.
49
+ *
50
+ * @param utc UTC value in `UTC-01:30` or `UTC+01:30` format.
51
+ * @returns The UTC value in `HH:MM` format.
52
+ */
53
+ function extractTimeFromUTC(utc) {
54
+ return utc.replace(/^UTC[+]?/g, "");
55
+ }
56
+ /**
57
+ * * Converts a UTC value in `UTC-01:30` or `UTC+01:30` format into total minutes in number.
58
+ *
59
+ * @param time - UTC value in `UTC-01:30` or `UTC+01:30` format.
60
+ * @returns The total minutes elapsed since `00:00`.
61
+ */
62
+ function extractMinutesFromUTC(utc) {
63
+ return getTotalMinutes(extractTimeFromUTC(utc));
64
+ }
65
+ /**
66
+ * * Converts a number of minutes into a time string in "HH:MM" format.
67
+ *
68
+ * @param minutes - The number of minutes to convert. Can be a number or a numeric string.
69
+ * @returns A string representing the time in "HH:MM" format.
70
+ *
71
+ * @remarks Always returns the absolute value of the minutes, ignoring the sign if they are negative.
72
+ *
73
+ * @example
74
+ * convertMinutesToTime(75); // "1:15"
75
+ * convertMinutesToTime(-45); // "0:45"
76
+ */
77
+ function convertMinutesToTime(minutes) {
78
+ const parsed = require_utilities.normalizeNumber(minutes);
79
+ if (require_primitives.isUndefined(parsed)) throw new TypeError(`Invalid numeric input!`, { cause: `${minutes} cannot be converted to a number.` });
80
+ const numMIn = Math.abs(parsed);
81
+ return `${String(Math.floor(numMIn / 60))}:${String(numMIn % 60).padStart(2, "0")}`;
82
+ }
83
+ /**
84
+ * * Converts a minute-based offset to a UTC offset string in the format `UTC±HH:MM`.
85
+ *
86
+ * @param minutes - The offset in minutes (positive or negative).
87
+ * @returns A formatted UTC offset string like `UTC+05:30` or `UTC-04:00`.
88
+ */
89
+ function formatUTCOffset(minutes) {
90
+ const parsed = require_utilities.normalizeNumber(minutes);
91
+ if (require_primitives.isUndefined(parsed)) throw new TypeError(`Invalid numeric input!`, { cause: `${minutes} cannot be converted to a number.` });
92
+ const sign = parsed < 0 ? "-" : "+";
93
+ const abs = Math.abs(parsed);
94
+ return `UTC${sign}${String(Math.floor(abs / 60)).padStart(2, "0")}:${String(abs % 60).padStart(2, "0")}`;
95
+ }
96
+ /** Get the current system's time zone identifier using {@link Intl.DateTimeFormat} API. */
97
+ function getNativeTimeZoneId() {
98
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
99
+ }
100
+ /**
101
+ * * Retrieves comprehensive time zone details using the {@link Intl.DateTimeFormat} API.
102
+ * @param tzId Optional timezone identifier. Defaults to the system timezone.
103
+ * @param date Optional date for which to resolve the information.
104
+ * @returns Object containing time zone identifier, names, and offset.
105
+ */
106
+ function getTimeZoneDetails(tzId, date) {
107
+ const TZ_NAME_TYPES = [
108
+ "long",
109
+ "longGeneric",
110
+ "longOffset"
111
+ ];
112
+ const $tzId = tzId || getNativeTimeZoneId();
113
+ const obj = { tzIdentifier: $tzId };
114
+ for (const type of TZ_NAME_TYPES) {
115
+ const key = `tzName${type[0].toUpperCase()}${type.slice(1)}`;
116
+ obj[key] = require_helpers._resolveNativeTzName($tzId, type, date);
117
+ }
118
+ return obj;
119
+ }
120
+ /** Cache for offset to time zone */
121
+ const TZ_MAP = /* @__PURE__ */ new Map();
122
+ /**
123
+ * * Resolves all IANA time-zone identifiers that match a given UTC offset.
124
+ *
125
+ * @remarks
126
+ * - Uses an internal in-memory cache that persists for the lifetime of the running application.
127
+ * - The cache is lazily populated so the `offset`-to-`time-zone` mapping is computed only once per offset.
128
+ * - Offset and time-zone identifier detection uses the {@link Intl.DateTimeFormat} API.
129
+ *
130
+ * @param offset The UTC offset in `"UTC±HH:MM"` format.
131
+ * @returns An array of matching IANA time-zone identifiers, or an empty array if the offset is invalid.
132
+ */
133
+ function getTimeZoneIds(offset) {
134
+ if (!require_guards.isValidUTCOffset(offset)) return [];
135
+ if (TZ_MAP.has(offset)) return TZ_MAP.get(offset) ?? [];
136
+ for (const zone of require_timezone.NATIVE_TZ_IDS) {
137
+ const off = require_helpers._gmtToUtcOffset(require_helpers._resolveNativeTzName(zone, "longOffset"));
138
+ if (off) TZ_MAP.set(off, [...TZ_MAP.get(off) ?? [], zone]);
139
+ }
140
+ return TZ_MAP.get(offset) ?? [];
141
+ }
142
+ /**
143
+ * * Formats a date into a specified string format.
144
+ *
145
+ * @param options Options to control date and time formatting.
146
+ *
147
+ * @remarks
148
+ * - If no date is provided, the current date and time will be used.
149
+ * - If the provided date is invalid, the function will return `'Invalid Date!'`.
150
+ * - The default format is `'dd, mmm DD, YYYY HH:mm:ss'` (e.g., `'Sun, Apr 06, 2025 16:11:55'`).
151
+ * - By default, local time is used; set `useUTC` to `true` to format in UTC.
152
+ * - The format string supports various tokens for date and time components, as well as literal text enclosed in square brackets.
153
+ * - See {@link https://toolbox.nazmul-nhb.dev/docs/utilities/date/formatDate#format-tokens format tokens} for details on supported tokens.
154
+ * - For more complex date/time manipulations, consider using the {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos Chronos} class.
155
+ *
156
+ * @returns Date/time string in specified format.
157
+ */
158
+ function formatDate(options) {
159
+ const { date = /* @__PURE__ */ new Date(), format = "dd, mmm DD, YYYY HH:mm:ss", useUTC = false } = options ?? {};
160
+ const $date = require_helpers._dateArgsToDate(date);
161
+ if (isNaN($date.getTime())) return "Invalid Date!";
162
+ /** Get unit value for {@link $date} for specific unit in local or UTC time */
163
+ const _getUnitValue = (suffix) => {
164
+ return useUTC ? $date[`getUTC${suffix}`]() : $date[`get${suffix}`]();
165
+ };
166
+ 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));
167
+ }
168
+ /**
169
+ * * Formats a time-only string into a formatted time string.
170
+ *
171
+ * @param time - Time string to be formatted. Supported formats include:
172
+ * - `HH:mm` → e.g., `'14:50'`
173
+ * - `HH:mm:ss` → e.g., `'14:50:00'`
174
+ * - `HH:mm:ss.mss` → e.g., `'14:50:00.800'`
175
+ * - `HH:mm+TimeZoneOffset(HH)` → e.g., `'14:50+06'`
176
+ * - `HH:mm+TimeZoneOffset(HH:mm)` → e.g., `'14:50+06:00'`
177
+ * - `HH:mm:ss+TimeZoneOffset(HH)` → e.g., `'14:50:00+06'`
178
+ * - `HH:mm:ss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00+05:30'`
179
+ * - `HH:mm:ss.mss+TimeZoneOffset(HH)` → e.g., `'14:50:00.800+06'`
180
+ * - `HH:mm:ss.mss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00.800+06:30'`
181
+ *
182
+ * - *Input will default to today's date and assume local timezone if no offset is provided.*
183
+ *
184
+ * @param format - Format tokens accepted by {@link formatDate} method ({@link TimeOnlyFormat}) for time part only.
185
+ * Default: `hh:mm:ss a` → 02:33:36 pm.
186
+ * @returns Formatted time string in local (System) time.
187
+ */
188
+ function formatTimePart(time, format) {
189
+ return formatDate({
190
+ date: `${formatDate({ format: "YYYY-MM-DD" })}T${require_helpers._normalizeOffset(time)}`,
191
+ format: format || "hh:mm:ss a"
192
+ });
193
+ }
194
+ /**
195
+ * * Formats a date as a relative time string (e.g., "5m ago", "2h from now").
196
+ *
197
+ * @param date - The date to format, which can be a `Date` object, a date string, or a timestamp number.
198
+ * @param format - Optional format string for dates older than 7 days. Defaults to `'mmm D, yyyy hh:mm a'`.
199
+ * @returns A relative time string if the date is within the last 7 days, otherwise a formatted date string.
200
+ *
201
+ * @remarks
202
+ * - If date is provided but `undefined`, current date and time will be used.
203
+ * - If the provided date is invalid, the function will return `'Invalid Date!'`.
204
+ * - For dates within the last 7 days, the output will be in the format of "Xm ago" or "Xh from now".
205
+ * - For dates older than 7 days, the output will be formatted using the provided `format` string or the default format if none is provided.
206
+ *
207
+ * @example
208
+ * formatDateRelative(Date.now() - 5 * 60000); // "5m ago"
209
+ * formatDateRelative(Date.now() + 2 * 3600000); // "2h from now"
210
+ * formatDateRelative(Date.now() - 10 * 86400000); // "Apr 6, 2026 04:11 PM" (formatted date string)
211
+ */
212
+ function formatDateRelative(date, format) {
213
+ const $date = require_helpers._dateArgsToDate(date);
214
+ if (isNaN($date.getTime())) return "Invalid Date!";
215
+ const now = Date.now();
216
+ const then = $date.getTime();
217
+ const diff = Math.abs(now - then);
218
+ const minutes = Math.floor(diff / 6e4);
219
+ const hours = Math.floor(diff / 36e5);
220
+ const days = Math.floor(diff / 864e5);
221
+ const suffix = then < now ? "ago" : "from now";
222
+ if (minutes < 1) return "Just now";
223
+ if (minutes < 60) return `${minutes}m ${suffix}`;
224
+ if (hours < 24) return `${hours}h ${suffix}`;
225
+ if (days < 7) return `${days}d ${suffix}`;
226
+ return formatDate({
227
+ date,
228
+ format: format || "mmm D, yyyy hh:mm a"
229
+ });
230
+ }
231
+ /** Get timestamp in ISO 8601 format. */
232
+ function getTimestamp(args, format) {
233
+ let $value;
234
+ let $format;
235
+ const _isTsOptions = (opt) => {
236
+ return require_non_primitives.isObject(opt) && ("value" in opt || "format" in opt);
237
+ };
238
+ if (_isTsOptions(args)) {
239
+ $value = args.value || /* @__PURE__ */ new Date();
240
+ $format = args.format || "utc";
241
+ } else {
242
+ $value = args || /* @__PURE__ */ new Date();
243
+ $format = format || "utc";
244
+ }
245
+ let date = require_helpers._dateArgsToDate($value);
246
+ if (isNaN(date.getTime())) date = /* @__PURE__ */ new Date();
247
+ if ($format === "local") {
248
+ const offsetMins = date.getTimezoneOffset();
249
+ const localDate = /* @__PURE__ */ new Date(date.getTime() - offsetMins * 6e4);
250
+ const offset = formatUTCOffset(-offsetMins).slice(3);
251
+ return localDate.toISOString().replace("Z", offset);
252
+ }
253
+ return date.toISOString();
254
+ }
255
+
256
+ //#endregion
257
+ Object.defineProperty(exports, 'convertMinutesToTime', {
258
+ enumerable: true,
259
+ get: function () {
260
+ return convertMinutesToTime;
261
+ }
262
+ });
263
+ Object.defineProperty(exports, 'extractHourMinute', {
264
+ enumerable: true,
265
+ get: function () {
266
+ return extractHourMinute;
267
+ }
268
+ });
269
+ Object.defineProperty(exports, 'extractMinutesFromUTC', {
270
+ enumerable: true,
271
+ get: function () {
272
+ return extractMinutesFromUTC;
273
+ }
274
+ });
275
+ Object.defineProperty(exports, 'extractTimeFromUTC', {
276
+ enumerable: true,
277
+ get: function () {
278
+ return extractTimeFromUTC;
279
+ }
280
+ });
281
+ Object.defineProperty(exports, 'formatDate', {
282
+ enumerable: true,
283
+ get: function () {
284
+ return formatDate;
285
+ }
286
+ });
287
+ Object.defineProperty(exports, 'formatDateRelative', {
288
+ enumerable: true,
289
+ get: function () {
290
+ return formatDateRelative;
291
+ }
292
+ });
293
+ Object.defineProperty(exports, 'formatTimePart', {
294
+ enumerable: true,
295
+ get: function () {
296
+ return formatTimePart;
297
+ }
298
+ });
299
+ Object.defineProperty(exports, 'formatUTCOffset', {
300
+ enumerable: true,
301
+ get: function () {
302
+ return formatUTCOffset;
303
+ }
304
+ });
305
+ Object.defineProperty(exports, 'getNativeTimeZoneId', {
306
+ enumerable: true,
307
+ get: function () {
308
+ return getNativeTimeZoneId;
309
+ }
310
+ });
311
+ Object.defineProperty(exports, 'getTimeZoneDetails', {
312
+ enumerable: true,
313
+ get: function () {
314
+ return getTimeZoneDetails;
315
+ }
316
+ });
317
+ Object.defineProperty(exports, 'getTimeZoneIds', {
318
+ enumerable: true,
319
+ get: function () {
320
+ return getTimeZoneIds;
321
+ }
322
+ });
323
+ Object.defineProperty(exports, 'getTimestamp', {
324
+ enumerable: true,
325
+ get: function () {
326
+ return getTimestamp;
327
+ }
328
+ });
329
+ Object.defineProperty(exports, 'getTotalMinutes', {
330
+ enumerable: true,
331
+ get: function () {
332
+ return getTotalMinutes;
333
+ }
334
+ });
package/dist/utils.cjs CHANGED
@@ -1 +1,92 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./basic-CKxaRSHQ.cjs`),t=require(`./primitives-Db2FUp4e.cjs`),n=require(`./utilities-D2-p26DX.cjs`),r=require(`./guards.cjs`),i=require(`./utilities-B8dOAQVD.cjs`),a=require(`./greet-C-6mruI9.cjs`);function o(e,i=!1){return t.r(e)||n.a(e)?s(`${e}s`,i):r.isTimeWithUnit(e)?s(e,i):NaN}function s(n,r=!1){if(!t.n(n)||n.length>100)throw RangeError(`Value must be a string with length between 1 and 99!`);let i=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(n);if(!i?.groups)return NaN;let a=(i.groups.unit??`ms`).toLowerCase(),o=e.l[a];if(!o)throw RangeError(`Unknown unit "${a}"!`);let s=parseFloat(i.groups.value)*o;return r?s/1e3:s}exports.convertMinutesToHourMinutes=i.t,exports.convertMinutesToTime=i.t,exports.getHourMinutesFromMinutes=i.t,exports.getTimeFromMinutes=i.t,exports.convertMinutesToUTCOffset=i.c,exports.formatUTCOffset=i.c,exports.minutesToUTCOffset=i.c,exports.extractHourMinute=i.n,exports.extractMinutesFromUTC=i.r,exports.getMinutesFromUTC=i.r,exports.getTotalMinutesFromUTC=i.r,exports.extractTimeFromUTC=i.i,exports.extractTimeStringFromUTC=i.i,exports.getTimeStringFromUTC=i.i,exports.extractTotalMinutesFromTime=i.p,exports.getTotalMinutes=i.p,exports.getTotalMinutesFromTime=i.p,exports.formatDate=i.a,exports.formatDateTime=i.a,exports.formatDateRelative=i.o,exports.formatRelativeDate=i.o,exports.formatRelativeTime=i.o,exports.formatTimePart=i.s,exports.generateGreeting=a.t,exports.getGreeting=a.t,exports.greet=a.t,exports.getNativeTimeZoneId=i.l,exports.getTimeZoneDetails=i.u,exports.getTimeZoneIds=i.d,exports.getTimestamp=i.f,exports.parseMSec=o,exports.parseMs=o;
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
18
+ const require_basic = require('./basic-DsQqC5nZ.cjs');
19
+ const require_primitives = require('./primitives-CtuSNmV7.cjs');
20
+ const require_utilities = require('./utilities-CpF3uys3.cjs');
21
+ const require_guards = require('./guards.cjs');
22
+ const require_utilities$1 = require('./utilities-D47SN9EZ.cjs');
23
+ const require_greet = require('./greet-hjVsd2dt.cjs');
24
+
25
+ //#region src/utils/parser.ts
26
+ /**
27
+ * * Parse the given value to milliseconds or optionally to seconds.
28
+ *
29
+ * @param value - The string (with unit) or number (or numeric string) to convert.
30
+ * @param sec - Whether to return the value in seconds. Defaults to `false`.
31
+ * @returns The given value parsed in milliseconds (or seconds if specified).
32
+ *
33
+ * @remarks
34
+ * - A numeric value (number or numeric string ({@link Numeric})) is interpreted as seconds count, e.g., `120` or `'120'` will be treated as `'120 seconds'`.
35
+ * - If you use time value with unit ({@link TimeWithUnit}) be sure you provide the time units (days, hours, etc.), otherwise it will return `NaN`, e.g., `'120 unknown'` will return `NaN`.
36
+ */
37
+ function parseMSec(value, sec = false) {
38
+ if (require_primitives.isNumber(value) || require_utilities.isNumericString(value)) return _parse(`${value}s`, sec);
39
+ else if (require_guards.isTimeWithUnit(value)) return _parse(value, sec);
40
+ else return NaN;
41
+ }
42
+ /**
43
+ * * Parse the given time string and return milliseconds or seconds.
44
+ *
45
+ * @param str - A time string to parse to milliseconds.
46
+ * @param sec - Whether to return the value in seconds. Defaults to `false`.
47
+ * @returns The parsed value in milliseconds (or seconds if specified), or `NaN` if the string can't be parsed.
48
+ */
49
+ function _parse(str, sec = false) {
50
+ if (!require_primitives.isNonEmptyString(str) || str.length > 100) throw new RangeError(`Value must be a string with length between 1 and 99!`);
51
+ const match = /^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(str);
52
+ if (!match?.groups) return NaN;
53
+ const unit = (match.groups.unit ?? "ms").toLowerCase();
54
+ const multiplier = require_basic.MS_MAP[unit];
55
+ if (!multiplier) throw new RangeError(`Unknown unit "${unit}"!`);
56
+ const ms = parseFloat(match.groups.value) * multiplier;
57
+ return sec ? ms / 1e3 : ms;
58
+ }
59
+
60
+ //#endregion
61
+ exports.convertMinutesToHourMinutes = require_utilities$1.convertMinutesToTime;
62
+ exports.convertMinutesToTime = require_utilities$1.convertMinutesToTime;
63
+ exports.convertMinutesToUTCOffset = require_utilities$1.formatUTCOffset;
64
+ exports.extractHourMinute = require_utilities$1.extractHourMinute;
65
+ exports.extractMinutesFromUTC = require_utilities$1.extractMinutesFromUTC;
66
+ exports.extractTimeFromUTC = require_utilities$1.extractTimeFromUTC;
67
+ exports.extractTimeStringFromUTC = require_utilities$1.extractTimeFromUTC;
68
+ exports.extractTotalMinutesFromTime = require_utilities$1.getTotalMinutes;
69
+ exports.formatDate = require_utilities$1.formatDate;
70
+ exports.formatDateRelative = require_utilities$1.formatDateRelative;
71
+ exports.formatDateTime = require_utilities$1.formatDate;
72
+ exports.formatRelativeDate = require_utilities$1.formatDateRelative;
73
+ exports.formatRelativeTime = require_utilities$1.formatDateRelative;
74
+ exports.formatTimePart = require_utilities$1.formatTimePart;
75
+ exports.formatUTCOffset = require_utilities$1.formatUTCOffset;
76
+ exports.generateGreeting = require_greet.getGreeting;
77
+ exports.getGreeting = require_greet.getGreeting;
78
+ exports.getHourMinutesFromMinutes = require_utilities$1.convertMinutesToTime;
79
+ exports.getMinutesFromUTC = require_utilities$1.extractMinutesFromUTC;
80
+ exports.getNativeTimeZoneId = require_utilities$1.getNativeTimeZoneId;
81
+ exports.getTimeFromMinutes = require_utilities$1.convertMinutesToTime;
82
+ exports.getTimeStringFromUTC = require_utilities$1.extractTimeFromUTC;
83
+ exports.getTimeZoneDetails = require_utilities$1.getTimeZoneDetails;
84
+ exports.getTimeZoneIds = require_utilities$1.getTimeZoneIds;
85
+ exports.getTimestamp = require_utilities$1.getTimestamp;
86
+ exports.getTotalMinutes = require_utilities$1.getTotalMinutes;
87
+ exports.getTotalMinutesFromTime = require_utilities$1.getTotalMinutes;
88
+ exports.getTotalMinutesFromUTC = require_utilities$1.extractMinutesFromUTC;
89
+ exports.greet = require_greet.getGreeting;
90
+ exports.minutesToUTCOffset = require_utilities$1.formatUTCOffset;
91
+ exports.parseMSec = parseMSec;
92
+ exports.parseMs = parseMSec;
package/dist/utils.d.cts CHANGED
@@ -1,4 +1,20 @@
1
- import { At as TimeZoneDetails, Cn as Numeric, It as TimestampOptions, Mt as TimeZoneIdNative, Ot as TimeWithUnit, Rt as UTCOffset, Sn as Maybe, X as $TimeZoneIdentifier, _n as StrictFormat, at as DateFormatOptions, dt as GreetingConfigs, ft as HourMinutes, ht as ISOTimeString, it as DateArgs, pt as ISODateFormat, rt as ClockTime, yn as TimeOnlyFormat } from "./types-DPTQ_yLx.cjs";
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { Dt as TimeWithUnit, Ft as TimestampOptions, Lt as UTCOffset, Sn as Numeric, X as $TimeZoneIdentifier, at as DateFormatOptions, dt as GreetingConfigs, ft as HourMinutes, gn as StrictFormat, it as DateArgs, jt as TimeZoneIdNative, kt as TimeZoneDetails, mt as ISODateTimeString, pt as ISODateFormat, rt as ClockTime, vn as TimeOnlyFormat, xn as Maybe } from "./types-CdmsXbU_.cjs";
2
18
 
3
19
  //#region src/utils/greet.d.ts
4
20
  /**
@@ -155,7 +171,7 @@ declare function formatDateRelative(date: Maybe<DateArgs>, format?: StrictFormat
155
171
  *
156
172
  * @returns Timestamp string in ISO 8601 format.
157
173
  */
158
- declare function getTimestamp(): ISOTimeString;
174
+ declare function getTimestamp(): ISODateTimeString;
159
175
  /**
160
176
  * * Get timestamp in ISO 8601 format.
161
177
  *
@@ -171,7 +187,7 @@ declare function getTimestamp(): ISOTimeString;
171
187
  *
172
188
  * @returns Timestamp string in ISO 8601 format.
173
189
  */
174
- declare function getTimestamp(value: DateArgs, format?: ISODateFormat): ISOTimeString;
190
+ declare function getTimestamp<F extends ISODateFormat = 'utc'>(value: DateArgs, format?: F): ISODateTimeString<F>;
175
191
  /**
176
192
  * * Get timestamp in ISO 8601 format.
177
193
  *
@@ -183,6 +199,6 @@ declare function getTimestamp(value: DateArgs, format?: ISODateFormat): ISOTimeS
183
199
  *
184
200
  * @returns Timestamp string in ISO 8601 format.
185
201
  */
186
- declare function getTimestamp(options: TimestampOptions): ISOTimeString;
202
+ declare function getTimestamp<F extends ISODateFormat = 'utc'>(options: TimestampOptions<F>): ISODateTimeString<F>;
187
203
  //#endregion
188
204
  export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTime, convertMinutesToTime as getHourMinutesFromMinutes, convertMinutesToTime as getTimeFromMinutes, formatUTCOffset as convertMinutesToUTCOffset, formatUTCOffset, formatUTCOffset as minutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractMinutesFromUTC as getMinutesFromUTC, extractMinutesFromUTC as getTotalMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, formatDate, formatDate as formatDateTime, formatDateRelative, formatDateRelative as formatRelativeDate, formatDateRelative as formatRelativeTime, formatTimePart, getGreeting as generateGreeting, getGreeting, getGreeting as greet, getNativeTimeZoneId, getTimeZoneDetails, getTimeZoneIds, getTimestamp, parseMSec, parseMSec as parseMs };
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,20 @@
1
- import { At as TimeZoneDetails, Cn as Numeric, It as TimestampOptions, Mt as TimeZoneIdNative, Ot as TimeWithUnit, Rt as UTCOffset, Sn as Maybe, X as $TimeZoneIdentifier, _n as StrictFormat, at as DateFormatOptions, dt as GreetingConfigs, ft as HourMinutes, ht as ISOTimeString, it as DateArgs, pt as ISODateFormat, rt as ClockTime, yn as TimeOnlyFormat } from "./types-B2fgrJ86.mjs";
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { Dt as TimeWithUnit, Ft as TimestampOptions, Lt as UTCOffset, Sn as Numeric, X as $TimeZoneIdentifier, at as DateFormatOptions, dt as GreetingConfigs, ft as HourMinutes, gn as StrictFormat, it as DateArgs, jt as TimeZoneIdNative, kt as TimeZoneDetails, mt as ISODateTimeString, pt as ISODateFormat, rt as ClockTime, vn as TimeOnlyFormat, xn as Maybe } from "./types-Cb4gxrgJ.mjs";
2
18
 
3
19
  //#region src/utils/greet.d.ts
4
20
  /**
@@ -155,7 +171,7 @@ declare function formatDateRelative(date: Maybe<DateArgs>, format?: StrictFormat
155
171
  *
156
172
  * @returns Timestamp string in ISO 8601 format.
157
173
  */
158
- declare function getTimestamp(): ISOTimeString;
174
+ declare function getTimestamp(): ISODateTimeString;
159
175
  /**
160
176
  * * Get timestamp in ISO 8601 format.
161
177
  *
@@ -171,7 +187,7 @@ declare function getTimestamp(): ISOTimeString;
171
187
  *
172
188
  * @returns Timestamp string in ISO 8601 format.
173
189
  */
174
- declare function getTimestamp(value: DateArgs, format?: ISODateFormat): ISOTimeString;
190
+ declare function getTimestamp<F extends ISODateFormat = 'utc'>(value: DateArgs, format?: F): ISODateTimeString<F>;
175
191
  /**
176
192
  * * Get timestamp in ISO 8601 format.
177
193
  *
@@ -183,6 +199,6 @@ declare function getTimestamp(value: DateArgs, format?: ISODateFormat): ISOTimeS
183
199
  *
184
200
  * @returns Timestamp string in ISO 8601 format.
185
201
  */
186
- declare function getTimestamp(options: TimestampOptions): ISOTimeString;
202
+ declare function getTimestamp<F extends ISODateFormat = 'utc'>(options: TimestampOptions<F>): ISODateTimeString<F>;
187
203
  //#endregion
188
204
  export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTime, convertMinutesToTime as getHourMinutesFromMinutes, convertMinutesToTime as getTimeFromMinutes, formatUTCOffset as convertMinutesToUTCOffset, formatUTCOffset, formatUTCOffset as minutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractMinutesFromUTC as getMinutesFromUTC, extractMinutesFromUTC as getTotalMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, formatDate, formatDate as formatDateTime, formatDateRelative, formatDateRelative as formatRelativeDate, formatDateRelative as formatRelativeTime, formatTimePart, getGreeting as generateGreeting, getGreeting, getGreeting as greet, getNativeTimeZoneId, getTimeZoneDetails, getTimeZoneIds, getTimestamp, parseMSec, parseMSec as parseMs };