@timestamp-js/core 0.1.0-alpha.2 → 0.1.0-alpha.3

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/index.js CHANGED
@@ -112,7 +112,7 @@ export const MILLISECONDS_IN_WEEK = TIME_CONSTANTS.MILLISECONDS_IN.WEEK;
112
112
  /**
113
113
  * Frozen empty timestamp template.
114
114
  *
115
- * Use {@link copyTimestamp} or parser helpers to create new timestamp objects
115
+ * Use copyTimestamp or parser helpers to create new timestamp objects
116
116
  * instead of mutating this shared default.
117
117
  */
118
118
  export const Timestamp = freezeTimestamp({
@@ -163,11 +163,11 @@ export function validateTimestamp(input) {
163
163
  * Fast low-level parser for date and date-time strings.
164
164
  *
165
165
  * This parser fills numeric fields, but does not update formatted date,
166
- * weekday, day-of-year, workweek, or relative flags. Use
167
- * {@link parseTimestamp} when those derived fields are needed.
166
+ * weekday, day-of-year, workweek, or relative flags. Use parseTimestamp()
167
+ * when those derived fields are needed.
168
168
  *
169
169
  * @param {string} input In the form `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like date time with optional milliseconds and timezone suffix.
170
- * @returns {Timestamp} This {@link Timestamp} is minimally filled in. The {@link Timestamp.date} and {@link Timestamp.time} as well as relative data will not be filled in.
170
+ * @returns {Timestamp} Minimal Timestamp object, or `null` when the input cannot be parsed.
171
171
  */
172
172
  export function parsed(input) {
173
173
  if (typeof input !== "string")
@@ -211,13 +211,7 @@ export function parsed(input) {
211
211
  timestamp.time = getTime(timestamp);
212
212
  return freezeTimestamp(timestamp);
213
213
  }
214
- /**
215
- * Takes a JavaScript Date and returns a {@link Timestamp}. The {@link Timestamp} is not updated with relative information.
216
- * @param {Date} date JavaScript Date
217
- * @param {boolean} utc If set the {@link Timestamp} will parse the Date as UTC
218
- * @returns {Timestamp} A minimal {@link Timestamp} without updated or relative updates.
219
- */
220
- export function parseDate(date, utc = false) {
214
+ function parseDateByMode(date, utc) {
221
215
  if (!(date instanceof Date))
222
216
  return null;
223
217
  const UTC = utc ? "UTC" : "";
@@ -255,6 +249,30 @@ export function parseDate(date, utc = false) {
255
249
  }
256
250
  return updateFormatted(timestamp);
257
251
  }
252
+ /**
253
+ * Converts a JavaScript Date into a formatted Timestamp using host-local fields.
254
+ *
255
+ * Use parseDateUTC() when the Date represents an instant that should be read
256
+ * with UTC getters instead of host-local getters.
257
+ *
258
+ * @param {Date} date JavaScript Date to convert.
259
+ * @returns {Timestamp} Formatted Timestamp object, or `null` for invalid input.
260
+ */
261
+ export function parseDate(date) {
262
+ return parseDateByMode(date, false);
263
+ }
264
+ /**
265
+ * Converts a JavaScript Date into a formatted Timestamp using UTC fields.
266
+ *
267
+ * Use this when server and client output should agree on the same UTC calendar
268
+ * and time fields for a native Date instant.
269
+ *
270
+ * @param {Date} date JavaScript Date to convert.
271
+ * @returns {Timestamp} Formatted Timestamp object, or `null` for invalid input.
272
+ */
273
+ export function parseDateUTC(date) {
274
+ return parseDateByMode(date, true);
275
+ }
258
276
  /**
259
277
  * Pads a number to a requested string length.
260
278
  *
@@ -290,9 +308,10 @@ export function daysInMonth(year, month) {
290
308
  return (isLeapYear(year) ? DAYS_IN_MONTH_LEAP[month] : DAYS_IN_MONTH[month]);
291
309
  }
292
310
  /**
293
- * Returns a {@link Timestamp} of next day from passed in {@link Timestamp}
294
- * @param {Timestamp} timestamp The {@link Timestamp} to use
295
- * @returns {Timestamp} A new {@link Timestamp} representing the next day
311
+ * Returns a new Timestamp for the next calendar day.
312
+ *
313
+ * @param {Timestamp} timestamp Base Timestamp object.
314
+ * @returns {Timestamp} New Timestamp representing the next day.
296
315
  */
297
316
  export function nextDay(timestamp) {
298
317
  const date = new Date(timestamp.year, timestamp.month - 1, timestamp.day + 1);
@@ -304,9 +323,10 @@ export function nextDay(timestamp) {
304
323
  }));
305
324
  }
306
325
  /**
307
- * Returns a {@link Timestamp} of previous day from passed in {@link Timestamp}
308
- * @param {Timestamp} timestamp The {@link Timestamp} to use
309
- * @returns {Timestamp} A new {@link Timestamp} representing the previous day
326
+ * Returns a new Timestamp for the previous calendar day.
327
+ *
328
+ * @param {Timestamp} timestamp Base Timestamp object.
329
+ * @returns {Timestamp} New Timestamp representing the previous day.
310
330
  */
311
331
  export function prevDay(timestamp) {
312
332
  const date = new Date(timestamp.year, timestamp.month - 1, timestamp.day - 1);
@@ -318,13 +338,48 @@ export function prevDay(timestamp) {
318
338
  }));
319
339
  }
320
340
  /**
321
- * Returns today's date
341
+ * Returns today's date using the host runtime timezone.
342
+ *
343
+ * For SSR or static rendering, server and client runtimes can produce different
344
+ * values when they run in different timezones. Use todayUTC() when the app
345
+ * wants a stable UTC calendar date instead.
346
+ *
322
347
  * @returns {string} Date string in the form `YYYY-MM-DD`
323
348
  */
324
349
  export function today() {
325
350
  const d = new Date(), month = d.getMonth() + 1, day = d.getDate(), year = d.getFullYear();
326
351
  return [year, padNumber(month, 2), padNumber(day, 2)].join("-");
327
352
  }
353
+ /**
354
+ * Returns today's date using UTC calendar fields.
355
+ *
356
+ * Pass a Date fixture to make SSR, tests, and hydration-sensitive render paths
357
+ * deterministic. This helper reads UTC fields only; it does not convert an
358
+ * existing Timestamp or timezone-suffixed string.
359
+ *
360
+ * @param {Date} date Date source to read. Defaults to the current Date.
361
+ * @returns {string} UTC date string in the form `YYYY-MM-DD`
362
+ */
363
+ export function todayUTC(date = new Date()) {
364
+ return [
365
+ padNumber(date.getUTCFullYear(), 4),
366
+ padNumber(date.getUTCMonth() + 1, 2),
367
+ padNumber(date.getUTCDate(), 2),
368
+ ].join("-");
369
+ }
370
+ /**
371
+ * Returns the current date-time as an immutable Timestamp using UTC fields.
372
+ *
373
+ * Use this when server and client output should agree on UTC calendar and time
374
+ * values. For fully deterministic SSR output, pass a Date captured by the
375
+ * caller instead of allowing each runtime to create its own current Date.
376
+ *
377
+ * @param {Date} date Date source to read. Defaults to the current Date.
378
+ * @returns {Timestamp} Immutable Timestamp built from UTC fields.
379
+ */
380
+ export function nowUTC(date = new Date()) {
381
+ return parseDateUTC(date);
382
+ }
328
383
  /**
329
384
  * Takes a date string ('YYYY-MM-DD') and validates if it is today's date
330
385
  * @param {string} date Date string in the form 'YYYY-MM-DD'
@@ -334,12 +389,25 @@ export function isToday(date) {
334
389
  return date === today();
335
390
  }
336
391
  /**
337
- * Returns the start of the week give a {@link Timestamp} and weekdays (in which it finds the day representing the start of the week).
338
- * If today {@link Timestamp} is passed in then this is used to update relative information in the returned {@link Timestamp}.
339
- * @param {Timestamp} timestamp The {@link Timestamp} to use to find the start of the week
392
+ * Checks whether a date string matches today's UTC date.
393
+ *
394
+ * Pass a Date fixture when SSR, tests, or hydration-sensitive render paths need
395
+ * deterministic behavior.
396
+ *
397
+ * @param {string} date Date string in the form `YYYY-MM-DD`.
398
+ * @param {Date} now Date source to read. Defaults to the current Date.
399
+ * @returns {boolean} True when the date matches the UTC date.
400
+ */
401
+ export function isTodayUTC(date, now = new Date()) {
402
+ return date === todayUTC(now);
403
+ }
404
+ /**
405
+ * Returns the start of the week for a Timestamp and weekday set.
406
+ * If a current Timestamp is provided, the returned Timestamp includes updated relative information.
407
+ * @param {Timestamp} timestamp The Timestamp to use to find the start of the week
340
408
  * @param {number[]} weekdays The array is [0,1,2,3,4,5,6] where 0=Sunday and 6=Saturday
341
- * @param {Timestamp=} today If passed in then the {@link Timestamp} is updated with relative information
342
- * @returns {Timestamp} A new {@link Timestamp} representing the start of the week
409
+ * @param {Timestamp=} today Current timestamp used to update relative information
410
+ * @returns {Timestamp} A new Timestamp representing the start of the week
343
411
  */
344
412
  export function getStartOfWeek(timestamp, weekdays, today) {
345
413
  let start = cloneTimestamp(timestamp);
@@ -359,12 +427,12 @@ export function getStartOfWeek(timestamp, weekdays, today) {
359
427
  return start;
360
428
  }
361
429
  /**
362
- * Returns the end of the week give a {@link Timestamp} and weekdays (in which it finds the day representing the last of the week).
363
- * If today {@link Timestamp} is passed in then this is used to update relative information in the returned {@link Timestamp}.
364
- * @param {Timestamp} timestamp The {@link Timestamp} to use to find the end of the week
430
+ * Returns the end of the week for a Timestamp and weekday set.
431
+ * If a current Timestamp is provided, the returned Timestamp includes updated relative information.
432
+ * @param {Timestamp} timestamp The Timestamp to use to find the end of the week
365
433
  * @param {number[]} weekdays The array is [0,1,2,3,4,5,6] where 0=Sunday and 6=Saturday
366
- * @param {Timestamp=} today If passed in then the {@link Timestamp} is updated with relative information
367
- * @returns {Timestamp} A new {@link Timestamp} representing the end of the week
434
+ * @param {Timestamp=} today Current timestamp used to update relative information
435
+ * @returns {Timestamp} A new Timestamp representing the end of the week
368
436
  */
369
437
  export function getEndOfWeek(timestamp, weekdays, today) {
370
438
  let end = cloneTimestamp(timestamp);
@@ -386,9 +454,9 @@ export function getEndOfWeek(timestamp, weekdays, today) {
386
454
  return end;
387
455
  }
388
456
  /**
389
- * Finds the start of the month based on the passed in {@link Timestamp}
390
- * @param {Timestamp} timestamp The {@link Timestamp} to use to find the start of the month
391
- * @returns {Timestamp} A {@link Timestamp} of the start of the month
457
+ * Finds the start of the month based on the passed in Timestamp
458
+ * @param {Timestamp} timestamp The Timestamp to use to find the start of the month
459
+ * @returns {Timestamp} A Timestamp of the start of the month
392
460
  */
393
461
  export function getStartOfMonth(timestamp) {
394
462
  let start = cloneTimestamp(timestamp);
@@ -397,9 +465,9 @@ export function getStartOfMonth(timestamp) {
397
465
  return start;
398
466
  }
399
467
  /**
400
- * Finds the end of the month based on the passed in {@link Timestamp}
401
- * @param {Timestamp} timestamp The {@link Timestamp} to use to find the end of the month
402
- * @returns {Timestamp} A {@link Timestamp} of the end of the month
468
+ * Finds the end of the month based on the passed in Timestamp
469
+ * @param {Timestamp} timestamp The Timestamp to use to find the end of the month
470
+ * @returns {Timestamp} A Timestamp of the end of the month
403
471
  */
404
472
  export function getEndOfMonth(timestamp) {
405
473
  let end = cloneTimestamp(timestamp);
@@ -445,10 +513,11 @@ export function parseTime(input) {
445
513
  return false;
446
514
  }
447
515
  /**
448
- * Compares two {@link Timestamp}s for exactness
449
- * @param {Timestamp} ts1 The first {@link Timestamp}
450
- * @param {Timestamp} ts2 The second {@link Timestamp}
451
- * @returns {boolean} True if the two {@link Timestamp}s are an exact match
516
+ * Compares two Timestamp objects for exact date, time, and timezone equality.
517
+ *
518
+ * @param {Timestamp} ts1 First Timestamp object.
519
+ * @param {Timestamp} ts2 Second Timestamp object.
520
+ * @returns {boolean} True when both timestamps match exactly.
452
521
  */
453
522
  export function compareTimestamps(ts1, ts2) {
454
523
  if (!ts1 || !ts2)
@@ -463,41 +532,44 @@ export function compareTimestamps(ts1, ts2) {
463
532
  ts1.timezone === ts2.timezone);
464
533
  }
465
534
  /**
466
- * Compares the date of two {@link Timestamp}s that have been updated with relative data
467
- * @param {Timestamp} ts1 The first {@link Timestamp}
468
- * @param {Timestamp} ts2 The second {@link Timestamp}
469
- * @returns {boolean} True if the two dates are the same
535
+ * Compares the calendar date portion of two Timestamp objects.
536
+ *
537
+ * @param {Timestamp} ts1 First Timestamp object.
538
+ * @param {Timestamp} ts2 Second Timestamp object.
539
+ * @returns {boolean} True when both dates are the same.
470
540
  */
471
541
  export function compareDate(ts1, ts2) {
472
542
  return getDate(ts1) === getDate(ts2);
473
543
  }
474
544
  /**
475
- * Compares the time of two {@link Timestamp}s that have been updated with relative data
476
- * @param {Timestamp} ts1 The first {@link Timestamp}
477
- * @param {Timestamp} ts2 The second {@link Timestamp}
478
- * @returns {boolean} True if the two times are an exact match
545
+ * Compares the formatted time portion of two Timestamp objects.
546
+ *
547
+ * @param {Timestamp} ts1 First Timestamp object.
548
+ * @param {Timestamp} ts2 Second Timestamp object.
549
+ * @returns {boolean} True when both times are the same.
479
550
  */
480
551
  export function compareTime(ts1, ts2) {
481
552
  return getTime(ts1) === getTime(ts2);
482
553
  }
483
554
  /**
484
- * Compares the date and time of two {@link Timestamp}s that have been updated with relative data
485
- * @param {Timestamp} ts1 The first {@link Timestamp}
486
- * @param {Timestamp} ts2 The second {@link Timestamp}
487
- * @returns {boolean} True if the date and time are an exact match
555
+ * Compares the formatted date and time portions of two Timestamp objects.
556
+ *
557
+ * @param {Timestamp} ts1 First Timestamp object.
558
+ * @param {Timestamp} ts2 Second Timestamp object.
559
+ * @returns {boolean} True when both date-time values are the same.
488
560
  */
489
561
  export function compareDateTime(ts1, ts2) {
490
562
  return getDateTime(ts1) === getDateTime(ts2);
491
563
  }
492
564
  /**
493
- * High-level parser that converts a string to a fully formatted {@link Timestamp}.
565
+ * Converts a supported date or date-time string into a formatted Timestamp object.
494
566
  *
495
567
  * If `now` is supplied, the returned timestamp also includes relative flags
496
568
  * such as `past`, `current`, `future`, and `currentWeekday`.
497
569
  *
498
- * @param {string} input In the form `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like date time with optional milliseconds and timezone suffix.
499
- * @param {Timestamp} now A {@link Timestamp} to use for relative data updates
500
- * @returns {Timestamp} The {@link Timestamp.date} will be filled in as well as the {@link Timestamp.time} if a time is supplied and formatted fields (doy, weekday, workweek, etc). If 'now' is supplied, then relative data will also be updated.
570
+ * @param {string} input Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.
571
+ * @param {Timestamp} now Optional Timestamp used to calculate relative flags.
572
+ * @returns {Timestamp} Formatted Timestamp object, or `null` when the input cannot be parsed.
501
573
  */
502
574
  export function parseTimestamp(input, now = null) {
503
575
  let timestamp = parsed(input);
@@ -510,9 +582,10 @@ export function parseTimestamp(input, now = null) {
510
582
  return timestamp;
511
583
  }
512
584
  /**
513
- * Converts a {@link Timestamp} into a numeric date identifier based on the passed {@link Timestamp}'s date
514
- * @param {Timestamp} timestamp The {@link Timestamp} to use
515
- * @returns {number} The numeric date identifier
585
+ * Converts a Timestamp date into a sortable numeric identifier.
586
+ *
587
+ * @param {Timestamp} timestamp Timestamp object to read.
588
+ * @returns {number} Numeric date identifier.
516
589
  */
517
590
  export function getDayIdentifier(timestamp) {
518
591
  return ((timestamp.year ?? 0) * 100000000 +
@@ -520,9 +593,10 @@ export function getDayIdentifier(timestamp) {
520
593
  (timestamp.day ?? 0) * 10000);
521
594
  }
522
595
  /**
523
- * Converts a {@link Timestamp} into a numeric time identifier based on the passed {@link Timestamp}'s time
524
- * @param {Timestamp} timestamp The {@link Timestamp} to use
525
- * @returns {number} The numeric time identifier
596
+ * Converts a Timestamp time into a sortable numeric identifier.
597
+ *
598
+ * @param {Timestamp} timestamp Timestamp object to read.
599
+ * @returns {number} Numeric time identifier.
526
600
  */
527
601
  export function getTimeIdentifier(timestamp) {
528
602
  return (timestamp.hour ?? 0) * 100 + (timestamp.minute ?? 0);
@@ -535,17 +609,18 @@ function getTimeComparisonValue(timestamp) {
535
609
  (timestamp.millisecond ?? 0));
536
610
  }
537
611
  /**
538
- * Converts a {@link Timestamp} into a numeric date and time identifier based on the passed {@link Timestamp}'s date and time
539
- * @param {Timestamp} timestamp The {@link Timestamp} to use
540
- * @returns {number} The numeric date+time identifier
612
+ * Converts a Timestamp date and time into a sortable numeric identifier.
613
+ *
614
+ * @param {Timestamp} timestamp Timestamp object to read.
615
+ * @returns {number} Numeric date-time identifier.
541
616
  */
542
617
  export function getDayTimeIdentifier(timestamp) {
543
618
  return getDayIdentifier(timestamp) + getTimeIdentifier(timestamp);
544
619
  }
545
620
  /**
546
- * Returns the difference between two {@link Timestamp}s
547
- * @param {Timestamp} ts1 The first {@link Timestamp}
548
- * @param {Timestamp} ts2 The second {@link Timestamp}
621
+ * Returns the difference between two Timestamps
622
+ * @param {Timestamp} ts1 The first Timestamp
623
+ * @param {Timestamp} ts2 The second Timestamp
549
624
  * @param {boolean=} strict Optional flag to not to return negative numbers
550
625
  * @returns {number} The difference
551
626
  */
@@ -560,11 +635,16 @@ export function diffTimestamp(ts1, ts2, strict = false) {
560
635
  return utc2 - utc1;
561
636
  }
562
637
  /**
563
- * Updates a {@link Timestamp} with relative data (past, current and future)
564
- * @param {Timestamp} timestamp The {@link Timestamp} that needs relative data updated
565
- * @param {Timestamp} now {@link Timestamp} that represents the current date (optional time)
566
- * @param {boolean=} time Optional flag to include time ('timestamp' and 'now' params should have time values)
567
- * @returns {Timestamp} A new {@link Timestamp}
638
+ * Returns a Timestamp with relative flags compared to a supplied `now` value.
639
+ *
640
+ * The returned object includes `past`, `current`, `future`, and
641
+ * `currentWeekday` flags. Pass `true` for `time` when both values should be
642
+ * compared at time-of-day precision.
643
+ *
644
+ * @param {Timestamp} timestamp Timestamp object to update.
645
+ * @param {Timestamp} now Timestamp representing the comparison point.
646
+ * @param {boolean=} time Include time-of-day in the comparison when true.
647
+ * @returns {Timestamp} New Timestamp object with relative flags.
568
648
  */
569
649
  export function updateRelative(timestamp, now, time = false) {
570
650
  const ts = cloneTimestamp(timestamp);
@@ -588,10 +668,10 @@ export function updateRelative(timestamp, now, time = false) {
588
668
  * The returned timestamp has updated hour/minute fields and clears second and
589
669
  * millisecond precision because this helper is minute-oriented.
590
670
  *
591
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
671
+ * @param {Timestamp} timestamp The Timestamp to transform
592
672
  * @param {number} minutes The number of minutes to set from midnight
593
- * @param {Timestamp=} now Optional {@link Timestamp} representing current date and time
594
- * @returns {Timestamp} A new {@link Timestamp}
673
+ * @param {Timestamp=} now Optional Timestamp representing current date and time
674
+ * @returns {Timestamp} A new Timestamp
595
675
  */
596
676
  export function updateMinutes(timestamp, minutes, now = null) {
597
677
  let ts = cloneTimestamp(timestamp);
@@ -607,8 +687,8 @@ export function updateMinutes(timestamp, minutes, now = null) {
607
687
  return freezeTimestamp(ts);
608
688
  }
609
689
  /**
610
- * Updates the {@link Timestamp} with the weekday
611
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
690
+ * Updates the Timestamp with the weekday
691
+ * @param {Timestamp} timestamp The Timestamp to transform
612
692
  * @returns A new Timestamp
613
693
  */
614
694
  export function updateWeekday(timestamp) {
@@ -617,8 +697,8 @@ export function updateWeekday(timestamp) {
617
697
  return freezeTimestamp(ts);
618
698
  }
619
699
  /**
620
- * Updates the {@link Timestamp} with the day of the year (doy)
621
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
700
+ * Updates the Timestamp with the day of the year (doy)
701
+ * @param {Timestamp} timestamp The Timestamp to transform
622
702
  * @returns A new Timestamp
623
703
  */
624
704
  export function updateDayOfYear(timestamp) {
@@ -627,9 +707,9 @@ export function updateDayOfYear(timestamp) {
627
707
  return freezeTimestamp(ts);
628
708
  }
629
709
  /**
630
- * Updates the {@link Timestamp} with the workweek
631
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
632
- * @returns A new {@link Timestamp}
710
+ * Updates the Timestamp with the workweek
711
+ * @param {Timestamp} timestamp The Timestamp to transform
712
+ * @returns A new Timestamp
633
713
  */
634
714
  export function updateWorkWeek(timestamp) {
635
715
  const ts = cloneTimestamp(timestamp);
@@ -682,13 +762,13 @@ function isTimestampInDisabledDay(timestamp, day) {
682
762
  return disabledDay !== null && getDayIdentifier(disabledDay) === target;
683
763
  }
684
764
  /**
685
- * Updates the passed {@link Timestamp} with disabled, if needed
686
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
765
+ * Updates the passed Timestamp with disabled, if needed
766
+ * @param {Timestamp} timestamp The Timestamp to transform
687
767
  * @param {string} [disabledBefore] In `YYYY-MM-DD` format
688
768
  * @param {string} [disabledAfter] In `YYYY-MM-DD` format
689
769
  * @param {number[]} [disabledWeekdays] An array of numbers representing weekdays [0 = Sun, ..., 6 = Sat]
690
770
  * @param {DisabledDays} [disabledDays] An array of days in 'YYYY-MM-DD' format. If an array with a pair of dates is in first array, then this is treated as a range. Object entries can include date/from/to plus color metadata.
691
- * @returns A new {@link Timestamp}
771
+ * @returns A new Timestamp
692
772
  */
693
773
  export function updateDisabled(timestamp, disabledBefore, disabledAfter, disabledWeekdays, disabledDays) {
694
774
  let ts = cloneTimestamp(timestamp);
@@ -730,9 +810,9 @@ export function updateDisabled(timestamp, disabledBefore, disabledAfter, disable
730
810
  return freezeTimestamp(ts);
731
811
  }
732
812
  /**
733
- * Updates the passed {@link Timestamp} with formatted data (time string, date string, weekday, day of year and workweek)
734
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
735
- * @returns A new {@link Timestamp}
813
+ * Updates the passed Timestamp with formatted data (time string, date string, weekday, day of year and workweek)
814
+ * @param {Timestamp} timestamp The Timestamp to transform
815
+ * @returns A new Timestamp
736
816
  */
737
817
  export function updateFormatted(timestamp) {
738
818
  const ts = cloneTimestamp(timestamp);
@@ -745,8 +825,8 @@ export function updateFormatted(timestamp) {
745
825
  return freezeTimestamp(ts);
746
826
  }
747
827
  /**
748
- * Returns day of the year (doy) for the passed in {@link Timestamp}
749
- * @param {Timestamp} timestamp The {@link Timestamp} to use
828
+ * Returns day of the year (doy) for the passed in Timestamp
829
+ * @param {Timestamp} timestamp The Timestamp to use
750
830
  * @returns {number} The day of the year
751
831
  */
752
832
  export function getDayOfYear(timestamp) {
@@ -760,8 +840,8 @@ export function getDayOfYear(timestamp) {
760
840
  1000);
761
841
  }
762
842
  /**
763
- * Returns workweek for the passed in {@link Timestamp}
764
- * @param {Timestamp} timestamp The {@link Timestamp} to use
843
+ * Returns workweek for the passed in Timestamp
844
+ * @param {Timestamp} timestamp The Timestamp to use
765
845
  * @returns {number} The work week
766
846
  */
767
847
  export function getWorkWeek(timestamp) {
@@ -787,8 +867,8 @@ export function getWorkWeek(timestamp) {
787
867
  return weekNumber;
788
868
  }
789
869
  /**
790
- * Returns weekday for the passed in {@link Timestamp}
791
- * @param {Timestamp} timestamp The {@link Timestamp} to use
870
+ * Returns weekday for the passed in Timestamp
871
+ * @param {Timestamp} timestamp The Timestamp to use
792
872
  * @returns {number} The weekday
793
873
  */
794
874
  export function getWeekday(timestamp) {
@@ -813,17 +893,19 @@ export function getWeekday(timestamp) {
813
893
  return weekday ?? 0;
814
894
  }
815
895
  /**
816
- * Makes a copy of the passed in {@link Timestamp}
817
- * @param {Timestamp} timestamp The original {@link Timestamp}
818
- * @returns {Timestamp} A copy of the original {@link Timestamp}
896
+ * Returns an immutable copy of a Timestamp object.
897
+ *
898
+ * @param {Timestamp} timestamp Timestamp object to copy.
899
+ * @returns {Timestamp} Frozen Timestamp copy.
819
900
  */
820
901
  export function copyTimestamp(timestamp) {
821
902
  return freezeTimestamp(timestamp);
822
903
  }
823
904
  /**
824
- * Used internally to convert {@link Timestamp} used with 'parsed' or 'parseDate' so the 'date' portion of the {@link Timestamp} is correct.
825
- * @param {Timestamp} timestamp The (raw) {@link Timestamp}
826
- * @returns {string} A formatted date ('YYYY-MM-DD')
905
+ * Formats the date portion of a Timestamp object.
906
+ *
907
+ * @param {Timestamp} timestamp Timestamp object to format.
908
+ * @returns {string} Date string such as `YYYY-MM-DD`.
827
909
  */
828
910
  export function getDate(timestamp) {
829
911
  let str = `${padNumber(timestamp.year, 4)}-${padNumber(timestamp.month, 2)}`;
@@ -832,9 +914,13 @@ export function getDate(timestamp) {
832
914
  return str;
833
915
  }
834
916
  /**
835
- * Used internally to convert {@link Timestamp} with 'parsed' or 'parseDate' so the 'time' portion of the {@link Timestamp} is correct.
836
- * @param {Timestamp} timestamp The (raw) {@link Timestamp}
837
- * @returns {string} A formatted time ('hh:mm')
917
+ * Formats the time portion of a Timestamp object.
918
+ *
919
+ * Minute precision is formatted as `HH:mm`; second precision as `HH:mm:ss`;
920
+ * millisecond precision as `HH:mm:ss.SSS`.
921
+ *
922
+ * @param {Timestamp} timestamp Timestamp object to format.
923
+ * @returns {string} Time string, or an empty string when the timestamp has no time.
838
924
  */
839
925
  export function getTime(timestamp) {
840
926
  if (!timestamp.hasTime) {
@@ -850,31 +936,32 @@ export function getTime(timestamp) {
850
936
  return time;
851
937
  }
852
938
  /**
853
- * Returns a formatted string date and time ('YYYY-YY-MM hh:mm')
854
- * @param {Timestamp} timestamp The {@link Timestamp}
855
- * @returns {string} A formatted date time ('YYYY-MM-DD HH:mm')
939
+ * Formats a Timestamp as date plus time.
940
+ *
941
+ * @param {Timestamp} timestamp Timestamp object to format.
942
+ * @returns {string} Date-time string such as `YYYY-MM-DD HH:mm`.
856
943
  */
857
944
  export function getDateTime(timestamp) {
858
945
  return getDate(timestamp) + " " + (timestamp.hasTime ? getTime(timestamp) : "00:00");
859
946
  }
860
947
  /**
861
- * An alias for {relativeDays}
862
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
948
+ * Alias for relativeDays.
949
+ * @param {Timestamp} timestamp The Timestamp to transform
863
950
  * @param {function} [mover=nextDay] The mover function to use (ie: {nextDay} or {prevDay}).
864
951
  * @param {number} [days=1] The number of days to move.
865
952
  * @param {number[]} [allowedWeekdays=[ 0, 1, 2, 3, 4, 5, 6 ]] An array of numbers representing the weekdays. ie: [0 = Sun, ..., 6 = Sat].
866
- * @returns A new {@link Timestamp}
953
+ * @returns A new Timestamp
867
954
  */
868
955
  export function moveRelativeDays(timestamp, mover = nextDay, days = 1, allowedWeekdays = [0, 1, 2, 3, 4, 5, 6]) {
869
956
  return relativeDays(timestamp, mover, days, allowedWeekdays);
870
957
  }
871
958
  /**
872
- * Moves the {@link Timestamp} the number of relative days
873
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
959
+ * Moves the Timestamp the number of relative days
960
+ * @param {Timestamp} timestamp The Timestamp to transform
874
961
  * @param {function} [mover=nextDay] The mover function to use (ie: {nextDay} or {prevDay}).
875
962
  * @param {number} [days=1] The number of days to move.
876
963
  * @param {number[]} [allowedWeekdays=[ 0, 1, 2, 3, 4, 5, 6 ]] An array of numbers representing the weekdays. ie: [0 = Sun, ..., 6 = Sat].
877
- * @returns A new {@link Timestamp}
964
+ * @returns A new Timestamp
878
965
  */
879
966
  export function relativeDays(timestamp, mover = nextDay, days = 1, allowedWeekdays = [0, 1, 2, 3, 4, 5, 6]) {
880
967
  let ts = copyTimestamp(timestamp);
@@ -890,12 +977,12 @@ export function relativeDays(timestamp, mover = nextDay, days = 1, allowedWeekda
890
977
  return ts;
891
978
  }
892
979
  /**
893
- * Finds the specified weekday (forward or back) based on the {@link Timestamp}
894
- * @param {Timestamp} timestamp The {@link Timestamp} to transform
980
+ * Finds the specified weekday (forward or back) based on the Timestamp
981
+ * @param {Timestamp} timestamp The Timestamp to transform
895
982
  * @param {number} weekday The weekday number (Sun = 0, ..., Sat = 6)
896
983
  * @param {function} [mover=nextDay] The function to use ({prevDay} or {nextDay}).
897
984
  * @param {number} [maxDays=6] The number of days to look forward or back.
898
- * @returns A new {@link Timestamp}
985
+ * @returns A new Timestamp
899
986
  */
900
987
  export function findWeekday(timestamp, weekday, mover = nextDay, maxDays = 6) {
901
988
  let ts = copyTimestamp(timestamp);
@@ -904,18 +991,22 @@ export function findWeekday(timestamp, weekday, mover = nextDay, maxDays = 6) {
904
991
  return ts;
905
992
  }
906
993
  /**
907
- * Creates an array of {@link Timestamp}s based on start and end params
908
- * @param {Timestamp} start The starting {@link Timestamp}
909
- * @param {Timestamp} end The ending {@link Timestamp}
910
- * @param {Timestamp} now The relative day
911
- * @param {number[]} weekdays An array of numbers (representing days of the week) that are 0 (=Sunday) to 6 (=Saturday)
912
- * @param {string} [disabledBefore] Days before this date are disabled (YYYY-MM-DD)
913
- * @param {string} [disabledAfter] Days after this date are disabled (YYYY-MM-DD)
914
- * @param {number[]} [disabledWeekdays] An array representing weekdays that are disabled [0 = Sun, ..., 6 = Sat]
915
- * @param {DisabledDays} [disabledDays] An array of days in 'YYYY-MM-DD' format. If an array with a pair of dates is in first array, then this is treated as a range.
916
- * @param {number} [max=42] Max days to do
917
- * @param {number} [min=0] Min days to do
918
- * @returns {Timestamp[]} The requested array of {@link Timestamp}s
994
+ * Creates an inclusive list of Timestamp days between start and end.
995
+ *
996
+ * The returned days are formatted, marked with relative flags against `now`,
997
+ * and can include disabled metadata when disabled options are supplied.
998
+ *
999
+ * @param {Timestamp} start First day in the list.
1000
+ * @param {Timestamp} end Last day boundary for the list.
1001
+ * @param {Timestamp} now Timestamp used to calculate relative flags.
1002
+ * @param {number[]} weekdays Weekday numbers to include, from `0` Sunday to `6` Saturday.
1003
+ * @param {string} [disabledBefore] Disable days before this `YYYY-MM-DD` date.
1004
+ * @param {string} [disabledAfter] Disable days after this `YYYY-MM-DD` date.
1005
+ * @param {number[]} [disabledWeekdays] Weekday numbers to mark disabled.
1006
+ * @param {DisabledDays} [disabledDays] Specific dates or date ranges to mark disabled.
1007
+ * @param {number} [max=42] Maximum number of days to return.
1008
+ * @param {number} [min=0] Minimum number of days to return.
1009
+ * @returns {Timestamp[]} Timestamp days.
919
1010
  */
920
1011
  export function createDayList(start, end, now, weekdays = [0, 1, 2, 3, 4, 5, 6], disabledBefore = undefined, disabledAfter = undefined, disabledWeekdays = [], disabledDays = [], max = 42, min = 0) {
921
1012
  const begin = getDayIdentifier(start);
@@ -947,13 +1038,14 @@ export function createDayList(start, end, now, weekdays = [0, 1, 2, 3, 4, 5, 6],
947
1038
  return days;
948
1039
  }
949
1040
  /**
950
- * Creates an array of interval {@link Timestamp}s based on params
951
- * @param {Timestamp} timestamp The starting {@link Timestamp}
952
- * @param {number} first The starting interval time
953
- * @param {number} minutes How many minutes between intervals (ie: 60, 30, 15 would be common ones)
954
- * @param {number} count The number of intervals needed
955
- * @param {Timestamp} now A relative {@link Timestamp} with time
956
- * @returns {Timestamp[]} The requested array of interval {@link Timestamp}s
1041
+ * Creates an array of interval Timestamp objects for one day.
1042
+ *
1043
+ * @param {Timestamp} timestamp Base date for the intervals.
1044
+ * @param {number} first Starting interval index.
1045
+ * @param {number} minutes Minutes between intervals, such as 60, 30, or 15.
1046
+ * @param {number} count Number of intervals to create.
1047
+ * @param {Timestamp} now Timestamp used to calculate relative flags.
1048
+ * @returns {Timestamp[]} Interval Timestamp objects.
957
1049
  */
958
1050
  export function createIntervalList(timestamp, first, minutes, count, now) {
959
1051
  const intervals = [];
@@ -965,76 +1057,109 @@ export function createIntervalList(timestamp, first, minutes, count, now) {
965
1057
  }
966
1058
  /**
967
1059
  * @callback getOptions
968
- * @param {Timestamp} timestamp A {@link Timestamp} object
1060
+ * @param {Timestamp} timestamp A Timestamp object
969
1061
  * @param {boolean} short True if using short options
970
1062
  * @returns {Object} An Intl object representing options to be used
971
1063
  */
972
1064
  /**
973
1065
  * @callback formatter
974
- * @param {Timestamp} timestamp The {@link Timestamp} being used
1066
+ * @param {Timestamp} timestamp The Timestamp being used
975
1067
  * @param {boolean} short If short format is being requested
976
- * @returns {string} The localized string of the formatted {@link Timestamp}
977
- */
978
- /**
979
- * Returns a locale formatter backed by `Intl.DateTimeFormat`.
980
- *
981
- * The helper is SSR-safe: if `Intl.DateTimeFormat` is unavailable in a target
982
- * runtime, it returns a formatter that produces an empty string instead of
983
- * throwing during module load.
984
- *
985
- * @param {string} locale The locale to use (ie: en-US)
986
- * @param {getOptions} cb The function to call for options. This function should return an Intl formatted object. The function is passed (timestamp, short).
987
- * @returns {formatter} The function has params (timestamp, short). The short is to use the short options.
1068
+ * @returns {string} The localized string of the formatted Timestamp
988
1069
  */
989
- export function createNativeLocaleFormatter(locale, cb) {
1070
+ function createNativeLocaleFormatterByMode(locale, cb, toDate) {
990
1071
  const emptyFormatter = () => "";
991
- /* istanbul ignore next */
992
1072
  if (typeof Intl === "undefined" || typeof Intl.DateTimeFormat === "undefined") {
993
1073
  return emptyFormatter;
994
1074
  }
995
1075
  return (timestamp, short) => {
996
1076
  try {
997
1077
  const intlFormatter = new Intl.DateTimeFormat(locale || undefined, cb(timestamp, short));
998
- return intlFormatter.format(makeDateTime(timestamp));
1078
+ return intlFormatter.format(toDate(timestamp));
999
1079
  }
1000
- catch (e) /* istanbul ignore next */ {
1080
+ catch (e) {
1001
1081
  console.error(`Intl.DateTimeFormat: ${e.message} -> ${getDateTime(timestamp)}`);
1002
1082
  return "";
1003
1083
  }
1004
1084
  };
1005
1085
  }
1006
1086
  /**
1007
- * Makes a JavaScript Date from the passed {@link Timestamp}
1008
- * @param {Timestamp} timestamp The {@link Timestamp} to use
1009
- * @param {boolean} utc True to get Date object using UTC
1010
- * @returns {Date} A JavaScript Date
1087
+ * Returns a host-local locale formatter backed by `Intl.DateTimeFormat`.
1088
+ *
1089
+ * The helper is SSR-safe: if `Intl.DateTimeFormat` is unavailable in a target
1090
+ * runtime, it returns a formatter that produces an empty string instead of
1091
+ * throwing during module load.
1092
+ *
1093
+ * Use `createNativeLocaleFormatterUTC()` when Timestamp values should be read
1094
+ * as UTC fields before formatting.
1095
+ *
1096
+ * @param {string} locale The locale to use (ie: en-US)
1097
+ * @param {getOptions} cb The function to call for options. This function should return an Intl formatted object. The function is passed (timestamp, short).
1098
+ * @returns {formatter} The function has params (timestamp, short). The short is to use the short options.
1011
1099
  */
1012
- export function makeDate(timestamp, utc = true) {
1013
- if (utc)
1014
- return new Date(Date.UTC(timestamp.year, timestamp.month - 1, timestamp.day, 0, 0));
1100
+ export function createNativeLocaleFormatter(locale, cb) {
1101
+ return createNativeLocaleFormatterByMode(locale, cb, makeDateTime);
1102
+ }
1103
+ /**
1104
+ * Returns a UTC locale formatter backed by `Intl.DateTimeFormat`.
1105
+ *
1106
+ * This helper constructs the native `Date` with UTC fields before formatting.
1107
+ * Pair it with `timeZone: "UTC"` when calendar labels must remain pinned to
1108
+ * the Timestamp's UTC date instead of the viewer's local timezone.
1109
+ *
1110
+ * @param {string} locale The locale to use (ie: en-US)
1111
+ * @param {getOptions} cb The function to call for options. This function should return an Intl formatted object. The function is passed (timestamp, short).
1112
+ * @returns {formatter} The function has params (timestamp, short). The short is to use the short options.
1113
+ */
1114
+ export function createNativeLocaleFormatterUTC(locale, cb) {
1115
+ return createNativeLocaleFormatterByMode(locale, cb, makeDateTimeUTC);
1116
+ }
1117
+ /**
1118
+ * Converts a Timestamp date into a host-local JavaScript Date.
1119
+ *
1120
+ * @param {Timestamp} timestamp Timestamp object to convert.
1121
+ * @returns {Date} Host-local JavaScript Date object.
1122
+ */
1123
+ export function makeDate(timestamp) {
1015
1124
  return new Date(timestamp.year, timestamp.month - 1, timestamp.day, 0, 0);
1016
1125
  }
1017
1126
  /**
1018
- * Makes a JavaScript Date from the passed {@link Timestamp} (with time)
1019
- * @param {Timestamp} timestamp The {@link Timestamp} to use
1020
- * @param {boolean} utc True to get Date object using UTC
1021
- * @returns {Date} A JavaScript Date
1127
+ * Converts a Timestamp date into a UTC JavaScript Date.
1128
+ *
1129
+ * @param {Timestamp} timestamp Timestamp object to convert.
1130
+ * @returns {Date} JavaScript Date object built with `Date.UTC()`.
1022
1131
  */
1023
- export function makeDateTime(timestamp, utc = true) {
1024
- if (utc)
1025
- return new Date(Date.UTC(timestamp.year, timestamp.month - 1, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second ?? 0, timestamp.millisecond ?? 0));
1132
+ export function makeDateUTC(timestamp) {
1133
+ return new Date(Date.UTC(timestamp.year, timestamp.month - 1, timestamp.day, 0, 0));
1134
+ }
1135
+ /**
1136
+ * Converts a Timestamp date and time into a host-local JavaScript Date.
1137
+ *
1138
+ * @param {Timestamp} timestamp Timestamp object to convert.
1139
+ * @returns {Date} Host-local JavaScript Date object.
1140
+ */
1141
+ export function makeDateTime(timestamp) {
1026
1142
  return new Date(timestamp.year, timestamp.month - 1, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second ?? 0, timestamp.millisecond ?? 0);
1027
1143
  }
1028
1144
  /**
1029
- * Converts a {@link Timestamp} to a local JavaScript `Date`.
1145
+ * Converts a Timestamp date and time into a UTC JavaScript Date.
1146
+ *
1147
+ * @param {Timestamp} timestamp Timestamp object to convert.
1148
+ * @returns {Date} JavaScript Date object built with `Date.UTC()`.
1149
+ */
1150
+ export function makeDateTimeUTC(timestamp) {
1151
+ return new Date(Date.UTC(timestamp.year, timestamp.month - 1, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second ?? 0, timestamp.millisecond ?? 0));
1152
+ }
1153
+ /**
1154
+ * Converts a Timestamp to a local JavaScript Date.
1030
1155
  *
1031
- * This is equivalent to `makeDateTime(timestamp, false)`.
1156
+ * This is equivalent to `makeDateTime(timestamp)`.
1032
1157
  *
1033
- * @param {Timestamp} timestamp The {@link Timestamp} to convert
1034
- * @returns {Date} A local JavaScript Date
1158
+ * @param {Timestamp} timestamp Timestamp object to convert.
1159
+ * @returns {Date} Local JavaScript Date object.
1035
1160
  */
1036
1161
  export function getDateObject(timestamp) {
1037
- return makeDateTime(timestamp, false);
1162
+ return makeDateTime(timestamp);
1038
1163
  }
1039
1164
  /**
1040
1165
  * Validates if the input is a finite number.
@@ -1047,10 +1172,11 @@ export function validateNumber(input) {
1047
1172
  return isFinite(Number(input));
1048
1173
  }
1049
1174
  /**
1050
- * Given an array of {@link Timestamp}s, finds the max date (and possible time)
1051
- * @param {Timestamp[]} timestamps This is an array of {@link Timestamp}s
1052
- * @param {boolean=} useTime Default false; if true, uses time in the comparison as well
1053
- * @returns The {@link Timestamp} with the highest date (and possibly time) value
1175
+ * Finds the latest Timestamp in an array.
1176
+ *
1177
+ * @param {Timestamp[]} timestamps Timestamp objects to compare.
1178
+ * @param {boolean=} useTime Include time-of-day in the comparison when true.
1179
+ * @returns Latest Timestamp object.
1054
1180
  */
1055
1181
  export function maxTimestamp(timestamps, useTime = false) {
1056
1182
  const func = useTime === true ? getDayTimeIdentifier : getDayIdentifier;
@@ -1059,10 +1185,11 @@ export function maxTimestamp(timestamps, useTime = false) {
1059
1185
  });
1060
1186
  }
1061
1187
  /**
1062
- * Given an array of {@link Timestamp}s, finds the min date (and possible time)
1063
- * @param {Timestamp[]} timestamps This is an array of {@link Timestamp}s
1064
- * @param {boolean=} useTime Default false; if true, uses time in the comparison as well
1065
- * @returns The {@link Timestamp} with the lowest date (and possibly time) value
1188
+ * Finds the earliest Timestamp in an array.
1189
+ *
1190
+ * @param {Timestamp[]} timestamps Timestamp objects to compare.
1191
+ * @param {boolean=} useTime Include time-of-day in the comparison when true.
1192
+ * @returns Earliest Timestamp object.
1066
1193
  */
1067
1194
  export function minTimestamp(timestamps, useTime = false) {
1068
1195
  const func = useTime === true ? getDayTimeIdentifier : getDayIdentifier;
@@ -1071,12 +1198,13 @@ export function minTimestamp(timestamps, useTime = false) {
1071
1198
  });
1072
1199
  }
1073
1200
  /**
1074
- * Determines if the passed {@link Timestamp} is between (or equal) to two {@link Timestamp}s (range)
1075
- * @param {Timestamp} timestamp The {@link Timestamp} for testing
1076
- * @param {Timestamp} startTimestamp The starting {@link Timestamp}
1077
- * @param {Timestamp} endTimestamp The ending {@link Timestamp}
1078
- * @param {boolean=} useTime If true, use time from the {@link Timestamp}s
1079
- * @returns {boolean} True if {@link Timestamp} is between (or equal) to two {@link Timestamp}s (range)
1201
+ * Checks whether a Timestamp falls inside an inclusive range.
1202
+ *
1203
+ * @param {Timestamp} timestamp Timestamp object to test.
1204
+ * @param {Timestamp} startTimestamp Inclusive start boundary.
1205
+ * @param {Timestamp} endTimestamp Inclusive end boundary.
1206
+ * @param {boolean=} useTime Include time-of-day in the comparison when true.
1207
+ * @returns {boolean} True when the timestamp is inside the range.
1080
1208
  */
1081
1209
  export function isBetweenDates(timestamp, startTimestamp, endTimestamp, useTime = false) {
1082
1210
  const cd = getDayIdentifier(timestamp) + (useTime === true ? getTimeIdentifier(timestamp) : 0);
@@ -1085,12 +1213,13 @@ export function isBetweenDates(timestamp, startTimestamp, endTimestamp, useTime
1085
1213
  return cd >= sd && cd <= ed;
1086
1214
  }
1087
1215
  /**
1088
- * Determine if two ranges of {@link Timestamp}s overlap each other
1089
- * @param {Timestamp} startTimestamp The starting {@link Timestamp} of first range
1090
- * @param {Timestamp} endTimestamp The endinging {@link Timestamp} of first range
1091
- * @param {Timestamp} firstTimestamp The starting {@link Timestamp} of second range
1092
- * @param {Timestamp} lastTimestamp The ending {@link Timestamp} of second range
1093
- * @returns {boolean} True if the two ranges overlap each other
1216
+ * Checks whether two inclusive Timestamp ranges overlap.
1217
+ *
1218
+ * @param {Timestamp} startTimestamp Start of the first range.
1219
+ * @param {Timestamp} endTimestamp End of the first range.
1220
+ * @param {Timestamp} firstTimestamp Start of the second range.
1221
+ * @param {Timestamp} lastTimestamp End of the second range.
1222
+ * @returns {boolean} True when the ranges overlap.
1094
1223
  */
1095
1224
  export function isOverlappingDates(startTimestamp, endTimestamp, firstTimestamp, lastTimestamp) {
1096
1225
  const start = getDayIdentifier(startTimestamp);
@@ -1105,11 +1234,12 @@ export function isOverlappingDates(startTimestamp, endTimestamp, firstTimestamp,
1105
1234
  /**
1106
1235
  * Adds or subtracts date/time units from a timestamp.
1107
1236
  *
1108
- * This function returns a new frozen {@link Timestamp}; it does not mutate the
1109
- * timestamp passed in.
1237
+ * This function returns a new frozen Timestamp; it does not mutate the
1238
+ * timestamp passed in. Invalid target dates are normalized through JavaScript
1239
+ * Date rules, so month overflow can roll into the following month.
1110
1240
  *
1111
- * @param {Timestamp} timestamp The {@link Timestamp} object
1112
- * @param {Object} options configuration data
1241
+ * @param {Timestamp} timestamp Timestamp object to offset.
1242
+ * @param {Object} options Date/time units to add or subtract.
1113
1243
  * @param {number=} options.year If positive, adds years. If negative, removes years.
1114
1244
  * @param {number=} options.month If positive, adds months. If negative, removes month.
1115
1245
  * @param {number=} options.day If positive, adds days. If negative, removes days.
@@ -1117,7 +1247,7 @@ export function isOverlappingDates(startTimestamp, endTimestamp, firstTimestamp,
1117
1247
  * @param {number=} options.minute If positive, adds minutes. If negative, removes minutes.
1118
1248
  * @param {number=} options.second If positive, adds seconds. If negative, removes seconds.
1119
1249
  * @param {number=} options.millisecond If positive, adds milliseconds. If negative, removes milliseconds.
1120
- * @returns {Timestamp} A new normalized {@link Timestamp}
1250
+ * @returns {Timestamp} New normalized Timestamp object.
1121
1251
  */
1122
1252
  export function addToDate(timestamp, options) {
1123
1253
  const ts = cloneTimestamp(timestamp);
@@ -1146,11 +1276,11 @@ export function addToDate(timestamp, options) {
1146
1276
  * March. Day and time offsets still use normal JavaScript Date normalization
1147
1277
  * after the year/month clamp is applied.
1148
1278
  *
1149
- * This function returns a new frozen {@link Timestamp}; it does not mutate the
1279
+ * This function returns a new frozen Timestamp; it does not mutate the
1150
1280
  * timestamp passed in.
1151
1281
  *
1152
- * @param {Timestamp} timestamp The {@link Timestamp} object
1153
- * @param {Object} options configuration data
1282
+ * @param {Timestamp} timestamp Timestamp object to offset.
1283
+ * @param {Object} options Date/time units to add or subtract.
1154
1284
  * @param {number=} options.year If positive, adds years. If negative, removes years.
1155
1285
  * @param {number=} options.month If positive, adds months. If negative, removes month.
1156
1286
  * @param {number=} options.day If positive, adds days. If negative, removes days.
@@ -1158,7 +1288,7 @@ export function addToDate(timestamp, options) {
1158
1288
  * @param {number=} options.minute If positive, adds minutes. If negative, removes minutes.
1159
1289
  * @param {number=} options.second If positive, adds seconds. If negative, removes seconds.
1160
1290
  * @param {number=} options.millisecond If positive, adds milliseconds. If negative, removes milliseconds.
1161
- * @returns {Timestamp} A new normalized {@link Timestamp}
1291
+ * @returns {Timestamp} New normalized Timestamp object.
1162
1292
  */
1163
1293
  export function addToDateClamped(timestamp, options) {
1164
1294
  const ts = cloneTimestamp(timestamp);
@@ -1225,9 +1355,9 @@ function normalizeTimestamp(ts) {
1225
1355
  return freezeTimestamp(timestamp);
1226
1356
  }
1227
1357
  /**
1228
- * Returns number of days between two {@link Timestamp}s
1229
- * @param {Timestamp} ts1 The first {@link Timestamp}
1230
- * @param {Timestamp} ts2 The second {@link Timestamp}
1358
+ * Returns number of days between two Timestamps
1359
+ * @param {Timestamp} ts1 The first Timestamp
1360
+ * @param {Timestamp} ts2 The second Timestamp
1231
1361
  * @returns Number of days
1232
1362
  */
1233
1363
  export function daysBetween(ts1, ts2) {
@@ -1235,9 +1365,9 @@ export function daysBetween(ts1, ts2) {
1235
1365
  return Math.floor(diff / TIME_CONSTANTS.MILLISECONDS_IN.DAY);
1236
1366
  }
1237
1367
  /**
1238
- * Returns number of weeks between two {@link Timestamp}s
1239
- * @param {Timestamp} ts1 The first {@link Timestamp}
1240
- * @param {Timestamp} ts2 The second {@link Timestamp}
1368
+ * Returns number of weeks between two Timestamps
1369
+ * @param {Timestamp} ts1 The first Timestamp
1370
+ * @param {Timestamp} ts2 The second Timestamp
1241
1371
  */
1242
1372
  export function weeksBetween(ts1, ts2) {
1243
1373
  let t1 = copyTimestamp(ts1);
@@ -1286,7 +1416,6 @@ export function getWeekdayFormatter() {
1286
1416
  short: { timeZone: "UTC", weekday: "short" },
1287
1417
  narrow: { timeZone: "UTC", weekday: "narrow" },
1288
1418
  };
1289
- /* istanbul ignore next */
1290
1419
  if (typeof Intl === "undefined" || typeof Intl.DateTimeFormat === "undefined") {
1291
1420
  return emptyFormatter;
1292
1421
  }
@@ -1303,7 +1432,7 @@ export function getWeekdayFormatter() {
1303
1432
  const intlFormatter = new Intl.DateTimeFormat(locale || undefined, resolveIntlNameFormat(options, type));
1304
1433
  return intlFormatter.format(weekdayDateMap[weekday]);
1305
1434
  }
1306
- catch (e) /* istanbul ignore next */ {
1435
+ catch (e) {
1307
1436
  if (e instanceof Error) {
1308
1437
  console.error(`Intl.DateTimeFormat: ${e.message} -> day of week: ${weekday}`);
1309
1438
  }
@@ -1313,11 +1442,11 @@ export function getWeekdayFormatter() {
1313
1442
  return weekdayFormatter;
1314
1443
  }
1315
1444
  /**
1316
- * Retrieves an array of localized weekday names.
1445
+ * Retrieves localized weekday names.
1317
1446
  *
1318
- * @param {string} type - The format type for the weekday names. Can be 'narrow', 'short', or 'long'.
1319
- * @param {string} [locale] - The locale to use for formatting. If not provided, the default locale is used.
1320
- * @returns {string[]} An array of localized weekday names in the specified format.
1447
+ * @param {string} type Format type: `narrow`, `short`, or `long`.
1448
+ * @param {string} locale Locale to use for formatting, such as `en-US`.
1449
+ * @returns {string[]} Localized weekday names in Sunday-first order.
1321
1450
  */
1322
1451
  export function getWeekdayNames(type, locale) {
1323
1452
  const shortWeekdays = Object.keys(weekdayDateMap);
@@ -1343,7 +1472,6 @@ export function getMonthFormatter() {
1343
1472
  short: { timeZone: "UTC", month: "short" },
1344
1473
  narrow: { timeZone: "UTC", month: "narrow" },
1345
1474
  };
1346
- /* istanbul ignore next */
1347
1475
  if (typeof Intl === "undefined" || typeof Intl.DateTimeFormat === "undefined") {
1348
1476
  return emptyFormatter;
1349
1477
  }
@@ -1363,7 +1491,7 @@ export function getMonthFormatter() {
1363
1491
  date.setMonth(month);
1364
1492
  return intlFormatter.format(date);
1365
1493
  }
1366
- catch (e) /* istanbul ignore next */ {
1494
+ catch (e) {
1367
1495
  if (e instanceof Error) {
1368
1496
  console.error(`Intl.DateTimeFormat: ${e.message} -> month: ${month}`);
1369
1497
  }
@@ -1373,94 +1501,14 @@ export function getMonthFormatter() {
1373
1501
  return monthFormatter;
1374
1502
  }
1375
1503
  /**
1376
- * Retrieves an array of localized month names.
1504
+ * Retrieves localized month names.
1377
1505
  *
1378
- * @param {string} type - The format type for the month names. Can be 'narrow', 'short', or 'long'.
1379
- * @param {string} [locale] - The locale to use for formatting. If not provided, the default locale is used.
1380
- * @returns {string[]} An array of localized month names in the specified format.
1506
+ * @param {string} type Format type: `narrow`, `short`, or `long`.
1507
+ * @param {string} locale Locale to use for formatting, such as `en-US`.
1508
+ * @returns {string[]} Localized month names in January-first order.
1381
1509
  */
1382
1510
  export function getMonthNames(type, locale) {
1383
1511
  const monthFormatter = getMonthFormatter();
1384
1512
  return [...Array(12).keys()].map((month) => monthFormatter(month, type, locale));
1385
1513
  }
1386
- // the exports...
1387
- export default {
1388
- PARSE_DATETIME,
1389
- PARSE_DATE,
1390
- PARSE_TIME,
1391
- DAYS_IN_MONTH,
1392
- DAYS_IN_MONTH_LEAP,
1393
- DAYS_IN_MONTH_MIN,
1394
- DAYS_IN_MONTH_MAX,
1395
- MONTH_MAX,
1396
- MONTH_MIN,
1397
- DAY_MIN,
1398
- TIME_CONSTANTS,
1399
- DAYS_IN_WEEK,
1400
- MINUTES_IN_HOUR,
1401
- HOURS_IN_DAY,
1402
- FIRST_HOUR,
1403
- MILLISECONDS_IN_MINUTE,
1404
- MILLISECONDS_IN_HOUR,
1405
- MILLISECONDS_IN_DAY,
1406
- MILLISECONDS_IN_WEEK,
1407
- Timestamp,
1408
- TimeObject,
1409
- today,
1410
- getStartOfWeek,
1411
- getEndOfWeek,
1412
- getStartOfMonth,
1413
- getEndOfMonth,
1414
- parseTime,
1415
- validateTimestamp,
1416
- parsed,
1417
- parseTimestamp,
1418
- parseDate,
1419
- getDayIdentifier,
1420
- getTimeIdentifier,
1421
- getDayTimeIdentifier,
1422
- diffTimestamp,
1423
- updateRelative,
1424
- updateMinutes,
1425
- updateWeekday,
1426
- updateDayOfYear,
1427
- updateWorkWeek,
1428
- updateDisabled,
1429
- updateFormatted,
1430
- getDayOfYear,
1431
- getWorkWeek,
1432
- getWeekday,
1433
- isLeapYear,
1434
- daysInMonth,
1435
- copyTimestamp,
1436
- padNumber,
1437
- getDate,
1438
- getTime,
1439
- getDateTime,
1440
- nextDay,
1441
- prevDay,
1442
- relativeDays,
1443
- findWeekday,
1444
- createDayList,
1445
- createIntervalList,
1446
- createNativeLocaleFormatter,
1447
- makeDate,
1448
- makeDateTime,
1449
- getDateObject,
1450
- validateNumber,
1451
- isBetweenDates,
1452
- isOverlappingDates,
1453
- daysBetween,
1454
- weeksBetween,
1455
- addToDate,
1456
- addToDateClamped,
1457
- compareTimestamps,
1458
- compareDate,
1459
- compareTime,
1460
- compareDateTime,
1461
- getWeekdayFormatter,
1462
- getWeekdayNames,
1463
- getMonthFormatter,
1464
- getMonthNames,
1465
- };
1466
1514
  //# sourceMappingURL=index.js.map