chronos-date 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/dist/constants.d.mts +1 -1
- package/dist/convert-C8LsoKmI-Blf3eLS6.mjs +285 -0
- package/dist/convert-C8LsoKmI-uBhT5hZQ.cjs +387 -0
- package/dist/dist-BPHYJA0t.mjs +70 -0
- package/dist/dist-CdMlZMZa.cjs +75 -0
- package/dist/{greet-DNGvP7nm.mjs → greet-BC86-X9W.mjs} +2 -2
- package/dist/{greet-CMkwXJ7o.cjs → greet-Brz0CVv1.cjs} +8 -8
- package/dist/guards-DTI799nG.mjs +46 -0
- package/dist/guards-dH9JJIso.cjs +51 -0
- package/dist/guards.cjs +14 -16
- package/dist/guards.d.cts +1 -1
- package/dist/guards.d.mts +1 -1
- package/dist/guards.mjs +1 -3
- package/dist/{helpers-Bq7Hczoa.cjs → helpers-BMDeRLjO.cjs} +6 -8
- package/dist/{helpers-C2spzGZ-.mjs → helpers-t49KkxOE.mjs} +2 -4
- package/dist/index.cjs +13 -14
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +4 -5
- package/dist/plugins/banglaPlugin.cjs +16 -33
- package/dist/plugins/banglaPlugin.d.cts +1 -1
- package/dist/plugins/banglaPlugin.d.mts +1 -1
- package/dist/plugins/banglaPlugin.mjs +2 -19
- package/dist/plugins/businessPlugin.cjs +4 -5
- package/dist/plugins/businessPlugin.d.cts +1 -1
- package/dist/plugins/businessPlugin.d.mts +1 -1
- package/dist/plugins/businessPlugin.mjs +1 -2
- package/dist/plugins/dateRangePlugin.cjs +4 -5
- package/dist/plugins/dateRangePlugin.d.cts +1 -1
- package/dist/plugins/dateRangePlugin.d.mts +1 -1
- package/dist/plugins/dateRangePlugin.mjs +1 -2
- package/dist/plugins/dayPartPlugin.cjs +2 -2
- package/dist/plugins/dayPartPlugin.d.cts +1 -1
- package/dist/plugins/dayPartPlugin.d.mts +1 -1
- package/dist/plugins/dayPartPlugin.mjs +1 -1
- package/dist/plugins/durationPlugin.d.cts +1 -1
- package/dist/plugins/durationPlugin.d.mts +1 -1
- package/dist/plugins/fromNowPlugin.cjs +2 -2
- package/dist/plugins/fromNowPlugin.d.cts +1 -1
- package/dist/plugins/fromNowPlugin.d.mts +1 -1
- package/dist/plugins/fromNowPlugin.mjs +1 -1
- package/dist/plugins/greetingPlugin.cjs +1 -1
- package/dist/plugins/greetingPlugin.d.cts +1 -1
- package/dist/plugins/greetingPlugin.d.mts +1 -1
- package/dist/plugins/greetingPlugin.mjs +1 -1
- package/dist/plugins/palindromePlugin.cjs +2 -9
- package/dist/plugins/palindromePlugin.d.cts +1 -1
- package/dist/plugins/palindromePlugin.d.mts +1 -1
- package/dist/plugins/palindromePlugin.mjs +1 -8
- package/dist/plugins/relativeTimePlugin.d.cts +1 -1
- package/dist/plugins/relativeTimePlugin.d.mts +1 -1
- package/dist/plugins/roundPlugin.cjs +8 -8
- package/dist/plugins/roundPlugin.d.cts +1 -1
- package/dist/plugins/roundPlugin.d.mts +1 -1
- package/dist/plugins/roundPlugin.mjs +1 -1
- package/dist/plugins/seasonPlugin.d.cts +1 -1
- package/dist/plugins/seasonPlugin.d.mts +1 -1
- package/dist/plugins/timeZonePlugin.cjs +3 -3
- package/dist/plugins/timeZonePlugin.d.cts +1 -1
- package/dist/plugins/timeZonePlugin.d.mts +1 -1
- package/dist/plugins/timeZonePlugin.mjs +2 -2
- package/dist/plugins/zodiacPlugin.cjs +1 -1
- package/dist/plugins/zodiacPlugin.d.cts +1 -1
- package/dist/plugins/zodiacPlugin.d.mts +1 -1
- package/dist/plugins/zodiacPlugin.mjs +1 -1
- package/dist/{types-Be4ZMpOV.d.mts → types-CiFnGEL8.d.mts} +967 -902
- package/dist/{types-dNpvroNQ.d.cts → types-zhhEJ8N7.d.cts} +966 -901
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/{utilities-C6NiChRE.mjs → utils-DBy7S7hH.mjs} +3 -5
- package/dist/{utilities-CCnKWAsS.cjs → utils-S_aw0TeC.cjs} +8 -10
- package/dist/utils.cjs +33 -34
- package/dist/utils.d.cts +4 -4
- package/dist/utils.d.mts +4 -4
- package/dist/utils.mjs +4 -5
- package/package.json +3 -3
- package/dist/convert-BDQBTK5P.cjs +0 -49
- package/dist/convert-D5Cd0cCg.mjs +0 -38
- package/dist/non-primitives-BqjRwK2B.cjs +0 -68
- package/dist/non-primitives-CbAOB6lb.mjs +0 -38
- package/dist/primitives-BXhrgs9R.mjs +0 -35
- package/dist/primitives-DfO90c3G.cjs +0 -65
- package/dist/utilities-BnHD2hHf.mjs +0 -59
- package/dist/utilities-C_KmjIRK.cjs +0 -88
- /package/dist/{seasons-B_kjFWIX.d.mts → seasons-DYk2jvtn.d.mts} +0 -0
|
@@ -14,129 +14,9 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { A as MILLISECOND_FORMATS, B as ZODIAC_PRESETS, C as DATE_PARTS, D as INTERNALS, E as HOUR_FORMATS, F as TIME_FORMATS, I as TIME_UNIT_VARIANTS, M as MONTHS, N as MONTH_FORMATS, O as LOCALE_CALENDARS, P as SECOND_FORMATS, R as WESTERN_ZODIAC_SIGNS, S as DATE_FORMATS, T as DAY_FORMATS, _ as TIME_ZONE_LABELS, b as BN_MONTH_TABLES, g as TIME_ZONE_IDS, h as TIME_ZONES_NATIVE, j as MINUTE_FORMATS, k as LOCALE_NUMBERING_SYSTEMS, m as TIME_ZONES, u as SEASON_PRESETS, v as BN_DAYS, w as DAYS, x as BN_SEASONS, y as BN_MONTHS, z as YEAR_FORMATS } from "./seasons-
|
|
17
|
+
import { A as MILLISECOND_FORMATS, B as ZODIAC_PRESETS, C as DATE_PARTS, D as INTERNALS, E as HOUR_FORMATS, F as TIME_FORMATS, I as TIME_UNIT_VARIANTS, M as MONTHS, N as MONTH_FORMATS, O as LOCALE_CALENDARS, P as SECOND_FORMATS, R as WESTERN_ZODIAC_SIGNS, S as DATE_FORMATS, T as DAY_FORMATS, _ as TIME_ZONE_LABELS, b as BN_MONTH_TABLES, g as TIME_ZONE_IDS, h as TIME_ZONES_NATIVE, j as MINUTE_FORMATS, k as LOCALE_NUMBERING_SYSTEMS, m as TIME_ZONES, u as SEASON_PRESETS, v as BN_DAYS, w as DAYS, x as BN_SEASONS, y as BN_MONTHS, z as YEAR_FORMATS } from "./seasons-DYk2jvtn.mjs";
|
|
18
18
|
|
|
19
|
-
//#region node_modules/.pnpm/
|
|
20
|
-
/**
|
|
21
|
-
* * Broadens a literal union (typically `string` or `number`) to also accept any other value of the base type, without losing IntelliSense autocomplete for the provided literals.
|
|
22
|
-
*
|
|
23
|
-
* *This is especially useful in API design where you want to provide suggestions for common options but still allow flexibility for custom user-defined values.*
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // ✅ String literal usage
|
|
27
|
-
* type Variant = LooseLiteral<'primary' | 'secondary'>;
|
|
28
|
-
* const v1: Variant = 'primary'; // suggested
|
|
29
|
-
* const v2: Variant = 'custom'; // also valid
|
|
30
|
-
*
|
|
31
|
-
* // ✅ Number literal usage
|
|
32
|
-
* type StatusCode = LooseLiteral<200 | 404 | 500>;
|
|
33
|
-
* const s1: StatusCode = 200; // suggested
|
|
34
|
-
* const s2: StatusCode = 999; // also valid
|
|
35
|
-
*
|
|
36
|
-
* // ✅ Mixed literal
|
|
37
|
-
* type Mixed = LooseLiteral<'one' | 2>;
|
|
38
|
-
* const m1: Mixed = 'one'; // ✅
|
|
39
|
-
* const m2: Mixed = 2; // ✅
|
|
40
|
-
* const m3: Mixed = 'anything'; // ✅
|
|
41
|
-
* const m4: Mixed = 123; // ✅
|
|
42
|
-
*
|
|
43
|
-
* @note Technically, this uses intersection with primitive base types (`string & {}` or `number & {}`) to retain IntelliSense while avoiding type narrowing.
|
|
44
|
-
*/
|
|
45
|
-
type LooseLiteral<T extends string | number> = T | (T extends string ? string & {} : number & {});
|
|
46
|
-
/** Internal helper type to build a tuple of length N. */
|
|
47
|
-
type $TupleOf<T, N extends number, R extends unknown[] = []> = R['length'] extends N ? R : $TupleOf<T, N, [...R, T]>;
|
|
48
|
-
/**
|
|
49
|
-
* * Creates a tuple type of a given length with elements of type T
|
|
50
|
-
*
|
|
51
|
-
* 📝 **Notes**:
|
|
52
|
-
* - This works recursively to build a tuple of exact length N.
|
|
53
|
-
*
|
|
54
|
-
* - N must be a literal number, not just number. You can’t pass a general number type because recursion can't compute unbounded lengths
|
|
55
|
-
* - You can use as const or mapped types when initializing values with this shape
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* type FiveStrings = TupleOf<string, 5>; // [string, string, string, string, string]
|
|
59
|
-
* type EmptyTuple = TupleOf<boolean, 0>; // []
|
|
60
|
-
*/
|
|
61
|
-
type TupleOf<T, N extends number> = $TupleOf<T, N>;
|
|
62
|
-
/** * Build a tuple of given length (helper for type-level arithmetic). */
|
|
63
|
-
type $BuildTuple<L extends number, T extends unknown[] = []> = T['length'] extends L ? T : $BuildTuple<L, [...T, unknown]>;
|
|
64
|
-
/** * Produce a union of numbers `From | From+1 | ... | To`. */
|
|
65
|
-
type $Range<From extends number, To extends number, Arr extends unknown[] = $BuildTuple<From>, Result = never> = Arr['length'] extends To ? Result | To : $Range<From, To, [...Arr, unknown], Result | Arr['length']>;
|
|
66
|
-
/**
|
|
67
|
-
* * Creates a tuple with length between `Min` and `Max` (inclusive).
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* type Ranged = RangeTuple<string, 2, 4>;
|
|
71
|
-
* // Ranged -> [string, string] | [string, string, string] | [string, string, string, string]
|
|
72
|
-
*/
|
|
73
|
-
type RangeTuple<T, Min extends number, Max extends number> = $Range<Min, Max> extends infer N ? (N extends number ? TupleOf<T, N> : never) : never;
|
|
74
|
-
/**
|
|
75
|
-
* * Cast one type to another while preserving compatibility.
|
|
76
|
-
*
|
|
77
|
-
* @remarks
|
|
78
|
-
* - Ensures that `A1` extends `A2`. If not, falls back to `A2`.
|
|
79
|
-
* - Useful for enforcing constraints on generics or parameters.
|
|
80
|
-
*
|
|
81
|
-
* @param A1 - Type to check.
|
|
82
|
-
* @param A2 - Type to cast to.
|
|
83
|
-
* @returns `A1` if it extends `A2`, otherwise `A2`.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* type T0 = Cast<'42', string>; // '42'
|
|
87
|
-
* type T1 = Cast<'42', number>; // number
|
|
88
|
-
* type T2 = Cast<42, number>; // 42
|
|
89
|
-
*/
|
|
90
|
-
type Cast<A1, A2> = A1 extends A2 ? A1 : A2;
|
|
91
|
-
/**
|
|
92
|
-
* * Remove the last element of a list (array).
|
|
93
|
-
*
|
|
94
|
-
* @remarks Produces a new tuple/list type with the last element removed.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* type T0 = Pop<[1, 2, 3]>; // [1, 2]
|
|
98
|
-
* type T1 = Pop<[]>; // []
|
|
99
|
-
* type T2 = Pop<['a']>; // []
|
|
100
|
-
*/
|
|
101
|
-
type Pop<L extends List> = L extends readonly [...infer El, any] | readonly [...infer El, any?] ? El : L;
|
|
102
|
-
type _Split<S extends string, D extends string, T extends string[] = []> = S extends `${infer BS}${D}${infer AS}` ? _Split<AS, D, [...T, BS]> : [...T, S];
|
|
103
|
-
type $Split<S extends string, D extends string = ''> = D extends '' ? Pop<_Split<S, D>> : _Split<S, D>;
|
|
104
|
-
/**
|
|
105
|
-
* ✂️ Split a string literal by a given delimiter into a list of strings.
|
|
106
|
-
*
|
|
107
|
-
* @remarks
|
|
108
|
-
* Produces a tuple of substrings by splitting `S` at each occurrence of `D`.
|
|
109
|
-
*
|
|
110
|
-
* @param S - String literal to split.
|
|
111
|
-
* @param D - Delimiter to split on (default: empty string, i.e., character split).
|
|
112
|
-
* @returns A list of string literals.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* type T0 = Split<'a,b,c', ','>; // ['a', 'b', 'c']
|
|
116
|
-
* type T1 = Split<'hello', ''>; // ['h', 'e', 'l', 'l', 'o']
|
|
117
|
-
* type T2 = Split<'foo-bar', '-'>; // ['foo', 'bar']
|
|
118
|
-
*/
|
|
119
|
-
type Split<S extends string, D extends string = ''> = $Split<S, D> extends infer X ? Cast<X, string[]> : never;
|
|
120
|
-
/**
|
|
121
|
-
* Recursively join the string S for each element in the tuple A.
|
|
122
|
-
* Returns an empty string for an empty tuple.
|
|
123
|
-
*/
|
|
124
|
-
type $JoinRepeat<S extends string, A extends unknown[]> = A extends [unknown, ...infer Rest] ? `${S}${$JoinRepeat<S, Rest>}` : '';
|
|
125
|
-
/**
|
|
126
|
-
* * Repeat string `S`, `N` times.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* type L10 = Repeat<'l', 10>; // "llllllllll"
|
|
130
|
-
*
|
|
131
|
-
* type AB3 = Repeat<'a' | 'b', 3>; // "aab" | "aaa" | "aba" | "abb" | "bab" | "baa" | "bba" | "bbb"
|
|
132
|
-
*
|
|
133
|
-
* @remarks **Limitations:**
|
|
134
|
-
* - `N` must be a literal number.
|
|
135
|
-
* - If `S` is a union (e.g. 'a' | 'b'), the resulting union grows exponentially with `N`.
|
|
136
|
-
*/
|
|
137
|
-
type Repeat<S extends string, N extends number> = $JoinRepeat<S, $BuildTuple<N>>;
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region node_modules/.pnpm/nhb-toolbox@4.30.14/node_modules/nhb-toolbox/dist/dts/number/constants.d.ts
|
|
19
|
+
//#region node_modules/.pnpm/toolbox-x@1.0.1-rc.6/node_modules/toolbox-x/dist/object-D70hzkoY.d.mts
|
|
140
20
|
/** List of all supported BCP 47 locales */
|
|
141
21
|
declare const LOCALE_CODES: readonly ["af-ZA", "am-ET", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SD", "ar-SY", "ar-TN", "ar-YE", "az-AZ", "be-BY", "bg-BG", "bn-BD", "bn-IN", "bs-BA", "ca-ES", "cs-CZ", "cy-GB", "da-DK", "de-AT", "de-CH", "de-DE", "el-GR", "en-AU", "en-CA", "en-GB", "en-IE", "en-IN", "en-NZ", "en-PH", "en-SG", "en-US", "en-ZA", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-ES", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV", "es-US", "es-UY", "es-VE", "et-EE", "eu-ES", "fa-IR", "fi-FI", "fil-PH", "fr-BE", "fr-CA", "fr-CH", "fr-FR", "ga-IE", "gl-ES", "gu-IN", "he-IL", "hi-IN", "hr-HR", "hu-HU", "hy-AM", "id-ID", "is-IS", "it-CH", "it-IT", "ja-JP", "ka-GE", "kk-KZ", "km-KH", "kn-IN", "ko-KR", "ky-KG", "lt-LT", "lv-LV", "mk-MK", "ml-IN", "mn-MN", "mr-IN", "ms-MY", "mt-MT", "nb-NO", "ne-NP", "nl-BE", "nl-NL", "pl-PL", "pt-BR", "pt-PT", "ro-RO", "ru-RU", "sk-SK", "sl-SI", "sq-AL", "sr-Latn", "sv-SE", "sw-KE", "ta-IN", "te-IN", "th-TH", "tr-TR", "uk-UA", "ur-PK", "uz-UZ", "vi-VN", "zh-CN", "zh-HK", "zh-TW"];
|
|
142
22
|
/** Mapping of CurrencyCodes to `LocaleCodes` */
|
|
@@ -298,6 +178,7 @@ declare const CURRENCY_LOCALES: Readonly<{
|
|
|
298
178
|
readonly ZMW: "en-ZM";
|
|
299
179
|
readonly ZWL: "en-ZW";
|
|
300
180
|
}>;
|
|
181
|
+
/** * Fiat currencies supported by Frankfurter API */
|
|
301
182
|
/** * Bangla digits from `০-৯` mapped against `0-9` */
|
|
302
183
|
declare const BN_DIGITS: Readonly<{
|
|
303
184
|
readonly '\u09E6': 0;
|
|
@@ -310,68 +191,252 @@ declare const BN_DIGITS: Readonly<{
|
|
|
310
191
|
readonly '\u09ED': 7;
|
|
311
192
|
readonly '\u09EE': 8;
|
|
312
193
|
readonly '\u09EF': 9;
|
|
313
|
-
}>;
|
|
314
|
-
//#
|
|
315
|
-
//#region node_modules/.pnpm/nhb-toolbox@4.30.14/node_modules/nhb-toolbox/dist/dts/number/types.d.ts
|
|
316
|
-
/** Enumerate & Enumerate Internal: builds a union of all numbers from 0 to N - 1 */
|
|
317
|
-
type $EnumerateInternal<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : $EnumerateInternal<N, [...Acc, Acc['length']]>;
|
|
194
|
+
}>; //#endregion
|
|
195
|
+
//#region src/number/Unit.d.ts
|
|
318
196
|
/**
|
|
319
|
-
*
|
|
197
|
+
* @class Class to handle conversions between various types of units.
|
|
320
198
|
*
|
|
321
|
-
*
|
|
322
|
-
* -
|
|
199
|
+
* Includes static methods for:
|
|
200
|
+
* - Length: meters, feet, kilometers, miles
|
|
201
|
+
* - Mass: kilograms, pounds, grams, ounces
|
|
202
|
+
* - Temperature: Celsius, Fahrenheit, Kelvin
|
|
203
|
+
* - Volume: liters, gallons
|
|
204
|
+
* - Area: square meters, square feet
|
|
205
|
+
* - Speed: km/h, mph
|
|
206
|
+
* - Time: hours, minutes, seconds, days
|
|
207
|
+
* - Digital Storage: kilobytes, megabytes, gigabytes
|
|
208
|
+
* - Energy: joules, calories
|
|
209
|
+
* - Pressure: atm, pascals
|
|
210
|
+
* - Frequency: Hz, kHz
|
|
211
|
+
*
|
|
212
|
+
* @remarks For more robust unit conversion, please use the `Converter` function which provides category-specific conversion classes.
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* * Broadens a literal union (typically `string` or `number`) to also accept any other value of the base type, without losing IntelliSense autocomplete for the provided literals.
|
|
216
|
+
*
|
|
217
|
+
* *This is especially useful in API design where you want to provide suggestions for common options but still allow flexibility for custom user-defined values.*
|
|
323
218
|
*
|
|
324
219
|
* @example
|
|
325
|
-
*
|
|
220
|
+
* // ✅ String literal usage
|
|
221
|
+
* type Variant = LooseLiteral<'primary' | 'secondary'>;
|
|
222
|
+
* const v1: Variant = 'primary'; // suggested
|
|
223
|
+
* const v2: Variant = 'custom'; // also valid
|
|
224
|
+
*
|
|
225
|
+
* // ✅ Number literal usage
|
|
226
|
+
* type StatusCode = LooseLiteral<200 | 404 | 500>;
|
|
227
|
+
* const s1: StatusCode = 200; // suggested
|
|
228
|
+
* const s2: StatusCode = 999; // also valid
|
|
229
|
+
*
|
|
230
|
+
* // ✅ Mixed literal
|
|
231
|
+
* type Mixed = LooseLiteral<'one' | 2>;
|
|
232
|
+
* const m1: Mixed = 'one'; // ✅
|
|
233
|
+
* const m2: Mixed = 2; // ✅
|
|
234
|
+
* const m3: Mixed = 'anything'; // ✅
|
|
235
|
+
* const m4: Mixed = 123; // ✅
|
|
236
|
+
*
|
|
237
|
+
* @note Technically, this uses intersection with primitive base types (`string & {}` or `number & {}`) to retain IntelliSense while avoiding type narrowing.
|
|
326
238
|
*/
|
|
327
|
-
type
|
|
328
|
-
/** Helper: Add 1 to a number */
|
|
329
|
-
type $AddOne<N extends number, Acc extends unknown[] = []> = Acc['length'] extends N ? [...Acc, unknown]['length'] : $AddOne<N, [...Acc, unknown]>;
|
|
239
|
+
type LooseLiteral<T extends string | number> = T | (T extends string ? string & {} : number & {});
|
|
330
240
|
/**
|
|
241
|
+
* * Extracts an object type containing only the optional keys from `T`.
|
|
331
242
|
*
|
|
332
|
-
*
|
|
243
|
+
* @typeParam T - The original object type
|
|
244
|
+
* @returns A new object type with only optional keys from `T`
|
|
245
|
+
* @example
|
|
246
|
+
* type Example = { a: string; b?: number; c?: boolean };
|
|
247
|
+
* type OptionalPart = ExtractOptional<Example>;
|
|
248
|
+
* // { b?: number; c?: boolean }
|
|
249
|
+
*/
|
|
250
|
+
/** Internal helper type to build a tuple of length N. */
|
|
251
|
+
type $TupleOf<T, N extends number, R extends unknown[] = []> = R['length'] extends N ? R : $TupleOf<T, N, [...R, T]>;
|
|
252
|
+
/**
|
|
253
|
+
* * Creates a tuple type of a given length with elements of type T
|
|
254
|
+
*
|
|
255
|
+
* 📝 **Notes**:
|
|
256
|
+
* - This works recursively to build a tuple of exact length N.
|
|
257
|
+
*
|
|
258
|
+
* - N must be a literal number, not just number. You can’t pass a general number type because recursion can't compute unbounded lengths
|
|
259
|
+
* - You can use as const or mapped types when initializing values with this shape
|
|
333
260
|
*
|
|
334
261
|
* @example
|
|
335
|
-
* type
|
|
336
|
-
* type
|
|
262
|
+
* type FiveStrings = TupleOf<string, 5>; // [string, string, string, string, string]
|
|
263
|
+
* type EmptyTuple = TupleOf<boolean, 0>; // []
|
|
264
|
+
*/
|
|
265
|
+
type TupleOf<T, N extends number> = $TupleOf<T, N>;
|
|
266
|
+
/** * Build a tuple of given length (helper for type-level arithmetic). */
|
|
267
|
+
type $BuildTuple<L extends number, T extends unknown[] = []> = T['length'] extends L ? T : $BuildTuple<L, [...T, unknown]>;
|
|
268
|
+
/** * Produce a union of numbers `From | From+1 | ... | To`. */
|
|
269
|
+
type $Range<From extends number, To extends number, Arr extends unknown[] = $BuildTuple<From>, Result = never> = Arr['length'] extends To ? Result | To : $Range<From, To, [...Arr, unknown], Result | Arr['length']>;
|
|
270
|
+
/**
|
|
271
|
+
* * Creates a tuple with length between `Min` and `Max` (inclusive).
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* type Ranged = RangeTuple<string, 2, 4>;
|
|
275
|
+
* // Ranged -> [string, string] | [string, string, string] | [string, string, string, string]
|
|
276
|
+
*/
|
|
277
|
+
type RangeTuple<T, Min extends number, Max extends number> = $Range<Min, Max> extends infer N ? (N extends number ? TupleOf<T, N> : never) : never;
|
|
278
|
+
/**
|
|
279
|
+
* * Makes selected or all properties of an object type optional (only the values, not the keys).
|
|
280
|
+
*
|
|
281
|
+
* If `K` is provided, only those properties' values become optional (keys remain required).
|
|
282
|
+
* If `K` is omitted, all property values become optional.
|
|
283
|
+
*
|
|
284
|
+
* @typeParam O - The original object type.
|
|
285
|
+
* @typeParam K - Optional union of keys in `O` whose values should become optional.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* type A = { name: string; age: number };
|
|
289
|
+
* type B = ValueOptional<A, 'name'>;
|
|
290
|
+
* // Equivalent to: { name: string | undefined; age: number }
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* type C = ValueOptional<A>;
|
|
294
|
+
* // Equivalent to: { name: string | undefined; age: number | undefined }
|
|
295
|
+
*/
|
|
296
|
+
/**
|
|
297
|
+
* * Cast one type to another while preserving compatibility.
|
|
337
298
|
*
|
|
338
299
|
* @remarks
|
|
339
|
-
* -
|
|
340
|
-
* -
|
|
341
|
-
* - Result is a union type, not a tuple or array.
|
|
300
|
+
* - Ensures that `A1` extends `A2`. If not, falls back to `A2`.
|
|
301
|
+
* - Useful for enforcing constraints on generics or parameters.
|
|
342
302
|
*
|
|
343
|
-
* @
|
|
344
|
-
* @
|
|
345
|
-
* @returns
|
|
303
|
+
* @param A1 - Type to check.
|
|
304
|
+
* @param A2 - Type to cast to.
|
|
305
|
+
* @returns `A1` if it extends `A2`, otherwise `A2`.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* type T0 = Cast<'42', string>; // '42'
|
|
309
|
+
* type T1 = Cast<'42', number>; // number
|
|
310
|
+
* type T2 = Cast<42, number>; // 42
|
|
346
311
|
*/
|
|
347
|
-
type
|
|
348
|
-
/** - List of all supported BCP 47 locales */
|
|
349
|
-
type LocaleCode = (typeof CURRENCY_LOCALES)[keyof typeof CURRENCY_LOCALES] | (typeof LOCALE_CODES)[number];
|
|
350
|
-
/** Bangla digits from `০-৯` */
|
|
351
|
-
type BanglaDigit = keyof typeof BN_DIGITS;
|
|
352
|
-
/** Bangla digits from `১-৯` */
|
|
353
|
-
type $BnOnes = Exclude<BanglaDigit, '০'>;
|
|
354
|
-
//#endregion
|
|
355
|
-
//#region node_modules/.pnpm/nhb-toolbox@4.30.14/node_modules/nhb-toolbox/dist/dts/types/index.d.ts
|
|
356
|
-
/** Represents a value that may or may not be present. */
|
|
357
|
-
type Maybe<T> = T | undefined;
|
|
358
|
-
/** Union of `number` and numeric string */
|
|
359
|
-
type Numeric = number | `${number}`;
|
|
312
|
+
type Cast<A1, A2> = A1 extends A2 ? A1 : A2;
|
|
360
313
|
/**
|
|
361
|
-
* *
|
|
314
|
+
* * Remove the last element of a list (array).
|
|
315
|
+
*
|
|
316
|
+
* @remarks Produces a new tuple/list type with the last element removed.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* type T0 = Pop<[1, 2, 3]>; // [1, 2]
|
|
320
|
+
* type T1 = Pop<[]>; // []
|
|
321
|
+
* type T2 = Pop<['a']>; // []
|
|
322
|
+
*/
|
|
323
|
+
type Pop<L extends List> = L extends readonly [...infer El, any] | readonly [...infer El, any?] ? El : L;
|
|
324
|
+
type _Split<S extends string, D extends string, T extends string[] = []> = S extends `${infer BS}${D}${infer AS}` ? _Split<AS, D, [...T, BS]> : [...T, S];
|
|
325
|
+
type $Split<S extends string, D extends string = ''> = D extends '' ? Pop<_Split<S, D>> : _Split<S, D>;
|
|
326
|
+
/**
|
|
327
|
+
* ✂️ Split a string literal by a given delimiter into a list of strings.
|
|
362
328
|
*
|
|
363
329
|
* @remarks
|
|
364
|
-
*
|
|
330
|
+
* Produces a tuple of substrings by splitting `S` at each occurrence of `D`.
|
|
331
|
+
*
|
|
332
|
+
* @param S - String literal to split.
|
|
333
|
+
* @param D - Delimiter to split on (default: empty string, i.e., character split).
|
|
334
|
+
* @returns A list of string literals.
|
|
365
335
|
*
|
|
366
336
|
* @example
|
|
367
|
-
* type
|
|
368
|
-
*
|
|
369
|
-
*
|
|
337
|
+
* type T0 = Split<'a,b,c', ','>; // ['a', 'b', 'c']
|
|
338
|
+
* type T1 = Split<'hello', ''>; // ['h', 'e', 'l', 'l', 'o']
|
|
339
|
+
* type T2 = Split<'foo-bar', '-'>; // ['foo', 'bar']
|
|
370
340
|
*/
|
|
371
|
-
type
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
341
|
+
type Split<S extends string, D extends string = ''> = $Split<S, D> extends infer X ? Cast<X, string[]> : never;
|
|
342
|
+
/**
|
|
343
|
+
* Recursively join the string S for each element in the tuple A.
|
|
344
|
+
* Returns an empty string for an empty tuple.
|
|
345
|
+
*/
|
|
346
|
+
type $JoinRepeat<S extends string, A extends unknown[]> = A extends [unknown, ...infer Rest] ? `${S}${$JoinRepeat<S, Rest>}` : '';
|
|
347
|
+
/**
|
|
348
|
+
* * Repeat string `S`, `N` times.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* type L10 = Repeat<'l', 10>; // "llllllllll"
|
|
352
|
+
*
|
|
353
|
+
* type AB3 = Repeat<'a' | 'b', 3>; // "aab" | "aaa" | "aba" | "abb" | "bab" | "baa" | "bba" | "bbb"
|
|
354
|
+
*
|
|
355
|
+
* @remarks **Limitations:**
|
|
356
|
+
* - `N` must be a literal number.
|
|
357
|
+
* - If `S` is a union (e.g. 'a' | 'b'), the resulting union grows exponentially with `N`.
|
|
358
|
+
*/
|
|
359
|
+
type Repeat<S extends string, N extends number> = $JoinRepeat<S, $BuildTuple<N>>;
|
|
360
|
+
/**
|
|
361
|
+
* * Replace all occurrences of substring `Search` in `Str` with `With`.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* type Dash = Replace<'hello world', ' ', '-'>; // "hello-world"
|
|
365
|
+
*
|
|
366
|
+
* type Underscore = Replace<'a-b-c', '-', '_'>; // "a_b_c"
|
|
367
|
+
*
|
|
368
|
+
* type NoSpaces = Replace<' spaced out ', ' ', ''>; // "spacedout"
|
|
369
|
+
*
|
|
370
|
+
* @remarks **Notes:**
|
|
371
|
+
* - Works recursively to replace **all** occurrences of `Search`.
|
|
372
|
+
* - If `Search` does not exist in `Str`, returns `Str` unchanged.
|
|
373
|
+
* - `Str`, `Search` (Default is space `" "`) and `With` (Default is `"-"`) must be literal string types.
|
|
374
|
+
*/
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/types/number.d.ts
|
|
377
|
+
/** Enumerate & Enumerate Internal: builds a union of all numbers from 0 to N - 1 */
|
|
378
|
+
type $EnumerateInternal<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : $EnumerateInternal<N, [...Acc, Acc['length']]>;
|
|
379
|
+
/**
|
|
380
|
+
* * Builds a union of numeric literals from `0` to `N - 1`.
|
|
381
|
+
*
|
|
382
|
+
* @remarks
|
|
383
|
+
* - This utility supports ranges up to 998 due to TypeScript recursion limits.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* type U = Enumerate<3>; // 0 | 1 | 2
|
|
387
|
+
*/
|
|
388
|
+
type Enumerate<N extends number> = $EnumerateInternal<N>;
|
|
389
|
+
/** Helper: Add 1 to a number */
|
|
390
|
+
type $AddOne<N extends number, Acc extends unknown[] = []> = Acc['length'] extends N ? [...Acc, unknown]['length'] : $AddOne<N, [...Acc, unknown]>;
|
|
391
|
+
/**
|
|
392
|
+
*
|
|
393
|
+
* * Creates a union type of all numeric literals starting from `From` up to `To`.
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* type R = NumberRange<2, 5>; // 2 | 3 | 4 5
|
|
397
|
+
* type N = NumberRange<0, 998>; // 0 | 1 | 2 | ... | 998
|
|
398
|
+
*
|
|
399
|
+
* @remarks
|
|
400
|
+
* - This utility supports ranges up to 998 due to TypeScript recursion limits.
|
|
401
|
+
* - `From` and `To` both are inclusive, — so `NumberRange<0, 998>` generates `0` to `998`.
|
|
402
|
+
* - Result is a union type, not a tuple or array.
|
|
403
|
+
*
|
|
404
|
+
* @generic From - A number from 0-998, start of the range.
|
|
405
|
+
* @generic To - A number from 1-998, end of the range.
|
|
406
|
+
* @returns A union of numeric literal types from `From` to `To - 1`.
|
|
407
|
+
*/
|
|
408
|
+
type NumberRange<From extends number, To extends number> = Exclude<Enumerate<$AddOne<To>>, Enumerate<From>>;
|
|
409
|
+
/** - Number value in percentage `(0% - 100%)` without `%` symbol. */
|
|
410
|
+
/** - List of all supported BCP 47 locales */
|
|
411
|
+
type LocaleCode = (typeof CURRENCY_LOCALES)[keyof typeof CURRENCY_LOCALES] | (typeof LOCALE_CODES)[number];
|
|
412
|
+
/** * Fiat currencies supported by Frankfurter API */
|
|
413
|
+
/** Bangla digits from `০-৯` */
|
|
414
|
+
type BanglaDigit = keyof typeof BN_DIGITS;
|
|
415
|
+
/** Bangla digits from `১-৯` */
|
|
416
|
+
type $BnOnes = Exclude<BanglaDigit, '০'>;
|
|
417
|
+
/** Result type for Bangla digit conversion based on `force` flag */
|
|
418
|
+
/** Represents a value that may or may not be present. */
|
|
419
|
+
type Maybe<T> = T | undefined;
|
|
420
|
+
/** Utility type to flatten Partial type */
|
|
421
|
+
/** Union of `number` and numeric string */
|
|
422
|
+
type Numeric = number | `${number}`;
|
|
423
|
+
/** Union of Basic Primitive Types (i.e. `string | number | boolean`) */
|
|
424
|
+
/**
|
|
425
|
+
* * A readonly array of elements of type `T`.
|
|
426
|
+
*
|
|
427
|
+
* @remarks
|
|
428
|
+
* - Shorthand for `ReadonlyArray<T>`. Used to represent immutable lists.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* type Numbers = List<number>; // readonly number[]
|
|
432
|
+
* const arr: Numbers = [1, 2, 3]; // ✅ OK
|
|
433
|
+
* arr.push(4); // ❌ Error (readonly)
|
|
434
|
+
*/
|
|
435
|
+
type List<T = any> = ReadonlyArray<T>;
|
|
436
|
+
/** Function type for serializing a value of type `T` to a string. */
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/types/format-tokens.d.ts
|
|
439
|
+
/** Year in either 4 or 2 digits format */
|
|
375
440
|
type YearToken = (typeof YEAR_FORMATS)[number];
|
|
376
441
|
/** Month in either 1 or 2 digits or 3 letters or full word format */
|
|
377
442
|
type MonthToken = (typeof MONTH_FORMATS)[number];
|
|
@@ -461,7 +526,7 @@ interface BanglaDateOptions<Locale extends $BnEn> extends BnCalendarConfig {
|
|
|
461
526
|
locale?: Locale | $BnEn;
|
|
462
527
|
}
|
|
463
528
|
//#endregion
|
|
464
|
-
//#region src/
|
|
529
|
+
//#region src/utilities/chronos-fn.d.ts
|
|
465
530
|
/**
|
|
466
531
|
* * Use `chronos` with all static methods from the `Chronos` class.
|
|
467
532
|
*
|
|
@@ -1333,835 +1398,835 @@ declare class Chronos<Tz extends ChronosTimeZone = 'System'> {
|
|
|
1333
1398
|
static register(plugin: ChronosPlugin): void;
|
|
1334
1399
|
}
|
|
1335
1400
|
//#endregion
|
|
1336
|
-
//#region src/types/
|
|
1337
|
-
/**
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1401
|
+
//#region src/types/date-time.d.ts
|
|
1402
|
+
/** - Represents the full name of a weekday, e.g., 'Monday', 'Tuesday' etc. */
|
|
1403
|
+
type WeekDay = (typeof DAYS)[number];
|
|
1404
|
+
/** - Represents the full name of a month, e.g., 'January', 'February' etc. */
|
|
1405
|
+
type MonthName = (typeof MONTHS)[number];
|
|
1406
|
+
/** Mapped type to {@link TIME_UNIT_VARIANTS} */
|
|
1407
|
+
type $TimeUnitVarMap = typeof TIME_UNIT_VARIANTS;
|
|
1408
|
+
/** Key of {@link TIME_UNIT_VARIANTS} */
|
|
1409
|
+
type $TimeUnitKey = keyof typeof TIME_UNIT_VARIANTS;
|
|
1410
|
+
/** Variants of different time units in lowercase */
|
|
1411
|
+
type $TimeUnitVar<U extends $TimeUnitKey = $TimeUnitKey> = $TimeUnitVarMap[U][number];
|
|
1412
|
+
/** Variants of different time units in lowercase, uppercase and capitalized */
|
|
1413
|
+
type $UnitAnyCase = Capitalize<$TimeUnitVar> | Uppercase<$TimeUnitVar> | $TimeUnitVar;
|
|
1414
|
+
/** Number (time value) with variants of different time units */
|
|
1415
|
+
type TimeWithUnit = `${number}${$UnitAnyCase}` | `${number} ${$UnitAnyCase}`;
|
|
1416
|
+
/** - Minute in numeric string from `00` to `23` */
|
|
1417
|
+
type ClockHour = `0${Enumerate<10>}` | `${NumberRange<10, 23>}`;
|
|
1418
|
+
/** - Minute in numeric string from `00` to `59` */
|
|
1419
|
+
type ClockMinute = `0${Enumerate<10>}` | `${NumberRange<10, 59>}`;
|
|
1420
|
+
/** - Second in numeric string from `00` to `59` */
|
|
1421
|
+
type ClockSecond = `0${Enumerate<10>}` | `${NumberRange<10, 59>}`;
|
|
1422
|
+
/** - Time in "HH:MM" format. */
|
|
1423
|
+
type ClockTime = `${ClockHour}:${ClockMinute}`;
|
|
1424
|
+
/** Normal time in `H:mm` format which does not follow the strict limit up to 23 hours, hour can be any number and minute can be numeric string from `00` to `59` */
|
|
1425
|
+
type HourMinutes = `${number}:${ClockMinute}`;
|
|
1426
|
+
/** Extends {@link Intl.DateTimeFormatOptions} with improved type system. */
|
|
1427
|
+
interface DateTimeFormatOptions extends Intl.DateTimeFormatOptions {
|
|
1428
|
+
/** {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones Time zone identifier} to use (excluding `'Factory'`). */
|
|
1429
|
+
timeZone?: $TimeZoneIdentifier;
|
|
1430
|
+
/** Locale calendar system to use. */
|
|
1431
|
+
calendar?: LocaleCalendar;
|
|
1432
|
+
/** Locale numbering system to use. */
|
|
1433
|
+
numberingSystem?: NumberingSystem;
|
|
1434
|
+
}
|
|
1435
|
+
/** Millisecond from `0-999` */
|
|
1436
|
+
type Milliseconds = Enumerate<999> | 999;
|
|
1437
|
+
/** Date of the month as `0` padded numeric string e.g. `01`, `18` */
|
|
1438
|
+
type DateString = `0${NumberRange<1, 9>}` | `${NumberRange<10, 31>}`;
|
|
1439
|
+
/** Month as `0` padded numeric string, e.g. `02`, `01` etc. */
|
|
1440
|
+
type MonthString = `0${NumberRange<1, 9>}` | '10' | '11' | '12';
|
|
1441
|
+
/** Date and month in `MM-DD` format, e.g. `01-12` means 'January 18' */
|
|
1442
|
+
type MonthDateString = Exclude<`${MonthString}-${DateString}`, '02-30' | '02-31' | '04-31' | '06-31' | '09-31' | '11-31'>;
|
|
1443
|
+
/** Options for `formatDate` utility */
|
|
1444
|
+
interface DateFormatOptions extends FormatOptions {
|
|
1445
|
+
/** - Date to format, must be parsable by {@link Date} constructor. Can be string, number or `Date`. Defaults to current time. */
|
|
1446
|
+
date?: DateArgs;
|
|
1447
|
+
format?: SafeFormat;
|
|
1448
|
+
}
|
|
1449
|
+
/** Interface representing a date-like object. */
|
|
1450
|
+
interface DateLike {
|
|
1451
|
+
toJSON?(): string;
|
|
1452
|
+
toISOString?(): string;
|
|
1453
|
+
toString?(): string;
|
|
1454
|
+
format?(): string;
|
|
1455
|
+
toISO?(): string;
|
|
1456
|
+
toFormat?(format: string): string;
|
|
1457
|
+
plus?(...args: unknown[]): unknown;
|
|
1458
|
+
minus?(...args: unknown[]): unknown;
|
|
1459
|
+
equals?(...args: unknown[]): boolean;
|
|
1460
|
+
getClass?(): unknown;
|
|
1461
|
+
constructor?: {
|
|
1462
|
+
name: string;
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
/** Quarters of the year */
|
|
1466
|
+
type Quarter = 1 | 2 | 3 | 4;
|
|
1467
|
+
/** Represents key of `ChronosStatics` (each static method and property) */
|
|
1468
|
+
type ChronosStaticKey = keyof ChronosStatics;
|
|
1469
|
+
/** Key of {@link TIME_ZONE_LABELS} ({@link UTCOffset}) */
|
|
1470
|
+
type $TZLabelKey = keyof typeof TIME_ZONE_LABELS;
|
|
1471
|
+
/** Abbreviated time zone names (from {@link https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations time zone abbreviations on Wikipedia}). */
|
|
1472
|
+
type TimeZone = keyof typeof TIME_ZONES;
|
|
1473
|
+
/** Time zone identifier (from {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database on Wikipedia}) excluding `'Factory'`. */
|
|
1474
|
+
type $TimeZoneIdentifier = Exclude<keyof typeof TIME_ZONE_IDS, 'Factory'>;
|
|
1475
|
+
/** Time zone identifier (from {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database on Wikipedia}) excluding `'Factory'` & abbreviations present in {@link TimeZone}. */
|
|
1476
|
+
type TimeZoneIdentifier = Exclude<$TimeZoneIdentifier, TimeZone>;
|
|
1477
|
+
/** Time zone identifier, array of timezone identifiers or UTC offset. */
|
|
1478
|
+
type TimeZoneId = $TimeZoneIdentifier | $TimeZoneIdentifier[] | UTCOffset;
|
|
1479
|
+
/** JavaScript native time zone identifier (from {@link Intl.supportedValuesOf} API) */
|
|
1480
|
+
type TimeZoneIdNative = keyof typeof TIME_ZONES_NATIVE;
|
|
1481
|
+
/** JavaScript native time zone name (from {@link Intl.supportedValuesOf} API) */
|
|
1482
|
+
type TimeZoneNameNative = (typeof TIME_ZONES_NATIVE)[TimeZoneIdNative]['tzName'];
|
|
1483
|
+
/** Native time zone name or IANA time zone identifier */
|
|
1484
|
+
type $NativeTzNameOrId = TimeZoneNameNative | $TimeZoneIdentifier;
|
|
1485
|
+
/** Full time zone names from {@link https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations Wikipedia}, {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database on Wikipedia} and JavaScript native API ({@link Intl.supportedValuesOf}). */
|
|
1486
|
+
type TimeZoneName = NonNullable<(typeof TIME_ZONE_LABELS)[$TZLabelKey] | (typeof TIME_ZONES)[TimeZone]['tzName'] | (typeof TIME_ZONE_IDS)[$TimeZoneIdentifier]['tzName'] | TimeZoneNameNative>;
|
|
1487
|
+
/** Positive UTC hours */
|
|
1488
|
+
type PositiveUTCHour = `+0${Enumerate<10>}` | `+${NumberRange<10, 14>}`;
|
|
1489
|
+
/** Negative UTC hours */
|
|
1490
|
+
type NegativeUTCHour = `-0${Enumerate<10>}` | `-${NumberRange<10, 14>}`;
|
|
1491
|
+
/** UTC Minutes as quarters */
|
|
1492
|
+
type UTCMinute = '00' | '15' | '30' | '45';
|
|
1493
|
+
/** UTC offset in `±HH:mm` format */
|
|
1494
|
+
type $UTCOffset = `${PositiveUTCHour | NegativeUTCHour}:${UTCMinute}`;
|
|
1495
|
+
/** UTC offset in `UTC±HH:mm` format */
|
|
1496
|
+
type UTCOffset = `UTC${$UTCOffset}`;
|
|
1497
|
+
/** GMT offset in `GMT±HH:mm` or simply `GMT` format */
|
|
1498
|
+
type $GMTOffset = `GMT${$UTCOffset}` | 'GMT';
|
|
1499
|
+
type $ISOTimeString = `${number}-${number}-${number}T${number}:${number}:${number}.${number}`;
|
|
1500
|
+
type ISODateTimeString<F extends ISODateFormat = 'utc'> = F extends 'utc' ? `${$ISOTimeString}Z` : `${$ISOTimeString}${$UTCOffset}`;
|
|
1501
|
+
/** Valid argument type accepted by `Date` constructor */
|
|
1502
|
+
type DateArgs = string | number | Date;
|
|
1503
|
+
/** Type for ISO date format options */
|
|
1504
|
+
type ISODateFormat = 'local' | 'utc';
|
|
1505
|
+
/** Options for `getTimestamp` utility */
|
|
1506
|
+
interface TimestampOptions<F extends ISODateFormat = 'utc'> {
|
|
1350
1507
|
/**
|
|
1351
|
-
*
|
|
1352
|
-
*
|
|
1353
|
-
* @description
|
|
1354
|
-
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1355
|
-
*
|
|
1356
|
-
* @param value - A date value in `number`, it should be a timestamp (milliseconds since the Unix epoch).
|
|
1357
|
-
*
|
|
1358
|
-
* @returns Instance of `Chronos` with all methods and properties.
|
|
1508
|
+
* Optional date input (string, number, or `Date` object).
|
|
1509
|
+
* Defaults to {@link Date new Date()}.
|
|
1359
1510
|
*/
|
|
1360
|
-
|
|
1511
|
+
value?: DateArgs;
|
|
1361
1512
|
/**
|
|
1362
|
-
*
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
1366
|
-
*
|
|
1367
|
-
* @description
|
|
1368
|
-
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1369
|
-
*
|
|
1370
|
-
* @param value - A date value in `string`, it should be in a format that can be parsed by the `Date` constructor.
|
|
1371
|
-
*
|
|
1372
|
-
* @returns Instance of `Chronos` with all methods and properties.
|
|
1513
|
+
* Output format for the timestamp.
|
|
1514
|
+
* - `'utc'` (default) → returns ISO string in UTC (`...Z`).
|
|
1515
|
+
* - `'local'` → returns ISO string with current system offset (`...+05:30`).
|
|
1373
1516
|
*/
|
|
1374
|
-
|
|
1517
|
+
format?: F | ISODateFormat;
|
|
1518
|
+
}
|
|
1519
|
+
/** `Chronos` Date Format options */
|
|
1520
|
+
interface FormatOptions {
|
|
1375
1521
|
/**
|
|
1376
|
-
* *
|
|
1377
|
-
*
|
|
1378
|
-
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
1379
|
-
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
1380
|
-
*
|
|
1381
|
-
* @description
|
|
1382
|
-
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1522
|
+
* * The desired format (Default format is `'dd, mmm DD, YYYY HH:mm:ss'` = `'Sun, Apr 06, 2025 16:11:55'`).
|
|
1383
1523
|
*
|
|
1384
|
-
*
|
|
1524
|
+
* - To output raw text (i.e., not interpreted as a date token), wrap it in square brackets.
|
|
1525
|
+
* - For example, `[Today is] ddd` results in `Today is Sunday`, and `YYYY[ year]` results in `2025 year`.
|
|
1385
1526
|
*
|
|
1386
|
-
*
|
|
1527
|
+
* - Supported format tokens include: `YYYY`, `YY`, `mmmm`, `mmm`, `MM`, `M`, `DD`, `D`, `dd`, `ddd`, `Do`, `HH`, `H`, `hh`, `h`, `mm`, `m`, `ss`, `s`, `ms`, `mss`, `a`, `A`, and `ZZ`.
|
|
1528
|
+
* - *Any token not wrapped in brackets will be parsed and replaced with its corresponding date component.*
|
|
1529
|
+
* - Please refer to {@link https://chronos.nazmul-nhb.dev/docs/chronos/format#format-tokens format tokens} for details.
|
|
1387
1530
|
*/
|
|
1388
|
-
|
|
1389
|
-
/**
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
(
|
|
1531
|
+
format?: string;
|
|
1532
|
+
/** - Whether to use UTC time. Defaults to `false`. */
|
|
1533
|
+
useUTC?: boolean;
|
|
1534
|
+
}
|
|
1535
|
+
/** - Configuration options for greeting. */
|
|
1536
|
+
interface GreetingConfigs {
|
|
1537
|
+
/** Time when the morning period ends (HH:MM format). Defaults to `11:59` */
|
|
1538
|
+
morningEnds?: ClockTime;
|
|
1539
|
+
/** Time when the noon period ends (HH:MM format). Defaults to `12:59` */
|
|
1540
|
+
noonEnds?: ClockTime;
|
|
1541
|
+
/** Time when the afternoon period ends (HH:MM format). Defaults to `17:59` */
|
|
1542
|
+
afternoonEnds?: ClockTime;
|
|
1543
|
+
/** Time when the evening period ends (HH:MM format). Defaults to `23:59` */
|
|
1544
|
+
eveningEnds?: ClockTime;
|
|
1545
|
+
/** Time when the midnight period ends (HH:MM format). Defaults to `02:59` */
|
|
1546
|
+
midnightEnds?: ClockTime;
|
|
1547
|
+
/** Current time in "HH:MM" format for some weird reason. Defaults to current time `new Date()` */
|
|
1548
|
+
currentTime?: ClockTime;
|
|
1549
|
+
/** Optional string to append after each message */
|
|
1550
|
+
appendToMsg?: string;
|
|
1551
|
+
/** Optional string to prepend before each message */
|
|
1552
|
+
prependToMsg?: string;
|
|
1553
|
+
/** Custom greeting message for the morning period. */
|
|
1554
|
+
morningMessage?: string;
|
|
1555
|
+
/** Custom greeting message for the noon period. */
|
|
1556
|
+
noonMessage?: string;
|
|
1557
|
+
/** Custom greeting message for the afternoon period. */
|
|
1558
|
+
afternoonMessage?: string;
|
|
1559
|
+
/** Custom greeting message for the evening period. */
|
|
1560
|
+
eveningMessage?: string;
|
|
1561
|
+
/** Custom greeting message for the midnight period. */
|
|
1562
|
+
midnightMessage?: string;
|
|
1563
|
+
/** Default greeting message if no period matches. */
|
|
1564
|
+
defaultMessage?: string;
|
|
1565
|
+
}
|
|
1566
|
+
/** Time zone details object */
|
|
1567
|
+
type TimeZoneDetails = {
|
|
1568
|
+
/** IANA time zone identifier */tzIdentifier: $TimeZoneIdentifier; /** Long localized form (e.g., `'Pacific Standard Time'`, `'Nordamerikanische Westküsten-Normalzeit'`) */
|
|
1569
|
+
tzNameLong: Maybe<LooseLiteral<TimeZoneName>>; /** Long generic non-location format (e.g.: `'Pacific Time'`, `'Nordamerikanische Westküstenzeit'`) */
|
|
1570
|
+
tzNameLongGeneric: Maybe<LooseLiteral<TimeZoneName>>; /** Long localized GMT format, prefixed with `"GMT"` (e.g., `"GMT-08:00"`) */
|
|
1571
|
+
tzNameLongOffset: Maybe<LooseLiteral<$GMTOffset>>;
|
|
1572
|
+
};
|
|
1573
|
+
/** Name of time unit from `year` to `millisecond` */
|
|
1574
|
+
type TimeUnit = 'year' | 'month' | 'day' | 'week' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
1575
|
+
/** Name of time unit from `year` to `millisecond`, excluding `week` */
|
|
1576
|
+
type FromNowUnit = Exclude<TimeUnit, 'week'>;
|
|
1577
|
+
/** Conditional value for {@link TimeUnit} */
|
|
1578
|
+
type TimeUnitValue<Unit extends TimeUnit> = Unit extends 'month' ? NumberRange<1, 12> : Unit extends 'week' ? NumberRange<1, 53> : Unit extends 'day' ? NumberRange<1, 31> : Unit extends 'hour' ? Enumerate<24> : Unit extends 'minute' | 'second' ? Enumerate<60> : Unit extends 'millisecond' ? Milliseconds : number;
|
|
1579
|
+
/** Unit suffix for {@link Date} getter methods (e.g., `'FullYear'` in `'getFullYear'`, `'Month'` in `'getMonth'` etc.). */
|
|
1580
|
+
type $DateUnit = 'FullYear' | 'Month' | 'Day' | 'Date' | 'Hours' | 'Minutes' | 'Seconds' | 'Milliseconds';
|
|
1581
|
+
/** `BCP47` locale string or {@link Intl.Locale} object that contain one or more language or locale tags */
|
|
1582
|
+
type $LocalArguments = LooseLiteral<LocaleCode | Split<LocaleCode, '-'>[0]> | Intl.Locale;
|
|
1583
|
+
/** `BCP47` locale string, array of locale strings, {@link Intl.Locale} object, or array of {@link Intl.Locale} objects that contain one or more language or locale tags. */
|
|
1584
|
+
type LocalesArguments = $LocalArguments | $LocalArguments[];
|
|
1585
|
+
/** Locale calendars supported by {@link Intl} API */
|
|
1586
|
+
type LocaleCalendar = (typeof LOCALE_CALENDARS)[number];
|
|
1587
|
+
/** Locale numbering systems supported by {@link Intl} API */
|
|
1588
|
+
type NumberingSystem = (typeof LOCALE_NUMBERING_SYSTEMS)[number];
|
|
1589
|
+
//#endregion
|
|
1590
|
+
//#region src/types/chronos-specific.d.ts
|
|
1591
|
+
/**
|
|
1592
|
+
* * Timezone identifier type for `Chronos`
|
|
1593
|
+
*
|
|
1594
|
+
* - {@link $TimeZoneIdentifier} — e.g., `"Asia/Dhaka"`.
|
|
1595
|
+
* - {@link TimeZone} — e.g., `[ 'Asia/Calcutta', 'Asia/Colombo' ]`, used when multiple timezones share the same UTC offset such as `"UTC+05:30"`.
|
|
1596
|
+
* - {@link UTCOffset} — e.g., `"UTC+06:45"` or `"UTC+02:15"`, returned when no named timezone corresponds to a given offset.
|
|
1597
|
+
* - `'System'` — The current system timezone.
|
|
1598
|
+
*/
|
|
1599
|
+
type ChronosTimeZone = TimeZoneIdentifier | TimeZone | UTCOffset | 'System';
|
|
1600
|
+
/**
|
|
1601
|
+
* * Options for `Chronos` _static_ method `with()`
|
|
1602
|
+
*
|
|
1603
|
+
* @remarks Should provide at least one property, otherwise use the current date and time.
|
|
1604
|
+
*/
|
|
1605
|
+
type ChronosWithOptions = Partial<{
|
|
1606
|
+
/** The full year (e.g., 2025). Years 0–99 are interpreted as 1900–1999. */year: number; /** Month number from 1 (January) to 12 (December). */
|
|
1607
|
+
month: NumberRange<1, 12>; /** Day of the month, from 1 to 31. */
|
|
1608
|
+
date: NumberRange<1, 31>; /** Hour of the day, from 0 (midnight) to 23 (11 PM). */
|
|
1609
|
+
hour: Enumerate<24>; /** Minutes of the hour, from 0 to 59. */
|
|
1610
|
+
minute: Enumerate<60>; /** Seconds of the minute, from 0 to 59. */
|
|
1611
|
+
second: Enumerate<60>; /** Milliseconds of the second, from 0 to 999. */
|
|
1612
|
+
millisecond: Milliseconds;
|
|
1613
|
+
}>;
|
|
1614
|
+
/** Interface for accessing internal private properties in extended `Chronos` class */
|
|
1615
|
+
interface ChronosInternals {
|
|
1403
1616
|
/**
|
|
1404
|
-
* *
|
|
1405
|
-
*
|
|
1406
|
-
* @description
|
|
1407
|
-
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1408
|
-
*
|
|
1409
|
-
* @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99, year is assumed to be 1900 + year.
|
|
1410
|
-
* @param month The month as a number between 1 and 12 (January to December).
|
|
1411
|
-
* @param date The date as a number between 1 and 31.
|
|
1412
|
-
* @param hours Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour.
|
|
1413
|
-
* @param minutes Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes.
|
|
1414
|
-
* @param seconds Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds.
|
|
1415
|
-
* @param ms A number from 0 to 999 that specifies the milliseconds.
|
|
1617
|
+
* * Access to `#withOrigin` private method.
|
|
1618
|
+
* * Creates a new `Chronos` instance with `origin` and other properties.
|
|
1416
1619
|
*
|
|
1417
|
-
* @
|
|
1620
|
+
* @param instance The `Chronos` instance to which attach the `origin` and other properties.
|
|
1621
|
+
* @param origin Origin of the instance, the method name from where it was created.
|
|
1622
|
+
* @param offset Optional UTC offset in `UTC±HH:mm` format.
|
|
1623
|
+
* @param tzName Optional time zone name to set.
|
|
1624
|
+
* @param tzId Optional time zone identifier(s) to set.
|
|
1625
|
+
* @param tzTracker Optional tracker to identify the instance created by {@link https://chronos.nazmul-nhb.dev/docs/plugins/timezone-plugin#timezone timeZone} method.
|
|
1626
|
+
* @returns The `Chronos` instance with the specified origin and other properties.
|
|
1418
1627
|
*/
|
|
1419
|
-
(
|
|
1628
|
+
withOrigin<Tz extends ChronosTimeZone>(instance: Chronos, method: PluginMethods, offset?: UTCOffset, tzName?: LooseLiteral<TimeZoneName>, tzId?: TimeZoneId, tzTracker?: $TimeZoneIdentifier | TimeZone | UTCOffset): Chronos<Tz>;
|
|
1420
1629
|
/**
|
|
1421
|
-
*
|
|
1422
|
-
*
|
|
1423
|
-
*
|
|
1424
|
-
* @
|
|
1425
|
-
*
|
|
1426
|
-
* - To prevent this incorrect *linter error* in `React` projects, prefer using {@link register} method (alias `use` method).
|
|
1427
|
-
*
|
|
1428
|
-
* - **NOTE:** *Once a plugin is injected, all the registered methods for that plugin will be available for the whole project.*
|
|
1429
|
-
* - See {@link https://chronos.nazmul-nhb.dev/docs/plugins#-official-plugins full list of plugins and the methods they register}.
|
|
1630
|
+
* * Access to `#toNewDate` private method
|
|
1631
|
+
* * Creates a new `Date` object from a `Chronos` input
|
|
1632
|
+
* @param instance - `Chronos` instance to operate on
|
|
1633
|
+
* @param value - Input value to convert (optional, uses current date if omitted)
|
|
1634
|
+
* @returns A new JavaScript `Date` object
|
|
1430
1635
|
*/
|
|
1431
|
-
|
|
1636
|
+
toNewDate(instance: Chronos, value?: ChronosInput): Date;
|
|
1432
1637
|
/**
|
|
1433
|
-
*
|
|
1434
|
-
* @param
|
|
1435
|
-
*
|
|
1436
|
-
* @remarks
|
|
1437
|
-
* - This is just an alias for {@link use} method.
|
|
1438
|
-
* - Using {@link use} method in `React` projects may trigger *linter error* like `"React Hooks must be called in a React function component or a custom React Hook function."`
|
|
1439
|
-
* - To prevent this incorrect *linter error* in `React` projects, prefer using this (`register`) method over {@link use} method.
|
|
1440
|
-
*
|
|
1441
|
-
* - **NOTE:** *Once a plugin is injected, all the registered methods for that plugin will be available for the whole project.*
|
|
1442
|
-
* - See {@link https://chronos.nazmul-nhb.dev/docs/plugins#-official-plugins full list of plugins and the methods they register}.
|
|
1638
|
+
* * Gets the internal `#date`, a readonly private property (core `Date` object)
|
|
1639
|
+
* @param instance - `Chronos` instance to access
|
|
1640
|
+
* @returns The core internal `Date` object
|
|
1443
1641
|
*/
|
|
1444
|
-
|
|
1642
|
+
internalDate(instance: Chronos): Date;
|
|
1445
1643
|
/**
|
|
1446
|
-
* *
|
|
1447
|
-
*
|
|
1448
|
-
* @
|
|
1449
|
-
* @returns Formatted date string in desired format.
|
|
1644
|
+
* * Gets current UTC Offset internally stored as `#offset` private property
|
|
1645
|
+
* @param instance - `Chronos` instance to access
|
|
1646
|
+
* @returns The stored formatted UTC offset
|
|
1450
1647
|
*/
|
|
1451
|
-
|
|
1648
|
+
offset(instance: Chronos): UTCOffset;
|
|
1649
|
+
/** * Ensures the input is a `Chronos` instance, creating one if necessary. */
|
|
1650
|
+
cast<Tz extends ChronosTimeZone>(date: ChronosInput): Chronos<Tz>;
|
|
1651
|
+
}
|
|
1652
|
+
/** @internal Helper type to assign instance origin when creating new `Chronos` instance. */
|
|
1653
|
+
type WithoutOrigin = Omit<Chronos, '#ORIGIN' | 'origin'>;
|
|
1654
|
+
/** Alias for `typeof Chronos` */
|
|
1655
|
+
type $Chronos = typeof Chronos;
|
|
1656
|
+
/** * Instance methods that return `Chronos` instance */
|
|
1657
|
+
type $InstanceMethods = { [Method in keyof WithoutOrigin]: Chronos extends { [Instance in Method]: (...args: any[]) => Chronos } ? Method : never }[keyof WithoutOrigin];
|
|
1658
|
+
/** * Static methods that return `Chronos` instance */
|
|
1659
|
+
type $StaticMethods = { [Method in keyof $Chronos]: $Chronos extends { [Instance in Method]: (...args: any[]) => Chronos } ? Method : never }[keyof $Chronos];
|
|
1660
|
+
/** * Plugin methods that return `Chronos` instance */
|
|
1661
|
+
type $PluginMethods = 'round' | `timeZone` | 'nextWorkday' | 'nextWeekend' | 'previousWorkday' | 'previousWeekend';
|
|
1662
|
+
/** * Plugin methods that return `Chronos` instance + any custom name */
|
|
1663
|
+
type PluginMethods = LooseLiteral<$PluginMethods>;
|
|
1664
|
+
/** Both instance and static methods (including built-in plugin methods) in `Chronos` class that return `Chronos` instance. */
|
|
1665
|
+
type ChronosMethods = $InstanceMethods | $StaticMethods | $PluginMethods;
|
|
1666
|
+
/**
|
|
1667
|
+
* * Accepted Input type for `Chronos`
|
|
1668
|
+
*
|
|
1669
|
+
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
1670
|
+
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
1671
|
+
*/
|
|
1672
|
+
type ChronosInput = number | string | Date | Chronos;
|
|
1673
|
+
/** Properties required to reconstruct a `Chronos` instance. */
|
|
1674
|
+
interface ChronosProperties {
|
|
1675
|
+
/** The method or plugin name from which the instance was created. */
|
|
1676
|
+
origin: LooseLiteral<ChronosMethods>;
|
|
1677
|
+
/** The native date value, either as a `Date` object or a date string. */
|
|
1678
|
+
native: Date | string;
|
|
1679
|
+
/** The UTC offset in `UTC±HH:mm` format. */
|
|
1680
|
+
utcOffset: UTCOffset;
|
|
1681
|
+
/** The full time zone name (e.g., `"Pacific Standard Time"`). */
|
|
1682
|
+
timeZoneName: LooseLiteral<TimeZoneName>;
|
|
1683
|
+
/** The time zone identifier(s) associated with the instance (e.g., `"Asia/Dhaka"`). */
|
|
1684
|
+
timeZoneId: TimeZoneId;
|
|
1685
|
+
/** Optional tracker to identify the instance created by `timeZone` method. */
|
|
1686
|
+
$tzTracker?: $TimeZoneIdentifier | TimeZone | UTCOffset;
|
|
1687
|
+
}
|
|
1688
|
+
/** Iterable `Chronos` object properties */
|
|
1689
|
+
interface ChronosObject {
|
|
1690
|
+
/** Full year (e.g., 2025). */
|
|
1691
|
+
year: number;
|
|
1692
|
+
/** Month index starting from 0 (January = 0). */
|
|
1693
|
+
month: Enumerate<12>;
|
|
1694
|
+
/** ISO month number starting from 1 (January = 1). */
|
|
1695
|
+
isoMonth: NumberRange<1, 12>;
|
|
1696
|
+
/** Day of the month (1–31). */
|
|
1697
|
+
date: NumberRange<1, 31>;
|
|
1698
|
+
/** Day of the week index (0–6, Sunday = 0). */
|
|
1699
|
+
weekDay: Enumerate<7>;
|
|
1700
|
+
/** ISO day of the week number (1–7, Monday = 1). */
|
|
1701
|
+
isoWeekDay: NumberRange<1, 7>;
|
|
1702
|
+
/** Hour of the day (0–23). */
|
|
1703
|
+
hour: Enumerate<24>;
|
|
1704
|
+
/** Minute of the hour (0–59). */
|
|
1705
|
+
minute: Enumerate<60>;
|
|
1706
|
+
/** Second of the minute (0–59). */
|
|
1707
|
+
second: Enumerate<60>;
|
|
1708
|
+
/** Milliseconds within the second. */
|
|
1709
|
+
millisecond: Milliseconds;
|
|
1710
|
+
/** Timestamp in milliseconds since the Unix epoch. */
|
|
1711
|
+
timestamp: number;
|
|
1712
|
+
/** Unix timestamp in seconds since the epoch. */
|
|
1713
|
+
unix: number;
|
|
1714
|
+
}
|
|
1715
|
+
/** Common options for formatting and rounding dates */
|
|
1716
|
+
interface $CommonRangeOptions {
|
|
1717
|
+
/** - Output format: return ISO strings in `'local'` or `'utc'` format. Defaults to `'local'`. */
|
|
1718
|
+
format?: ISODateFormat;
|
|
1719
|
+
/** - Whether to round the dates in the range to the start of the day. Default is `false`. */
|
|
1720
|
+
roundDate?: boolean;
|
|
1721
|
+
}
|
|
1722
|
+
/** - Options to define a **fixed date range** using explicit `from` and `to` dates. */
|
|
1723
|
+
interface DateRangeOptions extends $CommonRangeOptions {
|
|
1724
|
+
/** - Start date of the range (inclusive). Defaults to **now** if not provided. */
|
|
1725
|
+
from?: ChronosInput;
|
|
1726
|
+
/** - End date of the range (inclusive). Defaults to **4 weeks from now** if not provided. */
|
|
1727
|
+
to?: ChronosInput;
|
|
1728
|
+
}
|
|
1729
|
+
/** - Options to define a **relative date range** starting from the current date. */
|
|
1730
|
+
interface RelativeRangeOptions extends $CommonRangeOptions {
|
|
1452
1731
|
/**
|
|
1453
|
-
*
|
|
1732
|
+
* The number of time units to move **forward from `now`**.
|
|
1454
1733
|
*
|
|
1455
|
-
*
|
|
1734
|
+
* - Determines the size of the range.
|
|
1735
|
+
* - `now` → `start`, and `start + span` → `end`.
|
|
1736
|
+
* - Both `start` and `end` are included in the result.
|
|
1737
|
+
* - Controlled by the {@link unit} option.
|
|
1738
|
+
* - Defaults to `4`.
|
|
1456
1739
|
*/
|
|
1457
|
-
|
|
1740
|
+
span?: number;
|
|
1458
1741
|
/**
|
|
1459
|
-
*
|
|
1742
|
+
* The time unit used to advance the range.
|
|
1460
1743
|
*
|
|
1461
|
-
* @
|
|
1744
|
+
* - Works together with {@link span} to calculate the final date range.
|
|
1745
|
+
* - For example: `span: 2, unit: 'week'` → 2-week range.
|
|
1746
|
+
* - Defaults to `'week'`.
|
|
1462
1747
|
*/
|
|
1463
|
-
|
|
1748
|
+
unit?: 'year' | 'month' | 'week' | 'day';
|
|
1749
|
+
}
|
|
1750
|
+
/** - Unified type that supports either a fixed or relative date range configuration. */
|
|
1751
|
+
type WeekdayOptions = RelativeRangeOptions | DateRangeOptions;
|
|
1752
|
+
/** Common options to either skip or keep days */
|
|
1753
|
+
interface $SkipOrKeepDays {
|
|
1464
1754
|
/**
|
|
1465
|
-
*
|
|
1466
|
-
*
|
|
1467
|
-
*
|
|
1755
|
+
* An array of weekdays to exclude from the date range.
|
|
1756
|
+
* - Accepts either weekday names (e.g., `'Saturday'`, `'Sunday'`) or numeric indices (0 for Sunday to 6 for Saturday).
|
|
1757
|
+
* - Ignored if {@link onlyDays} is provided.
|
|
1758
|
+
*
|
|
1759
|
+
* @example
|
|
1760
|
+
* skipDays: ['Saturday', 'Sunday']
|
|
1761
|
+
* skipDays: [0, 6] // Sunday and Saturday
|
|
1468
1762
|
*/
|
|
1469
|
-
|
|
1763
|
+
skipDays?: Array<WeekDay> | Array<Enumerate<7>>;
|
|
1470
1764
|
/**
|
|
1471
|
-
*
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
* - `YYYY`: Full year (e.g., 2023)
|
|
1475
|
-
* - `YY`: Two-digit year (e.g., 23 for 2023, 99 for 1999)
|
|
1476
|
-
* - `MM`: Month (01-12)
|
|
1477
|
-
* - `M`: 1-Digit Month (1-9)
|
|
1478
|
-
* - `DD`: Day of the month (01-31)
|
|
1479
|
-
* - `D`: 1-Digit Day of the month (1-9)
|
|
1480
|
-
* - `HH`: Hour (00-23)
|
|
1481
|
-
* - `H`: 1-Digit Hour (0-9)
|
|
1482
|
-
* - `mm`: Minute (00-59)
|
|
1483
|
-
* - `m`: 1-Digit Minute (0-9)
|
|
1484
|
-
* - `ss`: Second (00-59)
|
|
1485
|
-
* - `s`: 1-Digit Second (0-9)
|
|
1765
|
+
* An array of weekdays to explicitly include in the date range.
|
|
1766
|
+
* - Accepts either weekday names (e.g., `'Monday'`, `'Wednesday'`) or numeric indices (0 for Sunday to 6 for Saturday).
|
|
1767
|
+
* - When provided, this overrides {@link skipDays} and includes only the specified days.
|
|
1486
1768
|
*
|
|
1487
1769
|
* @example
|
|
1488
|
-
*
|
|
1489
|
-
*
|
|
1770
|
+
* onlyDays: ['Monday', 'Wednesday']
|
|
1771
|
+
* onlyDays: [1, 3] // Monday and Wednesday
|
|
1772
|
+
*/
|
|
1773
|
+
onlyDays?: Array<WeekDay> | Array<Enumerate<7>>;
|
|
1774
|
+
}
|
|
1775
|
+
/** - Options to define a **fixed date range** using explicit `from` and `to` dates. */
|
|
1776
|
+
interface RangeWithDates extends DateRangeOptions, $SkipOrKeepDays {}
|
|
1777
|
+
/** - Options to define a **relative date range** starting from the current date. */
|
|
1778
|
+
interface RelativeDateRange extends RelativeRangeOptions, $SkipOrKeepDays {}
|
|
1779
|
+
/** - Unified type that supports either a fixed or relative date range configuration. */
|
|
1780
|
+
type DatesInRangeOptions = RangeWithDates | RelativeDateRange;
|
|
1781
|
+
//#endregion
|
|
1782
|
+
//#region src/types/chronos-plugins.d.ts
|
|
1783
|
+
/** * A plugin that augments the `Chronos` class with methods or properties. */
|
|
1784
|
+
type ChronosPlugin = (Chronos: $Chronos) => void;
|
|
1785
|
+
/** ISO date-based range (format: `MM-DD`) e.g. `01-14` for 'January 14' */
|
|
1786
|
+
type DateBoundary = {
|
|
1787
|
+
/** Start date in `MM-DD` format, e.g. `01-18` means 'January 18' */startDate: MonthDateString; /** End date in `MM-DD` format, e.g. `03-17` means 'March 17' */
|
|
1788
|
+
endDate: MonthDateString;
|
|
1789
|
+
};
|
|
1790
|
+
/** Inclusive month index-based range `0-11` (0 = January) */
|
|
1791
|
+
type MonthBoundary = {
|
|
1792
|
+
startMonth: Enumerate<12>;
|
|
1793
|
+
endMonth: Enumerate<12>;
|
|
1794
|
+
};
|
|
1795
|
+
/** Season definition for season configuration */
|
|
1796
|
+
interface SeasonDefinition {
|
|
1797
|
+
/** Name of the season */
|
|
1798
|
+
name: string;
|
|
1799
|
+
/** Inclusive date/month boundary of the season */
|
|
1800
|
+
boundary: MonthBoundary | DateBoundary;
|
|
1801
|
+
}
|
|
1802
|
+
/** Name of a predefined season preset */
|
|
1803
|
+
type SeasonPreset = keyof typeof SEASON_PRESETS;
|
|
1804
|
+
/** Options for configuring seasons */
|
|
1805
|
+
interface SeasonOptions {
|
|
1806
|
+
/** Custom season list to override or define seasons manually */
|
|
1807
|
+
seasons?: SeasonDefinition[];
|
|
1808
|
+
/** Predefined preset to use for season calculation */
|
|
1809
|
+
preset?: SeasonPreset;
|
|
1810
|
+
}
|
|
1811
|
+
interface $BusinessHourBaseOptions {
|
|
1812
|
+
/** - Optional starting hour of business time (0–23). Defaults to `9` (9 AM). */
|
|
1813
|
+
businessStartHour?: Enumerate<24>;
|
|
1814
|
+
/** - Optional ending hour of business time (0–23). Defaults to `17` (5 PM). */
|
|
1815
|
+
businessEndHour?: Enumerate<24>;
|
|
1816
|
+
}
|
|
1817
|
+
/** Options for configuring business hour with `weekStartsOn` and `weekendLength` */
|
|
1818
|
+
interface BusinessOptionsBasic extends $BusinessHourBaseOptions {
|
|
1819
|
+
/** - Optional day the week starts on (0–6). Default is `0` (Sunday). */
|
|
1820
|
+
weekStartsOn?: Enumerate<7>;
|
|
1821
|
+
/** - Optional weekend length (1-4). Default is `2`.*/
|
|
1822
|
+
weekendLength?: NumberRange<1, 4>;
|
|
1823
|
+
}
|
|
1824
|
+
/** Options for configuring business hour with `weekendDays` tuple */
|
|
1825
|
+
interface BusinessOptionsWeekends extends $BusinessHourBaseOptions {
|
|
1826
|
+
/** - Tuple of indices (0-6) of weekend days. Can pass only 1-4 elements. Default is `undefined`. */
|
|
1827
|
+
weekendDays?: RangeTuple<Enumerate<7>, 1, 4>;
|
|
1828
|
+
}
|
|
1829
|
+
/** Options for configuring business hour */
|
|
1830
|
+
type $BusinessHourOptions = BusinessOptionsBasic | BusinessOptionsWeekends;
|
|
1831
|
+
/** Names of standard Zodiac signs */
|
|
1832
|
+
type ZodiacSign = (typeof WESTERN_ZODIAC_SIGNS)[number][0];
|
|
1833
|
+
/** Presets for Zodiac Sign Configuration */
|
|
1834
|
+
type ZodiacPreset = keyof typeof ZODIAC_PRESETS;
|
|
1835
|
+
/** Shape of Zodiac signs array */
|
|
1836
|
+
type ZodiacArray<Sign extends string = ZodiacSign> = Array<[Sign, [NumberRange<1, 12>, NumberRange<1, 31>]] | Readonly<[Sign, Readonly<[NumberRange<1, 12>, NumberRange<1, 31>]>]>>;
|
|
1837
|
+
/** Zodiac metadata options */
|
|
1838
|
+
interface ZodiacMetaOptions<Sign extends string = ZodiacSign> {
|
|
1839
|
+
/**
|
|
1840
|
+
* Optional Zodiac preset to use. Default is `western`.
|
|
1841
|
+
* - **Note:** `western` and `tropical`, `vedic` and `sidereal` are same.
|
|
1842
|
+
*/
|
|
1843
|
+
preset?: ZodiacPreset;
|
|
1844
|
+
/** Custom Zodiac date ranges, overrides {@link preset presets}. */
|
|
1845
|
+
custom?: ZodiacArray<Sign> | Readonly<ZodiacArray<Sign>>;
|
|
1846
|
+
}
|
|
1847
|
+
/** Options for configuring Zodiac sign getter */
|
|
1848
|
+
interface ZodiacOptions<Sign extends string = ZodiacSign> extends ZodiacMetaOptions<Sign> {
|
|
1849
|
+
/** - Optional birthdate in `MM-DD` format (`1`-based month). */
|
|
1850
|
+
birthDate?: MonthDateString;
|
|
1851
|
+
}
|
|
1852
|
+
/** Represents resolved metadata for a zodiac sign */
|
|
1853
|
+
interface ZodiacMeta<Sign extends string = ZodiacSign> {
|
|
1854
|
+
/**
|
|
1855
|
+
* Index (`0`-based) of the zodiac sign within the resolved and chronologically sorted zodiac list.
|
|
1490
1856
|
*
|
|
1491
|
-
*
|
|
1492
|
-
*
|
|
1493
|
-
*
|
|
1494
|
-
* @throws `Error` If the date string does not match the format.
|
|
1857
|
+
* ⚠️ **Notes:**
|
|
1858
|
+
* - The `index` is determined by the Gregorian month–day order of zodiac start dates and may differ between variants (e.g. Western vs Vedic).
|
|
1859
|
+
* - This `index` should not be interpreted as a traditional or mythological zodiac ordering.
|
|
1495
1860
|
*/
|
|
1496
|
-
|
|
1861
|
+
index: number;
|
|
1862
|
+
/** The zodiac sign name. */
|
|
1863
|
+
sign: Sign;
|
|
1864
|
+
/** Inclusive start date of the zodiac sign in `MM-DD` format. */
|
|
1865
|
+
start: MonthDateString;
|
|
1866
|
+
/** Inclusive end date of the zodiac sign in `MM-DD` format. */
|
|
1867
|
+
end: MonthDateString;
|
|
1868
|
+
}
|
|
1869
|
+
/** Definition of day part names. */
|
|
1870
|
+
type DayPart = (typeof DATE_PARTS)[number];
|
|
1871
|
+
/** Object type for extracting day parts. */
|
|
1872
|
+
type DayPartConfig = Partial<Record<DayPart, [ClockHour, ClockHour]>>;
|
|
1873
|
+
/** Academic year, e.g. `2024-2025` */
|
|
1874
|
+
type AcademicYear = `${number}-${number}`;
|
|
1875
|
+
/** Return object type of `duration` method of `Chronos`. */
|
|
1876
|
+
interface TimeDuration {
|
|
1877
|
+
/** Total number of years. */
|
|
1878
|
+
years: number;
|
|
1879
|
+
/** Number of months remaining after full years are counted. */
|
|
1880
|
+
months: number;
|
|
1881
|
+
/** Number of days remaining after full months are counted. */
|
|
1882
|
+
days: number;
|
|
1883
|
+
/** Number of hours remaining after full days are counted. */
|
|
1884
|
+
hours: number;
|
|
1885
|
+
/** Number of minutes remaining after full hours are counted. */
|
|
1886
|
+
minutes: number;
|
|
1887
|
+
/** Number of seconds remaining after full minutes are counted. */
|
|
1888
|
+
seconds: number;
|
|
1889
|
+
/** Number of milliseconds remaining after full seconds are counted. */
|
|
1890
|
+
milliseconds: number;
|
|
1891
|
+
}
|
|
1892
|
+
/** Key of {@link TimeDuration} */
|
|
1893
|
+
type DurationKey = keyof TimeDuration;
|
|
1894
|
+
/** Options for formatting duration string */
|
|
1895
|
+
interface DurationOptions {
|
|
1896
|
+
/** The time to compare with. Defaults to `now`. */
|
|
1897
|
+
toTime?: ChronosInput;
|
|
1898
|
+
/** If true, returns all values as positive numbers. Defaults to `true`. */
|
|
1899
|
+
absolute?: boolean;
|
|
1900
|
+
/** Maximum number of units to display, e.g. 2 → "1 hour, 20 minutes" */
|
|
1901
|
+
maxUnits?: NumberRange<1, 7>;
|
|
1902
|
+
/** Separator between units (default: `", "`) */
|
|
1903
|
+
separator?: string;
|
|
1904
|
+
/** Display mode: `"full"` (default) → "2 hours", `"short"` → "2h" */
|
|
1905
|
+
style?: 'full' | 'short';
|
|
1906
|
+
/** Whether to include zero values (default: `false`) */
|
|
1907
|
+
showZero?: boolean;
|
|
1908
|
+
}
|
|
1909
|
+
//#endregion
|
|
1910
|
+
//#region src/types/chronos-statics.d.ts
|
|
1911
|
+
/** All the statics methods in `Chronos` class */
|
|
1912
|
+
interface ChronosStatics {
|
|
1497
1913
|
/**
|
|
1498
|
-
* *
|
|
1914
|
+
* * Converts a date into a `Chronos` object and access to all `Chronos` methods and properties.
|
|
1499
1915
|
*
|
|
1500
|
-
* @
|
|
1501
|
-
*
|
|
1916
|
+
* @description
|
|
1917
|
+
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1502
1918
|
*
|
|
1503
|
-
*
|
|
1504
|
-
* - Unspecified components are filled with the current time's (`Chronos`) respective values.
|
|
1505
|
-
* - For option `month`, value should be number from `1` (January) to `12` (December).
|
|
1506
|
-
* - If the `date` component is omitted and the current day is the last day of its month,
|
|
1507
|
-
* the resulting instance will also use the last day of the target month.
|
|
1508
|
-
* - _This rule does **not** apply if the `date` component is explicitly provided,
|
|
1509
|
-
* even if that value exceeds the last day of the target month._
|
|
1919
|
+
* Accepts no arguments (defaults to now).
|
|
1510
1920
|
*
|
|
1511
|
-
* @
|
|
1512
|
-
* // Override only the year and month
|
|
1513
|
-
* const c = Chronos.with({ year: 2025, month: 12 });
|
|
1921
|
+
* @returns Instance of `Chronos` with all methods and properties.
|
|
1514
1922
|
*/
|
|
1515
|
-
|
|
1923
|
+
(): Chronos;
|
|
1516
1924
|
/**
|
|
1517
|
-
* *
|
|
1518
|
-
* If no date is provided, it uses the current date and time.
|
|
1925
|
+
* * Converts a date into a `Chronos` object and access to all `Chronos` methods and properties.
|
|
1519
1926
|
*
|
|
1520
|
-
*
|
|
1927
|
+
* @description
|
|
1928
|
+
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1521
1929
|
*
|
|
1522
|
-
* @param
|
|
1523
|
-
*
|
|
1524
|
-
* @returns
|
|
1930
|
+
* @param value - A date value in `number`, it should be a timestamp (milliseconds since the Unix epoch).
|
|
1931
|
+
*
|
|
1932
|
+
* @returns Instance of `Chronos` with all methods and properties.
|
|
1525
1933
|
*/
|
|
1526
|
-
|
|
1934
|
+
(value: number): Chronos;
|
|
1527
1935
|
/**
|
|
1528
|
-
* *
|
|
1936
|
+
* * Converts a date into a `Chronos` object and access to all `Chronos` methods and properties.
|
|
1529
1937
|
*
|
|
1530
|
-
*
|
|
1531
|
-
*
|
|
1532
|
-
* - `HH:mm:ss` → e.g., `'14:50:00'`
|
|
1533
|
-
* - `HH:mm:ss.SSS` → e.g., `'14:50:00.800'`
|
|
1534
|
-
* - `HH:mm+TimeZoneOffset(HH)` → e.g., `'14:50+06'`
|
|
1535
|
-
* - `HH:mm:ss+TimeZoneOffset(HH)` → e.g., `'14:50:00+06'`
|
|
1536
|
-
* - `HH:mm:ss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00+05:30'`
|
|
1537
|
-
* - `HH:mm:ss.SSS+TimeZoneOffset(HH)` → e.g., `'14:50:00.800+06'`
|
|
1538
|
-
* - `HH:mm:ss.SSS+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00.800+06:30'`
|
|
1938
|
+
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
1939
|
+
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
1539
1940
|
*
|
|
1540
|
-
*
|
|
1941
|
+
* @description
|
|
1942
|
+
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1541
1943
|
*
|
|
1542
|
-
* @param
|
|
1543
|
-
*
|
|
1944
|
+
* @param value - A date value in `string`, it should be in a format that can be parsed by the `Date` constructor.
|
|
1945
|
+
*
|
|
1946
|
+
* @returns Instance of `Chronos` with all methods and properties.
|
|
1544
1947
|
*/
|
|
1545
|
-
|
|
1948
|
+
(value: string): Chronos;
|
|
1546
1949
|
/**
|
|
1547
|
-
* *
|
|
1950
|
+
* * Converts a date into a `Chronos` object and access to all `Chronos` methods and properties.
|
|
1548
1951
|
*
|
|
1549
|
-
*
|
|
1550
|
-
*
|
|
1551
|
-
* @returns Array of ISO date strings in the specified format. Returns empty array if no matches in the time span.
|
|
1952
|
+
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
1953
|
+
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
1552
1954
|
*
|
|
1553
|
-
* @
|
|
1554
|
-
* Chronos
|
|
1555
|
-
* //=> [ '2025-05-28T21:16:06.198+06:00', '2025-06-04T21:16:06.198+06:00' ]
|
|
1955
|
+
* @description
|
|
1956
|
+
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1556
1957
|
*
|
|
1557
|
-
* @
|
|
1558
|
-
*
|
|
1559
|
-
*
|
|
1560
|
-
* unit: 'day',
|
|
1561
|
-
* format: 'utc'
|
|
1562
|
-
* });
|
|
1563
|
-
* //=> [ '2025-05-28T15:17:10.812Z', '2025-06-04T15:17:10.812Z' ]
|
|
1958
|
+
* @param value - A date value as `Date` object, it will be used as is.
|
|
1959
|
+
*
|
|
1960
|
+
* @returns Instance of `Chronos` with all methods and properties.
|
|
1564
1961
|
*/
|
|
1565
|
-
|
|
1962
|
+
(value: Date): Chronos;
|
|
1566
1963
|
/**
|
|
1567
|
-
* *
|
|
1964
|
+
* * Converts a date into a `Chronos` object and access to all `Chronos` methods and properties.
|
|
1568
1965
|
*
|
|
1569
|
-
*
|
|
1570
|
-
*
|
|
1571
|
-
* @returns Array of ISO date strings in the specified format. Returns empty array if no matches in the range.
|
|
1966
|
+
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
1967
|
+
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
1572
1968
|
*
|
|
1573
|
-
* @
|
|
1574
|
-
* Chronos.
|
|
1575
|
-
*
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
1578
|
-
*
|
|
1579
|
-
* //=> [ '2025-01-06T...', '2025-01-13T...', ... ]
|
|
1969
|
+
* @description
|
|
1970
|
+
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1971
|
+
*
|
|
1972
|
+
* @param value - A date value as `Chronos` object.
|
|
1973
|
+
*
|
|
1974
|
+
* @returns Instance of `Chronos` with all methods and properties.
|
|
1580
1975
|
*/
|
|
1581
|
-
|
|
1976
|
+
(value: Chronos): Chronos;
|
|
1582
1977
|
/**
|
|
1583
|
-
* *
|
|
1978
|
+
* * Converts a date into a `Chronos` object and access to all `Chronos` methods and properties.
|
|
1584
1979
|
*
|
|
1585
|
-
* @
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1980
|
+
* @description
|
|
1981
|
+
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
1982
|
+
*
|
|
1983
|
+
* @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99, year is assumed to be 1900 + year.
|
|
1984
|
+
* @param month The month as a number between 1 and 12 (January to December).
|
|
1985
|
+
* @param date The date as a number between 1 and 31.
|
|
1986
|
+
* @param hours Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour.
|
|
1987
|
+
* @param minutes Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes.
|
|
1988
|
+
* @param seconds Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds.
|
|
1989
|
+
* @param ms A number from 0 to 999 that specifies the milliseconds.
|
|
1990
|
+
*
|
|
1991
|
+
* @returns Instance of `Chronos` with all methods and properties.
|
|
1588
1992
|
*/
|
|
1589
|
-
|
|
1993
|
+
(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Chronos;
|
|
1590
1994
|
/**
|
|
1591
|
-
*
|
|
1592
|
-
* @param
|
|
1995
|
+
* @static Injects a plugin into the `Chronos` system.
|
|
1996
|
+
* @param plugin The plugin to inject.
|
|
1997
|
+
*
|
|
1998
|
+
* @remarks
|
|
1999
|
+
* - Using this (`use`) method in `React` projects may trigger *linter error* like `"React Hooks must be called in a React function component or a custom React Hook function."`
|
|
2000
|
+
* - To prevent this incorrect *linter error* in `React` projects, prefer using {@link register} method (alias `use` method).
|
|
2001
|
+
*
|
|
2002
|
+
* - **NOTE:** *Once a plugin is injected, all the registered methods for that plugin will be available for the whole project.*
|
|
2003
|
+
* - See {@link https://chronos.nazmul-nhb.dev/docs/plugins#-official-plugins full list of plugins and the methods they register}.
|
|
1593
2004
|
*/
|
|
1594
|
-
|
|
2005
|
+
use(plugin: ChronosPlugin): void;
|
|
1595
2006
|
/**
|
|
1596
|
-
*
|
|
1597
|
-
* @param
|
|
2007
|
+
* @static Registers a plugin into the `Chronos` system.
|
|
2008
|
+
* @param plugin The plugin to register.
|
|
2009
|
+
*
|
|
2010
|
+
* @remarks
|
|
2011
|
+
* - This is just an alias for {@link use} method.
|
|
2012
|
+
* - Using {@link use} method in `React` projects may trigger *linter error* like `"React Hooks must be called in a React function component or a custom React Hook function."`
|
|
2013
|
+
* - To prevent this incorrect *linter error* in `React` projects, prefer using this (`register`) method over {@link use} method.
|
|
2014
|
+
*
|
|
2015
|
+
* - **NOTE:** *Once a plugin is injected, all the registered methods for that plugin will be available for the whole project.*
|
|
2016
|
+
* - See {@link https://chronos.nazmul-nhb.dev/docs/plugins#-official-plugins full list of plugins and the methods they register}.
|
|
1598
2017
|
*/
|
|
1599
|
-
|
|
2018
|
+
register(plugin: ChronosPlugin): void;
|
|
1600
2019
|
/**
|
|
1601
|
-
* *
|
|
1602
|
-
*
|
|
1603
|
-
* -
|
|
1604
|
-
*
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
*
|
|
1609
|
-
* If the provided date is a string or a `Date` object, it will be parsed and the year will be extracted.
|
|
1610
|
-
* If a `Chronos` instance is passed, the year will be directly accessed from the instance.
|
|
2020
|
+
* * Returns the current date and time in a specified format in local time.
|
|
2021
|
+
* * Default format is dd, `MMM DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55`
|
|
2022
|
+
* @param options - Configure format string and whether to format using utc offset.
|
|
2023
|
+
* @returns Formatted date string in desired format.
|
|
2024
|
+
*/
|
|
2025
|
+
today(options?: FormatOptions): string;
|
|
2026
|
+
/**
|
|
2027
|
+
* * Returns a new `Chronos` instance representing yesterday's date.
|
|
1611
2028
|
*
|
|
1612
|
-
* @
|
|
1613
|
-
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
2029
|
+
* @returns A `Chronos` instance for the next calendar day.
|
|
1614
2030
|
*/
|
|
1615
|
-
|
|
2031
|
+
yesterday(): Chronos;
|
|
1616
2032
|
/**
|
|
1617
|
-
* *
|
|
1618
|
-
*
|
|
1619
|
-
*
|
|
1620
|
-
* @param value - The value to test.
|
|
1621
|
-
* @returns `true` if the value is a valid Date object, otherwise `false`.
|
|
2033
|
+
* * Returns a new `Chronos` instance representing tomorrow's date.
|
|
2034
|
+
*
|
|
2035
|
+
* @returns A `Chronos` instance for the next calendar day.
|
|
1622
2036
|
*/
|
|
1623
|
-
|
|
2037
|
+
tomorrow(): Chronos;
|
|
1624
2038
|
/**
|
|
1625
|
-
* *
|
|
1626
|
-
*
|
|
1627
|
-
*
|
|
1628
|
-
* @param value - The value to test.
|
|
1629
|
-
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
2039
|
+
* * Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
|
|
2040
|
+
* * It basically calls `Date.now()`.
|
|
2041
|
+
* @returns The number of milliseconds elapsed since the Unix epoch.
|
|
1630
2042
|
*/
|
|
1631
|
-
|
|
2043
|
+
now(): number;
|
|
1632
2044
|
/**
|
|
1633
|
-
* *
|
|
1634
|
-
*
|
|
1635
|
-
*
|
|
1636
|
-
*
|
|
2045
|
+
* * Parses a date string with a given format (limited support only).
|
|
2046
|
+
*
|
|
2047
|
+
* * **Supported format tokens**:
|
|
2048
|
+
* - `YYYY`: Full year (e.g., 2023)
|
|
2049
|
+
* - `YY`: Two-digit year (e.g., 23 for 2023, 99 for 1999)
|
|
2050
|
+
* - `MM`: Month (01-12)
|
|
2051
|
+
* - `M`: 1-Digit Month (1-9)
|
|
2052
|
+
* - `DD`: Day of the month (01-31)
|
|
2053
|
+
* - `D`: 1-Digit Day of the month (1-9)
|
|
2054
|
+
* - `HH`: Hour (00-23)
|
|
2055
|
+
* - `H`: 1-Digit Hour (0-9)
|
|
2056
|
+
* - `mm`: Minute (00-59)
|
|
2057
|
+
* - `m`: 1-Digit Minute (0-9)
|
|
2058
|
+
* - `ss`: Second (00-59)
|
|
2059
|
+
* - `s`: 1-Digit Second (0-9)
|
|
2060
|
+
*
|
|
2061
|
+
* @example
|
|
2062
|
+
* Chronos.parse('23-12-31 15:30:45', 'YY-MM-DD HH:mm:ss');
|
|
2063
|
+
* // returns Chronos instance with the parsed date 2023-12-31T15:30:45
|
|
2064
|
+
*
|
|
2065
|
+
* @param dateStr - The date string to be parsed
|
|
2066
|
+
* @param format - The format of the date string. Tokens like `YYYY`, `MM`, `DD`, `HH`, `mm`, `ss` are used to specify the structure.
|
|
2067
|
+
* @returns A new `Chronos` instance representing the parsed date.
|
|
2068
|
+
* @throws `Error` If the date string does not match the format.
|
|
1637
2069
|
*/
|
|
1638
|
-
|
|
2070
|
+
parse(dateStr: string, format: string): Chronos;
|
|
1639
2071
|
/**
|
|
1640
|
-
* *
|
|
1641
|
-
*
|
|
1642
|
-
* @param
|
|
1643
|
-
* @returns `
|
|
2072
|
+
* * Creates a new `Chronos` instance with the provided time component(s).
|
|
2073
|
+
*
|
|
2074
|
+
* @param options - One or more time components to override.
|
|
2075
|
+
* @returns A new `Chronos` instance with the provided time components applied.
|
|
2076
|
+
*
|
|
2077
|
+
* @remarks
|
|
2078
|
+
* - Unspecified components are filled with the current time's (`Chronos`) respective values.
|
|
2079
|
+
* - For option `month`, value should be number from `1` (January) to `12` (December).
|
|
2080
|
+
* - If the `date` component is omitted and the current day is the last day of its month,
|
|
2081
|
+
* the resulting instance will also use the last day of the target month.
|
|
2082
|
+
* - _This rule does **not** apply if the `date` component is explicitly provided,
|
|
2083
|
+
* even if that value exceeds the last day of the target month._
|
|
2084
|
+
*
|
|
2085
|
+
* @example
|
|
2086
|
+
* // Override only the year and month
|
|
2087
|
+
* const c = Chronos.with({ year: 2025, month: 12 });
|
|
1644
2088
|
*/
|
|
1645
|
-
|
|
2089
|
+
with(options: ChronosWithOptions): Chronos;
|
|
1646
2090
|
/**
|
|
1647
|
-
* *
|
|
1648
|
-
*
|
|
1649
|
-
* - If the input is not reconstructable, an error is thrown.
|
|
2091
|
+
* * Creates a UTC-based Chronos instance.
|
|
2092
|
+
* If no date is provided, it uses the current date and time.
|
|
1650
2093
|
*
|
|
1651
|
-
*
|
|
1652
|
-
*
|
|
1653
|
-
* @
|
|
2094
|
+
* **This is the base time, meaning conversion in other timezone will consider UTC time as the base time.**
|
|
2095
|
+
*
|
|
2096
|
+
* @param dateLike Optional input date to base the UTC time on.
|
|
2097
|
+
* If omitted, the current system date/time is used.
|
|
2098
|
+
* @returns A new Chronos instance representing the UTC equivalent of the input.
|
|
1654
2099
|
*/
|
|
1655
|
-
|
|
1656
|
-
}
|
|
1657
|
-
//#endregion
|
|
1658
|
-
//#region src/types/date-time.d.ts
|
|
1659
|
-
/** - Represents the full name of a weekday, e.g., 'Monday', 'Tuesday' etc. */
|
|
1660
|
-
type WeekDay = (typeof DAYS)[number];
|
|
1661
|
-
/** - Represents the full name of a month, e.g., 'January', 'February' etc. */
|
|
1662
|
-
type MonthName = (typeof MONTHS)[number];
|
|
1663
|
-
/** Mapped type to {@link TIME_UNIT_VARIANTS} */
|
|
1664
|
-
type $TimeUnitVarMap = typeof TIME_UNIT_VARIANTS;
|
|
1665
|
-
/** Key of {@link TIME_UNIT_VARIANTS} */
|
|
1666
|
-
type $TimeUnitKey = keyof typeof TIME_UNIT_VARIANTS;
|
|
1667
|
-
/** Variants of different time units in lowercase */
|
|
1668
|
-
type $TimeUnitVar<U extends $TimeUnitKey = $TimeUnitKey> = $TimeUnitVarMap[U][number];
|
|
1669
|
-
/** Variants of different time units in lowercase, uppercase and capitalized */
|
|
1670
|
-
type $UnitAnyCase = Capitalize<$TimeUnitVar> | Uppercase<$TimeUnitVar> | $TimeUnitVar;
|
|
1671
|
-
/** Number (time value) with variants of different time units */
|
|
1672
|
-
type TimeWithUnit = `${number}${$UnitAnyCase}` | `${number} ${$UnitAnyCase}`;
|
|
1673
|
-
/** - Minute in numeric string from `00` to `23` */
|
|
1674
|
-
type ClockHour = `0${Enumerate<10>}` | `${NumberRange<10, 23>}`;
|
|
1675
|
-
/** - Minute in numeric string from `00` to `59` */
|
|
1676
|
-
type ClockMinute = `0${Enumerate<10>}` | `${NumberRange<10, 59>}`;
|
|
1677
|
-
/** - Second in numeric string from `00` to `59` */
|
|
1678
|
-
type ClockSecond = `0${Enumerate<10>}` | `${NumberRange<10, 59>}`;
|
|
1679
|
-
/** - Time in "HH:MM" format. */
|
|
1680
|
-
type ClockTime = `${ClockHour}:${ClockMinute}`;
|
|
1681
|
-
/** Normal time in `H:mm` format which does not follow the strict limit up to 23 hours, hour can be any number and minute can be numeric string from `00` to `59` */
|
|
1682
|
-
type HourMinutes = `${number}:${ClockMinute}`;
|
|
1683
|
-
/** Extends {@link Intl.DateTimeFormatOptions} with improved type system. */
|
|
1684
|
-
interface DateTimeFormatOptions extends Intl.DateTimeFormatOptions {
|
|
1685
|
-
/** {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones Time zone identifier} to use (excluding `'Factory'`). */
|
|
1686
|
-
timeZone?: $TimeZoneIdentifier;
|
|
1687
|
-
/** Locale calendar system to use. */
|
|
1688
|
-
calendar?: LocaleCalendar;
|
|
1689
|
-
/** Locale numbering system to use. */
|
|
1690
|
-
numberingSystem?: NumberingSystem;
|
|
1691
|
-
}
|
|
1692
|
-
/** Millisecond from `0-999` */
|
|
1693
|
-
type Milliseconds = Enumerate<999> | 999;
|
|
1694
|
-
/** Date of the month as `0` padded numeric string e.g. `01`, `18` */
|
|
1695
|
-
type DateString = `0${NumberRange<1, 9>}` | `${NumberRange<10, 31>}`;
|
|
1696
|
-
/** Month as `0` padded numeric string, e.g. `02`, `01` etc. */
|
|
1697
|
-
type MonthString = `0${NumberRange<1, 9>}` | '10' | '11' | '12';
|
|
1698
|
-
/** Date and month in `MM-DD` format, e.g. `01-12` means 'January 18' */
|
|
1699
|
-
type MonthDateString = Exclude<`${MonthString}-${DateString}`, '02-30' | '02-31' | '04-31' | '06-31' | '09-31' | '11-31'>;
|
|
1700
|
-
/** Options for `formatDate` utility */
|
|
1701
|
-
interface DateFormatOptions extends FormatOptions {
|
|
1702
|
-
/** - Date to format, must be parsable by {@link Date} constructor. Can be string, number or `Date`. Defaults to current time. */
|
|
1703
|
-
date?: DateArgs;
|
|
1704
|
-
format?: SafeFormat;
|
|
1705
|
-
}
|
|
1706
|
-
/** Interface representing a date-like object. */
|
|
1707
|
-
interface DateLike {
|
|
1708
|
-
toJSON?(): string;
|
|
1709
|
-
toISOString?(): string;
|
|
1710
|
-
toString?(): string;
|
|
1711
|
-
format?(): string;
|
|
1712
|
-
toISO?(): string;
|
|
1713
|
-
toFormat?(format: string): string;
|
|
1714
|
-
plus?(...args: unknown[]): unknown;
|
|
1715
|
-
minus?(...args: unknown[]): unknown;
|
|
1716
|
-
equals?(...args: unknown[]): boolean;
|
|
1717
|
-
getClass?(): unknown;
|
|
1718
|
-
constructor?: {
|
|
1719
|
-
name: string;
|
|
1720
|
-
};
|
|
1721
|
-
}
|
|
1722
|
-
/** Quarters of the year */
|
|
1723
|
-
type Quarter = 1 | 2 | 3 | 4;
|
|
1724
|
-
/** Represents key of `ChronosStatics` (each static method and property) */
|
|
1725
|
-
type ChronosStaticKey = keyof ChronosStatics;
|
|
1726
|
-
/** Key of {@link TIME_ZONE_LABELS} ({@link UTCOffset}) */
|
|
1727
|
-
type $TZLabelKey = keyof typeof TIME_ZONE_LABELS;
|
|
1728
|
-
/** Abbreviated time zone names (from {@link https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations time zone abbreviations on Wikipedia}). */
|
|
1729
|
-
type TimeZone = keyof typeof TIME_ZONES;
|
|
1730
|
-
/** Time zone identifier (from {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database on Wikipedia}) excluding `'Factory'`. */
|
|
1731
|
-
type $TimeZoneIdentifier = Exclude<keyof typeof TIME_ZONE_IDS, 'Factory'>;
|
|
1732
|
-
/** Time zone identifier (from {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database on Wikipedia}) excluding `'Factory'` & abbreviations present in {@link TimeZone}. */
|
|
1733
|
-
type TimeZoneIdentifier = Exclude<$TimeZoneIdentifier, TimeZone>;
|
|
1734
|
-
/** Time zone identifier, array of timezone identifiers or UTC offset. */
|
|
1735
|
-
type TimeZoneId = $TimeZoneIdentifier | $TimeZoneIdentifier[] | UTCOffset;
|
|
1736
|
-
/** JavaScript native time zone identifier (from {@link Intl.supportedValuesOf} API) */
|
|
1737
|
-
type TimeZoneIdNative = keyof typeof TIME_ZONES_NATIVE;
|
|
1738
|
-
/** JavaScript native time zone name (from {@link Intl.supportedValuesOf} API) */
|
|
1739
|
-
type TimeZoneNameNative = (typeof TIME_ZONES_NATIVE)[TimeZoneIdNative]['tzName'];
|
|
1740
|
-
/** Native time zone name or IANA time zone identifier */
|
|
1741
|
-
type $NativeTzNameOrId = TimeZoneNameNative | $TimeZoneIdentifier;
|
|
1742
|
-
/** Full time zone names from {@link https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations Wikipedia}, {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database on Wikipedia} and JavaScript native API ({@link Intl.supportedValuesOf}). */
|
|
1743
|
-
type TimeZoneName = NonNullable<(typeof TIME_ZONE_LABELS)[$TZLabelKey] | (typeof TIME_ZONES)[TimeZone]['tzName'] | (typeof TIME_ZONE_IDS)[$TimeZoneIdentifier]['tzName'] | TimeZoneNameNative>;
|
|
1744
|
-
/** Positive UTC hours */
|
|
1745
|
-
type PositiveUTCHour = `+0${Enumerate<10>}` | `+${NumberRange<10, 14>}`;
|
|
1746
|
-
/** Negative UTC hours */
|
|
1747
|
-
type NegativeUTCHour = `-0${Enumerate<10>}` | `-${NumberRange<10, 14>}`;
|
|
1748
|
-
/** UTC Minutes as quarters */
|
|
1749
|
-
type UTCMinute = '00' | '15' | '30' | '45';
|
|
1750
|
-
/** UTC offset in `±HH:mm` format */
|
|
1751
|
-
type $UTCOffset = `${PositiveUTCHour | NegativeUTCHour}:${UTCMinute}`;
|
|
1752
|
-
/** UTC offset in `UTC±HH:mm` format */
|
|
1753
|
-
type UTCOffset = `UTC${$UTCOffset}`;
|
|
1754
|
-
/** GMT offset in `GMT±HH:mm` or simply `GMT` format */
|
|
1755
|
-
type $GMTOffset = `GMT${$UTCOffset}` | 'GMT';
|
|
1756
|
-
type $ISOTimeString = `${number}-${number}-${number}T${number}:${number}:${number}.${number}`;
|
|
1757
|
-
type ISODateTimeString<F extends ISODateFormat = 'utc'> = F extends 'utc' ? `${$ISOTimeString}Z` : `${$ISOTimeString}${$UTCOffset}`;
|
|
1758
|
-
/** Valid argument type accepted by `Date` constructor */
|
|
1759
|
-
type DateArgs = string | number | Date;
|
|
1760
|
-
/** Type for ISO date format options */
|
|
1761
|
-
type ISODateFormat = 'local' | 'utc';
|
|
1762
|
-
/** Options for `getTimestamp` utility */
|
|
1763
|
-
interface TimestampOptions<F extends ISODateFormat = 'utc'> {
|
|
1764
|
-
/**
|
|
1765
|
-
* Optional date input (string, number, or `Date` object).
|
|
1766
|
-
* Defaults to {@link Date new Date()}.
|
|
1767
|
-
*/
|
|
1768
|
-
value?: DateArgs;
|
|
1769
|
-
/**
|
|
1770
|
-
* Output format for the timestamp.
|
|
1771
|
-
* - `'utc'` (default) → returns ISO string in UTC (`...Z`).
|
|
1772
|
-
* - `'local'` → returns ISO string with current system offset (`...+05:30`).
|
|
1773
|
-
*/
|
|
1774
|
-
format?: F | ISODateFormat;
|
|
1775
|
-
}
|
|
1776
|
-
/** `Chronos` Date Format options */
|
|
1777
|
-
interface FormatOptions {
|
|
2100
|
+
utc(dateLike?: ChronosInput): Chronos<'UTC'>;
|
|
1778
2101
|
/**
|
|
1779
|
-
* *
|
|
1780
|
-
*
|
|
1781
|
-
* - To output raw text (i.e., not interpreted as a date token), wrap it in square brackets.
|
|
1782
|
-
* - For example, `[Today is] ddd` results in `Today is Sunday`, and `YYYY[ year]` results in `2025 year`.
|
|
2102
|
+
* * Formats a time-only string into a formatted time string.
|
|
1783
2103
|
*
|
|
1784
|
-
*
|
|
1785
|
-
*
|
|
1786
|
-
*
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
interface GreetingConfigs {
|
|
1794
|
-
/** Time when the morning period ends (HH:MM format). Defaults to `11:59` */
|
|
1795
|
-
morningEnds?: ClockTime;
|
|
1796
|
-
/** Time when the noon period ends (HH:MM format). Defaults to `12:59` */
|
|
1797
|
-
noonEnds?: ClockTime;
|
|
1798
|
-
/** Time when the afternoon period ends (HH:MM format). Defaults to `17:59` */
|
|
1799
|
-
afternoonEnds?: ClockTime;
|
|
1800
|
-
/** Time when the evening period ends (HH:MM format). Defaults to `23:59` */
|
|
1801
|
-
eveningEnds?: ClockTime;
|
|
1802
|
-
/** Time when the midnight period ends (HH:MM format). Defaults to `02:59` */
|
|
1803
|
-
midnightEnds?: ClockTime;
|
|
1804
|
-
/** Current time in "HH:MM" format for some weird reason. Defaults to current time `new Date()` */
|
|
1805
|
-
currentTime?: ClockTime;
|
|
1806
|
-
/** Optional string to append after each message */
|
|
1807
|
-
appendToMsg?: string;
|
|
1808
|
-
/** Optional string to prepend before each message */
|
|
1809
|
-
prependToMsg?: string;
|
|
1810
|
-
/** Custom greeting message for the morning period. */
|
|
1811
|
-
morningMessage?: string;
|
|
1812
|
-
/** Custom greeting message for the noon period. */
|
|
1813
|
-
noonMessage?: string;
|
|
1814
|
-
/** Custom greeting message for the afternoon period. */
|
|
1815
|
-
afternoonMessage?: string;
|
|
1816
|
-
/** Custom greeting message for the evening period. */
|
|
1817
|
-
eveningMessage?: string;
|
|
1818
|
-
/** Custom greeting message for the midnight period. */
|
|
1819
|
-
midnightMessage?: string;
|
|
1820
|
-
/** Default greeting message if no period matches. */
|
|
1821
|
-
defaultMessage?: string;
|
|
1822
|
-
}
|
|
1823
|
-
/** Time zone details object */
|
|
1824
|
-
type TimeZoneDetails = {
|
|
1825
|
-
/** IANA time zone identifier */tzIdentifier: $TimeZoneIdentifier; /** Long localized form (e.g., `'Pacific Standard Time'`, `'Nordamerikanische Westküsten-Normalzeit'`) */
|
|
1826
|
-
tzNameLong: Maybe<LooseLiteral<TimeZoneName>>; /** Long generic non-location format (e.g.: `'Pacific Time'`, `'Nordamerikanische Westküstenzeit'`) */
|
|
1827
|
-
tzNameLongGeneric: Maybe<LooseLiteral<TimeZoneName>>; /** Long localized GMT format, prefixed with `"GMT"` (e.g., `"GMT-08:00"`) */
|
|
1828
|
-
tzNameLongOffset: Maybe<LooseLiteral<$GMTOffset>>;
|
|
1829
|
-
};
|
|
1830
|
-
/** Name of time unit from `year` to `millisecond` */
|
|
1831
|
-
type TimeUnit = 'year' | 'month' | 'day' | 'week' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
1832
|
-
/** Name of time unit from `year` to `millisecond`, excluding `week` */
|
|
1833
|
-
type FromNowUnit = Exclude<TimeUnit, 'week'>;
|
|
1834
|
-
/** Conditional value for {@link TimeUnit} */
|
|
1835
|
-
type TimeUnitValue<Unit extends TimeUnit> = Unit extends 'month' ? NumberRange<1, 12> : Unit extends 'week' ? NumberRange<1, 53> : Unit extends 'day' ? NumberRange<1, 31> : Unit extends 'hour' ? Enumerate<24> : Unit extends 'minute' | 'second' ? Enumerate<60> : Unit extends 'millisecond' ? Milliseconds : number;
|
|
1836
|
-
/** Unit suffix for {@link Date} getter methods (e.g., `'FullYear'` in `'getFullYear'`, `'Month'` in `'getMonth'` etc.). */
|
|
1837
|
-
type $DateUnit = 'FullYear' | 'Month' | 'Day' | 'Date' | 'Hours' | 'Minutes' | 'Seconds' | 'Milliseconds';
|
|
1838
|
-
/** `BCP47` locale string or {@link Intl.Locale} object that contain one or more language or locale tags */
|
|
1839
|
-
type $LocalArguments = LooseLiteral<LocaleCode | Split<LocaleCode, '-'>[0]> | Intl.Locale;
|
|
1840
|
-
/** `BCP47` locale string, array of locale strings, {@link Intl.Locale} object, or array of {@link Intl.Locale} objects that contain one or more language or locale tags. */
|
|
1841
|
-
type LocalesArguments = $LocalArguments | $LocalArguments[];
|
|
1842
|
-
/** Locale calendars supported by {@link Intl} API */
|
|
1843
|
-
type LocaleCalendar = (typeof LOCALE_CALENDARS)[number];
|
|
1844
|
-
/** Locale numbering systems supported by {@link Intl} API */
|
|
1845
|
-
type NumberingSystem = (typeof LOCALE_NUMBERING_SYSTEMS)[number];
|
|
1846
|
-
//#endregion
|
|
1847
|
-
//#region src/types/chronos-specific.d.ts
|
|
1848
|
-
/**
|
|
1849
|
-
* * Timezone identifier type for `Chronos`
|
|
1850
|
-
*
|
|
1851
|
-
* - {@link $TimeZoneIdentifier} — e.g., `"Asia/Dhaka"`.
|
|
1852
|
-
* - {@link TimeZone} — e.g., `[ 'Asia/Calcutta', 'Asia/Colombo' ]`, used when multiple timezones share the same UTC offset such as `"UTC+05:30"`.
|
|
1853
|
-
* - {@link UTCOffset} — e.g., `"UTC+06:45"` or `"UTC+02:15"`, returned when no named timezone corresponds to a given offset.
|
|
1854
|
-
* - `'System'` — The current system timezone.
|
|
1855
|
-
*/
|
|
1856
|
-
type ChronosTimeZone = TimeZoneIdentifier | TimeZone | UTCOffset | 'System';
|
|
1857
|
-
/**
|
|
1858
|
-
* * Options for `Chronos` _static_ method `with()`
|
|
1859
|
-
*
|
|
1860
|
-
* @remarks Should provide at least one property, otherwise use the current date and time.
|
|
1861
|
-
*/
|
|
1862
|
-
type ChronosWithOptions = Partial<{
|
|
1863
|
-
/** The full year (e.g., 2025). Years 0–99 are interpreted as 1900–1999. */year: number; /** Month number from 1 (January) to 12 (December). */
|
|
1864
|
-
month: NumberRange<1, 12>; /** Day of the month, from 1 to 31. */
|
|
1865
|
-
date: NumberRange<1, 31>; /** Hour of the day, from 0 (midnight) to 23 (11 PM). */
|
|
1866
|
-
hour: Enumerate<24>; /** Minutes of the hour, from 0 to 59. */
|
|
1867
|
-
minute: Enumerate<60>; /** Seconds of the minute, from 0 to 59. */
|
|
1868
|
-
second: Enumerate<60>; /** Milliseconds of the second, from 0 to 999. */
|
|
1869
|
-
millisecond: Milliseconds;
|
|
1870
|
-
}>;
|
|
1871
|
-
/** Interface for accessing internal private properties in extended `Chronos` class */
|
|
1872
|
-
interface ChronosInternals {
|
|
1873
|
-
/**
|
|
1874
|
-
* * Access to `#withOrigin` private method.
|
|
1875
|
-
* * Creates a new `Chronos` instance with `origin` and other properties.
|
|
2104
|
+
* @param time - Time string to be formatted. Supported formats include:
|
|
2105
|
+
* - `HH:mm` → e.g., `'14:50'`
|
|
2106
|
+
* - `HH:mm:ss` → e.g., `'14:50:00'`
|
|
2107
|
+
* - `HH:mm:ss.SSS` → e.g., `'14:50:00.800'`
|
|
2108
|
+
* - `HH:mm+TimeZoneOffset(HH)` → e.g., `'14:50+06'`
|
|
2109
|
+
* - `HH:mm:ss+TimeZoneOffset(HH)` → e.g., `'14:50:00+06'`
|
|
2110
|
+
* - `HH:mm:ss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00+05:30'`
|
|
2111
|
+
* - `HH:mm:ss.SSS+TimeZoneOffset(HH)` → e.g., `'14:50:00.800+06'`
|
|
2112
|
+
* - `HH:mm:ss.SSS+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00.800+06:30'`
|
|
1876
2113
|
*
|
|
1877
|
-
*
|
|
1878
|
-
* @param origin Origin of the instance, the method name from where it was created.
|
|
1879
|
-
* @param offset Optional UTC offset in `UTC±HH:mm` format.
|
|
1880
|
-
* @param tzName Optional time zone name to set.
|
|
1881
|
-
* @param tzId Optional time zone identifier(s) to set.
|
|
1882
|
-
* @param tzTracker Optional tracker to identify the instance created by {@link https://chronos.nazmul-nhb.dev/docs/plugins/timezone-plugin#timezone timeZone} method.
|
|
1883
|
-
* @returns The `Chronos` instance with the specified origin and other properties.
|
|
1884
|
-
*/
|
|
1885
|
-
withOrigin<Tz extends ChronosTimeZone>(instance: Chronos, method: PluginMethods, offset?: UTCOffset, tzName?: LooseLiteral<TimeZoneName>, tzId?: TimeZoneId, tzTracker?: $TimeZoneIdentifier | TimeZone | UTCOffset): Chronos<Tz>;
|
|
1886
|
-
/**
|
|
1887
|
-
* * Access to `#toNewDate` private method
|
|
1888
|
-
* * Creates a new `Date` object from a `Chronos` input
|
|
1889
|
-
* @param instance - `Chronos` instance to operate on
|
|
1890
|
-
* @param value - Input value to convert (optional, uses current date if omitted)
|
|
1891
|
-
* @returns A new JavaScript `Date` object
|
|
1892
|
-
*/
|
|
1893
|
-
toNewDate(instance: Chronos, value?: ChronosInput): Date;
|
|
1894
|
-
/**
|
|
1895
|
-
* * Gets the internal `#date`, a readonly private property (core `Date` object)
|
|
1896
|
-
* @param instance - `Chronos` instance to access
|
|
1897
|
-
* @returns The core internal `Date` object
|
|
1898
|
-
*/
|
|
1899
|
-
internalDate(instance: Chronos): Date;
|
|
1900
|
-
/**
|
|
1901
|
-
* * Gets current UTC Offset internally stored as `#offset` private property
|
|
1902
|
-
* @param instance - `Chronos` instance to access
|
|
1903
|
-
* @returns The stored formatted UTC offset
|
|
1904
|
-
*/
|
|
1905
|
-
offset(instance: Chronos): UTCOffset;
|
|
1906
|
-
/** * Ensures the input is a `Chronos` instance, creating one if necessary. */
|
|
1907
|
-
cast<Tz extends ChronosTimeZone>(date: ChronosInput): Chronos<Tz>;
|
|
1908
|
-
}
|
|
1909
|
-
/** @internal Helper type to assign instance origin when creating new `Chronos` instance. */
|
|
1910
|
-
type WithoutOrigin = Omit<Chronos, '#ORIGIN' | 'origin'>;
|
|
1911
|
-
/** Alias for `typeof Chronos` */
|
|
1912
|
-
type $Chronos = typeof Chronos;
|
|
1913
|
-
/** * Instance methods that return `Chronos` instance */
|
|
1914
|
-
type $InstanceMethods = { [Method in keyof WithoutOrigin]: Chronos extends { [Instance in Method]: (...args: any[]) => Chronos } ? Method : never }[keyof WithoutOrigin];
|
|
1915
|
-
/** * Static methods that return `Chronos` instance */
|
|
1916
|
-
type $StaticMethods = { [Method in keyof $Chronos]: $Chronos extends { [Instance in Method]: (...args: any[]) => Chronos } ? Method : never }[keyof $Chronos];
|
|
1917
|
-
/** * Plugin methods that return `Chronos` instance */
|
|
1918
|
-
type $PluginMethods = 'round' | `timeZone` | 'nextWorkday' | 'nextWeekend' | 'previousWorkday' | 'previousWeekend';
|
|
1919
|
-
/** * Plugin methods that return `Chronos` instance + any custom name */
|
|
1920
|
-
type PluginMethods = LooseLiteral<$PluginMethods>;
|
|
1921
|
-
/** Both instance and static methods (including built-in plugin methods) in `Chronos` class that return `Chronos` instance. */
|
|
1922
|
-
type ChronosMethods = $InstanceMethods | $StaticMethods | $PluginMethods;
|
|
1923
|
-
/**
|
|
1924
|
-
* * Accepted Input type for `Chronos`
|
|
1925
|
-
*
|
|
1926
|
-
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
1927
|
-
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
1928
|
-
*/
|
|
1929
|
-
type ChronosInput = number | string | Date | Chronos;
|
|
1930
|
-
/** Properties required to reconstruct a `Chronos` instance. */
|
|
1931
|
-
interface ChronosProperties {
|
|
1932
|
-
/** The method or plugin name from which the instance was created. */
|
|
1933
|
-
origin: LooseLiteral<ChronosMethods>;
|
|
1934
|
-
/** The native date value, either as a `Date` object or a date string. */
|
|
1935
|
-
native: Date | string;
|
|
1936
|
-
/** The UTC offset in `UTC±HH:mm` format. */
|
|
1937
|
-
utcOffset: UTCOffset;
|
|
1938
|
-
/** The full time zone name (e.g., `"Pacific Standard Time"`). */
|
|
1939
|
-
timeZoneName: LooseLiteral<TimeZoneName>;
|
|
1940
|
-
/** The time zone identifier(s) associated with the instance (e.g., `"Asia/Dhaka"`). */
|
|
1941
|
-
timeZoneId: TimeZoneId;
|
|
1942
|
-
/** Optional tracker to identify the instance created by `timeZone` method. */
|
|
1943
|
-
$tzTracker?: $TimeZoneIdentifier | TimeZone | UTCOffset;
|
|
1944
|
-
}
|
|
1945
|
-
/** Iterable `Chronos` object properties */
|
|
1946
|
-
interface ChronosObject {
|
|
1947
|
-
/** Full year (e.g., 2025). */
|
|
1948
|
-
year: number;
|
|
1949
|
-
/** Month index starting from 0 (January = 0). */
|
|
1950
|
-
month: Enumerate<12>;
|
|
1951
|
-
/** ISO month number starting from 1 (January = 1). */
|
|
1952
|
-
isoMonth: NumberRange<1, 12>;
|
|
1953
|
-
/** Day of the month (1–31). */
|
|
1954
|
-
date: NumberRange<1, 31>;
|
|
1955
|
-
/** Day of the week index (0–6, Sunday = 0). */
|
|
1956
|
-
weekDay: Enumerate<7>;
|
|
1957
|
-
/** ISO day of the week number (1–7, Monday = 1). */
|
|
1958
|
-
isoWeekDay: NumberRange<1, 7>;
|
|
1959
|
-
/** Hour of the day (0–23). */
|
|
1960
|
-
hour: Enumerate<24>;
|
|
1961
|
-
/** Minute of the hour (0–59). */
|
|
1962
|
-
minute: Enumerate<60>;
|
|
1963
|
-
/** Second of the minute (0–59). */
|
|
1964
|
-
second: Enumerate<60>;
|
|
1965
|
-
/** Milliseconds within the second. */
|
|
1966
|
-
millisecond: Milliseconds;
|
|
1967
|
-
/** Timestamp in milliseconds since the Unix epoch. */
|
|
1968
|
-
timestamp: number;
|
|
1969
|
-
/** Unix timestamp in seconds since the epoch. */
|
|
1970
|
-
unix: number;
|
|
1971
|
-
}
|
|
1972
|
-
/** Common options for formatting and rounding dates */
|
|
1973
|
-
interface $CommonRangeOptions {
|
|
1974
|
-
/** - Output format: return ISO strings in `'local'` or `'utc'` format. Defaults to `'local'`. */
|
|
1975
|
-
format?: ISODateFormat;
|
|
1976
|
-
/** - Whether to round the dates in the range to the start of the day. Default is `false`. */
|
|
1977
|
-
roundDate?: boolean;
|
|
1978
|
-
}
|
|
1979
|
-
/** - Options to define a **fixed date range** using explicit `from` and `to` dates. */
|
|
1980
|
-
interface DateRangeOptions extends $CommonRangeOptions {
|
|
1981
|
-
/** - Start date of the range (inclusive). Defaults to **now** if not provided. */
|
|
1982
|
-
from?: ChronosInput;
|
|
1983
|
-
/** - End date of the range (inclusive). Defaults to **4 weeks from now** if not provided. */
|
|
1984
|
-
to?: ChronosInput;
|
|
1985
|
-
}
|
|
1986
|
-
/** - Options to define a **relative date range** starting from the current date. */
|
|
1987
|
-
interface RelativeRangeOptions extends $CommonRangeOptions {
|
|
1988
|
-
/**
|
|
1989
|
-
* The number of time units to move **forward from `now`**.
|
|
2114
|
+
* * *Input will default to today's date and assume local timezone if no offset is provided.*
|
|
1990
2115
|
*
|
|
1991
|
-
* -
|
|
1992
|
-
*
|
|
1993
|
-
* - Both `start` and `end` are included in the result.
|
|
1994
|
-
* - Controlled by the {@link unit} option.
|
|
1995
|
-
* - Defaults to `4`.
|
|
2116
|
+
* @param format - Format string accepted by `formatSafe()` method (`TimeParts`). Default: `hh:mm:ss a` → 02:33:36 pm.
|
|
2117
|
+
* @returns Formatted time string in local (System) time.
|
|
1996
2118
|
*/
|
|
1997
|
-
|
|
2119
|
+
formatTimePart(time: string, format?: TimeFormatToken): string;
|
|
1998
2120
|
/**
|
|
1999
|
-
*
|
|
2121
|
+
* * Returns ISO date strings for each occurrence of a weekday from today, spanning a relative time range.
|
|
2000
2122
|
*
|
|
2001
|
-
*
|
|
2002
|
-
* -
|
|
2003
|
-
*
|
|
2123
|
+
* @param day - The weekday to match (e.g., `'Wednesday'`, `'Sunday'`).
|
|
2124
|
+
* @param options - Relative range (e.g., 7 days, 4 weeks) and output format (local with timezone or utc).
|
|
2125
|
+
* @returns Array of ISO date strings in the specified format. Returns empty array if no matches in the time span.
|
|
2126
|
+
*
|
|
2127
|
+
* @example
|
|
2128
|
+
* Chronos.getDatesForDay('Wednesday', { span: 7, unit: 'day' });
|
|
2129
|
+
* //=> [ '2025-05-28T21:16:06.198+06:00', '2025-06-04T21:16:06.198+06:00' ]
|
|
2130
|
+
*
|
|
2131
|
+
* @example
|
|
2132
|
+
* Chronos.getDatesForDay('Wednesday', {
|
|
2133
|
+
* span: 7,
|
|
2134
|
+
* unit: 'day',
|
|
2135
|
+
* format: 'utc'
|
|
2136
|
+
* });
|
|
2137
|
+
* //=> [ '2025-05-28T15:17:10.812Z', '2025-06-04T15:17:10.812Z' ]
|
|
2004
2138
|
*/
|
|
2005
|
-
|
|
2006
|
-
}
|
|
2007
|
-
/** - Unified type that supports either a fixed or relative date range configuration. */
|
|
2008
|
-
type WeekdayOptions = RelativeRangeOptions | DateRangeOptions;
|
|
2009
|
-
/** Common options to either skip or keep days */
|
|
2010
|
-
interface $SkipOrKeepDays {
|
|
2139
|
+
getDatesForDay(day: WeekDay, options?: RelativeRangeOptions): ISODateTimeString<'utc' | 'local'>[];
|
|
2011
2140
|
/**
|
|
2012
|
-
*
|
|
2013
|
-
*
|
|
2014
|
-
* -
|
|
2141
|
+
* * Returns ISO date strings for each occurrence of a weekday between two fixed dates.
|
|
2142
|
+
*
|
|
2143
|
+
* @param day - The weekday to match (e.g., `'Monday'`, `'Friday'`).
|
|
2144
|
+
* @param options - Absolute date range (e.g. `'2025-06-30'`, ` new Date()`, `new Chronos()` etc.) and output format (local with timezone or utc).
|
|
2145
|
+
* @returns Array of ISO date strings in the specified format. Returns empty array if no matches in the range.
|
|
2015
2146
|
*
|
|
2016
2147
|
* @example
|
|
2017
|
-
*
|
|
2018
|
-
*
|
|
2148
|
+
* Chronos.getDatesForDay('Monday', {
|
|
2149
|
+
* from: '2025-05-28',
|
|
2150
|
+
* to: '2025-06-30',
|
|
2151
|
+
* format: 'local'
|
|
2152
|
+
* });
|
|
2153
|
+
* //=> [ '2025-01-06T...', '2025-01-13T...', ... ]
|
|
2019
2154
|
*/
|
|
2020
|
-
|
|
2155
|
+
getDatesForDay(day: WeekDay, options?: DateRangeOptions): ISODateTimeString<'utc' | 'local'>[];
|
|
2021
2156
|
/**
|
|
2022
|
-
*
|
|
2023
|
-
* - Accepts either weekday names (e.g., `'Monday'`, `'Wednesday'`) or numeric indices (0 for Sunday to 6 for Saturday).
|
|
2024
|
-
* - When provided, this overrides {@link skipDays} and includes only the specified days.
|
|
2157
|
+
* * Returns ISO date strings for each occurrence of a weekday.
|
|
2025
2158
|
*
|
|
2026
|
-
* @
|
|
2027
|
-
*
|
|
2028
|
-
*
|
|
2159
|
+
* @param day - The weekday to match (e.g., `'Wednesday'`, `'Sunday'`).
|
|
2160
|
+
* @param options - Relative range (e.g., 7 days, 4 weeks) or Absolute date range and output format.
|
|
2161
|
+
* @returns Array of ISO date strings in the specified format.
|
|
2029
2162
|
*/
|
|
2030
|
-
|
|
2031
|
-
}
|
|
2032
|
-
/** - Options to define a **fixed date range** using explicit `from` and `to` dates. */
|
|
2033
|
-
interface RangeWithDates extends DateRangeOptions, $SkipOrKeepDays {}
|
|
2034
|
-
/** - Options to define a **relative date range** starting from the current date. */
|
|
2035
|
-
interface RelativeDateRange extends RelativeRangeOptions, $SkipOrKeepDays {}
|
|
2036
|
-
/** - Unified type that supports either a fixed or relative date range configuration. */
|
|
2037
|
-
type DatesInRangeOptions = RangeWithDates | RelativeDateRange;
|
|
2038
|
-
//#endregion
|
|
2039
|
-
//#region src/types/chronos-plugins.d.ts
|
|
2040
|
-
/** * A plugin that augments the `Chronos` class with methods or properties. */
|
|
2041
|
-
type ChronosPlugin = (Chronos: $Chronos) => void;
|
|
2042
|
-
/** ISO date-based range (format: `MM-DD`) e.g. `01-14` for 'January 14' */
|
|
2043
|
-
type DateBoundary = {
|
|
2044
|
-
/** Start date in `MM-DD` format, e.g. `01-18` means 'January 18' */startDate: MonthDateString; /** End date in `MM-DD` format, e.g. `03-17` means 'March 17' */
|
|
2045
|
-
endDate: MonthDateString;
|
|
2046
|
-
};
|
|
2047
|
-
/** Inclusive month index-based range `0-11` (0 = January) */
|
|
2048
|
-
type MonthBoundary = {
|
|
2049
|
-
startMonth: Enumerate<12>;
|
|
2050
|
-
endMonth: Enumerate<12>;
|
|
2051
|
-
};
|
|
2052
|
-
/** Season definition for season configuration */
|
|
2053
|
-
interface SeasonDefinition {
|
|
2054
|
-
/** Name of the season */
|
|
2055
|
-
name: string;
|
|
2056
|
-
/** Inclusive date/month boundary of the season */
|
|
2057
|
-
boundary: MonthBoundary | DateBoundary;
|
|
2058
|
-
}
|
|
2059
|
-
/** Name of a predefined season preset */
|
|
2060
|
-
type SeasonPreset = keyof typeof SEASON_PRESETS;
|
|
2061
|
-
/** Options for configuring seasons */
|
|
2062
|
-
interface SeasonOptions {
|
|
2063
|
-
/** Custom season list to override or define seasons manually */
|
|
2064
|
-
seasons?: SeasonDefinition[];
|
|
2065
|
-
/** Predefined preset to use for season calculation */
|
|
2066
|
-
preset?: SeasonPreset;
|
|
2067
|
-
}
|
|
2068
|
-
interface $BusinessHourBaseOptions {
|
|
2069
|
-
/** - Optional starting hour of business time (0–23). Defaults to `9` (9 AM). */
|
|
2070
|
-
businessStartHour?: Enumerate<24>;
|
|
2071
|
-
/** - Optional ending hour of business time (0–23). Defaults to `17` (5 PM). */
|
|
2072
|
-
businessEndHour?: Enumerate<24>;
|
|
2073
|
-
}
|
|
2074
|
-
/** Options for configuring business hour with `weekStartsOn` and `weekendLength` */
|
|
2075
|
-
interface BusinessOptionsBasic extends $BusinessHourBaseOptions {
|
|
2076
|
-
/** - Optional day the week starts on (0–6). Default is `0` (Sunday). */
|
|
2077
|
-
weekStartsOn?: Enumerate<7>;
|
|
2078
|
-
/** - Optional weekend length (1-4). Default is `2`.*/
|
|
2079
|
-
weekendLength?: NumberRange<1, 4>;
|
|
2080
|
-
}
|
|
2081
|
-
/** Options for configuring business hour with `weekendDays` tuple */
|
|
2082
|
-
interface BusinessOptionsWeekends extends $BusinessHourBaseOptions {
|
|
2083
|
-
/** - Tuple of indices (0-6) of weekend days. Can pass only 1-4 elements. Default is `undefined`. */
|
|
2084
|
-
weekendDays?: RangeTuple<Enumerate<7>, 1, 4>;
|
|
2085
|
-
}
|
|
2086
|
-
/** Options for configuring business hour */
|
|
2087
|
-
type $BusinessHourOptions = BusinessOptionsBasic | BusinessOptionsWeekends;
|
|
2088
|
-
/** Names of standard Zodiac signs */
|
|
2089
|
-
type ZodiacSign = (typeof WESTERN_ZODIAC_SIGNS)[number][0];
|
|
2090
|
-
/** Presets for Zodiac Sign Configuration */
|
|
2091
|
-
type ZodiacPreset = keyof typeof ZODIAC_PRESETS;
|
|
2092
|
-
/** Shape of Zodiac signs array */
|
|
2093
|
-
type ZodiacArray<Sign extends string = ZodiacSign> = Array<[Sign, [NumberRange<1, 12>, NumberRange<1, 31>]] | Readonly<[Sign, Readonly<[NumberRange<1, 12>, NumberRange<1, 31>]>]>>;
|
|
2094
|
-
/** Zodiac metadata options */
|
|
2095
|
-
interface ZodiacMetaOptions<Sign extends string = ZodiacSign> {
|
|
2163
|
+
getDatesForDay(day: WeekDay, options?: WeekdayOptions): ISODateTimeString<'utc' | 'local'>[];
|
|
2096
2164
|
/**
|
|
2097
|
-
*
|
|
2098
|
-
*
|
|
2165
|
+
* * Returns earliest Chronos
|
|
2166
|
+
* @param dates Date inputs.
|
|
2099
2167
|
*/
|
|
2100
|
-
|
|
2101
|
-
/** Custom Zodiac date ranges, overrides {@link preset presets}. */
|
|
2102
|
-
custom?: ZodiacArray<Sign> | Readonly<ZodiacArray<Sign>>;
|
|
2103
|
-
}
|
|
2104
|
-
/** Options for configuring Zodiac sign getter */
|
|
2105
|
-
interface ZodiacOptions<Sign extends string = ZodiacSign> extends ZodiacMetaOptions<Sign> {
|
|
2106
|
-
/** - Optional birthdate in `MM-DD` format (`1`-based month). */
|
|
2107
|
-
birthDate?: MonthDateString;
|
|
2108
|
-
}
|
|
2109
|
-
/** Represents resolved metadata for a zodiac sign */
|
|
2110
|
-
interface ZodiacMeta<Sign extends string = ZodiacSign> {
|
|
2168
|
+
min(...dates: ChronosInput[]): Chronos<ChronosTimeZone>;
|
|
2111
2169
|
/**
|
|
2112
|
-
*
|
|
2170
|
+
* * Returns latest Chronos
|
|
2171
|
+
* @param dates Date inputs.
|
|
2172
|
+
*/
|
|
2173
|
+
max(...dates: ChronosInput[]): Chronos<ChronosTimeZone>;
|
|
2174
|
+
/**
|
|
2175
|
+
* * Checks if the year in the date string or year (from 0 - 9999) is a leap year.
|
|
2176
|
+
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
2177
|
+
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
2113
2178
|
*
|
|
2114
|
-
*
|
|
2115
|
-
*
|
|
2116
|
-
*
|
|
2179
|
+
* @description
|
|
2180
|
+
* This method accepts different types of date inputs and extracts the year to check if it's a leap year.
|
|
2181
|
+
* If the provided date is a `number`, it will be treated as a year (must be a valid year from 0 to 9999).
|
|
2182
|
+
* If the year is out of this range (negative or larger than 9999), it will be treated as a Unix timestamp.
|
|
2183
|
+
* If the provided date is a string or a `Date` object, it will be parsed and the year will be extracted.
|
|
2184
|
+
* If a `Chronos` instance is passed, the year will be directly accessed from the instance.
|
|
2185
|
+
*
|
|
2186
|
+
* @param date - A `number` (year or Unix timestamp), `string`, `Date`, or `Chronos` instance representing a date.
|
|
2187
|
+
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
2117
2188
|
*/
|
|
2118
|
-
|
|
2119
|
-
/**
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
/**
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
/**
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
/** Separator between units (default: `", "`) */
|
|
2160
|
-
separator?: string;
|
|
2161
|
-
/** Display mode: `"full"` (default) → "2 hours", `"short"` → "2h" */
|
|
2162
|
-
style?: 'full' | 'short';
|
|
2163
|
-
/** Whether to include zero values (default: `false`) */
|
|
2164
|
-
showZero?: boolean;
|
|
2189
|
+
isLeapYear(date: ChronosInput): boolean;
|
|
2190
|
+
/**
|
|
2191
|
+
* * Checks if the given value is a valid `Date` object.
|
|
2192
|
+
* - A value is considered valid if it is an instance of the built-in `Date` class.
|
|
2193
|
+
* - This does not check whether the date itself is valid (e.g., `new Date('invalid')`).
|
|
2194
|
+
* @param value - The value to test.
|
|
2195
|
+
* @returns `true` if the value is a valid Date object, otherwise `false`.
|
|
2196
|
+
*/
|
|
2197
|
+
isValidDate(value: unknown): value is Date;
|
|
2198
|
+
/**
|
|
2199
|
+
* * Checks if the given value is a valid date string.
|
|
2200
|
+
* - A value is considered a valid date string if it is a string and can be parsed by `Date.parse()`.
|
|
2201
|
+
* - This uses the native JavaScript date parser internally.
|
|
2202
|
+
* @param value - The value to test.
|
|
2203
|
+
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
2204
|
+
*/
|
|
2205
|
+
isDateString(value: unknown): value is string;
|
|
2206
|
+
/**
|
|
2207
|
+
* * Checks if the given value is an instance of `Chronos`.
|
|
2208
|
+
* - Useful for verifying Chronos objects in type guards or validations.
|
|
2209
|
+
* @param value - The value to test.
|
|
2210
|
+
* @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
|
|
2211
|
+
*/
|
|
2212
|
+
isValidChronos(value: unknown): value is Chronos<ChronosTimeZone>;
|
|
2213
|
+
/**
|
|
2214
|
+
* * Checks if the given value has the necessary properties to be reconstructed into a `Chronos` instance.
|
|
2215
|
+
* - Can be used for validating objects that may represent serialized `Chronos` data.
|
|
2216
|
+
* @param value - The value to check.
|
|
2217
|
+
* @returns `true` if the value has the required properties for reconstruction, otherwise `false`.
|
|
2218
|
+
*/
|
|
2219
|
+
isReconstructable(value: unknown): value is ChronosProperties;
|
|
2220
|
+
/**
|
|
2221
|
+
* * Reconstructs a `Chronos` instance from an object containing the necessary properties.
|
|
2222
|
+
* - The input object must have the properties defined in {@link ChronosProperties} interface.
|
|
2223
|
+
* - If the input is not reconstructable, an error is thrown.
|
|
2224
|
+
*
|
|
2225
|
+
* @param value - An object containing the properties required to reconstruct a `Chronos` instance.
|
|
2226
|
+
* @returns A new `Chronos` instance created from the provided properties.
|
|
2227
|
+
* @throws `TypeError` if the input value does not have the necessary properties for reconstruction.
|
|
2228
|
+
*/
|
|
2229
|
+
reconstruct(value: ChronosProperties): Chronos<ChronosTimeZone>;
|
|
2165
2230
|
}
|
|
2166
2231
|
//#endregion
|
|
2167
|
-
export { $
|
|
2232
|
+
export { $UTCOffset as $, BanglaDateOptions as $t, ChronosMethods as A, TimeZone as At, RelativeRangeOptions as B, WeekDay as Bt, ZodiacSign as C, LooseLiteral as Cn, NegativeUTCHour as Ct, $StaticMethods as D, RangeTuple as Dn, TimeUnit as Dt, $PluginMethods as E, Numeric as En, Quarter as Et, DateRangeOptions as F, TimeZoneName as Ft, $ISOTimeString as G, $BanglaYear as Gt, WithoutOrigin as H, chronos as Ht, DatesInRangeOptions as I, TimeZoneNameNative as It, $TZLabelKey as J, $BnMonthPadded as Jt, $LocalArguments as K, $BnDatePadded as Kt, PluginMethods as L, TimestampOptions as Lt, ChronosProperties as M, TimeZoneId as Mt, ChronosTimeZone as N, TimeZoneIdNative as Nt, ChronosInput as O, TimeUnitValue as Ot, ChronosWithOptions as P, TimeZoneIdentifier as Pt, $TimeZoneIdentifier as Q, BanglaDateObject as Qt, RangeWithDates as R, UTCMinute as Rt, ZodiacPreset as S, Enumerate as Sn, MonthString as St, $InstanceMethods as T, NumberRange as Tn, PositiveUTCHour as Tt, $DateUnit as U, $BanglaMonth as Ut, WeekdayOptions as V, Chronos as Vt, $GMTOffset as W, $BanglaMonthDate as Wt, $TimeUnitVar as X, BanglaDate as Xt, $TimeUnitKey as Y, $BnYearPadded as Yt, $TimeUnitVarMap as Z, BanglaDateFormat as Zt, TimeDuration as _, SecondToken as _n, LocaleCalendar as _t, BusinessOptionsBasic as a, BnCalendarConfig as an, ClockTime as at, ZodiacMetaOptions as b, TimeToken as bn, MonthDateString as bt, DateBoundary as c, DateFormatToken as cn, DateLike as ct, DurationKey as d, FormatToken as dn, FormatOptions as dt, BanglaDayName as en, $UnitAnyCase as et, DurationOptions as f, HourToken as fn, FromNowUnit as ft, SeasonPreset as g, SafeFormat as gn, ISODateTimeString as gt, SeasonOptions as h, MonthToken as hn, ISODateFormat as ht, AcademicYear as i, BanglaYear as in, ClockSecond as it, ChronosObject as j, TimeZoneDetails as jt, ChronosInternals as k, TimeWithUnit as kt, DayPart as l, DateToken as ln, DateString as lt, SeasonDefinition as m, MinuteToken as mn, HourMinutes as mt, $BusinessHourBaseOptions as n, BanglaMonthName as nn, ClockHour as nt, BusinessOptionsWeekends as o, BnCalendarVariant as on, DateArgs as ot, MonthBoundary as p, MSToken as pn, GreetingConfigs as pt, $NativeTzNameOrId as q, $BnEn as qt, $BusinessHourOptions as r, BanglaSeasonName as rn, ClockMinute as rt, ChronosPlugin as s, DateWithSeasonToken as sn, DateFormatOptions as st, ChronosStatics as t, BanglaMonth as tn, ChronosStaticKey as tt, DayPartConfig as u, DayToken as un, DateTimeFormatOptions as ut, ZodiacArray as v, TimeFormatToken as vn, LocalesArguments as vt, $Chronos as w, Maybe as wn, NumberingSystem as wt, ZodiacOptions as x, YearToken as xn, MonthName as xt, ZodiacMeta as y, TimeOnlyFormat as yn, Milliseconds as yt, RelativeDateRange as z, UTCOffset as zt };
|