nhb-toolbox 3.9.50 → 3.9.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/date/Chronos.d.ts +184 -88
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +240 -99
- package/dist/date/chronos-fn.d.ts +4 -2
- package/dist/date/chronos-fn.d.ts.map +1 -1
- package/dist/date/chronos-fn.js +4 -2
- package/dist/date/constants.d.ts +3 -1
- package/dist/date/constants.d.ts.map +1 -1
- package/dist/date/constants.js +9 -0
- package/dist/date/types.d.ts +17 -0
- package/dist/date/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/date/Chronos.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LocaleCode } from '../number/types';
|
|
2
2
|
import { ORIGIN } from './constants';
|
|
3
|
-
import type { ChronosInput, ChronosMethods, ChronosObject, FormatOptions, StrictFormat, TimeUnit, TimeZone, UTCOffSet } from './types';
|
|
3
|
+
import type { ChronosInput, ChronosMethods, ChronosObject, DayPart, DayPartConfig, FormatOptions, Quarter, StrictFormat, TimeUnit, TimeZone, UTCOffSet } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* * Creates a new immutable `Chronos` instance.
|
|
6
6
|
*
|
|
@@ -126,42 +126,34 @@ export declare class Chronos {
|
|
|
126
126
|
get unix(): number;
|
|
127
127
|
/** Gets the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
128
128
|
get timestamp(): number;
|
|
129
|
-
/** @
|
|
129
|
+
/** @instance Returns a debug-friendly string for `console.log` or `util.inspect`. */
|
|
130
130
|
inspect(): string;
|
|
131
|
-
/** @
|
|
131
|
+
/** @instance Clones and returns a new Chronos instance with the same date. */
|
|
132
132
|
clone(): Chronos;
|
|
133
|
-
/** @
|
|
133
|
+
/** @instance Enables JSON.stringify and console logging to show readable output. */
|
|
134
134
|
toJSON(): string;
|
|
135
|
-
/** @
|
|
135
|
+
/** @instance Enables arithmetic and comparison operations (e.g., +new Chronos()). */
|
|
136
136
|
valueOf(): number;
|
|
137
|
-
/** @
|
|
137
|
+
/** @instance Gets the native `Date` instance (read-only). */
|
|
138
138
|
toDate(): Date;
|
|
139
|
-
/** @
|
|
139
|
+
/** @instance Returns a string representation of a date. The format of the string depends on the locale. */
|
|
140
140
|
toString(): string;
|
|
141
|
-
/** @
|
|
141
|
+
/** @instance Returns ISO string with local time zone offset */
|
|
142
142
|
toLocalISOString(): string;
|
|
143
|
-
/** @
|
|
143
|
+
/** @instance Returns a date as a string value in ISO format. */
|
|
144
144
|
toISOString(): string;
|
|
145
145
|
/**
|
|
146
|
-
* @
|
|
146
|
+
* @instance Wrapper over native `toLocaleString`
|
|
147
147
|
* @description Converts a date and time to a string by using the current or specified locale.
|
|
148
148
|
*
|
|
149
149
|
* @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
|
|
150
150
|
* @param options An object that contains one or more properties that specify comparison options.
|
|
151
151
|
*/
|
|
152
152
|
toLocaleString(locale?: LocaleCode | Intl.Locale | (LocaleCode | Intl.Locale)[], options?: Intl.DateTimeFormatOptions): string;
|
|
153
|
-
/** @
|
|
153
|
+
/** @instance Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
154
154
|
getTimeStamp(): number;
|
|
155
155
|
/**
|
|
156
|
-
* @
|
|
157
|
-
* @description Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55`
|
|
158
|
-
*
|
|
159
|
-
* @param options - Configure format string and whether to format using utc offset.
|
|
160
|
-
* @returns Formatted date string in desired format.
|
|
161
|
-
*/
|
|
162
|
-
today(options?: FormatOptions): string;
|
|
163
|
-
/**
|
|
164
|
-
* @public @instance Formats the date into a custom string format (local time).
|
|
156
|
+
* @instance Formats the date into a custom string format (local time).
|
|
165
157
|
*
|
|
166
158
|
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
167
159
|
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`. Equivalent to `formatUTC()` method if set to `true`.
|
|
@@ -169,7 +161,7 @@ export declare class Chronos {
|
|
|
169
161
|
*/
|
|
170
162
|
format(format?: string, useUTC?: boolean): string;
|
|
171
163
|
/**
|
|
172
|
-
* @
|
|
164
|
+
* @instance Formats the date into a strict custom string format (local time).
|
|
173
165
|
* @description Select from `21,000+` pre-defined formats.
|
|
174
166
|
*
|
|
175
167
|
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55`).
|
|
@@ -178,94 +170,94 @@ export declare class Chronos {
|
|
|
178
170
|
*/
|
|
179
171
|
formatStrict(format?: StrictFormat, useUTC?: boolean): string;
|
|
180
172
|
/**
|
|
181
|
-
* @
|
|
173
|
+
* @instance Formats the date into a custom string format (UTC time).
|
|
182
174
|
*
|
|
183
175
|
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
184
176
|
* @returns Formatted date string in desired format (UTC time).
|
|
185
177
|
*/
|
|
186
178
|
formatUTC(format?: string): string;
|
|
187
179
|
/**
|
|
188
|
-
* @
|
|
180
|
+
* @instance Adds seconds and returns a new immutable instance.
|
|
189
181
|
* @param seconds - Number of seconds to add.
|
|
190
182
|
* @returns A new `Chronos` instance with the updated date.
|
|
191
183
|
*/
|
|
192
184
|
addSeconds(seconds: number): Chronos;
|
|
193
185
|
/**
|
|
194
|
-
* @
|
|
186
|
+
* @instance Adds minutes and returns a new immutable instance.
|
|
195
187
|
* @param minutes - Number of minutes to add.
|
|
196
188
|
* @returns A new `Chronos` instance with the updated date.
|
|
197
189
|
*/
|
|
198
190
|
addMinutes(minutes: number): Chronos;
|
|
199
191
|
/**
|
|
200
|
-
* @
|
|
192
|
+
* @instance Adds hours and returns a new immutable instance.
|
|
201
193
|
* @param hours - Number of hours to add.
|
|
202
194
|
* @returns A new `Chronos` instance with the updated date.
|
|
203
195
|
*/
|
|
204
196
|
addHours(hours: number): Chronos;
|
|
205
197
|
/**
|
|
206
|
-
* @
|
|
198
|
+
* @instance Adds days and returns a new immutable instance.
|
|
207
199
|
* @param days - Number of days to add.
|
|
208
200
|
* @returns A new `Chronos` instance with the updated date.
|
|
209
201
|
*/
|
|
210
202
|
addDays(days: number): Chronos;
|
|
211
203
|
/**
|
|
212
|
-
* @
|
|
204
|
+
* @instance Adds weeks and returns a new immutable instance.
|
|
213
205
|
* @param weeks - Number of weeks to add.
|
|
214
206
|
* @returns A new `Chronos` instance with the updated date.
|
|
215
207
|
*/
|
|
216
208
|
addWeeks(weeks: number): Chronos;
|
|
217
209
|
/**
|
|
218
|
-
* @
|
|
210
|
+
* @instance Adds months and returns a new immutable instance.
|
|
219
211
|
* @param months - Number of months to add.
|
|
220
212
|
* @returns A new `Chronos` instance with the updated date.
|
|
221
213
|
*/
|
|
222
214
|
addMonths(months: number): Chronos;
|
|
223
215
|
/**
|
|
224
|
-
* @
|
|
216
|
+
* @instance Adds years and returns a new immutable instance.
|
|
225
217
|
* @param years - Number of years to add.
|
|
226
218
|
* @returns A new `Chronos` instance with the updated date.
|
|
227
219
|
*/
|
|
228
220
|
addYears(years: number): Chronos;
|
|
229
221
|
/**
|
|
230
|
-
* @
|
|
222
|
+
* @instance Create a new instance of `Chronos` in the specified timezone.
|
|
231
223
|
*
|
|
232
224
|
* @param zone - Standard timezone abbreviation (e.g., 'IST', 'UTC', 'EST') or UTC Offset in `UTC-01:30` format.
|
|
233
225
|
* @returns A new instance of `Chronos` with time in the given timezone. Invalid input sets time-zone to `UTC`.
|
|
234
226
|
*/
|
|
235
227
|
timeZone(zone: TimeZone | UTCOffSet): Chronos;
|
|
236
228
|
/**
|
|
237
|
-
* @
|
|
229
|
+
* @instance Checks if the year is a leap year.
|
|
238
230
|
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
239
231
|
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
240
232
|
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
241
233
|
*/
|
|
242
234
|
isLeapYear(): boolean;
|
|
243
|
-
/** @
|
|
235
|
+
/** @instance Checks if the current date is today. */
|
|
244
236
|
isToday(): boolean;
|
|
245
|
-
/** @
|
|
237
|
+
/** @instance Checks if the current date is tomorrow. */
|
|
246
238
|
isTomorrow(): boolean;
|
|
247
|
-
/** @
|
|
239
|
+
/** @instance Checks if the current date is yesterday. */
|
|
248
240
|
isYesterday(): boolean;
|
|
249
241
|
/**
|
|
250
|
-
* @
|
|
242
|
+
* @instance Checks if another date is the same as this one in a specific unit.
|
|
251
243
|
* @param other The other date to compare.
|
|
252
244
|
* @param unit The unit to compare.
|
|
253
245
|
*/
|
|
254
246
|
isSame(other: ChronosInput, unit: TimeUnit): boolean;
|
|
255
247
|
/**
|
|
256
|
-
* @
|
|
248
|
+
* @instance Checks if this date is before another date in a specific unit.
|
|
257
249
|
* @param other The other date to compare.
|
|
258
250
|
* @param unit The unit to compare.
|
|
259
251
|
*/
|
|
260
252
|
isBefore(other: ChronosInput, unit: TimeUnit): boolean;
|
|
261
253
|
/**
|
|
262
|
-
* @
|
|
254
|
+
* @instance Checks if this date is after another date in a specific unit.
|
|
263
255
|
* @param other The other date to compare.
|
|
264
256
|
* @param unit The unit to compare.
|
|
265
257
|
*/
|
|
266
258
|
isAfter(other: ChronosInput, unit: TimeUnit): boolean;
|
|
267
259
|
/**
|
|
268
|
-
* @
|
|
260
|
+
* @instance Checks if the current date is between the given start and end dates.
|
|
269
261
|
*
|
|
270
262
|
* @param start - The start of the range.
|
|
271
263
|
* @param end - The end of the range.
|
|
@@ -278,10 +270,37 @@ export declare class Chronos {
|
|
|
278
270
|
* @returns `true` if the current date is within the specified range based on the `inclusive` mode.
|
|
279
271
|
*/
|
|
280
272
|
isBetween(start: ChronosInput, end: ChronosInput, inclusive?: '[]' | '[)' | '(]' | '()'): boolean;
|
|
281
|
-
/**
|
|
273
|
+
/**
|
|
274
|
+
* @instance Checks if the current date is a palindrome in either padded or non-padded format.
|
|
275
|
+
*
|
|
276
|
+
* @remarks
|
|
277
|
+
* A palindrome date reads the same forward and backward, excluding delimiters.
|
|
278
|
+
* This method checks both zero-padded (`MM-DD`) and non-padded (`M-D`) formats for flexibility.
|
|
279
|
+
*
|
|
280
|
+
* Examples of palindromes:
|
|
281
|
+
* - `'2020-02-02'` → `'20200202'` ✅
|
|
282
|
+
* - `'2112-11-12'` → `'21121112'` ❌
|
|
283
|
+
* - `'2011-01-11'` (from `'YY-M-D'`) → `'11111'` ✅
|
|
284
|
+
* - `'2011-01-11'` (from `'YYYY-M-D'`) → `'11111'` ❌
|
|
285
|
+
*
|
|
286
|
+
* @param shortYear - If `true`, uses `'YY-MM-DD'` and `'YY-M-D'` formats.
|
|
287
|
+
* If `false`, uses `'YYYY-MM-DD'` and `'YYYY-M-D'` formats.
|
|
288
|
+
* Defaults to `false`.
|
|
289
|
+
*
|
|
290
|
+
* @returns `true` if either padded or non-padded formatted date is a palindrome, otherwise `false`.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* new Chronos('2020-02-02').isPalindromeDate(); // true
|
|
294
|
+
* new Chronos('2112-11-12').isPalindromeDate(); // false
|
|
295
|
+
* new Chronos('2011-1-11').isPalindromeDate(); // false (from '2011111')
|
|
296
|
+
* new Chronos('2011-1-11').isPalindromeDate(true); // true (from '11111')
|
|
297
|
+
* new Chronos('2024-04-11').isPalindromeDate(); // false
|
|
298
|
+
*/
|
|
299
|
+
isPalindromeDate(shortYear?: boolean): boolean;
|
|
300
|
+
/** @instance Checks if currently in DST */
|
|
282
301
|
isDST(): boolean;
|
|
283
302
|
/**
|
|
284
|
-
* @
|
|
303
|
+
* @instance Returns full time difference from now (or a specified time) down to a given level.
|
|
285
304
|
*
|
|
286
305
|
* @param level Determines the smallest unit to include in the output (e.g., 'minute' will show up to minutes, ignoring seconds). Defaults to `minute`.
|
|
287
306
|
* @param withSuffixPrefix If `true`, adds `"in"` or `"ago"` depending on whether the time is in the future or past. Defaults to `true`.
|
|
@@ -290,19 +309,53 @@ export declare class Chronos {
|
|
|
290
309
|
*/
|
|
291
310
|
fromNow(level?: Exclude<TimeUnit, 'millisecond'>, withSuffixPrefix?: boolean, time?: ChronosInput): string;
|
|
292
311
|
/**
|
|
293
|
-
*
|
|
312
|
+
* * Returns the part of day (`'midnight', 'lateNight', 'night', 'morning', 'afternoon', 'evening'`) based on the current hour.
|
|
313
|
+
*
|
|
314
|
+
* *Supports both normal and wraparound (overnight) ranges.*
|
|
315
|
+
*
|
|
316
|
+
* @param config - Optional custom hour ranges for each part of day.
|
|
317
|
+
* Each range must be a tuple of strings as `[startHour, endHour]` in 24-hour format (e.g., `['06', '11']`).
|
|
318
|
+
* Supports wraparound ranges like `['22', '04']` that cross midnight.
|
|
319
|
+
*
|
|
320
|
+
* **Default Ranges:**
|
|
321
|
+
* - night: ['21', '23']
|
|
322
|
+
* - midnight: ['00', '01']
|
|
323
|
+
* - lateNight: ['02', '04']
|
|
324
|
+
* - morning: ['05', '11']
|
|
325
|
+
* - afternoon: ['12', '16']
|
|
326
|
+
* - evening: ['17', '20']
|
|
327
|
+
*
|
|
328
|
+
* @returns The current part of the day as a string.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* chronosInstance.getPartOfDay(); // e.g., 'morning'
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* // Example with custom ranges
|
|
335
|
+
* chronosInstance.getPartOfDay({
|
|
336
|
+
* night: ['22', '04'],
|
|
337
|
+
* morning: ['05', '11'],
|
|
338
|
+
* afternoon: ['12', '16'],
|
|
339
|
+
* evening: ['17', '21'],
|
|
340
|
+
* lateNight: ['01', '03'],
|
|
341
|
+
* midnight: ['00', '00'],
|
|
342
|
+
* });
|
|
343
|
+
*/
|
|
344
|
+
getPartOfDay(config?: Partial<DayPartConfig>): DayPart;
|
|
345
|
+
/**
|
|
346
|
+
* @instance Returns the number of full years between the input date and now.
|
|
294
347
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
295
348
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
296
349
|
*/
|
|
297
350
|
getRelativeYear(time?: ChronosInput): number;
|
|
298
351
|
/**
|
|
299
|
-
* @
|
|
352
|
+
* @instance Returns the number of full months between the input date and now.
|
|
300
353
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
301
354
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
302
355
|
*/
|
|
303
356
|
getRelativeMonth(time?: ChronosInput): number;
|
|
304
357
|
/**
|
|
305
|
-
* @
|
|
358
|
+
* @instance Determines if the given date is today, tomorrow, yesterday or any relative day.
|
|
306
359
|
* @param date - The date to compare (Date object).
|
|
307
360
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
308
361
|
* @returns
|
|
@@ -313,37 +366,37 @@ export declare class Chronos {
|
|
|
313
366
|
*/
|
|
314
367
|
getRelativeDay(time?: ChronosInput): number;
|
|
315
368
|
/**
|
|
316
|
-
* @
|
|
369
|
+
* @instance Determines how many full weeks apart the input date is from the `Chronos` instance.
|
|
317
370
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
318
371
|
* @returns Difference in weeks; negative if past, positive if future.
|
|
319
372
|
*/
|
|
320
373
|
getRelativeWeek(time?: ChronosInput): number;
|
|
321
374
|
/**
|
|
322
|
-
* @
|
|
375
|
+
* @instance Returns the number of full hours between the input date and now.
|
|
323
376
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
324
377
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
325
378
|
*/
|
|
326
379
|
getRelativeHour(time?: ChronosInput): number;
|
|
327
380
|
/**
|
|
328
|
-
* @
|
|
381
|
+
* @instance Returns the number of full minutes between the input date and now.
|
|
329
382
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
330
383
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
331
384
|
*/
|
|
332
385
|
getRelativeMinute(time?: ChronosInput): number;
|
|
333
386
|
/**
|
|
334
|
-
* @
|
|
387
|
+
* @instance Returns the number of full seconds between the input date and now.
|
|
335
388
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
336
389
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
337
390
|
*/
|
|
338
391
|
getRelativeSecond(time?: ChronosInput): number;
|
|
339
392
|
/**
|
|
340
|
-
* @
|
|
393
|
+
* @instance Returns the number of milliseconds between the input date and now.
|
|
341
394
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
342
395
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
343
396
|
*/
|
|
344
397
|
getRelativeMilliSecond(time?: ChronosInput): number;
|
|
345
398
|
/**
|
|
346
|
-
* @
|
|
399
|
+
* @instance Compares the stored date with now, returning the difference in the specified unit.
|
|
347
400
|
*
|
|
348
401
|
* @param unit The time unit to compare by. Defaults to 'minute'.
|
|
349
402
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
@@ -351,53 +404,53 @@ export declare class Chronos {
|
|
|
351
404
|
*/
|
|
352
405
|
compare(unit?: TimeUnit, time?: ChronosInput): number;
|
|
353
406
|
/**
|
|
354
|
-
* @
|
|
407
|
+
* @instance Returns a new Chronos instance at the start of a given unit.
|
|
355
408
|
* @param unit The unit to reset (e.g., year, month, day).
|
|
356
409
|
*/
|
|
357
410
|
startOf(unit: TimeUnit): Chronos;
|
|
358
411
|
/**
|
|
359
|
-
* @
|
|
412
|
+
* @instance Returns a new Chronos instance at the end of a given unit.
|
|
360
413
|
* @param unit The unit to adjust (e.g., year, month, day).
|
|
361
414
|
*/
|
|
362
415
|
endOf(unit: TimeUnit): Chronos;
|
|
363
416
|
/**
|
|
364
|
-
* @
|
|
417
|
+
* @instance Returns a new Chronos instance with the specified unit added.
|
|
365
418
|
* @param amount The amount to add (can be negative).
|
|
366
419
|
* @param unit The time unit to add.
|
|
367
420
|
*/
|
|
368
421
|
add(amount: number, unit: TimeUnit): Chronos;
|
|
369
422
|
/**
|
|
370
|
-
* @
|
|
423
|
+
* @instance Returns a new Chronos instance with the specified unit subtracted.
|
|
371
424
|
* @param amount The amount to subtract (can be negative).
|
|
372
425
|
* @param unit The time unit to add.
|
|
373
426
|
*/
|
|
374
427
|
subtract(amount: number, unit: TimeUnit): Chronos;
|
|
375
428
|
/**
|
|
376
|
-
* @
|
|
429
|
+
* @instance Gets the value of a specific time unit from the date.
|
|
377
430
|
* @param unit The unit to retrieve.
|
|
378
431
|
*/
|
|
379
432
|
get(unit: TimeUnit): number;
|
|
380
433
|
/**
|
|
381
|
-
* @
|
|
434
|
+
* @instance Returns a new Chronos instance with the specified unit set to the given value.
|
|
382
435
|
* @param unit The unit to modify.
|
|
383
436
|
* @param value The value to set for the unit.
|
|
384
437
|
*/
|
|
385
438
|
set(unit: TimeUnit, value: number): Chronos;
|
|
386
439
|
/**
|
|
387
|
-
* @
|
|
440
|
+
* @instance Returns the difference between this and another date in the given unit.
|
|
388
441
|
* @param other The other date to compare.
|
|
389
442
|
* @param unit The unit in which to return the difference.
|
|
390
443
|
*/
|
|
391
444
|
diff(other: ChronosInput, unit: TimeUnit): number;
|
|
392
445
|
/**
|
|
393
|
-
* @
|
|
446
|
+
* @instance Returns a human-readable relative calendar time like "Today at 3:00 PM"
|
|
394
447
|
* @param baseDate Optional base date to compare with.
|
|
395
448
|
*/
|
|
396
449
|
calendar(baseDate?: ChronosInput): string;
|
|
397
|
-
/** @
|
|
450
|
+
/** @instance Returns a short human-readable string like "2h ago", "in 5m" */
|
|
398
451
|
fromNowShort(): string;
|
|
399
452
|
/**
|
|
400
|
-
* @
|
|
453
|
+
* @instance Sets the date to the Monday of the specified ISO week number within the current year.
|
|
401
454
|
* This method assumes ISO week logic, where week 1 is the week containing January 4th.
|
|
402
455
|
*
|
|
403
456
|
* @param week The ISO week number (1–53) to set the date to.
|
|
@@ -405,41 +458,59 @@ export declare class Chronos {
|
|
|
405
458
|
*/
|
|
406
459
|
setWeek(week: number): Chronos;
|
|
407
460
|
/**
|
|
408
|
-
* @
|
|
461
|
+
* @instance Calculates the ISO week number of the year.
|
|
409
462
|
* @returns Week number (1-53).
|
|
410
463
|
*/
|
|
411
464
|
getWeek(): number;
|
|
412
|
-
/** @
|
|
465
|
+
/** @instance Returns ISO week year */
|
|
413
466
|
getWeekYear(): number;
|
|
414
|
-
/** @
|
|
467
|
+
/** @instance Returns day of year (1 - 366) */
|
|
415
468
|
getDayOfYear(): number;
|
|
416
|
-
/** @
|
|
469
|
+
/** @instance Returns number of days in current month */
|
|
417
470
|
daysInMonth(): number;
|
|
418
|
-
/** @
|
|
471
|
+
/** @instance Converts to object with all date unit parts */
|
|
419
472
|
toObject(): ChronosObject;
|
|
420
|
-
/** @
|
|
473
|
+
/** @instance Converts to array with all date unit parts */
|
|
421
474
|
toArray(): any[];
|
|
422
|
-
/** @public @instance Returns offset like +06:00 */
|
|
423
|
-
getUTCOffset(): string;
|
|
424
|
-
/** @public @instance Returns new Chronos instance in UTC */
|
|
425
|
-
toUTC(): Chronos;
|
|
426
|
-
/** @public @instance Returns new Chronos instance in local time */
|
|
427
|
-
toLocal(): Chronos;
|
|
428
475
|
/**
|
|
429
|
-
* @
|
|
430
|
-
*
|
|
431
|
-
* @param options - Configure format string and whether to format using utc offset.
|
|
432
|
-
* @returns Formatted date string in desired format.
|
|
476
|
+
* @instance Returns the academic year based on a typical start in July and end in June.
|
|
477
|
+
* @returns The academic year in format `YYYY-YYYY`.
|
|
433
478
|
*/
|
|
434
|
-
|
|
479
|
+
toAcademicYear(): `${number}-${number}`;
|
|
435
480
|
/**
|
|
436
|
-
* @
|
|
437
|
-
*
|
|
438
|
-
* @
|
|
481
|
+
* @instance Returns the **calendar quarter** (1 to 4) of the current date.
|
|
482
|
+
*
|
|
483
|
+
* @remarks
|
|
484
|
+
* A calendar year is divided into four quarters:
|
|
485
|
+
*
|
|
486
|
+
* - `Q1`: January to March
|
|
487
|
+
* - `Q2`: April to June
|
|
488
|
+
* - `Q3`: July to September
|
|
489
|
+
* - `Q4`: October to December
|
|
490
|
+
*
|
|
491
|
+
* This method strictly uses the **calendar year**. For fiscal quarters, use `toFiscalQuarter()` instead.
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* new Chronos('2025-02-14').toQuarter(); // 1
|
|
495
|
+
* new Chronos('2025-08-09').toQuarter(); // 3
|
|
496
|
+
*
|
|
497
|
+
* @returns The calendar quarter number (1–4).
|
|
439
498
|
*/
|
|
440
|
-
|
|
499
|
+
toQuarter(): Quarter;
|
|
500
|
+
/**
|
|
501
|
+
* @instance Returns the fiscal quarter based on custom fiscal year start (defaults to July).
|
|
502
|
+
* @param startMonth - The fiscal year start month (1-12), default is July (7).
|
|
503
|
+
* @returns The fiscal quarter (1-4).
|
|
504
|
+
*/
|
|
505
|
+
toFiscalQuarter(startMonth?: number): Quarter;
|
|
506
|
+
/** @instance Returns offset like +06:00 */
|
|
507
|
+
getUTCOffset(): string;
|
|
508
|
+
/** @instance Returns new Chronos instance in UTC */
|
|
509
|
+
toUTC(): Chronos;
|
|
510
|
+
/** @instance Returns new Chronos instance in local time */
|
|
511
|
+
toLocal(): Chronos;
|
|
441
512
|
/**
|
|
442
|
-
* @
|
|
513
|
+
* @static Parses a date string with a given format (partial support)
|
|
443
514
|
*
|
|
444
515
|
* * **Supported format tokens**:
|
|
445
516
|
* - `YYYY`: Full year (e.g., 2023)
|
|
@@ -463,22 +534,47 @@ export declare class Chronos {
|
|
|
463
534
|
*/
|
|
464
535
|
static parse(dateStr: string, format: string): Chronos;
|
|
465
536
|
/**
|
|
466
|
-
* @
|
|
537
|
+
* @static Returns the current date and time in a specified format in local time.
|
|
538
|
+
* * Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55`
|
|
539
|
+
* @param options - Configure format string and whether to format using utc offset.
|
|
540
|
+
* @returns Formatted date string in desired format.
|
|
541
|
+
*/
|
|
542
|
+
static today(options?: FormatOptions): string;
|
|
543
|
+
/**
|
|
544
|
+
* @static Returns a new `Chronos` instance representing yesterday's date.
|
|
545
|
+
*
|
|
546
|
+
* @returns A `Chronos` instance for the previous calendar day.
|
|
547
|
+
*/
|
|
548
|
+
static yesterday(): Chronos;
|
|
549
|
+
/**
|
|
550
|
+
* @static Returns a new `Chronos` instance representing tomorrow's date.
|
|
551
|
+
*
|
|
552
|
+
* @returns A `Chronos` instance for the next calendar day.
|
|
553
|
+
*/
|
|
554
|
+
static tomorrow(): Chronos;
|
|
555
|
+
/**
|
|
556
|
+
* @static Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
|
|
557
|
+
* * It basically calls `Date.now()`.
|
|
558
|
+
* @returns The number of milliseconds elapsed since the Unix epoch.
|
|
559
|
+
*/
|
|
560
|
+
static now(): number;
|
|
561
|
+
/**
|
|
562
|
+
* @static Creates UTC Chronos
|
|
467
563
|
* @param dateLike Date input to create utc time.
|
|
468
564
|
*/
|
|
469
565
|
static utc(dateLike: ChronosInput): Chronos;
|
|
470
566
|
/**
|
|
471
|
-
* @
|
|
567
|
+
* @static Returns earliest Chronos
|
|
472
568
|
* @param dates Date inputs.
|
|
473
569
|
*/
|
|
474
570
|
static min(...dates: ChronosInput[]): Chronos;
|
|
475
571
|
/**
|
|
476
|
-
* @
|
|
572
|
+
* @static Returns latest Chronos
|
|
477
573
|
* @param dates Date inputs.
|
|
478
574
|
*/
|
|
479
575
|
static max(...dates: ChronosInput[]): Chronos;
|
|
480
576
|
/**
|
|
481
|
-
* @
|
|
577
|
+
* @static Checks if the year in the date string or year (from 0 - 9999) is a leap year.
|
|
482
578
|
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
483
579
|
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
484
580
|
*
|
|
@@ -494,7 +590,7 @@ export declare class Chronos {
|
|
|
494
590
|
*/
|
|
495
591
|
static isLeapYear(date: ChronosInput): boolean;
|
|
496
592
|
/**
|
|
497
|
-
* @
|
|
593
|
+
* @static Checks if the given value is a valid `Date` object.
|
|
498
594
|
* - A value is considered valid if it is an instance of the built-in `Date` class.
|
|
499
595
|
* - This does not check whether the date itself is valid (e.g., `new Date('invalid')`).
|
|
500
596
|
* @param value - The value to test.
|
|
@@ -502,7 +598,7 @@ export declare class Chronos {
|
|
|
502
598
|
*/
|
|
503
599
|
static isValidDate(value: unknown): value is Date;
|
|
504
600
|
/**
|
|
505
|
-
* @
|
|
601
|
+
* @static Checks if the given value is a valid date string.
|
|
506
602
|
* - A value is considered a valid date string if it is a string and can be parsed by `Date.parse()`.
|
|
507
603
|
* - This uses the native JavaScript date parser internally.
|
|
508
604
|
* @param value - The value to test.
|
|
@@ -510,7 +606,7 @@ export declare class Chronos {
|
|
|
510
606
|
*/
|
|
511
607
|
static isDateString(value: unknown): value is string;
|
|
512
608
|
/**
|
|
513
|
-
* @
|
|
609
|
+
* @static Checks if the given value is an instance of `Chronos`.
|
|
514
610
|
* - Useful for verifying Chronos objects in type guards or validations.
|
|
515
611
|
* @param value - The value to test.
|
|
516
612
|
* @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlD,OAAO,EAIN,MAAM,EAIN,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAEX,YAAY,EACZ,cAAc,EACd,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