nhb-toolbox 3.9.39 → 3.9.60
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/colors/Color.d.ts +38 -24
- package/dist/colors/Color.d.ts.map +1 -1
- package/dist/colors/Color.js +19 -17
- package/dist/date/Chronos.d.ts +233 -116
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +225 -154
- package/dist/date/chronos-fn.d.ts +24 -32
- package/dist/date/chronos-fn.d.ts.map +1 -1
- package/dist/date/chronos-fn.js +61 -6
- 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 +101 -12
- package/dist/date/types.d.ts.map +1 -1
- package/dist/date/utils.js +1 -1
- package/package.json +1 -1
package/dist/date/Chronos.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { isString } from '../guards/primitives';
|
|
2
2
|
import { getOrdinal } from '../number/utilities';
|
|
3
3
|
import { formatUnitWithPlural } from '../string/convert';
|
|
4
|
-
import { DAYS, MONTHS, ORIGIN, sortedFormats, TIME_ZONE_LABELS, TIME_ZONES, } from './constants';
|
|
4
|
+
import { DAYS, DEFAULT_RANGES, MONTHS, ORIGIN, sortedFormats, TIME_ZONE_LABELS, TIME_ZONES, } from './constants';
|
|
5
5
|
import { isLeapYear, isValidUTCOffSet } from './guards';
|
|
6
6
|
import { extractMinutesFromUTC, formatUTCOffset } from './utils';
|
|
7
|
+
/**
|
|
8
|
+
* * Creates a new immutable `Chronos` instance.
|
|
9
|
+
*
|
|
10
|
+
* @param value - A date value (`number`, `string`, `Date`, or `Chronos` object).
|
|
11
|
+
* - If a string is provided, it should be in a format that can be parsed by the Date constructor.
|
|
12
|
+
* - If a number is provided, it should be a timestamp (milliseconds since the Unix epoch).
|
|
13
|
+
* - If a Date object is provided, it will be used as is.
|
|
14
|
+
* - If a Chronos object is provided, it will be converted to a Date object.
|
|
15
|
+
*
|
|
16
|
+
* **It also accepts number values as following:**
|
|
17
|
+
* - **`year, month, date, hours, minutes, seconds, milliseconds`**: Individual components of a date-time to construct a `Chronos` instance.
|
|
18
|
+
* - **`year`**: A number representing the year. If the year is between 0 and 99, it will be assumed to be the year 1900 + the provided year.
|
|
19
|
+
* - **`month`**: A number between 1 and 12 representing the month (1 for January, 12 for December). It is adjusted internally to a 0-based index (0 for January, 11 for December).
|
|
20
|
+
* - **`date`**: A number between 1 and 31 representing the day of the month.
|
|
21
|
+
* - **`hours`**: A number between 0 and 23 representing the hour of the day.
|
|
22
|
+
* - **`minutes`**: A number between 0 and 59 representing the minutes past the hour.
|
|
23
|
+
* - **`seconds`**: A number between 0 and 59 representing the seconds past the minute.
|
|
24
|
+
* - **`milliseconds`**: A number between 0 and 999 representing the milliseconds past the second.
|
|
25
|
+
*
|
|
26
|
+
* @returns Instance of `Chronos` with all methods and properties.
|
|
27
|
+
*/
|
|
7
28
|
export class Chronos {
|
|
8
29
|
#date;
|
|
9
30
|
#offset;
|
|
@@ -11,15 +32,25 @@ export class Chronos {
|
|
|
11
32
|
/**
|
|
12
33
|
* * Creates a new immutable `Chronos` instance.
|
|
13
34
|
*
|
|
14
|
-
* @param
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
35
|
+
* @param valueOrYear The value in number, string, Date or Chronos format or the full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year.
|
|
36
|
+
* @param month The month as a number between 1 and 12 (January to December).
|
|
37
|
+
* @param date The date as a number between 1 and 31.
|
|
38
|
+
* @param hours Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour.
|
|
39
|
+
* @param minutes Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes.
|
|
40
|
+
* @param seconds Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds.
|
|
41
|
+
* @param ms A number from 0 to 999 that specifies the milliseconds.
|
|
42
|
+
*
|
|
43
|
+
* @returns Instance of `Chronos` with all methods and properties.
|
|
19
44
|
*/
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
22
|
-
|
|
45
|
+
constructor(valueOrYear, month, date, hours, minutes, seconds, ms) {
|
|
46
|
+
let newDate;
|
|
47
|
+
if (typeof valueOrYear === 'number' && typeof month === 'number') {
|
|
48
|
+
newDate = new Date(valueOrYear, month - 1, date ?? 1, hours ?? 0, minutes ?? 0, seconds ?? 0, ms ?? 0);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
newDate = this.#toNewDate(valueOrYear);
|
|
52
|
+
}
|
|
53
|
+
this.#date = newDate;
|
|
23
54
|
this[ORIGIN] = 'root';
|
|
24
55
|
this.#offset = `UTC${this.getUTCOffset()}`;
|
|
25
56
|
}
|
|
@@ -86,20 +117,6 @@ export class Chronos {
|
|
|
86
117
|
return this.#toLocalISOString();
|
|
87
118
|
}
|
|
88
119
|
}
|
|
89
|
-
/**
|
|
90
|
-
* @private @instance Method to tag origin of the `Chronos` instance.
|
|
91
|
-
*
|
|
92
|
-
* @param origin Origin of the instance, the method name from where it was created.
|
|
93
|
-
* @param offset Optional UTC offset in `UTC+12:00` format.
|
|
94
|
-
* @returns The `Chronos` instance with the specified origin.
|
|
95
|
-
*/
|
|
96
|
-
#withOrigin(origin, offset) {
|
|
97
|
-
const instance = new Chronos(this.#date);
|
|
98
|
-
instance[ORIGIN] = origin;
|
|
99
|
-
if (offset)
|
|
100
|
-
instance.#offset = offset;
|
|
101
|
-
return instance;
|
|
102
|
-
}
|
|
103
120
|
/**
|
|
104
121
|
* @private @instance Method to create native `Date` instance from date-like data types.
|
|
105
122
|
* @param value The value to convert into `Date`.
|
|
@@ -115,6 +132,20 @@ export class Chronos {
|
|
|
115
132
|
}
|
|
116
133
|
return date;
|
|
117
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* @private @instance Method to tag origin of the `Chronos` instance.
|
|
137
|
+
*
|
|
138
|
+
* @param origin Origin of the instance, the method name from where it was created.
|
|
139
|
+
* @param offset Optional UTC offset in `UTC+12:00` format.
|
|
140
|
+
* @returns The `Chronos` instance with the specified origin.
|
|
141
|
+
*/
|
|
142
|
+
#withOrigin(origin, offset) {
|
|
143
|
+
const instance = new Chronos(this.#date);
|
|
144
|
+
instance[ORIGIN] = origin;
|
|
145
|
+
if (offset)
|
|
146
|
+
instance.#offset = offset;
|
|
147
|
+
return instance;
|
|
148
|
+
}
|
|
118
149
|
/**
|
|
119
150
|
* @private @instance Formats the current `Chronos` date using the specified template.
|
|
120
151
|
*
|
|
@@ -237,23 +268,27 @@ export class Chronos {
|
|
|
237
268
|
get unix() {
|
|
238
269
|
return this.#date.getTime();
|
|
239
270
|
}
|
|
240
|
-
/**
|
|
271
|
+
/** Gets the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
272
|
+
get timestamp() {
|
|
273
|
+
return this.#date.getTime();
|
|
274
|
+
}
|
|
275
|
+
/** @instance Returns a debug-friendly string for `console.log` or `util.inspect`. */
|
|
241
276
|
inspect() {
|
|
242
277
|
return `[Chronos ${this.toLocalISOString()}]`;
|
|
243
278
|
}
|
|
244
|
-
/** @
|
|
279
|
+
/** @instance Clones and returns a new Chronos instance with the same date. */
|
|
245
280
|
clone() {
|
|
246
281
|
return new Chronos(this.#date).#withOrigin(this[ORIGIN]);
|
|
247
282
|
}
|
|
248
|
-
/** @
|
|
283
|
+
/** @instance Enables JSON.stringify and console logging to show readable output. */
|
|
249
284
|
toJSON() {
|
|
250
285
|
return this.toLocalISOString();
|
|
251
286
|
}
|
|
252
|
-
/** @
|
|
287
|
+
/** @instance Enables arithmetic and comparison operations (e.g., +new Chronos()). */
|
|
253
288
|
valueOf() {
|
|
254
289
|
return this.getTimeStamp();
|
|
255
290
|
}
|
|
256
|
-
/** @
|
|
291
|
+
/** @instance Gets the native `Date` instance (read-only). */
|
|
257
292
|
toDate() {
|
|
258
293
|
switch (this[ORIGIN]) {
|
|
259
294
|
case 'toUTC':
|
|
@@ -266,7 +301,7 @@ export class Chronos {
|
|
|
266
301
|
return new Date(this.#date);
|
|
267
302
|
}
|
|
268
303
|
}
|
|
269
|
-
/** @
|
|
304
|
+
/** @instance Returns a string representation of a date. The format of the string depends on the locale. */
|
|
270
305
|
toString() {
|
|
271
306
|
switch (this[ORIGIN]) {
|
|
272
307
|
case 'timeZone': {
|
|
@@ -286,7 +321,7 @@ export class Chronos {
|
|
|
286
321
|
return this.#date.toString();
|
|
287
322
|
}
|
|
288
323
|
}
|
|
289
|
-
/** @
|
|
324
|
+
/** @instance Returns ISO string with local time zone offset */
|
|
290
325
|
toLocalISOString() {
|
|
291
326
|
switch (this[ORIGIN]) {
|
|
292
327
|
case 'timeZone':
|
|
@@ -300,7 +335,7 @@ export class Chronos {
|
|
|
300
335
|
return this.#toLocalISOString();
|
|
301
336
|
}
|
|
302
337
|
}
|
|
303
|
-
/** @
|
|
338
|
+
/** @instance Returns a date as a string value in ISO format. */
|
|
304
339
|
toISOString() {
|
|
305
340
|
switch (this[ORIGIN]) {
|
|
306
341
|
case 'timeZone':
|
|
@@ -313,7 +348,7 @@ export class Chronos {
|
|
|
313
348
|
}
|
|
314
349
|
}
|
|
315
350
|
/**
|
|
316
|
-
* @
|
|
351
|
+
* @instance Wrapper over native `toLocaleString`
|
|
317
352
|
* @description Converts a date and time to a string by using the current or specified locale.
|
|
318
353
|
*
|
|
319
354
|
* @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.
|
|
@@ -322,24 +357,12 @@ export class Chronos {
|
|
|
322
357
|
toLocaleString(locale, options) {
|
|
323
358
|
return this.#date.toLocaleString(locale, options);
|
|
324
359
|
}
|
|
325
|
-
/** @
|
|
360
|
+
/** @instance Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
326
361
|
getTimeStamp() {
|
|
327
362
|
return this.#date.getTime();
|
|
328
363
|
}
|
|
329
364
|
/**
|
|
330
|
-
* @
|
|
331
|
-
* @description Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
332
|
-
*
|
|
333
|
-
* @param options - Configure format string and whether to format using utc offset.
|
|
334
|
-
* @returns Formatted date string in desired format.
|
|
335
|
-
*/
|
|
336
|
-
today(options) {
|
|
337
|
-
const { format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false } = options || {};
|
|
338
|
-
const today = new Date();
|
|
339
|
-
return new Chronos(today).#format(format, useUTC);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* @public @instance Formats the date into a custom string format (local time).
|
|
365
|
+
* @instance Formats the date into a custom string format (local time).
|
|
343
366
|
*
|
|
344
367
|
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
345
368
|
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`. Equivalent to `formatUTC()` method if set to `true`.
|
|
@@ -349,7 +372,7 @@ export class Chronos {
|
|
|
349
372
|
return this.#format(format, useUTC);
|
|
350
373
|
}
|
|
351
374
|
/**
|
|
352
|
-
* @
|
|
375
|
+
* @instance Formats the date into a strict custom string format (local time).
|
|
353
376
|
* @description Select from `21,000+` pre-defined formats.
|
|
354
377
|
*
|
|
355
378
|
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55`).
|
|
@@ -360,7 +383,7 @@ export class Chronos {
|
|
|
360
383
|
return this.#format(format, useUTC);
|
|
361
384
|
}
|
|
362
385
|
/**
|
|
363
|
-
* @
|
|
386
|
+
* @instance Formats the date into a custom string format (UTC time).
|
|
364
387
|
*
|
|
365
388
|
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
366
389
|
* @returns Formatted date string in desired format (UTC time).
|
|
@@ -375,7 +398,7 @@ export class Chronos {
|
|
|
375
398
|
}
|
|
376
399
|
}
|
|
377
400
|
/**
|
|
378
|
-
* @
|
|
401
|
+
* @instance Adds seconds and returns a new immutable instance.
|
|
379
402
|
* @param seconds - Number of seconds to add.
|
|
380
403
|
* @returns A new `Chronos` instance with the updated date.
|
|
381
404
|
*/
|
|
@@ -385,7 +408,7 @@ export class Chronos {
|
|
|
385
408
|
return new Chronos(newDate).#withOrigin('addSeconds');
|
|
386
409
|
}
|
|
387
410
|
/**
|
|
388
|
-
* @
|
|
411
|
+
* @instance Adds minutes and returns a new immutable instance.
|
|
389
412
|
* @param minutes - Number of minutes to add.
|
|
390
413
|
* @returns A new `Chronos` instance with the updated date.
|
|
391
414
|
*/
|
|
@@ -395,7 +418,7 @@ export class Chronos {
|
|
|
395
418
|
return new Chronos(newDate).#withOrigin('addMinutes');
|
|
396
419
|
}
|
|
397
420
|
/**
|
|
398
|
-
* @
|
|
421
|
+
* @instance Adds hours and returns a new immutable instance.
|
|
399
422
|
* @param hours - Number of hours to add.
|
|
400
423
|
* @returns A new `Chronos` instance with the updated date.
|
|
401
424
|
*/
|
|
@@ -405,7 +428,7 @@ export class Chronos {
|
|
|
405
428
|
return new Chronos(newDate).#withOrigin('addHours');
|
|
406
429
|
}
|
|
407
430
|
/**
|
|
408
|
-
* @
|
|
431
|
+
* @instance Adds days and returns a new immutable instance.
|
|
409
432
|
* @param days - Number of days to add.
|
|
410
433
|
* @returns A new `Chronos` instance with the updated date.
|
|
411
434
|
*/
|
|
@@ -415,7 +438,7 @@ export class Chronos {
|
|
|
415
438
|
return new Chronos(newDate).#withOrigin('addDays');
|
|
416
439
|
}
|
|
417
440
|
/**
|
|
418
|
-
* @
|
|
441
|
+
* @instance Adds weeks and returns a new immutable instance.
|
|
419
442
|
* @param weeks - Number of weeks to add.
|
|
420
443
|
* @returns A new `Chronos` instance with the updated date.
|
|
421
444
|
*/
|
|
@@ -425,7 +448,7 @@ export class Chronos {
|
|
|
425
448
|
return new Chronos(newDate).#withOrigin('addWeeks');
|
|
426
449
|
}
|
|
427
450
|
/**
|
|
428
|
-
* @
|
|
451
|
+
* @instance Adds months and returns a new immutable instance.
|
|
429
452
|
* @param months - Number of months to add.
|
|
430
453
|
* @returns A new `Chronos` instance with the updated date.
|
|
431
454
|
*/
|
|
@@ -435,7 +458,7 @@ export class Chronos {
|
|
|
435
458
|
return new Chronos(newDate).#withOrigin('addMonths');
|
|
436
459
|
}
|
|
437
460
|
/**
|
|
438
|
-
* @
|
|
461
|
+
* @instance Adds years and returns a new immutable instance.
|
|
439
462
|
* @param years - Number of years to add.
|
|
440
463
|
* @returns A new `Chronos` instance with the updated date.
|
|
441
464
|
*/
|
|
@@ -445,7 +468,7 @@ export class Chronos {
|
|
|
445
468
|
return new Chronos(newDate).#withOrigin('addYears');
|
|
446
469
|
}
|
|
447
470
|
/**
|
|
448
|
-
* @
|
|
471
|
+
* @instance Create a new instance of `Chronos` in the specified timezone.
|
|
449
472
|
*
|
|
450
473
|
* @param zone - Standard timezone abbreviation (e.g., 'IST', 'UTC', 'EST') or UTC Offset in `UTC-01:30` format.
|
|
451
474
|
* @returns A new instance of `Chronos` with time in the given timezone. Invalid input sets time-zone to `UTC`.
|
|
@@ -466,7 +489,7 @@ export class Chronos {
|
|
|
466
489
|
return new Chronos(adjusted).#withOrigin('timeZone', stringOffset);
|
|
467
490
|
}
|
|
468
491
|
/**
|
|
469
|
-
* @
|
|
492
|
+
* @instance Checks if the year is a leap year.
|
|
470
493
|
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
471
494
|
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
472
495
|
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
@@ -475,20 +498,20 @@ export class Chronos {
|
|
|
475
498
|
const year = this.#date.getFullYear();
|
|
476
499
|
return isLeapYear(year);
|
|
477
500
|
}
|
|
478
|
-
/** @
|
|
501
|
+
/** @instance Checks if the current date is today. */
|
|
479
502
|
isToday() {
|
|
480
503
|
return this.getRelativeDay() === 0;
|
|
481
504
|
}
|
|
482
|
-
/** @
|
|
505
|
+
/** @instance Checks if the current date is tomorrow. */
|
|
483
506
|
isTomorrow() {
|
|
484
507
|
return this.getRelativeDay() === 1;
|
|
485
508
|
}
|
|
486
|
-
/** @
|
|
509
|
+
/** @instance Checks if the current date is yesterday. */
|
|
487
510
|
isYesterday() {
|
|
488
511
|
return this.getRelativeDay() === -1;
|
|
489
512
|
}
|
|
490
513
|
/**
|
|
491
|
-
* @
|
|
514
|
+
* @instance Checks if another date is the same as this one in a specific unit.
|
|
492
515
|
* @param other The other date to compare.
|
|
493
516
|
* @param unit The unit to compare.
|
|
494
517
|
*/
|
|
@@ -498,7 +521,7 @@ export class Chronos {
|
|
|
498
521
|
time.startOf(unit).toDate().getTime());
|
|
499
522
|
}
|
|
500
523
|
/**
|
|
501
|
-
* @
|
|
524
|
+
* @instance Checks if this date is before another date in a specific unit.
|
|
502
525
|
* @param other The other date to compare.
|
|
503
526
|
* @param unit The unit to compare.
|
|
504
527
|
*/
|
|
@@ -508,7 +531,7 @@ export class Chronos {
|
|
|
508
531
|
time.startOf(unit).toDate().getTime());
|
|
509
532
|
}
|
|
510
533
|
/**
|
|
511
|
-
* @
|
|
534
|
+
* @instance Checks if this date is after another date in a specific unit.
|
|
512
535
|
* @param other The other date to compare.
|
|
513
536
|
* @param unit The unit to compare.
|
|
514
537
|
*/
|
|
@@ -518,7 +541,7 @@ export class Chronos {
|
|
|
518
541
|
time.startOf(unit).toDate().getTime());
|
|
519
542
|
}
|
|
520
543
|
/**
|
|
521
|
-
* @
|
|
544
|
+
* @instance Checks if the current date is between the given start and end dates.
|
|
522
545
|
*
|
|
523
546
|
* @param start - The start of the range.
|
|
524
547
|
* @param end - The end of the range.
|
|
@@ -545,7 +568,7 @@ export class Chronos {
|
|
|
545
568
|
return t > s && t < e;
|
|
546
569
|
}
|
|
547
570
|
}
|
|
548
|
-
/** @
|
|
571
|
+
/** @instance Checks if currently in DST */
|
|
549
572
|
isDST() {
|
|
550
573
|
const jan = new Date(this.year, 0, 1);
|
|
551
574
|
const jul = new Date(this.year, 6, 1);
|
|
@@ -553,7 +576,7 @@ export class Chronos {
|
|
|
553
576
|
this.#date.getTimezoneOffset());
|
|
554
577
|
}
|
|
555
578
|
/**
|
|
556
|
-
* @
|
|
579
|
+
* @instance Returns full time difference from now (or a specified time) down to a given level.
|
|
557
580
|
*
|
|
558
581
|
* @param level Determines the smallest unit to include in the output (e.g., 'minute' will show up to minutes, ignoring seconds). Defaults to `minute`.
|
|
559
582
|
* @param withSuffixPrefix If `true`, adds `"in"` or `"ago"` depending on whether the time is in the future or past. Defaults to `true`.
|
|
@@ -645,7 +668,63 @@ export class Chronos {
|
|
|
645
668
|
return `${prefix}${parts.join(' ')}${suffix}`;
|
|
646
669
|
}
|
|
647
670
|
/**
|
|
648
|
-
*
|
|
671
|
+
* * Returns the part of day (`'midnight', 'lateNight', 'night', 'morning', 'afternoon', 'evening'`) based on the current hour.
|
|
672
|
+
*
|
|
673
|
+
* *Supports both normal and wraparound (overnight) ranges.*
|
|
674
|
+
*
|
|
675
|
+
* @param config - Optional custom hour ranges for each part of day.
|
|
676
|
+
* Each range must be a tuple of strings as `[startHour, endHour]` in 24-hour format (e.g., `['06', '11']`).
|
|
677
|
+
* Supports wraparound ranges like `['22', '04']` that cross midnight.
|
|
678
|
+
*
|
|
679
|
+
* **Default Ranges:**
|
|
680
|
+
* - night: ['21', '23']
|
|
681
|
+
* - midnight: ['00', '01']
|
|
682
|
+
* - lateNight: ['02', '04']
|
|
683
|
+
* - morning: ['05', '11']
|
|
684
|
+
* - afternoon: ['12', '16']
|
|
685
|
+
* - evening: ['17', '20']
|
|
686
|
+
*
|
|
687
|
+
* @returns The current part of the day as a string.
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* chronosInstance.getPartOfDay(); // e.g., 'morning'
|
|
691
|
+
*
|
|
692
|
+
* @example
|
|
693
|
+
* // Example with custom ranges
|
|
694
|
+
* chronosInstance.getPartOfDay({
|
|
695
|
+
* night: ['22', '04'],
|
|
696
|
+
* morning: ['05', '11'],
|
|
697
|
+
* afternoon: ['12', '16'],
|
|
698
|
+
* evening: ['17', '21'],
|
|
699
|
+
* lateNight: ['01', '03'],
|
|
700
|
+
* midnight: ['00', '00'],
|
|
701
|
+
* });
|
|
702
|
+
*/
|
|
703
|
+
getPartOfDay(config) {
|
|
704
|
+
const hour = this.#date.getHours();
|
|
705
|
+
const ranges = {
|
|
706
|
+
...DEFAULT_RANGES,
|
|
707
|
+
...config,
|
|
708
|
+
};
|
|
709
|
+
for (const [part, [start, end]] of Object.entries(ranges)) {
|
|
710
|
+
const from = Number(start);
|
|
711
|
+
const to = Number(end);
|
|
712
|
+
if (from <= to) {
|
|
713
|
+
if (hour >= from && hour <= to) {
|
|
714
|
+
return part;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
// Wraparound logic (e.g., 20 to 04 means 20–23 OR 00–04)
|
|
719
|
+
if (hour >= from || hour <= to) {
|
|
720
|
+
return part;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return 'night';
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* @instance Returns the number of full years between the input date and now.
|
|
649
728
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
650
729
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
651
730
|
*/
|
|
@@ -661,7 +740,7 @@ export class Chronos {
|
|
|
661
740
|
return years;
|
|
662
741
|
}
|
|
663
742
|
/**
|
|
664
|
-
* @
|
|
743
|
+
* @instance Returns the number of full months between the input date and now.
|
|
665
744
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
666
745
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
667
746
|
*/
|
|
@@ -676,7 +755,7 @@ export class Chronos {
|
|
|
676
755
|
return months;
|
|
677
756
|
}
|
|
678
757
|
/**
|
|
679
|
-
* @
|
|
758
|
+
* @instance Determines if the given date is today, tomorrow, yesterday or any relative day.
|
|
680
759
|
* @param date - The date to compare (Date object).
|
|
681
760
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
682
761
|
* @returns
|
|
@@ -697,7 +776,7 @@ export class Chronos {
|
|
|
697
776
|
return diffDays;
|
|
698
777
|
}
|
|
699
778
|
/**
|
|
700
|
-
* @
|
|
779
|
+
* @instance Determines how many full weeks apart the input date is from the `Chronos` instance.
|
|
701
780
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
702
781
|
* @returns Difference in weeks; negative if past, positive if future.
|
|
703
782
|
*/
|
|
@@ -706,7 +785,7 @@ export class Chronos {
|
|
|
706
785
|
return Math.floor(relativeDays / 7);
|
|
707
786
|
}
|
|
708
787
|
/**
|
|
709
|
-
* @
|
|
788
|
+
* @instance Returns the number of full hours between the input date and now.
|
|
710
789
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
711
790
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
712
791
|
*/
|
|
@@ -715,7 +794,7 @@ export class Chronos {
|
|
|
715
794
|
return Math.floor(diff / (1000 * 60 * 60));
|
|
716
795
|
}
|
|
717
796
|
/**
|
|
718
|
-
* @
|
|
797
|
+
* @instance Returns the number of full minutes between the input date and now.
|
|
719
798
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
720
799
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
721
800
|
*/
|
|
@@ -724,7 +803,7 @@ export class Chronos {
|
|
|
724
803
|
return Math.floor(diff / (1000 * 60));
|
|
725
804
|
}
|
|
726
805
|
/**
|
|
727
|
-
* @
|
|
806
|
+
* @instance Returns the number of full seconds between the input date and now.
|
|
728
807
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
729
808
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
730
809
|
*/
|
|
@@ -733,7 +812,7 @@ export class Chronos {
|
|
|
733
812
|
return Math.floor(diff / 1000);
|
|
734
813
|
}
|
|
735
814
|
/**
|
|
736
|
-
* @
|
|
815
|
+
* @instance Returns the number of milliseconds between the input date and now.
|
|
737
816
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
738
817
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
739
818
|
*/
|
|
@@ -741,7 +820,7 @@ export class Chronos {
|
|
|
741
820
|
return this.#date.getTime() - this.#toNewDate(time).getTime();
|
|
742
821
|
}
|
|
743
822
|
/**
|
|
744
|
-
* @
|
|
823
|
+
* @instance Compares the stored date with now, returning the difference in the specified unit.
|
|
745
824
|
*
|
|
746
825
|
* @param unit The time unit to compare by. Defaults to 'minute'.
|
|
747
826
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
@@ -770,7 +849,7 @@ export class Chronos {
|
|
|
770
849
|
}
|
|
771
850
|
}
|
|
772
851
|
/**
|
|
773
|
-
* @
|
|
852
|
+
* @instance Returns a new Chronos instance at the start of a given unit.
|
|
774
853
|
* @param unit The unit to reset (e.g., year, month, day).
|
|
775
854
|
*/
|
|
776
855
|
startOf(unit) {
|
|
@@ -809,7 +888,7 @@ export class Chronos {
|
|
|
809
888
|
return new Chronos(d).#withOrigin('startOf');
|
|
810
889
|
}
|
|
811
890
|
/**
|
|
812
|
-
* @
|
|
891
|
+
* @instance Returns a new Chronos instance at the end of a given unit.
|
|
813
892
|
* @param unit The unit to adjust (e.g., year, month, day).
|
|
814
893
|
*/
|
|
815
894
|
endOf(unit) {
|
|
@@ -819,7 +898,7 @@ export class Chronos {
|
|
|
819
898
|
.#withOrigin('endOf');
|
|
820
899
|
}
|
|
821
900
|
/**
|
|
822
|
-
* @
|
|
901
|
+
* @instance Returns a new Chronos instance with the specified unit added.
|
|
823
902
|
* @param amount The amount to add (can be negative).
|
|
824
903
|
* @param unit The time unit to add.
|
|
825
904
|
*/
|
|
@@ -854,7 +933,7 @@ export class Chronos {
|
|
|
854
933
|
return new Chronos(d).#withOrigin('add');
|
|
855
934
|
}
|
|
856
935
|
/**
|
|
857
|
-
* @
|
|
936
|
+
* @instance Returns a new Chronos instance with the specified unit subtracted.
|
|
858
937
|
* @param amount The amount to subtract (can be negative).
|
|
859
938
|
* @param unit The time unit to add.
|
|
860
939
|
*/
|
|
@@ -862,7 +941,7 @@ export class Chronos {
|
|
|
862
941
|
return this.add(-amount, unit).#withOrigin('subtract');
|
|
863
942
|
}
|
|
864
943
|
/**
|
|
865
|
-
* @
|
|
944
|
+
* @instance Gets the value of a specific time unit from the date.
|
|
866
945
|
* @param unit The unit to retrieve.
|
|
867
946
|
*/
|
|
868
947
|
get(unit) {
|
|
@@ -886,7 +965,7 @@ export class Chronos {
|
|
|
886
965
|
}
|
|
887
966
|
}
|
|
888
967
|
/**
|
|
889
|
-
* @
|
|
968
|
+
* @instance Returns a new Chronos instance with the specified unit set to the given value.
|
|
890
969
|
* @param unit The unit to modify.
|
|
891
970
|
* @param value The value to set for the unit.
|
|
892
971
|
*/
|
|
@@ -920,7 +999,7 @@ export class Chronos {
|
|
|
920
999
|
return new Chronos(d).#withOrigin('set');
|
|
921
1000
|
}
|
|
922
1001
|
/**
|
|
923
|
-
* @
|
|
1002
|
+
* @instance Returns the difference between this and another date in the given unit.
|
|
924
1003
|
* @param other The other date to compare.
|
|
925
1004
|
* @param unit The unit in which to return the difference.
|
|
926
1005
|
*/
|
|
@@ -948,7 +1027,7 @@ export class Chronos {
|
|
|
948
1027
|
}
|
|
949
1028
|
}
|
|
950
1029
|
/**
|
|
951
|
-
* @
|
|
1030
|
+
* @instance Returns a human-readable relative calendar time like "Today at 3:00 PM"
|
|
952
1031
|
* @param baseDate Optional base date to compare with.
|
|
953
1032
|
*/
|
|
954
1033
|
calendar(baseDate) {
|
|
@@ -975,7 +1054,7 @@ export class Chronos {
|
|
|
975
1054
|
minute: '2-digit',
|
|
976
1055
|
});
|
|
977
1056
|
}
|
|
978
|
-
/** @
|
|
1057
|
+
/** @instance Returns a short human-readable string like "2h ago", "in 5m" */
|
|
979
1058
|
fromNowShort() {
|
|
980
1059
|
const now = new Chronos();
|
|
981
1060
|
const diffInSeconds = this.diff(now, 'second');
|
|
@@ -1002,7 +1081,7 @@ export class Chronos {
|
|
|
1002
1081
|
}
|
|
1003
1082
|
}
|
|
1004
1083
|
/**
|
|
1005
|
-
* @
|
|
1084
|
+
* @instance Sets the date to the Monday of the specified ISO week number within the current year.
|
|
1006
1085
|
* This method assumes ISO week logic, where week 1 is the week containing January 4th.
|
|
1007
1086
|
*
|
|
1008
1087
|
* @param week The ISO week number (1–53) to set the date to.
|
|
@@ -1021,27 +1100,8 @@ export class Chronos {
|
|
|
1021
1100
|
d.setDate(weekStart.getDate());
|
|
1022
1101
|
return new Chronos(d).#withOrigin('setWeek');
|
|
1023
1102
|
}
|
|
1024
|
-
// /**
|
|
1025
|
-
// * @public @instance Sets the date to the Monday of the specified ISO week number and year.
|
|
1026
|
-
// * @param week ISO week number (1–53)
|
|
1027
|
-
// * @param isoYear Optional ISO week year. Defaults to the current ISO week year.
|
|
1028
|
-
// * @returns New Chronos instance set to the start of the specified ISO week.
|
|
1029
|
-
// */
|
|
1030
|
-
// setISOWeek(week: number, isoYear?: number): Chronos {
|
|
1031
|
-
// // ❗ Use calendar year instead of ISO week year unless explicitly provided
|
|
1032
|
-
// const targetISOYear = isoYear ?? this.#date.getFullYear();
|
|
1033
|
-
// const jan4 = new Date(Date.UTC(targetISOYear, 0, 4));
|
|
1034
|
-
// const dayOfWeek = jan4.getUTCDay();
|
|
1035
|
-
// const offset = (dayOfWeek + 6) % 7;
|
|
1036
|
-
// const firstISOWeekStart = new Date(jan4);
|
|
1037
|
-
// firstISOWeekStart.setUTCDate(jan4.getUTCDate() - offset);
|
|
1038
|
-
// firstISOWeekStart.setUTCDate(
|
|
1039
|
-
// firstISOWeekStart.getUTCDate() + (week - 1) * 7,
|
|
1040
|
-
// );
|
|
1041
|
-
// return new Chronos(firstISOWeekStart).#withOrigin('setISOWeek');
|
|
1042
|
-
// }
|
|
1043
1103
|
/**
|
|
1044
|
-
* @
|
|
1104
|
+
* @instance Calculates the ISO week number of the year.
|
|
1045
1105
|
* @returns Week number (1-53).
|
|
1046
1106
|
*/
|
|
1047
1107
|
getWeek() {
|
|
@@ -1053,78 +1113,50 @@ export class Chronos {
|
|
|
1053
1113
|
const week = target.diff(firstThursday, 'week');
|
|
1054
1114
|
return week;
|
|
1055
1115
|
}
|
|
1056
|
-
/** @
|
|
1116
|
+
/** @instance Returns ISO week year */
|
|
1057
1117
|
getWeekYear() {
|
|
1058
1118
|
const d = this.startOf('week').add(3, 'day'); // Thursday of current ISO week
|
|
1059
1119
|
return d.year;
|
|
1060
1120
|
}
|
|
1061
|
-
|
|
1062
|
-
// * @private @instance Gets the ISO week-numbering year.
|
|
1063
|
-
// * @returns The ISO year (can differ from calendar year).
|
|
1064
|
-
// */
|
|
1065
|
-
// getISOWeekYear(): number {
|
|
1066
|
-
// const date = new Date(this.#date);
|
|
1067
|
-
// date.setDate(date.getDate() + 4 - (date.getDay() || 7)); // Thursday of the week
|
|
1068
|
-
// return date.getFullYear();
|
|
1069
|
-
// }
|
|
1070
|
-
/** @public @instance Returns day of year (1 - 366) */
|
|
1121
|
+
/** @instance Returns day of year (1 - 366) */
|
|
1071
1122
|
getDayOfYear() {
|
|
1072
1123
|
const start = new Date(this.year, 0, 1);
|
|
1073
1124
|
const diff = this.#date.getTime() - start.getTime();
|
|
1074
1125
|
return Math.floor(diff / 86400000) + 1;
|
|
1075
1126
|
}
|
|
1076
|
-
/** @
|
|
1127
|
+
/** @instance Returns number of days in current month */
|
|
1077
1128
|
daysInMonth() {
|
|
1078
1129
|
return new Date(this.year, this.month + 1, 0).getDate();
|
|
1079
1130
|
}
|
|
1080
|
-
/** @
|
|
1131
|
+
/** @instance Converts to object with all date unit parts */
|
|
1081
1132
|
toObject() {
|
|
1082
1133
|
return Object.fromEntries([...this]);
|
|
1083
1134
|
}
|
|
1084
|
-
/** @
|
|
1135
|
+
/** @instance Converts to array with all date unit parts */
|
|
1085
1136
|
toArray() {
|
|
1086
1137
|
return Object.values(this.toObject());
|
|
1087
1138
|
}
|
|
1088
|
-
/** @
|
|
1139
|
+
/** @instance Returns offset like +06:00 */
|
|
1089
1140
|
getUTCOffset() {
|
|
1090
1141
|
const offset = -this.#date.getTimezoneOffset();
|
|
1091
1142
|
const sign = offset >= 0 ? '+' : '-';
|
|
1092
1143
|
const pad = (n) => String(Math.floor(Math.abs(n))).padStart(2, '0');
|
|
1093
1144
|
return `${sign}${pad(offset / 60)}:${pad(offset % 60)}`;
|
|
1094
1145
|
}
|
|
1095
|
-
/** @
|
|
1146
|
+
/** @instance Returns new Chronos instance in UTC */
|
|
1096
1147
|
toUTC() {
|
|
1097
1148
|
const date = this.#date;
|
|
1098
1149
|
const utc = new Date(date.getTime() + date.getTimezoneOffset() * 60000);
|
|
1099
1150
|
return new Chronos(utc).#withOrigin('toUTC');
|
|
1100
1151
|
}
|
|
1101
|
-
/** @
|
|
1152
|
+
/** @instance Returns new Chronos instance in local time */
|
|
1102
1153
|
toLocal() {
|
|
1103
1154
|
const date = this.#date;
|
|
1104
1155
|
const utc = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
|
|
1105
1156
|
return new Chronos(utc).#withOrigin('toLocal');
|
|
1106
1157
|
}
|
|
1107
1158
|
/**
|
|
1108
|
-
* @
|
|
1109
|
-
* * Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
1110
|
-
* @param options - Configure format string and whether to format using utc offset.
|
|
1111
|
-
* @returns Formatted date string in desired format.
|
|
1112
|
-
*/
|
|
1113
|
-
static today(options) {
|
|
1114
|
-
const { format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false } = options || {};
|
|
1115
|
-
const today = new Date();
|
|
1116
|
-
return new Chronos(today).#format(format, useUTC);
|
|
1117
|
-
}
|
|
1118
|
-
/**
|
|
1119
|
-
* @public @static Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
|
|
1120
|
-
* * It basically calls `Date.now()`.
|
|
1121
|
-
* @returns The number of milliseconds elapsed since the Unix epoch.
|
|
1122
|
-
*/
|
|
1123
|
-
static now() {
|
|
1124
|
-
return Date.now();
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* @public @static Parses a date string with a given format (partial support)
|
|
1159
|
+
* @static Parses a date string with a given format (partial support)
|
|
1128
1160
|
*
|
|
1129
1161
|
* * **Supported format tokens**:
|
|
1130
1162
|
* - `YYYY`: Full year (e.g., 2023)
|
|
@@ -1141,15 +1173,15 @@ export class Chronos {
|
|
|
1141
1173
|
* // returns Chronos instance with the parsed date 2023-12-31T15:30:45
|
|
1142
1174
|
* ```
|
|
1143
1175
|
*
|
|
1144
|
-
* @param
|
|
1145
|
-
* @param
|
|
1146
|
-
* @returns
|
|
1147
|
-
* @throws
|
|
1176
|
+
* @param dateStr - The date string to be parsed
|
|
1177
|
+
* @param format - The format of the date string. Tokens like `YYYY`, `MM`, `DD`, `HH`, `mm`, `ss` are used to specify the structure.
|
|
1178
|
+
* @returns A new `Chronos` instance representing the parsed date.
|
|
1179
|
+
* @throws `Error` If the date string does not match the format.
|
|
1148
1180
|
*/
|
|
1149
1181
|
static parse(dateStr, format) {
|
|
1150
1182
|
const formatMap = {
|
|
1151
1183
|
YYYY: 'year',
|
|
1152
|
-
YY: 'year',
|
|
1184
|
+
YY: 'year',
|
|
1153
1185
|
MM: 'month',
|
|
1154
1186
|
DD: 'date',
|
|
1155
1187
|
HH: 'hour',
|
|
@@ -1178,7 +1210,46 @@ export class Chronos {
|
|
|
1178
1210
|
return new Chronos(new Date(values.year ?? 1970, (values.month ?? 1) - 1, values.date ?? 1, values.hour ?? 0, values.minute ?? 0, values.second ?? 0)).#withOrigin('parse');
|
|
1179
1211
|
}
|
|
1180
1212
|
/**
|
|
1181
|
-
* @
|
|
1213
|
+
* @static Returns the current date and time in a specified format in local time.
|
|
1214
|
+
* * Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55`
|
|
1215
|
+
* @param options - Configure format string and whether to format using utc offset.
|
|
1216
|
+
* @returns Formatted date string in desired format.
|
|
1217
|
+
*/
|
|
1218
|
+
static today(options) {
|
|
1219
|
+
const { format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false } = options || {};
|
|
1220
|
+
const today = new Date();
|
|
1221
|
+
return new Chronos(today).#format(format, useUTC);
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* @static Returns a new `Chronos` instance representing yesterday's date.
|
|
1225
|
+
*
|
|
1226
|
+
* @returns A `Chronos` instance for the previous calendar day.
|
|
1227
|
+
*/
|
|
1228
|
+
static yesterday() {
|
|
1229
|
+
const today = new Date();
|
|
1230
|
+
const yesterday = today.setDate(today.getDate() - 1);
|
|
1231
|
+
return new Chronos(yesterday).#withOrigin('yesterday');
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* @static Returns a new `Chronos` instance representing tomorrow's date.
|
|
1235
|
+
*
|
|
1236
|
+
* @returns A `Chronos` instance for the next calendar day.
|
|
1237
|
+
*/
|
|
1238
|
+
static tomorrow() {
|
|
1239
|
+
const today = new Date();
|
|
1240
|
+
const yesterday = today.setDate(today.getDate() + 1);
|
|
1241
|
+
return new Chronos(yesterday).#withOrigin('tomorrow');
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* @static Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
|
|
1245
|
+
* * It basically calls `Date.now()`.
|
|
1246
|
+
* @returns The number of milliseconds elapsed since the Unix epoch.
|
|
1247
|
+
*/
|
|
1248
|
+
static now() {
|
|
1249
|
+
return Date.now();
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* @static Creates UTC Chronos
|
|
1182
1253
|
* @param dateLike Date input to create utc time.
|
|
1183
1254
|
*/
|
|
1184
1255
|
static utc(dateLike) {
|
|
@@ -1187,21 +1258,21 @@ export class Chronos {
|
|
|
1187
1258
|
return new Chronos(utc).#withOrigin('utc');
|
|
1188
1259
|
}
|
|
1189
1260
|
/**
|
|
1190
|
-
* @
|
|
1261
|
+
* @static Returns earliest Chronos
|
|
1191
1262
|
* @param dates Date inputs.
|
|
1192
1263
|
*/
|
|
1193
1264
|
static min(...dates) {
|
|
1194
1265
|
return new Chronos(Math.min(...dates.map((d) => new Chronos(d).valueOf()))).#withOrigin('min');
|
|
1195
1266
|
}
|
|
1196
1267
|
/**
|
|
1197
|
-
* @
|
|
1268
|
+
* @static Returns latest Chronos
|
|
1198
1269
|
* @param dates Date inputs.
|
|
1199
1270
|
*/
|
|
1200
1271
|
static max(...dates) {
|
|
1201
1272
|
return new Chronos(Math.max(...dates.map((d) => new Chronos(d).valueOf()))).#withOrigin('max');
|
|
1202
1273
|
}
|
|
1203
1274
|
/**
|
|
1204
|
-
* @
|
|
1275
|
+
* @static Checks if the year in the date string or year (from 0 - 9999) is a leap year.
|
|
1205
1276
|
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
1206
1277
|
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
1207
1278
|
*
|
|
@@ -1231,7 +1302,7 @@ export class Chronos {
|
|
|
1231
1302
|
return isLeapYear(year);
|
|
1232
1303
|
}
|
|
1233
1304
|
/**
|
|
1234
|
-
* @
|
|
1305
|
+
* @static Checks if the given value is a valid `Date` object.
|
|
1235
1306
|
* - A value is considered valid if it is an instance of the built-in `Date` class.
|
|
1236
1307
|
* - This does not check whether the date itself is valid (e.g., `new Date('invalid')`).
|
|
1237
1308
|
* @param value - The value to test.
|
|
@@ -1241,7 +1312,7 @@ export class Chronos {
|
|
|
1241
1312
|
return value instanceof Date;
|
|
1242
1313
|
}
|
|
1243
1314
|
/**
|
|
1244
|
-
* @
|
|
1315
|
+
* @static Checks if the given value is a valid date string.
|
|
1245
1316
|
* - A value is considered a valid date string if it is a string and can be parsed by `Date.parse()`.
|
|
1246
1317
|
* - This uses the native JavaScript date parser internally.
|
|
1247
1318
|
* @param value - The value to test.
|
|
@@ -1251,7 +1322,7 @@ export class Chronos {
|
|
|
1251
1322
|
return isString(value) && !isNaN(Date.parse(value));
|
|
1252
1323
|
}
|
|
1253
1324
|
/**
|
|
1254
|
-
* @
|
|
1325
|
+
* @static Checks if the given value is an instance of `Chronos`.
|
|
1255
1326
|
* - Useful for verifying Chronos objects in type guards or validations.
|
|
1256
1327
|
* @param value - The value to test.
|
|
1257
1328
|
* @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
|