@dereekb/date 13.2.0 → 13.2.2

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/index.esm.js CHANGED
@@ -1,9 +1,10 @@
1
- import { MS_IN_HOUR, MS_IN_MINUTE, MINUTES_IN_DAY, isISO8601DateString, filterMaybeArrayValues, asArray, dayOfWeek, sortNumbersAscendingFunction, MS_IN_SECOND, SORT_VALUE_LESS_THAN, SORT_VALUE_GREATER_THAN, SORT_VALUE_EQUAL, copyArray, compareFnOrder, MS_IN_DAY, daysOfWeekArray, groupValues, minutesToFractionalHours, safeCompareEquality, DATE_NOW_VALUE, mapIdentityFunction, UTC_TIMEZONE_STRING, cachedGetter, parseISO8601DayStringToUTCDate, isConsideredUtcTimezoneString, isSameNonNullValue, replaceStringsFunction, repeatString, isEqualDate, startOfDayForUTCDateInUTC, range, pushArrayItemsIntoArray, sumOfIntegersBetween, makeValuesGroupMap, lastValue, sortAscendingIndexNumberRefFunction, indexRangeCheckFunction, asGetter, mergeFilterFunctions, isDate as isDate$2, HOURS_IN_DAY, getNextDay, iterablesAreSetEquivalent, daysOfWeekFromEnabledDays, forEachInIterable, enabledDaysFromDaysOfWeek, addToSet, invertFilter, firstValueFromIterable, HashSet, roundNumberUpToStep, protectedFactory, TimeAM, isLogicalDateStringCode as isLogicalDateStringCode$1, dateFromLogicalDate as dateFromLogicalDate$1, flattenArray, splitJoinRemainder } from '@dereekb/util';
1
+ import { MS_IN_HOUR, MS_IN_MINUTE, MINUTES_IN_DAY, isISO8601DateString, filterMaybeArrayValues, asArray, dayOfWeek, sortNumbersAscendingFunction, MS_IN_SECOND, SORT_VALUE_LESS_THAN, SORT_VALUE_GREATER_THAN, SORT_VALUE_EQUAL, copyArray, compareFnOrder, MS_IN_DAY, daysOfWeekArray, groupValues, DATE_NOW_VALUE, mapIdentityFunction, UTC_TIMEZONE_STRING, cachedGetter, parseISO8601DayStringToUTCDate, isConsideredUtcTimezoneString, isSameNonNullValue, repeatString, isEqualDate, startOfDayForUTCDateInUTC, minutesToFractionalHours, range, pushArrayItemsIntoArray, sumOfIntegersBetween, makeValuesGroupMap, lastValue, sortAscendingIndexNumberRefFunction, indexRangeCheckFunction, asGetter, mergeFilterFunctions, isDate as isDate$2, HOURS_IN_DAY, safeCompareEquality, getNextDay, iterablesAreSetEquivalent, daysOfWeekFromEnabledDays, forEachInIterable, enabledDaysFromDaysOfWeek, addToSet, invertFilter, firstValueFromIterable, replaceStringsFunction, HashSet, roundNumberUpToStep, protectedFactory, TimeAM, isLogicalDateStringCode as isLogicalDateStringCode$1, dateFromLogicalDate as dateFromLogicalDate$1, flattenArray, splitJoinRemainder } from '@dereekb/util';
2
2
  export { dateFromDateOrTimeMillisecondsNumber, unixDateTimeSecondsNumberForNow, unixDateTimeSecondsNumberFromDate, unixDateTimeSecondsNumberFromDateOrTimeNumber, unixDateTimeSecondsNumberToDate } from '@dereekb/util';
3
- import { isEqual, isSameDay, isDate as isDate$1, startOfMinute, isValid, parseISO, min, max, isAfter as isAfter$1, isBefore as isBefore$1, set, addMilliseconds, startOfMonth, endOfWeek, startOfWeek, endOfMonth, addDays, addHours, addMinutes, differenceInDays, startOfDay, addMonths, addWeeks, endOfDay, endOfHour, startOfHour, endOfMinute, differenceInMinutes, differenceInHours, millisecondsToHours, millisecondsToMinutes, formatDistanceStrict, formatDistance, formatDistanceToNow, format as format$1, parse, differenceInMilliseconds, getMinutes, getSeconds, getMilliseconds, setWeek, getWeek, getYear, getDay, isPast, addSeconds } from 'date-fns';
4
- import { type } from 'arktype';
3
+ import { isEqual, isSameDay, isDate as isDate$1, startOfMinute, isValid, parseISO, min, max, isAfter as isAfter$1, isBefore as isBefore$1, set, addMilliseconds, startOfMonth, endOfWeek, startOfWeek, endOfMonth, addDays, addHours, addMinutes, differenceInDays, startOfDay, addMonths, addWeeks, endOfDay, endOfHour, startOfHour, endOfMinute, differenceInHours, millisecondsToHours, millisecondsToMinutes, formatDistanceStrict, formatDistance, formatDistanceToNow, format as format$1, differenceInMinutes, parse, differenceInMilliseconds, getMinutes, getSeconds, getMilliseconds, setWeek, getWeek, getYear, getDay, isPast, addSeconds } from 'date-fns';
5
4
  import { toZonedTime, format, formatInTimeZone } from 'date-fns-tz';
5
+ import { type } from 'arktype';
6
6
  import { timeZonesNames } from '@vvo/tzdb';
7
+ import { ARKTYPE_DATE_DTO_TYPE } from '@dereekb/model';
7
8
  import { interval, startWith, map, distinctUntilChanged } from 'rxjs';
8
9
  import { RRule } from 'rrule';
9
10
 
@@ -686,13 +687,6 @@ function isDateRangeStart(value) {
686
687
  * ```
687
688
  */
688
689
  const sortDateRangeStartAscendingCompareFunction = sortByDateFunction((x) => x.start);
689
- /**
690
- * ArkType schema for {@link DateRange}.
691
- */
692
- const dateRangeType = type({
693
- start: 'Date',
694
- end: 'Date'
695
- });
696
690
  /**
697
691
  * Counts the total number of calendar days spanned by the range, inclusive of both endpoints.
698
692
  * Always returns at least 1, even for same-day ranges.
@@ -868,14 +862,6 @@ var DateRangeType;
868
862
  */
869
863
  DateRangeType["CALENDAR_MONTH"] = "calendar_month";
870
864
  })(DateRangeType || (DateRangeType = {}));
871
- /**
872
- * ArkType schema for {@link DateRangeParams}.
873
- */
874
- const dateRangeParamsType = type({
875
- type: type.enumerated(...Object.values(DateRangeType)),
876
- date: 'Date',
877
- 'distance?': 'number'
878
- });
879
865
  /**
880
866
  * Creates a {@link DateRange} from the given type and optional parameters. Supports many range
881
867
  * strategies including fixed periods (day, week, month), directional ranges, and radii.
@@ -1472,75 +1458,6 @@ function getDaysOfWeekInDateRange(dateRange) {
1472
1458
  return days;
1473
1459
  }
1474
1460
 
1475
- /**
1476
- * ArkType schema for {@link DateDurationSpan}.
1477
- */
1478
- const dateDurationSpanType = type({
1479
- startsAt: 'Date',
1480
- duration: 'number >= 0'
1481
- });
1482
- /**
1483
- * Computes the end date for a duration span by adding the duration to the start time.
1484
- *
1485
- * @param span - the duration span to compute the end for
1486
- * @returns the date when the span ends
1487
- *
1488
- * @example
1489
- * ```ts
1490
- * const span = { startsAt: new Date('2024-01-01T10:00:00Z'), duration: 60 };
1491
- * dateDurationSpanEndDate(span); // 2024-01-01T11:00:00Z
1492
- * ```
1493
- */
1494
- function dateDurationSpanEndDate(span) {
1495
- return addMinutes(span.startsAt, span.duration);
1496
- }
1497
- /**
1498
- * Converts a {@link DateDurationSpan} to a {@link DateRange} with start and end dates.
1499
- *
1500
- * @param span - the duration span to convert
1501
- * @returns a date range from startsAt to startsAt + duration
1502
- */
1503
- function durationSpanToDateRange(span) {
1504
- return {
1505
- start: span.startsAt,
1506
- end: addMinutes(span.startsAt, span.duration)
1507
- };
1508
- }
1509
- /**
1510
- * Creates a {@link DateDurationSpan} from a {@link DateRange} by computing the duration in minutes between start and end.
1511
- *
1512
- * @param dateRange - the date range to convert
1513
- * @returns a duration span with the range's start as startsAt
1514
- */
1515
- function durationSpanFromDateRange(dateRange) {
1516
- return {
1517
- startsAt: dateRange.start,
1518
- duration: differenceInMinutes(dateRange.end, dateRange.start)
1519
- };
1520
- }
1521
- /**
1522
- * Determines whether a duration span is in the past, present, or future relative to the given time.
1523
- *
1524
- * @param span - the duration span to check
1525
- * @param now - reference time (defaults to current time)
1526
- * @returns 'past', 'present', or 'future'
1527
- */
1528
- function durationSpanDateRelativeState(span, now) {
1529
- return dateRangeRelativeState(durationSpanToDateRange(span), now);
1530
- }
1531
- /**
1532
- * Converts a duration span's duration from minutes to fractional hours.
1533
- *
1534
- * @param span - the duration span to measure
1535
- * @returns the duration expressed as fractional hours (e.g. 90 minutes = 1.5)
1536
- */
1537
- function fractionalHoursInDurationSpan(span) {
1538
- return minutesToFractionalHours(span.duration);
1539
- }
1540
- function isSameDurationSpan(a, b) {
1541
- return safeCompareEquality(a, b, (a, b) => a.duration === b.duration && isSameDate(a.startsAt, b.startsAt));
1542
- }
1543
-
1544
1461
  /**
1545
1462
  * String code for the start of the current day.
1546
1463
  */
@@ -2452,158 +2369,6 @@ function copyHoursAndMinutesFromDateWithTimezoneNormal(input, copyFrom, timezone
2452
2369
  return result;
2453
2370
  }
2454
2371
 
2455
- /**
2456
- * Returns all recognized IANA timezone strings, including the explicit UTC entry.
2457
- *
2458
- * @example
2459
- * ```ts
2460
- * const zones = allTimezoneStrings();
2461
- * // ['Africa/Abidjan', ..., 'UTC']
2462
- * ```
2463
- */
2464
- function allTimezoneStrings() {
2465
- return timeZonesNames.concat(UTC_TIMEZONE_STRING);
2466
- }
2467
- /**
2468
- * Lazily-computed set of all known timezone strings for O(1) membership checks.
2469
- *
2470
- * @example
2471
- * ```ts
2472
- * allKnownTimezoneStrings().has('America/New_York'); // true
2473
- * ```
2474
- */
2475
- const allKnownTimezoneStrings = cachedGetter(() => {
2476
- return new Set(allTimezoneStrings());
2477
- });
2478
- /**
2479
- * Lazily-computed array of {@link TimezoneInfo} for every known timezone.
2480
- *
2481
- * Abbreviations are resolved at the time of first access, so results reflect
2482
- * the DST state at that moment.
2483
- */
2484
- const allTimezoneInfos = cachedGetter(() => {
2485
- const now = new Date();
2486
- return allTimezoneStrings().map((x) => timezoneStringToTimezoneInfo(x, now));
2487
- });
2488
- /**
2489
- * Returns the {@link TimezoneInfo} for the current system timezone, falling back to UTC.
2490
- *
2491
- * @example
2492
- * ```ts
2493
- * const info = timezoneInfoForSystem();
2494
- * console.log(info.abbreviation); // e.g., 'CST'
2495
- * ```
2496
- */
2497
- function timezoneInfoForSystem() {
2498
- return timezoneStringToTimezoneInfo(guessCurrentTimezone() ?? UTC_TIMEZONE_STRING);
2499
- }
2500
- /**
2501
- * Returns the short abbreviation (e.g., `"EST"`, `"PDT"`) for the given timezone at the specified date.
2502
- *
2503
- * The date matters because abbreviations change with DST transitions.
2504
- * Returns `"UKNOWN"` if no timezone is provided.
2505
- *
2506
- * @example
2507
- * ```ts
2508
- * getTimezoneAbbreviation('America/New_York'); // 'EST' or 'EDT'
2509
- * ```
2510
- */
2511
- function getTimezoneAbbreviation(timezone, date = new Date()) {
2512
- return timezone === UTC_TIMEZONE_STRING ? UTC_TIMEZONE_STRING : timezone ? formatInTimeZone(date, timezone, 'zzz') : 'UKNOWN';
2513
- }
2514
- /**
2515
- * Returns the full display name (e.g., `"Eastern Standard Time"`) for the given timezone.
2516
- *
2517
- * Returns `"Unknown Timezone"` if no timezone is provided.
2518
- *
2519
- * @example
2520
- * ```ts
2521
- * getTimezoneLongName('America/New_York'); // 'Eastern Standard Time'
2522
- * ```
2523
- */
2524
- function getTimezoneLongName(timezone, date = new Date()) {
2525
- return timezone ? formatInTimeZone(date, timezone, 'zzzz') : 'Unknown Timezone';
2526
- }
2527
- /**
2528
- * Builds a {@link TimezoneInfo} for the given timezone, computing abbreviation and search variants.
2529
- *
2530
- * @example
2531
- * ```ts
2532
- * const info = timezoneStringToTimezoneInfo('America/Chicago');
2533
- * // info.abbreviation => 'CST' or 'CDT'
2534
- * // info.search => 'america chicago'
2535
- * ```
2536
- */
2537
- function timezoneStringToTimezoneInfo(timezone, date = new Date()) {
2538
- const abbreviation = getTimezoneAbbreviation(timezone, date);
2539
- const result = {
2540
- timezone,
2541
- search: timezoneStringToSearchableString(timezone),
2542
- lowercase: timezone.toLowerCase(),
2543
- abbreviation,
2544
- lowercaseAbbreviation: abbreviation.toLowerCase()
2545
- };
2546
- return result;
2547
- }
2548
- /**
2549
- * Filters timezone infos by a search string, matching against the searchable name,
2550
- * lowercase identifier, and abbreviation.
2551
- *
2552
- * For queries longer than 2 characters, substring matching on the searchable name is also used.
2553
- *
2554
- * @example
2555
- * ```ts
2556
- * const results = searchTimezoneInfos('eastern', allTimezoneInfos());
2557
- * ```
2558
- */
2559
- function searchTimezoneInfos(search, infos) {
2560
- const searchString = search.toLocaleLowerCase();
2561
- return infos.filter((x) => (search.length > 2 && x.search.includes(searchString)) || x.lowercase.startsWith(searchString) || x.lowercaseAbbreviation.startsWith(searchString) || x.abbreviation.includes(search) || x.search === x.timezone);
2562
- }
2563
- const timezoneStringToSearchableStringReplace = replaceStringsFunction({
2564
- replace: ['/', '_'],
2565
- replaceWith: ' '
2566
- });
2567
- /**
2568
- * Converts a timezone identifier into a lowercase, space-separated string for search indexing.
2569
- *
2570
- * Replaces `/` and `_` with spaces (e.g., `"America/New_York"` becomes `"america new york"`).
2571
- *
2572
- * @example
2573
- * ```ts
2574
- * timezoneStringToSearchableString('America/New_York'); // 'america new york'
2575
- * ```
2576
- */
2577
- function timezoneStringToSearchableString(timezone) {
2578
- return timezoneStringToSearchableStringReplace(timezone.toLocaleLowerCase());
2579
- }
2580
- /**
2581
- * Checks whether the input string is a recognized IANA timezone identifier.
2582
- *
2583
- * Uses the cached set from {@link allKnownTimezoneStrings} for O(1) lookup.
2584
- *
2585
- * @example
2586
- * ```ts
2587
- * isKnownTimezone('America/New_York'); // true
2588
- * isKnownTimezone('Mars/Olympus'); // false
2589
- * ```
2590
- */
2591
- function isKnownTimezone(input) {
2592
- return allKnownTimezoneStrings().has(input);
2593
- }
2594
-
2595
- /**
2596
- * ArkType schema that validates a string is a recognized IANA timezone.
2597
- *
2598
- * Delegates to {@link isKnownTimezone} for the actual check.
2599
- *
2600
- * @example
2601
- * ```ts
2602
- * const result = knownTimezoneType('America/Denver');
2603
- * ```
2604
- */
2605
- const knownTimezoneType = type('string > 0').narrow((val, ctx) => (val != null && isKnownTimezone(val)) || ctx.mustBe('a known timezone'));
2606
-
2607
2372
  /**
2608
2373
  * Creates a {@link FitDateRangeToDayPeriodFunction} that collapses a multi-day date range into a single-day period within the given timezone.
2609
2374
  *
@@ -3144,12 +2909,6 @@ function parseISO8601DayStringToDate(dayString) {
3144
2909
  function isValidDateCellIndex(input) {
3145
2910
  return input >= 0 && Number.isInteger(input);
3146
2911
  }
3147
- /**
3148
- * ArkType schema for {@link DateCell}.
3149
- */
3150
- const dateCellType = type({
3151
- i: 'number.integer >= 0'
3152
- });
3153
2912
  /**
3154
2913
  * Normalizes a number or {@link DateCell} to a DateCell object.
3155
2914
  *
@@ -3190,13 +2949,6 @@ function dateCellTimingStartsAtForStartOfDay(input = {}) {
3190
2949
  timezone
3191
2950
  };
3192
2951
  }
3193
- /**
3194
- * ArkType schema for {@link DateCellTiming}.
3195
- */
3196
- const dateCellTimingType = dateDurationSpanType.merge({
3197
- end: 'Date',
3198
- timezone: knownTimezoneType
3199
- });
3200
2952
  /**
3201
2953
  * Creates a {@link DateTimezoneUtcNormalInstance} from the input, guaranteeing that a timezone string is configured.
3202
2954
  *
@@ -3782,12 +3534,6 @@ function isValidFullDateCellTiming(timing) {
3782
3534
  return isValid;
3783
3535
  }
3784
3536
 
3785
- /**
3786
- * ArkType schema for {@link DateCellRange}.
3787
- */
3788
- const dateCellRangeType = dateCellType.merge({
3789
- 'to?': 'number.integer >= 0'
3790
- });
3791
3537
  /**
3792
3538
  * Returns true if the input is a DateCellRange.
3793
3539
  *
@@ -5241,16 +4987,78 @@ function isDateWithinDateCellRangeFunction(config) {
5241
4987
  }
5242
4988
 
5243
4989
  /**
5244
- * Creates a filter that passes date cell duration spans whose start time is at or before the given reference time.
5245
- *
5246
- * Useful for identifying events or blocks that have already begun relative to a point in time.
4990
+ * Computes the end date for a duration span by adding the duration to the start time.
5247
4991
  *
5248
- * @param now - Reference time to compare against. Defaults to the current time.
4992
+ * @param span - the duration span to compute the end for
4993
+ * @returns the date when the span ends
5249
4994
  *
5250
4995
  * @example
5251
4996
  * ```ts
5252
- * const hasStarted = dateCellDurationSpanHasStartedFilterFunction(new Date());
5253
- * const startedSpans = allSpans.filter(hasStarted);
4997
+ * const span = { startsAt: new Date('2024-01-01T10:00:00Z'), duration: 60 };
4998
+ * dateDurationSpanEndDate(span); // 2024-01-01T11:00:00Z
4999
+ * ```
5000
+ */
5001
+ function dateDurationSpanEndDate(span) {
5002
+ return addMinutes(span.startsAt, span.duration);
5003
+ }
5004
+ /**
5005
+ * Converts a {@link DateDurationSpan} to a {@link DateRange} with start and end dates.
5006
+ *
5007
+ * @param span - the duration span to convert
5008
+ * @returns a date range from startsAt to startsAt + duration
5009
+ */
5010
+ function durationSpanToDateRange(span) {
5011
+ return {
5012
+ start: span.startsAt,
5013
+ end: addMinutes(span.startsAt, span.duration)
5014
+ };
5015
+ }
5016
+ /**
5017
+ * Creates a {@link DateDurationSpan} from a {@link DateRange} by computing the duration in minutes between start and end.
5018
+ *
5019
+ * @param dateRange - the date range to convert
5020
+ * @returns a duration span with the range's start as startsAt
5021
+ */
5022
+ function durationSpanFromDateRange(dateRange) {
5023
+ return {
5024
+ startsAt: dateRange.start,
5025
+ duration: differenceInMinutes(dateRange.end, dateRange.start)
5026
+ };
5027
+ }
5028
+ /**
5029
+ * Determines whether a duration span is in the past, present, or future relative to the given time.
5030
+ *
5031
+ * @param span - the duration span to check
5032
+ * @param now - reference time (defaults to current time)
5033
+ * @returns 'past', 'present', or 'future'
5034
+ */
5035
+ function durationSpanDateRelativeState(span, now) {
5036
+ return dateRangeRelativeState(durationSpanToDateRange(span), now);
5037
+ }
5038
+ /**
5039
+ * Converts a duration span's duration from minutes to fractional hours.
5040
+ *
5041
+ * @param span - the duration span to measure
5042
+ * @returns the duration expressed as fractional hours (e.g. 90 minutes = 1.5)
5043
+ */
5044
+ function fractionalHoursInDurationSpan(span) {
5045
+ return minutesToFractionalHours(span.duration);
5046
+ }
5047
+ function isSameDurationSpan(a, b) {
5048
+ return safeCompareEquality(a, b, (a, b) => a.duration === b.duration && isSameDate(a.startsAt, b.startsAt));
5049
+ }
5050
+
5051
+ /**
5052
+ * Creates a filter that passes date cell duration spans whose start time is at or before the given reference time.
5053
+ *
5054
+ * Useful for identifying events or blocks that have already begun relative to a point in time.
5055
+ *
5056
+ * @param now - Reference time to compare against. Defaults to the current time.
5057
+ *
5058
+ * @example
5059
+ * ```ts
5060
+ * const hasStarted = dateCellDurationSpanHasStartedFilterFunction(new Date());
5061
+ * const startedSpans = allSpans.filter(hasStarted);
5254
5062
  * ```
5255
5063
  */
5256
5064
  function dateCellDurationSpanHasStartedFilterFunction(now = new Date()) {
@@ -6059,14 +5867,6 @@ function isSameDateCellSchedule(a, b) {
6059
5867
  return a == b;
6060
5868
  }
6061
5869
  }
6062
- /**
6063
- * ArkType schema for {@link DateCellSchedule}.
6064
- */
6065
- const dateCellScheduleType = type({
6066
- w: [DATE_CELL_SCHEDULE_ENCODED_WEEK_REGEX, '&', 'string'],
6067
- 'd?': 'number.integer >= 0 []',
6068
- 'ex?': 'number.integer >= 0 []'
6069
- });
6070
5870
  /**
6071
5871
  * Returns true if the input is possibly a DateCellScheduleDateRange (has schedule fields and valid start/end dates).
6072
5872
  *
@@ -6576,17 +6376,144 @@ function dateCellIndexsForDateCellScheduleDayCodes(sundayIndex, dayCodes) {
6576
6376
  }
6577
6377
 
6578
6378
  /**
6579
- * ArkType schema that validates a value is a valid {@link DateCellTiming}.
6379
+ * Returns all recognized IANA timezone strings, including the explicit UTC entry.
6380
+ *
6381
+ * @example
6382
+ * ```ts
6383
+ * const zones = allTimezoneStrings();
6384
+ * // ['Africa/Abidjan', ..., 'UTC']
6385
+ * ```
6386
+ */
6387
+ function allTimezoneStrings() {
6388
+ return timeZonesNames.concat(UTC_TIMEZONE_STRING);
6389
+ }
6390
+ /**
6391
+ * Lazily-computed set of all known timezone strings for O(1) membership checks.
6392
+ *
6393
+ * @example
6394
+ * ```ts
6395
+ * allKnownTimezoneStrings().has('America/New_York'); // true
6396
+ * ```
6580
6397
  */
6581
- const validDateCellTimingType = dateCellTimingType.narrow((val, ctx) => (val != null && isValidDateCellTiming(val)) || ctx.mustBe('a valid DateCellTiming'));
6398
+ const allKnownTimezoneStrings = cachedGetter(() => {
6399
+ return new Set(allTimezoneStrings());
6400
+ });
6582
6401
  /**
6583
- * ArkType schema that validates a value is a valid {@link DateCellRange} (non-negative indexes, `to >= i`).
6402
+ * Lazily-computed array of {@link TimezoneInfo} for every known timezone.
6403
+ *
6404
+ * Abbreviations are resolved at the time of first access, so results reflect
6405
+ * the DST state at that moment.
6584
6406
  */
6585
- const validDateCellRangeType = dateCellRangeType.narrow((val, ctx) => (val != null && isValidDateCellRange(val)) || ctx.mustBe('a valid DateCellRange'));
6407
+ const allTimezoneInfos = cachedGetter(() => {
6408
+ const now = new Date();
6409
+ return allTimezoneStrings().map((x) => timezoneStringToTimezoneInfo(x, now));
6410
+ });
6586
6411
  /**
6587
- * ArkType schema that validates a value is a sorted array of non-overlapping {@link DateCellRange} values.
6412
+ * Returns the {@link TimezoneInfo} for the current system timezone, falling back to UTC.
6413
+ *
6414
+ * @example
6415
+ * ```ts
6416
+ * const info = timezoneInfoForSystem();
6417
+ * console.log(info.abbreviation); // e.g., 'CST'
6418
+ * ```
6588
6419
  */
6589
- const validDateCellRangeSeriesType = type(dateCellRangeType.array()).narrow((val, ctx) => (val != null && isValidDateCellRangeSeries(val)) || ctx.mustBe('a valid DateCellRange series with items sorted in ascending order and no repeat indexes'));
6420
+ function timezoneInfoForSystem() {
6421
+ return timezoneStringToTimezoneInfo(guessCurrentTimezone() ?? UTC_TIMEZONE_STRING);
6422
+ }
6423
+ /**
6424
+ * Returns the short abbreviation (e.g., `"EST"`, `"PDT"`) for the given timezone at the specified date.
6425
+ *
6426
+ * The date matters because abbreviations change with DST transitions.
6427
+ * Returns `"UKNOWN"` if no timezone is provided.
6428
+ *
6429
+ * @example
6430
+ * ```ts
6431
+ * getTimezoneAbbreviation('America/New_York'); // 'EST' or 'EDT'
6432
+ * ```
6433
+ */
6434
+ function getTimezoneAbbreviation(timezone, date = new Date()) {
6435
+ return timezone === UTC_TIMEZONE_STRING ? UTC_TIMEZONE_STRING : timezone ? formatInTimeZone(date, timezone, 'zzz') : 'UKNOWN';
6436
+ }
6437
+ /**
6438
+ * Returns the full display name (e.g., `"Eastern Standard Time"`) for the given timezone.
6439
+ *
6440
+ * Returns `"Unknown Timezone"` if no timezone is provided.
6441
+ *
6442
+ * @example
6443
+ * ```ts
6444
+ * getTimezoneLongName('America/New_York'); // 'Eastern Standard Time'
6445
+ * ```
6446
+ */
6447
+ function getTimezoneLongName(timezone, date = new Date()) {
6448
+ return timezone ? formatInTimeZone(date, timezone, 'zzzz') : 'Unknown Timezone';
6449
+ }
6450
+ /**
6451
+ * Builds a {@link TimezoneInfo} for the given timezone, computing abbreviation and search variants.
6452
+ *
6453
+ * @example
6454
+ * ```ts
6455
+ * const info = timezoneStringToTimezoneInfo('America/Chicago');
6456
+ * // info.abbreviation => 'CST' or 'CDT'
6457
+ * // info.search => 'america chicago'
6458
+ * ```
6459
+ */
6460
+ function timezoneStringToTimezoneInfo(timezone, date = new Date()) {
6461
+ const abbreviation = getTimezoneAbbreviation(timezone, date);
6462
+ const result = {
6463
+ timezone,
6464
+ search: timezoneStringToSearchableString(timezone),
6465
+ lowercase: timezone.toLowerCase(),
6466
+ abbreviation,
6467
+ lowercaseAbbreviation: abbreviation.toLowerCase()
6468
+ };
6469
+ return result;
6470
+ }
6471
+ /**
6472
+ * Filters timezone infos by a search string, matching against the searchable name,
6473
+ * lowercase identifier, and abbreviation.
6474
+ *
6475
+ * For queries longer than 2 characters, substring matching on the searchable name is also used.
6476
+ *
6477
+ * @example
6478
+ * ```ts
6479
+ * const results = searchTimezoneInfos('eastern', allTimezoneInfos());
6480
+ * ```
6481
+ */
6482
+ function searchTimezoneInfos(search, infos) {
6483
+ const searchString = search.toLocaleLowerCase();
6484
+ return infos.filter((x) => (search.length > 2 && x.search.includes(searchString)) || x.lowercase.startsWith(searchString) || x.lowercaseAbbreviation.startsWith(searchString) || x.abbreviation.includes(search) || x.search === x.timezone);
6485
+ }
6486
+ const timezoneStringToSearchableStringReplace = replaceStringsFunction({
6487
+ replace: ['/', '_'],
6488
+ replaceWith: ' '
6489
+ });
6490
+ /**
6491
+ * Converts a timezone identifier into a lowercase, space-separated string for search indexing.
6492
+ *
6493
+ * Replaces `/` and `_` with spaces (e.g., `"America/New_York"` becomes `"america new york"`).
6494
+ *
6495
+ * @example
6496
+ * ```ts
6497
+ * timezoneStringToSearchableString('America/New_York'); // 'america new york'
6498
+ * ```
6499
+ */
6500
+ function timezoneStringToSearchableString(timezone) {
6501
+ return timezoneStringToSearchableStringReplace(timezone.toLocaleLowerCase());
6502
+ }
6503
+ /**
6504
+ * Checks whether the input string is a recognized IANA timezone identifier.
6505
+ *
6506
+ * Uses the cached set from {@link allKnownTimezoneStrings} for O(1) lookup.
6507
+ *
6508
+ * @example
6509
+ * ```ts
6510
+ * isKnownTimezone('America/New_York'); // true
6511
+ * isKnownTimezone('Mars/Olympus'); // false
6512
+ * ```
6513
+ */
6514
+ function isKnownTimezone(input) {
6515
+ return allKnownTimezoneStrings().has(input);
6516
+ }
6590
6517
 
6591
6518
  /**
6592
6519
  * Distinguishes between time-based calendar events and all-day/multi-day events.
@@ -6602,12 +6529,6 @@ var CalendarDateType;
6602
6529
  */
6603
6530
  CalendarDateType["DAYS"] = "days";
6604
6531
  })(CalendarDateType || (CalendarDateType = {}));
6605
- /**
6606
- * ArkType schema for {@link CalendarDate}.
6607
- */
6608
- const calendarDateType = dateDurationSpanType.merge({
6609
- type: type.enumerated(...Object.values(CalendarDateType))
6610
- });
6611
6532
  /**
6612
6533
  * Creates a {@link CalendarDateFactory} that produces all-day calendar events with timezone-aware start times.
6613
6534
  *
@@ -6677,6 +6598,151 @@ function calendarDateForDateDurationSpan(dateDurationSpan) {
6677
6598
  };
6678
6599
  }
6679
6600
 
6601
+ // MARK: Timezone
6602
+ /**
6603
+ * ArkType DTO schema that validates a string is a recognized IANA timezone.
6604
+ *
6605
+ * Delegates to {@link isKnownTimezone} for the actual check.
6606
+ *
6607
+ * Intended for validating and parsing DTO/JSON data where timezones arrive as strings.
6608
+ *
6609
+ * @example
6610
+ * ```ts
6611
+ * const result = knownTimezoneType('America/Denver');
6612
+ * ```
6613
+ */
6614
+ const knownTimezoneType = type('string > 0').narrow((val, ctx) => (val != null && isKnownTimezone(val)) || ctx.mustBe('a known timezone'));
6615
+ // MARK: DateDurationSpan
6616
+ /**
6617
+ * ArkType DTO schema for {@link DateDurationSpan}.
6618
+ *
6619
+ * Accepts both Date objects and date strings (parsed via `string.date.parse`).
6620
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6621
+ * or runtime Date objects into the corresponding runtime types.
6622
+ */
6623
+ const dateDurationSpanType = type({
6624
+ startsAt: ARKTYPE_DATE_DTO_TYPE,
6625
+ duration: 'number >= 0'
6626
+ });
6627
+ // MARK: DateRange
6628
+ /**
6629
+ * ArkType DTO schema for {@link DateRange}.
6630
+ *
6631
+ * Accepts both Date objects and date strings (parsed via `string.date.parse`).
6632
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6633
+ * or runtime Date objects into the corresponding runtime types.
6634
+ */
6635
+ const dateRangeType = type({
6636
+ start: ARKTYPE_DATE_DTO_TYPE,
6637
+ end: ARKTYPE_DATE_DTO_TYPE
6638
+ });
6639
+ // MARK: DateRangeParams
6640
+ /**
6641
+ * ArkType DTO schema for {@link DateRangeParams}.
6642
+ *
6643
+ * Accepts both Date objects and date strings (parsed via `string.date.parse`).
6644
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6645
+ * or runtime Date objects into the corresponding runtime types.
6646
+ */
6647
+ const dateRangeParamsType = type({
6648
+ type: type.enumerated(...Object.values(DateRangeType)),
6649
+ date: ARKTYPE_DATE_DTO_TYPE,
6650
+ 'distance?': 'number'
6651
+ });
6652
+ // MARK: DateCell
6653
+ /**
6654
+ * ArkType DTO schema for {@link DateCell}.
6655
+ *
6656
+ * Validates a cell index from JSON/DTO input.
6657
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6658
+ * into the corresponding runtime types.
6659
+ */
6660
+ const dateCellType = type({
6661
+ i: 'number.integer >= 0'
6662
+ });
6663
+ // MARK: DateCellRange
6664
+ /**
6665
+ * ArkType DTO schema for {@link DateCellRange}.
6666
+ *
6667
+ * Validates cell range indexes from JSON/DTO input.
6668
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6669
+ * into the corresponding runtime types.
6670
+ */
6671
+ const dateCellRangeType = dateCellType.merge({
6672
+ 'to?': 'number.integer >= 0'
6673
+ });
6674
+ // MARK: DateCellTiming
6675
+ /**
6676
+ * ArkType DTO schema for {@link DateCellTiming}.
6677
+ *
6678
+ * Accepts both Date objects and date strings (parsed via `string.date.parse`).
6679
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6680
+ * or runtime Date objects into the corresponding runtime types.
6681
+ */
6682
+ const dateCellTimingType = dateDurationSpanType.merge({
6683
+ end: ARKTYPE_DATE_DTO_TYPE,
6684
+ timezone: knownTimezoneType
6685
+ });
6686
+ // MARK: CalendarDate
6687
+ /**
6688
+ * ArkType DTO schema for {@link CalendarDate}.
6689
+ *
6690
+ * Accepts both Date objects and date strings (parsed via `string.date.parse`).
6691
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6692
+ * or runtime Date objects into the corresponding runtime types.
6693
+ */
6694
+ const calendarDateType = dateDurationSpanType.merge({
6695
+ type: type.enumerated(...Object.values(CalendarDateType))
6696
+ });
6697
+ // MARK: DateCellSchedule
6698
+ /**
6699
+ * ArkType DTO schema for {@link DateCellSchedule}.
6700
+ *
6701
+ * Validates schedule data from JSON/DTO input.
6702
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6703
+ * into the corresponding runtime types.
6704
+ */
6705
+ const dateCellScheduleType = type({
6706
+ w: [DATE_CELL_SCHEDULE_ENCODED_WEEK_REGEX, '&', 'string'],
6707
+ 'd?': 'number.integer >= 0 []',
6708
+ 'ex?': 'number.integer >= 0 []'
6709
+ });
6710
+ // MARK: ModelRecurrenceInfo
6711
+ /**
6712
+ * ArkType DTO schema for {@link ModelRecurrenceInfo}.
6713
+ *
6714
+ * Accepts both Date objects and date strings (parsed via `string.date.parse`).
6715
+ * Use this schema when validating and converting serialized data (e.g., API responses, JSON payloads)
6716
+ * or runtime Date objects into the corresponding runtime types.
6717
+ */
6718
+ const modelRecurrenceInfoType = type({
6719
+ 'timezone?': 'string',
6720
+ rrule: 'string',
6721
+ start: ARKTYPE_DATE_DTO_TYPE,
6722
+ end: ARKTYPE_DATE_DTO_TYPE,
6723
+ 'forever?': 'boolean'
6724
+ });
6725
+ // MARK: Validators
6726
+ /**
6727
+ * ArkType DTO schema that validates a value is a valid {@link DateCellTiming}.
6728
+ *
6729
+ * Accepts both Date objects and date strings (parsed via `string.date.parse`), then validates the resulting timing
6730
+ * using {@link isValidDateCellTiming}.
6731
+ */
6732
+ const validDateCellTimingType = dateCellTimingType.narrow((val, ctx) => (val != null && isValidDateCellTiming(val)) || ctx.mustBe('a valid DateCellTiming'));
6733
+ /**
6734
+ * ArkType DTO schema that validates a value is a valid {@link DateCellRange} (non-negative indexes, `to >= i`).
6735
+ *
6736
+ * Validates cell range data from JSON/DTO input.
6737
+ */
6738
+ const validDateCellRangeType = dateCellRangeType.narrow((val, ctx) => (val != null && isValidDateCellRange(val)) || ctx.mustBe('a valid DateCellRange'));
6739
+ /**
6740
+ * ArkType DTO schema that validates a value is a sorted array of non-overlapping {@link DateCellRange} values.
6741
+ *
6742
+ * Validates cell range series data from JSON/DTO input.
6743
+ */
6744
+ const validDateCellRangeSeriesType = type(dateCellRangeType.array()).narrow((val, ctx) => (val != null && isValidDateCellRangeSeries(val)) || ctx.mustBe('a valid DateCellRange series with items sorted in ascending order and no repeat indexes'));
6745
+
6680
6746
  /**
6681
6747
  * A {@link HashSet} specialized for Date values, using the millisecond timestamp as the hash key.
6682
6748
  *
@@ -8780,16 +8846,6 @@ class DateRRuleUtility {
8780
8846
  }
8781
8847
  }
8782
8848
 
8783
- /**
8784
- * ArkType schema for {@link ModelRecurrenceInfo}.
8785
- */
8786
- const modelRecurrenceInfoType = type({
8787
- 'timezone?': 'string',
8788
- rrule: 'string',
8789
- start: 'Date',
8790
- end: 'Date',
8791
- 'forever?': 'boolean'
8792
- });
8793
8849
  /**
8794
8850
  * Stateless utility for converting between recurrence input
8795
8851
  * ({@link ModelRecurrenceStart}) and the indexed storage form