@northguild/gmt 1.16.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +742 -21
- package/dist/calendar/calculate/bucketRange.d.ts +3 -3
- package/dist/calendar/calculate/bucketRange.js +6 -6
- package/dist/calendar/calculate/floorToZone.d.ts +5 -3
- package/dist/calendar/calculate/floorToZone.js +6 -5
- package/dist/calendar/calculate/getFiscalPeriod.d.ts +21 -8
- package/dist/calendar/calculate/getFiscalPeriod.js +9 -8
- package/dist/calendar/calculate/getIsoWeekDate.d.ts +10 -5
- package/dist/calendar/calculate/getIsoWeekDate.js +1 -5
- package/dist/calendar/calculate/getOrdinalDate.d.ts +10 -3
- package/dist/calendar/calculate/getOrdinalDate.js +2 -3
- package/dist/calendar/calculate/getQuarter.d.ts +21 -9
- package/dist/calendar/calculate/getQuarter.js +8 -12
- package/dist/calendar/hours/addOperatingTime.d.ts +53 -0
- package/dist/calendar/hours/addOperatingTime.js +59 -0
- package/dist/calendar/hours/index.d.ts +7 -0
- package/dist/calendar/hours/index.js +7 -0
- package/dist/calendar/hours/isOpenAt.d.ts +39 -0
- package/dist/calendar/hours/isOpenAt.js +44 -0
- package/dist/calendar/hours/nextCloseAt.d.ts +49 -0
- package/dist/calendar/hours/nextCloseAt.js +51 -0
- package/dist/calendar/hours/nextOpenAt.d.ts +45 -0
- package/dist/calendar/hours/nextOpenAt.js +47 -0
- package/dist/calendar/hours/operatingIntervals.d.ts +43 -0
- package/dist/calendar/hours/operatingIntervals.js +52 -0
- package/dist/calendar/hours/operatingTimeBetween.d.ts +40 -0
- package/dist/calendar/hours/operatingTimeBetween.js +49 -0
- package/dist/calendar/hours/recurringWindows.d.ts +61 -0
- package/dist/calendar/hours/recurringWindows.js +80 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/duration/calculate/durationAs.d.ts +13 -8
- package/dist/duration/calculate/durationAs.js +4 -8
- package/dist/duration/compare/compareDurations.d.ts +12 -6
- package/dist/duration/compare/compareDurations.js +3 -6
- package/dist/duration/format/formatDuration.d.ts +16 -4
- package/dist/duration/format/formatDuration.js +4 -5
- package/dist/duration/normalize/normalizeDuration.d.ts +39 -14
- package/dist/duration/normalize/normalizeDuration.js +6 -15
- package/dist/duration/parse/parseDuration.d.ts +21 -3
- package/dist/duration/parse/parseDuration.js +1 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/instant/convert/classifyLocal.d.ts +1 -1
- package/dist/instant/convert/classifyLocal.js +1 -1
- package/dist/instant/convert/fromOffsetInstant.d.ts +3 -1
- package/dist/instant/convert/fromOffsetInstant.js +6 -12
- package/dist/instant/convert/resolveLocal.d.ts +12 -7
- package/dist/instant/convert/resolveLocal.js +6 -10
- package/dist/instant/convert/toOffsetInstant.d.ts +37 -1
- package/dist/instant/convert/toOffsetInstant.js +12 -28
- package/dist/intermodal/calculate/billingTimeline.d.ts +114 -0
- package/dist/intermodal/calculate/billingTimeline.js +168 -0
- package/dist/intermodal/calculate/chargeableDays.d.ts +100 -0
- package/dist/intermodal/calculate/chargeableDays.js +96 -0
- package/dist/intermodal/calculate/demurrageClock.d.ts +102 -0
- package/dist/intermodal/calculate/demurrageClock.js +140 -0
- package/dist/intermodal/calculate/freeTimeExpiry.d.ts +67 -0
- package/dist/intermodal/calculate/freeTimeExpiry.js +82 -0
- package/dist/intermodal/calculate/index.d.ts +4 -0
- package/dist/intermodal/calculate/index.js +4 -0
- package/dist/intermodal/index.d.ts +2 -0
- package/dist/intermodal/index.js +3 -0
- package/dist/internal/businessCalendar.d.ts +5 -0
- package/dist/internal/businessCalendar.js +5 -1
- package/dist/internal/cycleFieldValue.d.ts +6 -4
- package/dist/internal/cycleFieldValue.js +6 -4
- package/dist/internal/daylightTime.d.ts +33 -0
- package/dist/internal/daylightTime.js +164 -0
- package/dist/internal/durationUntilString.js +4 -3
- package/dist/internal/englishCalendarNames.js +1 -2
- package/dist/internal/epochNanoseconds.d.ts +2 -0
- package/dist/internal/epochNanoseconds.js +2 -0
- package/dist/internal/exactDuration.d.ts +37 -0
- package/dist/internal/exactDuration.js +64 -0
- package/dist/internal/exactMoment.d.ts +72 -0
- package/dist/internal/exactMoment.js +114 -0
- package/dist/internal/fiscalCalendar.d.ts +4 -3
- package/dist/internal/fiscalCalendar.js +4 -3
- package/dist/internal/formatCalendarDays.d.ts +2 -2
- package/dist/internal/formatRelativeDuration.d.ts +21 -1
- package/dist/internal/formatRelativeDuration.js +47 -7
- package/dist/internal/freeTimeLedger.d.ts +93 -0
- package/dist/internal/freeTimeLedger.js +262 -0
- package/dist/internal/index.d.ts +10 -3
- package/dist/internal/index.js +10 -3
- package/dist/internal/instantFormatOptions.js +2 -1
- package/dist/internal/instantNanoseconds.d.ts +75 -9
- package/dist/internal/instantNanoseconds.js +192 -11
- package/dist/internal/isoStringBody.d.ts +26 -0
- package/dist/internal/isoStringBody.js +22 -2
- package/dist/internal/joinDateTimeConnector.d.ts +1 -1
- package/dist/internal/monthGridWeekRow.d.ts +2 -1
- package/dist/internal/monthGridWeekRow.js +2 -1
- package/dist/internal/normalizeTimeZone.d.ts +2 -2
- package/dist/internal/normalizeTimeZone.js +2 -2
- package/dist/internal/operatingSchedule.d.ts +129 -0
- package/dist/internal/operatingSchedule.js +668 -0
- package/dist/internal/optionOrDefault.d.ts +18 -0
- package/dist/internal/optionOrDefault.js +20 -0
- package/dist/internal/patternToken.d.ts +2 -2
- package/dist/internal/patternToken.js +28 -13
- package/dist/internal/plainDateUntil.js +10 -6
- package/dist/internal/punctuality.d.ts +38 -0
- package/dist/internal/punctuality.js +59 -0
- package/dist/internal/readDateTimeFormatOptions.d.ts +30 -0
- package/dist/internal/readDateTimeFormatOptions.js +93 -0
- package/dist/internal/resolveDurationRelativeTo.d.ts +4 -0
- package/dist/internal/resolveDurationRelativeTo.js +11 -1
- package/dist/internal/resolveRelativeRounding.d.ts +17 -6
- package/dist/internal/resolveRelativeRounding.js +27 -7
- package/dist/internal/resolveRelativeUnit.d.ts +30 -0
- package/dist/internal/resolveRelativeUnit.js +40 -0
- package/dist/internal/splitStep.d.ts +24 -1
- package/dist/internal/splitStep.js +34 -2
- package/dist/internal/startOrEndOfZoned.js +2 -3
- package/dist/internal/temporalCompat/capabilities.d.ts +26 -0
- package/dist/internal/temporalCompat/capabilities.js +35 -3
- package/dist/internal/temporalCompat/fieldSearch.js +1 -1
- package/dist/internal/temporalCompat/index.d.ts +1 -1
- package/dist/internal/temporalCompat/index.js +1 -1
- package/dist/internal/temporalCompat/repros.d.ts +1 -1
- package/dist/internal/temporalCompat/repros.js +157 -0
- package/dist/internal/timestampEvents.d.ts +32 -0
- package/dist/internal/timestampEvents.js +76 -0
- package/dist/internal/utcZonedDateTime.d.ts +5 -2
- package/dist/internal/utcZonedDateTime.js +8 -5
- package/dist/internal/wallClockAtOffset.d.ts +22 -0
- package/dist/internal/wallClockAtOffset.js +26 -0
- package/dist/internal/zonedBucket.js +8 -6
- package/dist/internal/zonedLocalDates.js +1 -1
- package/dist/internal/zonedTransitionSearch.d.ts +27 -0
- package/dist/internal/zonedTransitionSearch.js +218 -0
- package/dist/internal/zonedWallClock.d.ts +21 -7
- package/dist/internal/zonedWallClock.js +87 -18
- package/dist/internal/zonedWallClockDifference.js +5 -4
- package/dist/internal/zonedWallClockOperations.d.ts +26 -13
- package/dist/internal/zonedWallClockOperations.js +87 -34
- package/dist/interval/validate/isValidInterval.d.ts +6 -3
- package/dist/interval/validate/isValidInterval.js +6 -3
- package/dist/plain/calculate/addDate.d.ts +11 -8
- package/dist/plain/calculate/addDate.js +5 -8
- package/dist/plain/calculate/addDateTime.d.ts +7 -4
- package/dist/plain/calculate/addDateTime.js +1 -4
- package/dist/plain/calculate/cycleDate.d.ts +16 -7
- package/dist/plain/calculate/cycleDate.js +3 -7
- package/dist/plain/calculate/cycleDateTime.d.ts +14 -4
- package/dist/plain/calculate/cycleDateTime.js +1 -4
- package/dist/plain/calculate/cycleTime.d.ts +10 -5
- package/dist/plain/calculate/cycleTime.js +3 -5
- package/dist/plain/calculate/diffDate.d.ts +1 -1
- package/dist/plain/calculate/diffDate.js +1 -1
- package/dist/plain/calculate/diffDateAsDuration.d.ts +1 -1
- package/dist/plain/calculate/diffDateAsDuration.js +1 -1
- package/dist/plain/calculate/diffDateTime.d.ts +1 -1
- package/dist/plain/calculate/diffDateTime.js +1 -1
- package/dist/plain/calculate/diffDateTimeAsDuration.d.ts +1 -1
- package/dist/plain/calculate/diffDateTimeAsDuration.js +1 -1
- package/dist/plain/calculate/diffTime.d.ts +1 -1
- package/dist/plain/calculate/diffTime.js +1 -1
- package/dist/plain/calculate/endOfDate.d.ts +8 -3
- package/dist/plain/calculate/endOfDate.js +1 -3
- package/dist/plain/calculate/endOfDateTime.d.ts +15 -5
- package/dist/plain/calculate/endOfDateTime.js +1 -5
- package/dist/plain/calculate/endOfTime.d.ts +8 -2
- package/dist/plain/calculate/endOfTime.js +1 -2
- package/dist/plain/calculate/getLocaleWeekYear.d.ts +16 -9
- package/dist/plain/calculate/getLocaleWeekYear.js +9 -9
- package/dist/plain/calculate/getWeekOfMonth.d.ts +7 -4
- package/dist/plain/calculate/getWeekOfMonth.js +7 -4
- package/dist/plain/calculate/getWeeksInLocaleWeekYear.d.ts +13 -6
- package/dist/plain/calculate/getWeeksInLocaleWeekYear.js +6 -6
- package/dist/plain/calculate/getWeeksInMonth.d.ts +5 -2
- package/dist/plain/calculate/getWeeksInMonth.js +5 -2
- package/dist/plain/calculate/nextWeekday.d.ts +7 -3
- package/dist/plain/calculate/nextWeekday.js +1 -3
- package/dist/plain/calculate/previousWeekday.d.ts +7 -3
- package/dist/plain/calculate/previousWeekday.js +1 -3
- package/dist/plain/calculate/roundDate.d.ts +20 -7
- package/dist/plain/calculate/roundDate.js +3 -10
- package/dist/plain/calculate/roundDateTime.d.ts +22 -8
- package/dist/plain/calculate/roundDateTime.js +3 -11
- package/dist/plain/calculate/roundTime.d.ts +20 -4
- package/dist/plain/calculate/roundTime.js +3 -7
- package/dist/plain/calculate/setDate.d.ts +7 -5
- package/dist/plain/calculate/setDate.js +1 -5
- package/dist/plain/calculate/setDateTime.d.ts +8 -5
- package/dist/plain/calculate/setDateTime.js +1 -5
- package/dist/plain/calculate/setTime.d.ts +10 -6
- package/dist/plain/calculate/setTime.js +4 -6
- package/dist/plain/calculate/startOfDate.d.ts +8 -2
- package/dist/plain/calculate/startOfDate.js +1 -2
- package/dist/plain/calculate/startOfDateTime.d.ts +15 -2
- package/dist/plain/calculate/startOfDateTime.js +1 -2
- package/dist/plain/calculate/startOfTime.d.ts +8 -1
- package/dist/plain/calculate/startOfTime.js +1 -1
- package/dist/plain/calculate/subtractDate.d.ts +7 -4
- package/dist/plain/calculate/subtractDate.js +1 -4
- package/dist/plain/calculate/subtractDateTime.d.ts +7 -4
- package/dist/plain/calculate/subtractDateTime.js +1 -4
- package/dist/plain/compare/areDateTimesEqualBy.d.ts +13 -5
- package/dist/plain/compare/areDateTimesEqualBy.js +6 -5
- package/dist/plain/compare/areDatesEqualBy.d.ts +15 -6
- package/dist/plain/compare/areDatesEqualBy.js +8 -6
- package/dist/plain/compare/isBetweenDate.d.ts +13 -2
- package/dist/plain/compare/isBetweenDate.js +4 -4
- package/dist/plain/compare/isBetweenDateTime.d.ts +13 -2
- package/dist/plain/compare/isBetweenDateTime.js +4 -4
- package/dist/plain/compare/isBetweenTime.d.ts +13 -2
- package/dist/plain/compare/isBetweenTime.js +4 -4
- package/dist/plain/compare/isRelativeDay.d.ts +1 -1
- package/dist/plain/compare/isRelativeDay.js +1 -1
- package/dist/plain/compare/isThisUnit.d.ts +1 -1
- package/dist/plain/compare/isThisUnit.js +1 -1
- package/dist/plain/format/formatCalendar.d.ts +21 -14
- package/dist/plain/format/formatCalendar.js +21 -16
- package/dist/plain/format/formatDate.js +5 -3
- package/dist/plain/format/formatDateRange.js +4 -2
- package/dist/plain/format/formatDateTime.js +4 -2
- package/dist/plain/format/formatDateTimeRange.js +4 -2
- package/dist/plain/format/formatDateTimeToParts.d.ts +15 -4
- package/dist/plain/format/formatDateTimeToParts.js +10 -6
- package/dist/plain/format/formatDateToParts.d.ts +13 -2
- package/dist/plain/format/formatDateToParts.js +8 -4
- package/dist/plain/format/formatRelativeDate.d.ts +16 -3
- package/dist/plain/format/formatRelativeDate.js +26 -15
- package/dist/plain/format/formatRelativeDateTime.d.ts +16 -3
- package/dist/plain/format/formatRelativeDateTime.js +8 -5
- package/dist/plain/format/formatRelativeTime.d.ts +16 -3
- package/dist/plain/format/formatRelativeTime.js +21 -13
- package/dist/plain/format/formatTime.js +4 -2
- package/dist/plain/interval/intervalDifferenceDate.d.ts +9 -0
- package/dist/plain/interval/intervalDifferenceDateTime.d.ts +9 -0
- package/dist/plain/interval/intervalDifferenceTime.d.ts +9 -0
- package/dist/plain/interval/intervalDivideEquallyDate.d.ts +19 -4
- package/dist/plain/interval/intervalDivideEquallyDate.js +3 -4
- package/dist/plain/interval/intervalDivideEquallyDateTime.d.ts +19 -4
- package/dist/plain/interval/intervalDivideEquallyDateTime.js +3 -4
- package/dist/plain/interval/intervalDivideEquallyTime.d.ts +19 -4
- package/dist/plain/interval/intervalDivideEquallyTime.js +3 -4
- package/dist/plain/interval/intervalFromDurationDate.d.ts +16 -3
- package/dist/plain/interval/intervalFromDurationDate.js +1 -3
- package/dist/plain/interval/intervalFromDurationDateTime.d.ts +16 -3
- package/dist/plain/interval/intervalFromDurationDateTime.js +1 -3
- package/dist/plain/interval/intervalFromDurationTime.d.ts +9 -0
- package/dist/plain/interval/intervalIntersectionDate.d.ts +9 -0
- package/dist/plain/interval/intervalIntersectionDateTime.d.ts +9 -0
- package/dist/plain/interval/intervalIntersectionTime.d.ts +9 -0
- package/dist/plain/interval/intervalSplitAtDate.d.ts +11 -0
- package/dist/plain/interval/intervalSplitAtDate.js +2 -0
- package/dist/plain/interval/intervalSplitAtDateTime.d.ts +11 -0
- package/dist/plain/interval/intervalSplitAtDateTime.js +2 -0
- package/dist/plain/interval/intervalSplitAtTime.d.ts +11 -0
- package/dist/plain/interval/intervalSplitAtTime.js +2 -0
- package/dist/plain/interval/intervalUnionDate.d.ts +9 -0
- package/dist/plain/interval/intervalUnionDateTime.d.ts +9 -0
- package/dist/plain/interval/intervalUnionTime.d.ts +9 -0
- package/dist/plain/interval/intervalXorAllDate.d.ts +9 -0
- package/dist/plain/interval/intervalXorAllDateTime.d.ts +9 -0
- package/dist/plain/interval/intervalXorAllTime.d.ts +9 -0
- package/dist/plain/interval/intervalXorDate.d.ts +9 -0
- package/dist/plain/interval/intervalXorDateTime.d.ts +9 -0
- package/dist/plain/interval/intervalXorTime.d.ts +9 -0
- package/dist/plain/interval/mergeIntervalsDate.d.ts +9 -0
- package/dist/plain/interval/mergeIntervalsDateTime.d.ts +9 -0
- package/dist/plain/interval/mergeIntervalsTime.d.ts +9 -0
- package/dist/plain/interval/splitIntervalByUnitDate.d.ts +23 -7
- package/dist/plain/interval/splitIntervalByUnitDate.js +7 -7
- package/dist/plain/interval/splitIntervalByUnitDateTime.d.ts +22 -6
- package/dist/plain/interval/splitIntervalByUnitDateTime.js +6 -6
- package/dist/plain/interval/splitIntervalByUnitTime.d.ts +17 -4
- package/dist/plain/interval/splitIntervalByUnitTime.js +1 -4
- package/dist/plain/map/mapDatesInRange.d.ts +8 -4
- package/dist/plain/map/mapDatesInRange.js +1 -4
- package/dist/plain/parse/parseDateTimeWithPattern.d.ts +10 -7
- package/dist/plain/parse/parseDateTimeWithPattern.js +10 -7
- package/dist/plain/parse/parseDateWithPattern.d.ts +10 -7
- package/dist/plain/parse/parseDateWithPattern.js +10 -7
- package/dist/plain/parse/parseTimeWithPattern.d.ts +10 -7
- package/dist/plain/parse/parseTimeWithPattern.js +10 -7
- package/dist/plain/parse/parseUnitFromDate.d.ts +11 -3
- package/dist/plain/parse/parseUnitFromDate.js +3 -3
- package/dist/plain/parse/parseUnitFromDateTime.d.ts +11 -3
- package/dist/plain/parse/parseUnitFromDateTime.js +3 -3
- package/dist/plain/parse/parseWeekFromDate.d.ts +10 -6
- package/dist/plain/parse/parseWeekFromDate.js +2 -6
- package/dist/plain/parse/parseWeekFromDateTime.d.ts +10 -6
- package/dist/plain/parse/parseWeekFromDateTime.js +2 -6
- package/dist/plain/validate/isValidDateRange.d.ts +19 -4
- package/dist/plain/validate/isValidDateRange.js +1 -4
- package/dist/plain/validate/isValidDateTimeRange.d.ts +20 -5
- package/dist/plain/validate/isValidDateTimeRange.js +2 -5
- package/dist/plain/validate/isValidTimeRange.d.ts +20 -5
- package/dist/plain/validate/isValidTimeRange.js +2 -5
- package/dist/precision/convert/fromExcelSerial.d.ts +10 -4
- package/dist/precision/convert/fromExcelSerial.js +4 -5
- package/dist/precision/convert/fromNanoseconds.d.ts +1 -1
- package/dist/precision/convert/fromNanoseconds.js +1 -1
- package/dist/precision/convert/toExcelSerial.d.ts +9 -3
- package/dist/precision/convert/toExcelSerial.js +3 -4
- package/dist/precision/convert/toNanoseconds.d.ts +11 -6
- package/dist/precision/convert/toNanoseconds.js +11 -6
- package/dist/precision/validate/isValidInstant.d.ts +12 -3
- package/dist/precision/validate/isValidInstant.js +12 -3
- package/dist/span/calculate/spanMs.d.ts +10 -4
- package/dist/span/calculate/spanMs.js +10 -4
- package/dist/span/calculate/spanNs.d.ts +10 -4
- package/dist/span/calculate/spanNs.js +10 -4
- package/dist/span/validate/isValidSpan.d.ts +8 -3
- package/dist/span/validate/isValidSpan.js +8 -3
- package/dist/transport/calculate/bestAvailable.d.ts +47 -0
- package/dist/transport/calculate/bestAvailable.js +76 -0
- package/dist/transport/calculate/crossingTime.d.ts +58 -0
- package/dist/transport/calculate/crossingTime.js +76 -0
- package/dist/transport/calculate/cutoffAt.d.ts +90 -0
- package/dist/transport/calculate/cutoffAt.js +209 -0
- package/dist/transport/calculate/cutoffSchedule.d.ts +70 -0
- package/dist/transport/calculate/cutoffSchedule.js +71 -0
- package/dist/transport/calculate/dwellTime.d.ts +81 -0
- package/dist/transport/calculate/dwellTime.js +130 -0
- package/dist/transport/calculate/estimateDrift.d.ts +65 -0
- package/dist/transport/calculate/estimateDrift.js +75 -0
- package/dist/transport/calculate/index.d.ts +10 -0
- package/dist/transport/calculate/index.js +10 -0
- package/dist/transport/calculate/nextDeparture.d.ts +78 -0
- package/dist/transport/calculate/nextDeparture.js +131 -0
- package/dist/transport/calculate/punctualityRate.d.ts +42 -0
- package/dist/transport/calculate/punctualityRate.js +59 -0
- package/dist/transport/calculate/scheduleDelivery.d.ts +150 -0
- package/dist/transport/calculate/scheduleDelivery.js +300 -0
- package/dist/transport/calculate/transitTime.d.ts +71 -0
- package/dist/transport/calculate/transitTime.js +101 -0
- package/dist/transport/compare/classifyPunctuality.d.ts +46 -0
- package/dist/transport/compare/classifyPunctuality.js +64 -0
- package/dist/transport/compare/index.d.ts +4 -0
- package/dist/transport/compare/index.js +4 -0
- package/dist/transport/compare/isPastCutoff.d.ts +33 -0
- package/dist/transport/compare/isPastCutoff.js +48 -0
- package/dist/transport/compare/scheduleDeviation.d.ts +37 -0
- package/dist/transport/compare/scheduleDeviation.js +53 -0
- package/dist/transport/compare/timeToCutoff.d.ts +31 -0
- package/dist/transport/compare/timeToCutoff.js +47 -0
- package/dist/transport/convert/etaAtZone.d.ts +43 -0
- package/dist/transport/convert/etaAtZone.js +58 -0
- package/dist/transport/convert/index.d.ts +1 -0
- package/dist/transport/convert/index.js +1 -0
- package/dist/transport/index.d.ts +4 -0
- package/dist/transport/index.js +5 -0
- package/dist/types/business-calendar.d.ts +19 -14
- package/dist/types/calendar-options.d.ts +15 -3
- package/dist/types/date-cycle-field.d.ts +5 -0
- package/dist/types/date-duration-unit.d.ts +4 -0
- package/dist/types/date-time-cycle-field.d.ts +4 -0
- package/dist/types/date-time-duration-units.d.ts +4 -0
- package/dist/types/date-time-unit.d.ts +4 -0
- package/dist/types/date-unit.d.ts +4 -0
- package/dist/types/disambiguation.d.ts +8 -0
- package/dist/types/duration-relative-to.d.ts +8 -0
- package/dist/types/duration-string-options.d.ts +28 -0
- package/dist/types/fiscal-calendar.d.ts +1 -1
- package/dist/types/fractional-digit.d.ts +5 -0
- package/dist/types/free-time-options.d.ts +44 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +3 -1
- package/dist/types/interval.d.ts +8 -1
- package/dist/types/offset.d.ts +9 -0
- package/dist/types/operating-schedule.d.ts +71 -0
- package/dist/types/operating-schedule.js +0 -0
- package/dist/types/overflow.d.ts +6 -0
- package/dist/types/relative-rounding-method.d.ts +6 -0
- package/dist/types/relative-time-options.d.ts +33 -5
- package/dist/types/rounding-options.d.ts +27 -0
- package/dist/types/time-cycle-field.d.ts +4 -0
- package/dist/types/time-duration-unit.d.ts +4 -0
- package/dist/types/time-unit.d.ts +4 -0
- package/dist/types/transport-timestamps.d.ts +54 -0
- package/dist/types/transport-timestamps.js +0 -0
- package/dist/unix/calculate/addUnix.d.ts +19 -5
- package/dist/unix/calculate/addUnix.js +1 -5
- package/dist/unix/calculate/diffUnix.d.ts +13 -3
- package/dist/unix/calculate/diffUnix.js +1 -3
- package/dist/unix/calculate/diffUnixAsDuration.d.ts +13 -3
- package/dist/unix/calculate/diffUnixAsDuration.js +1 -3
- package/dist/unix/calculate/endOfQuarterForUnix.d.ts +13 -3
- package/dist/unix/calculate/endOfQuarterForUnix.js +1 -3
- package/dist/unix/calculate/endOfUnix.d.ts +20 -4
- package/dist/unix/calculate/endOfUnix.js +1 -4
- package/dist/unix/calculate/isBetweenUnix.d.ts +26 -4
- package/dist/unix/calculate/isBetweenUnix.js +4 -6
- package/dist/unix/calculate/roundUnix.d.ts +31 -3
- package/dist/unix/calculate/roundUnix.js +3 -6
- package/dist/unix/calculate/setUnix.d.ts +35 -9
- package/dist/unix/calculate/setUnix.js +4 -13
- package/dist/unix/calculate/startOfQuarterForUnix.d.ts +13 -3
- package/dist/unix/calculate/startOfQuarterForUnix.js +1 -3
- package/dist/unix/calculate/startOfUnix.d.ts +20 -4
- package/dist/unix/calculate/startOfUnix.js +1 -4
- package/dist/unix/calculate/subtractUnix.d.ts +19 -5
- package/dist/unix/calculate/subtractUnix.js +1 -5
- package/dist/unix/compare/areUnixEqual.d.ts +7 -1
- package/dist/unix/compare/areUnixEqual.js +1 -1
- package/dist/unix/compare/areUnixEqualBy.d.ts +24 -7
- package/dist/unix/compare/areUnixEqualBy.js +13 -9
- package/dist/unix/compare/isAfterUnix.d.ts +7 -1
- package/dist/unix/compare/isAfterUnix.js +1 -1
- package/dist/unix/compare/isBeforeUnix.d.ts +7 -1
- package/dist/unix/compare/isBeforeUnix.js +1 -1
- package/dist/unix/convert/convertUnixToPlainDate.d.ts +14 -4
- package/dist/unix/convert/convertUnixToPlainDate.js +2 -4
- package/dist/unix/convert/convertUnixToPlainDateTime.d.ts +14 -4
- package/dist/unix/convert/convertUnixToPlainDateTime.js +2 -4
- package/dist/unix/convert/convertUnixToPlainTime.d.ts +14 -4
- package/dist/unix/convert/convertUnixToPlainTime.js +2 -4
- package/dist/unix/convert/convertUnixToUtc.d.ts +9 -4
- package/dist/unix/convert/convertUnixToUtc.js +3 -4
- package/dist/unix/convert/convertUnixToZoned.d.ts +10 -5
- package/dist/unix/convert/convertUnixToZoned.js +4 -5
- package/dist/unix/format/formatCalendarUnix.d.ts +27 -19
- package/dist/unix/format/formatCalendarUnix.js +4 -5
- package/dist/unix/format/formatRelativeUnix.d.ts +54 -5
- package/dist/unix/format/formatRelativeUnix.js +3 -5
- package/dist/unix/format/formatUnix.d.ts +24 -6
- package/dist/unix/format/formatUnix.js +8 -7
- package/dist/unix/get/getUnixNow.d.ts +8 -3
- package/dist/unix/get/getUnixNow.js +1 -3
- package/dist/unix/interval/intervalCountUnix.d.ts +14 -5
- package/dist/unix/interval/intervalCountUnix.js +2 -5
- package/dist/unix/interval/intervalDifferenceUnix.d.ts +6 -0
- package/dist/unix/interval/intervalDivideEquallyUnix.d.ts +18 -4
- package/dist/unix/interval/intervalDivideEquallyUnix.js +5 -4
- package/dist/unix/interval/intervalFromDurationUnix.d.ts +33 -5
- package/dist/unix/interval/intervalFromDurationUnix.js +6 -5
- package/dist/unix/interval/intervalIntersectionUnix.d.ts +6 -0
- package/dist/unix/interval/intervalLengthUnix.d.ts +16 -6
- package/dist/unix/interval/intervalLengthUnix.js +4 -6
- package/dist/unix/interval/intervalOverlappingDaysUnix.d.ts +13 -3
- package/dist/unix/interval/intervalOverlappingDaysUnix.js +1 -3
- package/dist/unix/interval/intervalSplitAtUnix.d.ts +8 -0
- package/dist/unix/interval/intervalSplitAtUnix.js +2 -0
- package/dist/unix/interval/intervalUnionUnix.d.ts +6 -0
- package/dist/unix/interval/intervalXorAllUnix.d.ts +6 -0
- package/dist/unix/interval/intervalXorUnix.d.ts +6 -0
- package/dist/unix/interval/mergeIntervalsUnix.d.ts +6 -0
- package/dist/unix/interval/splitIntervalByUnitUnix.d.ts +42 -11
- package/dist/unix/interval/splitIntervalByUnitUnix.js +21 -16
- package/dist/unix/parse/parseDateFromUnix.d.ts +13 -2
- package/dist/unix/parse/parseDateFromUnix.js +1 -2
- package/dist/unix/parse/parseDayFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseDayFromUnix.js +2 -2
- package/dist/unix/parse/parseDayOfWeekFromUnix.d.ts +13 -1
- package/dist/unix/parse/parseDayOfWeekFromUnix.js +1 -1
- package/dist/unix/parse/parseHourFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseHourFromUnix.js +2 -2
- package/dist/unix/parse/parseMicrosecondFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseMicrosecondFromUnix.js +2 -2
- package/dist/unix/parse/parseMillisecondFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseMillisecondFromUnix.js +2 -2
- package/dist/unix/parse/parseMinuteFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseMinuteFromUnix.js +2 -2
- package/dist/unix/parse/parseMonthFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseMonthFromUnix.js +2 -2
- package/dist/unix/parse/parseNanosecondFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseNanosecondFromUnix.js +2 -2
- package/dist/unix/parse/parseSecondFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseSecondFromUnix.js +2 -2
- package/dist/unix/parse/parseTimeFromUnix.d.ts +13 -2
- package/dist/unix/parse/parseTimeFromUnix.js +1 -2
- package/dist/unix/parse/parseUnitFromUnix.d.ts +22 -3
- package/dist/unix/parse/parseUnitFromUnix.js +2 -3
- package/dist/unix/parse/parseWeekFromUnix.d.ts +23 -7
- package/dist/unix/parse/parseWeekFromUnix.js +3 -7
- package/dist/unix/parse/parseYearFromUnix.d.ts +14 -2
- package/dist/unix/parse/parseYearFromUnix.js +2 -2
- package/dist/unix/validate/isValidUnixRange.d.ts +20 -4
- package/dist/unix/validate/isValidUnixRange.js +1 -4
- package/dist/utc/calculate/addUtc.d.ts +7 -4
- package/dist/utc/calculate/addUtc.js +1 -4
- package/dist/utc/calculate/diffUtc.d.ts +1 -1
- package/dist/utc/calculate/diffUtc.js +1 -1
- package/dist/utc/calculate/diffUtcAsDuration.d.ts +1 -1
- package/dist/utc/calculate/diffUtcAsDuration.js +1 -1
- package/dist/utc/calculate/endOfUtc.d.ts +16 -3
- package/dist/utc/calculate/endOfUtc.js +2 -3
- package/dist/utc/calculate/isBetweenUtc.d.ts +13 -2
- package/dist/utc/calculate/isBetweenUtc.js +4 -4
- package/dist/utc/calculate/roundUtc.d.ts +26 -9
- package/dist/utc/calculate/roundUtc.js +3 -12
- package/dist/utc/calculate/setUtc.d.ts +7 -4
- package/dist/utc/calculate/setUtc.js +1 -4
- package/dist/utc/calculate/startOfUtc.d.ts +15 -2
- package/dist/utc/calculate/startOfUtc.js +1 -2
- package/dist/utc/calculate/subtractUtc.d.ts +7 -4
- package/dist/utc/calculate/subtractUtc.js +1 -4
- package/dist/utc/compare/areUtcEqualBy.d.ts +9 -3
- package/dist/utc/compare/areUtcEqualBy.js +2 -3
- package/dist/utc/convert/convertUtcToPlainDate.d.ts +8 -3
- package/dist/utc/convert/convertUtcToPlainDate.js +5 -6
- package/dist/utc/convert/convertUtcToPlainDateTime.d.ts +8 -3
- package/dist/utc/convert/convertUtcToPlainDateTime.js +5 -6
- package/dist/utc/convert/convertUtcToPlainTime.d.ts +8 -3
- package/dist/utc/convert/convertUtcToPlainTime.js +5 -6
- package/dist/utc/convert/convertUtcToUnix.d.ts +9 -4
- package/dist/utc/convert/convertUtcToUnix.js +3 -4
- package/dist/utc/convert/convertUtcToZoned.d.ts +1 -1
- package/dist/utc/convert/convertUtcToZoned.js +1 -1
- package/dist/utc/format/formatCalendarUtc.d.ts +19 -8
- package/dist/utc/format/formatCalendarUtc.js +8 -6
- package/dist/utc/format/formatHttp.d.ts +1 -1
- package/dist/utc/format/formatHttp.js +1 -1
- package/dist/utc/format/formatRelativeUtc.d.ts +30 -10
- package/dist/utc/format/formatRelativeUtc.js +9 -11
- package/dist/utc/format/formatUtc.d.ts +17 -15
- package/dist/utc/format/formatUtc.js +8 -8
- package/dist/utc/interval/intervalDifferenceUtc.d.ts +6 -0
- package/dist/utc/interval/intervalDivideEquallyUtc.d.ts +18 -4
- package/dist/utc/interval/intervalDivideEquallyUtc.js +5 -4
- package/dist/utc/interval/intervalFromDurationUtc.d.ts +13 -3
- package/dist/utc/interval/intervalFromDurationUtc.js +1 -3
- package/dist/utc/interval/intervalIntersectionUtc.d.ts +6 -0
- package/dist/utc/interval/intervalSplitAtUtc.d.ts +8 -0
- package/dist/utc/interval/intervalSplitAtUtc.js +2 -0
- package/dist/utc/interval/intervalUnionUtc.d.ts +6 -0
- package/dist/utc/interval/intervalXorAllUtc.d.ts +6 -0
- package/dist/utc/interval/intervalXorUtc.d.ts +6 -0
- package/dist/utc/interval/mergeIntervalsUtc.d.ts +6 -0
- package/dist/utc/interval/splitIntervalByUnitUtc.d.ts +19 -6
- package/dist/utc/interval/splitIntervalByUnitUtc.js +6 -6
- package/dist/utc/parse/parseDateFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseDateFromUtc.js +1 -3
- package/dist/utc/parse/parseDayFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseDayFromUtc.js +1 -3
- package/dist/utc/parse/parseDayOfWeekFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseDayOfWeekFromUtc.js +4 -6
- package/dist/utc/parse/parseHourFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseHourFromUtc.js +1 -3
- package/dist/utc/parse/parseHttp.d.ts +1 -1
- package/dist/utc/parse/parseHttp.js +1 -1
- package/dist/utc/parse/parseMicrosecondFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseMicrosecondFromUtc.js +1 -3
- package/dist/utc/parse/parseMillisecondFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseMillisecondFromUtc.js +1 -3
- package/dist/utc/parse/parseMinuteFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseMinuteFromUtc.js +1 -3
- package/dist/utc/parse/parseMonthFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseMonthFromUtc.js +1 -3
- package/dist/utc/parse/parseNanosecondFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseNanosecondFromUtc.js +1 -3
- package/dist/utc/parse/parseSecondFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseSecondFromUtc.js +1 -3
- package/dist/utc/parse/parseTimeFromUtc.d.ts +8 -3
- package/dist/utc/parse/parseTimeFromUtc.js +5 -6
- package/dist/utc/parse/parseUnitFromUtc.d.ts +17 -5
- package/dist/utc/parse/parseUnitFromUtc.js +6 -8
- package/dist/utc/parse/parseWeekFromUtc.d.ts +18 -10
- package/dist/utc/parse/parseWeekFromUtc.js +7 -13
- package/dist/utc/parse/parseYearFromUtc.d.ts +7 -3
- package/dist/utc/parse/parseYearFromUtc.js +1 -3
- package/dist/utc/validate/isValidUtcRange.d.ts +16 -5
- package/dist/utc/validate/isValidUtcRange.js +2 -5
- package/dist/zoned/calculate/addZoned.d.ts +20 -10
- package/dist/zoned/calculate/addZoned.js +6 -13
- package/dist/zoned/calculate/cycleZoned.d.ts +33 -8
- package/dist/zoned/calculate/cycleZoned.js +1 -8
- package/dist/zoned/calculate/diffZoned.d.ts +1 -1
- package/dist/zoned/calculate/diffZoned.js +1 -1
- package/dist/zoned/calculate/diffZonedAsDuration.d.ts +1 -1
- package/dist/zoned/calculate/diffZonedAsDuration.js +1 -1
- package/dist/zoned/calculate/endOfQuarterForZoned.d.ts +9 -2
- package/dist/zoned/calculate/endOfQuarterForZoned.js +4 -5
- package/dist/zoned/calculate/endOfZoned.d.ts +16 -3
- package/dist/zoned/calculate/endOfZoned.js +2 -3
- package/dist/zoned/calculate/getLocaleZonedEndOfWeek.d.ts +10 -3
- package/dist/zoned/calculate/getLocaleZonedEndOfWeek.js +5 -6
- package/dist/zoned/calculate/getLocaleZonedStartOfWeek.d.ts +7 -1
- package/dist/zoned/calculate/getLocaleZonedStartOfWeek.js +3 -4
- package/dist/zoned/calculate/roundZoned.d.ts +21 -4
- package/dist/zoned/calculate/roundZoned.js +3 -7
- package/dist/zoned/calculate/setZoned.d.ts +25 -8
- package/dist/zoned/calculate/setZoned.js +4 -12
- package/dist/zoned/calculate/startOfQuarterForZoned.d.ts +7 -2
- package/dist/zoned/calculate/startOfQuarterForZoned.js +3 -5
- package/dist/zoned/calculate/startOfZoned.d.ts +15 -3
- package/dist/zoned/calculate/startOfZoned.js +1 -3
- package/dist/zoned/calculate/subtractZoned.d.ts +20 -10
- package/dist/zoned/calculate/subtractZoned.js +6 -13
- package/dist/zoned/compare/areZonedEqualBy.d.ts +14 -5
- package/dist/zoned/compare/areZonedEqualBy.js +7 -5
- package/dist/zoned/compare/isBetweenZoned.d.ts +13 -1
- package/dist/zoned/compare/isBetweenZoned.js +4 -3
- package/dist/zoned/compare/isInDaylightSaving.d.ts +38 -11
- package/dist/zoned/compare/isInDaylightSaving.js +40 -44
- package/dist/zoned/convert/convertPlainDateTimeToZoned.d.ts +18 -5
- package/dist/zoned/convert/convertPlainDateTimeToZoned.js +6 -11
- package/dist/zoned/convert/convertZonedToUnix.d.ts +9 -4
- package/dist/zoned/convert/convertZonedToUnix.js +2 -4
- package/dist/zoned/convert/convertZonedToZoned.d.ts +1 -1
- package/dist/zoned/convert/convertZonedToZoned.js +1 -1
- package/dist/zoned/format/formatCalendarZoned.d.ts +18 -12
- package/dist/zoned/format/formatCalendarZoned.js +13 -9
- package/dist/zoned/format/formatRelativeZoned.d.ts +41 -12
- package/dist/zoned/format/formatRelativeZoned.js +7 -4
- package/dist/zoned/format/formatRfc2822.d.ts +2 -2
- package/dist/zoned/format/formatRfc2822.js +2 -2
- package/dist/zoned/format/formatRfc3339.d.ts +2 -3
- package/dist/zoned/format/formatRfc3339.js +2 -3
- package/dist/zoned/format/formatTimeZoneName.d.ts +12 -3
- package/dist/zoned/format/formatTimeZoneName.js +5 -4
- package/dist/zoned/format/formatZonedDateTime.js +2 -1
- package/dist/zoned/format/formatZonedRange.js +2 -1
- package/dist/zoned/format/formatZonedToParts.d.ts +15 -4
- package/dist/zoned/format/formatZonedToParts.js +8 -5
- package/dist/zoned/get/getDstTransitions.d.ts +9 -10
- package/dist/zoned/get/getDstTransitions.js +12 -3
- package/dist/zoned/get/getTimeZoneOffset.d.ts +4 -1
- package/dist/zoned/get/getTimeZoneOffset.js +6 -3
- package/dist/zoned/get/getZonedNow.d.ts +13 -1
- package/dist/zoned/get/getZonedNow.js +12 -3
- package/dist/zoned/interval/intervalDifferenceZoned.d.ts +9 -0
- package/dist/zoned/interval/intervalDivideEquallyZoned.d.ts +22 -4
- package/dist/zoned/interval/intervalDivideEquallyZoned.js +6 -4
- package/dist/zoned/interval/intervalFromDurationZoned.d.ts +29 -10
- package/dist/zoned/interval/intervalFromDurationZoned.js +6 -13
- package/dist/zoned/interval/intervalIntersectionZoned.d.ts +9 -0
- package/dist/zoned/interval/intervalSplitAtZoned.d.ts +11 -0
- package/dist/zoned/interval/intervalSplitAtZoned.js +2 -0
- package/dist/zoned/interval/intervalUnionZoned.d.ts +9 -0
- package/dist/zoned/interval/intervalXorAllZoned.d.ts +9 -0
- package/dist/zoned/interval/intervalXorZoned.d.ts +9 -0
- package/dist/zoned/interval/mergeIntervalsZoned.d.ts +9 -0
- package/dist/zoned/interval/splitIntervalByUnitZoned.d.ts +27 -6
- package/dist/zoned/interval/splitIntervalByUnitZoned.js +11 -6
- package/dist/zoned/map/mapZonedDatesInRange.d.ts +9 -4
- package/dist/zoned/map/mapZonedDatesInRange.js +2 -4
- package/dist/zoned/parse/parseRfc2822.d.ts +1 -1
- package/dist/zoned/parse/parseRfc2822.js +1 -1
- package/dist/zoned/parse/parseUnitFromZoned.d.ts +9 -3
- package/dist/zoned/parse/parseUnitFromZoned.js +1 -3
- package/dist/zoned/parse/parseWeekFromZoned.d.ts +10 -3
- package/dist/zoned/parse/parseWeekFromZoned.js +2 -3
- package/dist/zoned/validate/hasDaylightSaving.d.ts +42 -11
- package/dist/zoned/validate/hasDaylightSaving.js +47 -31
- package/dist/zoned/validate/isValidZonedDateTime.d.ts +13 -0
- package/dist/zoned/validate/isValidZonedDateTime.js +14 -1
- package/dist/zoned/validate/isValidZonedRange.d.ts +15 -4
- package/dist/zoned/validate/isValidZonedRange.js +1 -4
- package/package.json +53 -5
- package/skills/gmt-arithmetic/SKILL.md +1 -1
- package/skills/gmt-basics/SKILL.md +10 -1
- package/skills/gmt-integration/SKILL.md +10 -5
- package/skills/gmt-timezone/SKILL.md +210 -14
- package/dist/internal/resolveReadingTimeZone.d.ts +0 -11
- package/dist/internal/resolveReadingTimeZone.js +0 -18
- package/dist/types/duration-unit.d.ts +0 -5
- /package/dist/types/{duration-unit.js → free-time-options.js} +0 -0
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { normalizeDateTime } from "./normalizeDateTime.js";
|
|
2
2
|
import { resolveRelativeRounding } from "./resolveRelativeRounding.js";
|
|
3
|
+
import { optionOrDefault } from "./optionOrDefault.js";
|
|
4
|
+
import { resolveRelativeUnit } from "./resolveRelativeUnit.js";
|
|
5
|
+
// The units of the seven-unit functions: Temporal's datetime unit group down to the second, less
|
|
6
|
+
// the sub-second units, which Intl.RelativeTimeFormat does not have.
|
|
7
|
+
const RELATIVE_UNITS = [
|
|
8
|
+
"year",
|
|
9
|
+
"month",
|
|
10
|
+
"week",
|
|
11
|
+
"day",
|
|
12
|
+
"hour",
|
|
13
|
+
"minute",
|
|
14
|
+
"second",
|
|
15
|
+
];
|
|
3
16
|
// Seconds up to a day, then formatRelativeDate's day thresholds (7, 28 and 365 days).
|
|
4
17
|
const SECONDS_PER_DAY = 86_400;
|
|
5
18
|
const AUTO_UNITS = [
|
|
@@ -26,20 +39,47 @@ const AUTO_UNITS = [
|
|
|
26
39
|
* @example formatRelativeDuration(Temporal.Duration.from({ days: 400 }), "en-US", {}, () => 1) // "next year" (month/year totals come from calendarTotal)
|
|
27
40
|
*/
|
|
28
41
|
export function formatRelativeDuration(diff, locale, options, calendarTotal) {
|
|
42
|
+
// Each option is read once (GetOption), and largestUnit is validated before anything is measured.
|
|
43
|
+
const forcedUnit = resolveRelativeUnit(options.largestUnit, RELATIVE_UNITS);
|
|
44
|
+
const roundingMethod = options.roundingMethod;
|
|
29
45
|
const absSeconds = Math.abs(diff.total("second"));
|
|
30
|
-
const unit =
|
|
46
|
+
const unit = forcedUnit === undefined
|
|
31
47
|
? (AUTO_UNITS.find((t) => absSeconds < t.maxSeconds)?.unit ?? "year")
|
|
32
|
-
:
|
|
33
|
-
let
|
|
48
|
+
: forcedUnit;
|
|
49
|
+
let total;
|
|
34
50
|
try {
|
|
35
|
-
|
|
51
|
+
total = diff.total(unit);
|
|
36
52
|
}
|
|
37
53
|
catch {
|
|
38
54
|
// month/year are calendrical and need a relativeTo anchor.
|
|
39
|
-
|
|
55
|
+
total = calendarTotal(unit);
|
|
40
56
|
}
|
|
57
|
+
// Outside the retry: an invalid roundingMethod throws once, straight to the caller's sentinel.
|
|
58
|
+
return formatRelativeAmount(total, unit, locale, options, roundingMethod);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Round a distance to a whole number of `unit` and render it with `Intl.RelativeTimeFormat`. The
|
|
62
|
+
* shared last step of every `formatRelative*` function.
|
|
63
|
+
*
|
|
64
|
+
* - `numeric` and `style` are read here, once each (GetOption); `roundingMethod` is passed in
|
|
65
|
+
* because the caller has already read it.
|
|
66
|
+
*
|
|
67
|
+
* @param total the signed fractional distance in `unit`
|
|
68
|
+
* @param unit the singular unit the distance is written in
|
|
69
|
+
* @param locale BCP 47 locale(s) passed through to `Intl.RelativeTimeFormat`
|
|
70
|
+
* @param options the caller's options, read for `numeric` (default `"auto"`) and `style`
|
|
71
|
+
* (default `"long"`)
|
|
72
|
+
* @param roundingMethod the caller's `roundingMethod`, `undefined` for the default `"round"`
|
|
73
|
+
* @returns the formatted phrase; throws where `Intl` throws or the rounding method is invalid, for
|
|
74
|
+
* the caller's sentinel
|
|
75
|
+
* @example formatRelativeAmount(-1.5, "hour", "en-US", {}, "floor") // "2 hours ago"
|
|
76
|
+
* @example formatRelativeAmount(1, "day", "en-US", { numeric: "always" }, undefined) // "in 1 day"
|
|
77
|
+
* @example formatRelativeAmount(1, "day", "en-US", { style: "wide" as never }, undefined) // throws RangeError
|
|
78
|
+
*/
|
|
79
|
+
export function formatRelativeAmount(total, unit, locale, options, roundingMethod) {
|
|
80
|
+
const amount = resolveRelativeRounding(total, roundingMethod);
|
|
41
81
|
return normalizeDateTime(new Intl.RelativeTimeFormat(locale, {
|
|
42
|
-
numeric: options.numeric
|
|
43
|
-
style: options.style
|
|
82
|
+
numeric: optionOrDefault(options.numeric, "auto"),
|
|
83
|
+
style: optionOrDefault(options.style, "long"),
|
|
44
84
|
}).format(amount, unit));
|
|
45
85
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { type ResolvedBusinessCalendar } from "./businessCalendar.js";
|
|
3
|
+
/**
|
|
4
|
+
* Local days a free-time walk may visit before giving up: the same cap as `bucketRange`. A
|
|
5
|
+
* valid business calendar leaves at least one working day a week, so a working-day count needs
|
|
6
|
+
* at most about seven local days per free or chargeable day. A walk that runs out answers with
|
|
7
|
+
* the sentinel, never a partial ledger.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MAX_WALKED_DAYS = 10000;
|
|
10
|
+
/**
|
|
11
|
+
* The tariff terms reduced to what the walk reads. `calendar` is the working-day calendar free
|
|
12
|
+
* days are counted against, `null` on the calendar basis; `chargeCalendar` is the one charged days
|
|
13
|
+
* are counted against, `null` when every local day after expiry is charged.
|
|
14
|
+
*/
|
|
15
|
+
export type FreeTimeTerms = {
|
|
16
|
+
timeZone: string;
|
|
17
|
+
firstDay: "eventDay" | "nextDay";
|
|
18
|
+
calendar: ResolvedBusinessCalendar | null;
|
|
19
|
+
chargeCalendar: ResolvedBusinessCalendar | null;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Read a `FreeTimeOptions` bag, or `null` when it is not one: a non-object, an unknown `basis`
|
|
23
|
+
* or `firstDay`, a missing `firstDay` (no default: the two conventions differ by a day of
|
|
24
|
+
* charges), an invalid `timeZone`, or a `"working"` basis without a valid `BusinessCalendar`.
|
|
25
|
+
* The `calendar` is read only when a basis that needs it is `"working"`.
|
|
26
|
+
*
|
|
27
|
+
* With `readChargeBasis`, `chargeBasis` is required too, and has no default for the same reason:
|
|
28
|
+
* where free time is in working days, tariffs mostly charge every calendar day after it, but some
|
|
29
|
+
* tariffs charge working days only, and the two differ by every closed day after expiry.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseFreeTimeTerms(options: unknown, readChargeBasis?: boolean): FreeTimeTerms | null;
|
|
32
|
+
/** A whole number of free days no smaller than `minimum`, or `null`. */
|
|
33
|
+
export declare function parseFreeDays(freeDays: unknown, minimum: 0 | 1): number | null;
|
|
34
|
+
/**
|
|
35
|
+
* Read a `tiers` option: omitted means no bands, otherwise a strictly ascending list of positive
|
|
36
|
+
* safe whole chargeable-day ordinals, each the last day of its band, with no holes. Anything
|
|
37
|
+
* else is `null`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseTiers(tiers: unknown): number[] | null;
|
|
40
|
+
/**
|
|
41
|
+
* Split `chargeable` days into the bands `tiers` describes: `[5, 10]` is days 1–5, 6–10 and 11
|
|
42
|
+
* onward. Every band is listed, an empty one with `days: 0`, so a caller's rate table lines up
|
|
43
|
+
* by index; the last band is always open (`to: null`).
|
|
44
|
+
*/
|
|
45
|
+
export declare function bandsByTier(tiers: number[], chargeable: number): {
|
|
46
|
+
from: number;
|
|
47
|
+
to: number | null;
|
|
48
|
+
days: number;
|
|
49
|
+
}[];
|
|
50
|
+
/** One local date of the terminal: its first instant, and its ISO label. */
|
|
51
|
+
export interface LedgerDay {
|
|
52
|
+
start: Temporal.ZonedDateTime;
|
|
53
|
+
date: string;
|
|
54
|
+
/**
|
|
55
|
+
* True when the date began before the first instant Temporal represents, so `start` is the
|
|
56
|
+
* clock start standing in for it. Such a start is never output: it can only anchor the walk.
|
|
57
|
+
*/
|
|
58
|
+
clamped?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** What `walkFreeTime` returns: the free days, the expiry, and what the dwell used and owes. */
|
|
61
|
+
export interface FreeTimeLedger {
|
|
62
|
+
/** The free days in order, exactly `freeDays` of them. */
|
|
63
|
+
free: LedgerDay[];
|
|
64
|
+
/** The first instant of the local day after the last free day; with no free days, of day one. */
|
|
65
|
+
expiresAt: Temporal.ZonedDateTime;
|
|
66
|
+
/** Free days the half-open dwell `[clockStart, clockEnd)` touched; `0` with no `clockEnd`. */
|
|
67
|
+
used: number;
|
|
68
|
+
/** Counted days from `expiresAt` that the dwell touched, in order; empty with no `clockEnd`. */
|
|
69
|
+
charged: LedgerDay[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Walk the terminal's real local days from the clock start and lay out free time and charges.
|
|
73
|
+
*
|
|
74
|
+
* Each day is a bucket `zonedUnitStart` / `nextZonedBucketStart` returns for `"day"`, the same
|
|
75
|
+
* boundaries `floorToZone` and `bucketRange` use, so a 23- or 25-hour day is one day, a date the
|
|
76
|
+
* zone deleted is never visited, and a date the clock falls back into is one day. Free days and
|
|
77
|
+
* charged days are counted against their own terms: on a working basis a weekend day or holiday is
|
|
78
|
+
* visited but not counted; on a calendar basis every day counts. The day of the event is neither
|
|
79
|
+
* free nor charged under `"nextDay"`.
|
|
80
|
+
*
|
|
81
|
+
* - Free days are the first `freeDays` days counted on `calendar`. `expiresAt` is the start of the
|
|
82
|
+
* day after the last of them, whether or not that day counts; with `freeDays` of `0` it is the
|
|
83
|
+
* start of the first counted day.
|
|
84
|
+
* - With a `clockEnd`, the dwell `[clockStart, clockEnd)` is half-open: a day is touched when it
|
|
85
|
+
* starts before `clockEnd`, and a zero-length dwell touches the day it sits on, as `dwellTime`
|
|
86
|
+
* counts. `used` is the free days touched; `charged` the days from `expiresAt` touched that count
|
|
87
|
+
* on `chargeCalendar`.
|
|
88
|
+
* - An event day that began before the first representable instant is still walked from the
|
|
89
|
+
* clock start; only an expiry that would be that unrepresentable start is refused.
|
|
90
|
+
* - Returns `null` when the walk would visit more than `MAX_WALKED_DAYS` local days, when a day
|
|
91
|
+
* boundary cannot be found, or when the expiry lies outside the representable range.
|
|
92
|
+
*/
|
|
93
|
+
export declare function walkFreeTime(clockStart: Temporal.ZonedDateTime, freeDays: number, terms: FreeTimeTerms, clockEnd?: Temporal.ZonedDateTime): FreeTimeLedger | null;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { isValidTimeZone } from "../zoned/validate/isValidTimeZone.js";
|
|
3
|
+
import { isBusinessDate, parseBusinessCalendar, } from "./businessCalendar.js";
|
|
4
|
+
import { isObject } from "./isObject.js";
|
|
5
|
+
import { nextZonedBucketStart, zonedUnitStart } from "./zonedBucket.js";
|
|
6
|
+
/**
|
|
7
|
+
* Local days a free-time walk may visit before giving up: the same cap as `bucketRange`. A
|
|
8
|
+
* valid business calendar leaves at least one working day a week, so a working-day count needs
|
|
9
|
+
* at most about seven local days per free or chargeable day. A walk that runs out answers with
|
|
10
|
+
* the sentinel, never a partial ledger.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_WALKED_DAYS = 10_000;
|
|
13
|
+
/**
|
|
14
|
+
* Buckets stepped over while looking for a later date. A fall-back that re-enters the previous
|
|
15
|
+
* date (`America/Goose_Bay`, 2010-11-07 00:01 back into the 6th) opens a one-minute 7 November
|
|
16
|
+
* bucket, then a 6 November one, then 7 November again: two buckets in a row whose date is not
|
|
17
|
+
* later than the day being left. One transition can do no more than that, so eight is a
|
|
18
|
+
* generous bound.
|
|
19
|
+
*/
|
|
20
|
+
const MAX_REVISITED_BUCKETS = 8;
|
|
21
|
+
/** `parseFreeTimeTerms` without the guard; every read of `options` happens here. */
|
|
22
|
+
function readFreeTimeTerms(options, readChargeBasis = false) {
|
|
23
|
+
if (!isObject(options)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const { basis, chargeBasis, firstDay, timeZone, calendar } = options;
|
|
27
|
+
const isBasis = (value) => value === "calendar" || value === "working";
|
|
28
|
+
if (!isBasis(basis)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (readChargeBasis && !isBasis(chargeBasis)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (firstDay !== "eventDay" && firstDay !== "nextDay") {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (typeof timeZone !== "string" || !isValidTimeZone(timeZone)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const needsCalendar = basis === "working" || (readChargeBasis && chargeBasis === "working");
|
|
41
|
+
const resolved = needsCalendar ? parseBusinessCalendar(calendar) : null;
|
|
42
|
+
if (needsCalendar && resolved === null) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
timeZone,
|
|
47
|
+
firstDay,
|
|
48
|
+
calendar: basis === "working" ? resolved : null,
|
|
49
|
+
chargeCalendar: readChargeBasis && chargeBasis === "working" ? resolved : null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Read a `FreeTimeOptions` bag, or `null` when it is not one: a non-object, an unknown `basis`
|
|
54
|
+
* or `firstDay`, a missing `firstDay` (no default: the two conventions differ by a day of
|
|
55
|
+
* charges), an invalid `timeZone`, or a `"working"` basis without a valid `BusinessCalendar`.
|
|
56
|
+
* The `calendar` is read only when a basis that needs it is `"working"`.
|
|
57
|
+
*
|
|
58
|
+
* With `readChargeBasis`, `chargeBasis` is required too, and has no default for the same reason:
|
|
59
|
+
* where free time is in working days, tariffs mostly charge every calendar day after it, but some
|
|
60
|
+
* tariffs charge working days only, and the two differ by every closed day after expiry.
|
|
61
|
+
*/
|
|
62
|
+
export function parseFreeTimeTerms(options, readChargeBasis = false) {
|
|
63
|
+
try {
|
|
64
|
+
return readFreeTimeTerms(options, readChargeBasis);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Never throws (Core Rule 3): a Proxy or getter that throws on access is invalid input.
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** A whole number of free days no smaller than `minimum`, or `null`. */
|
|
72
|
+
export function parseFreeDays(freeDays, minimum) {
|
|
73
|
+
return typeof freeDays === "number" &&
|
|
74
|
+
Number.isSafeInteger(freeDays) &&
|
|
75
|
+
freeDays >= minimum
|
|
76
|
+
? freeDays
|
|
77
|
+
: null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Read a `tiers` option: omitted means no bands, otherwise a strictly ascending list of positive
|
|
81
|
+
* safe whole chargeable-day ordinals, each the last day of its band, with no holes. Anything
|
|
82
|
+
* else is `null`.
|
|
83
|
+
*/
|
|
84
|
+
export function parseTiers(tiers) {
|
|
85
|
+
if (tiers === undefined) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
if (!Array.isArray(tiers)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
// `Array.from` fills holes with `undefined`, which the check below rejects; `every` alone
|
|
92
|
+
// would skip them and let `[5, , ]` through to a `NaN` band.
|
|
93
|
+
const items = Array.from(tiers);
|
|
94
|
+
const ascending = items.every((tier, index) => typeof tier === "number" &&
|
|
95
|
+
Number.isSafeInteger(tier) &&
|
|
96
|
+
tier >= 1 &&
|
|
97
|
+
(index === 0 || tier > items[index - 1]));
|
|
98
|
+
return ascending ? items : null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Split `chargeable` days into the bands `tiers` describes: `[5, 10]` is days 1–5, 6–10 and 11
|
|
102
|
+
* onward. Every band is listed, an empty one with `days: 0`, so a caller's rate table lines up
|
|
103
|
+
* by index; the last band is always open (`to: null`).
|
|
104
|
+
*/
|
|
105
|
+
export function bandsByTier(tiers, chargeable) {
|
|
106
|
+
const bands = [];
|
|
107
|
+
let from = 1;
|
|
108
|
+
for (const to of tiers) {
|
|
109
|
+
bands.push({
|
|
110
|
+
from,
|
|
111
|
+
to,
|
|
112
|
+
days: Math.max(0, Math.min(chargeable, to) - from + 1),
|
|
113
|
+
});
|
|
114
|
+
from = to + 1;
|
|
115
|
+
}
|
|
116
|
+
bands.push({ from, to: null, days: Math.max(0, chargeable - from + 1) });
|
|
117
|
+
return bands;
|
|
118
|
+
}
|
|
119
|
+
/** The local day holding `zoned`, or `null` when its start cannot be found. */
|
|
120
|
+
function localDayOf(zoned) {
|
|
121
|
+
let start;
|
|
122
|
+
try {
|
|
123
|
+
start = zonedUnitStart(zoned, "day");
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (!(error instanceof RangeError))
|
|
127
|
+
throw error;
|
|
128
|
+
// The event day began before Temporal's first instant (-271821-04-20T00:00Z in a zone west
|
|
129
|
+
// of UTC). Its date is still known, and every later day boundary is representable, so the
|
|
130
|
+
// clock start anchors the walk in its place.
|
|
131
|
+
return {
|
|
132
|
+
start: zoned,
|
|
133
|
+
date: zoned.toPlainDate().toString(),
|
|
134
|
+
clamped: true,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return start === null
|
|
138
|
+
? null
|
|
139
|
+
: { start, date: start.toPlainDate().toString() };
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The first local day after `day` whose date is later than `day`'s. A bucket that re-enters an
|
|
143
|
+
* earlier or equal date is folded into the day already laid out: a clock that starts in the
|
|
144
|
+
* one-minute first pass of Goose Bay's 7 November must not free or charge the 6th, and
|
|
145
|
+
* `countZonedLocalDates` counts a re-entered date once. `undefined` when the next day starts
|
|
146
|
+
* past the last representable instant, `null` when the walk gives up.
|
|
147
|
+
*/
|
|
148
|
+
function nextLocalDay(day) {
|
|
149
|
+
const current = day.start.toPlainDate();
|
|
150
|
+
let cursor = day.start;
|
|
151
|
+
for (let i = 0; i < MAX_REVISITED_BUCKETS; i++) {
|
|
152
|
+
let next;
|
|
153
|
+
try {
|
|
154
|
+
next = nextZonedBucketStart(cursor, "day");
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (error instanceof RangeError)
|
|
158
|
+
return undefined;
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
if (next === null) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const date = next.toPlainDate();
|
|
165
|
+
if (Temporal.PlainDate.compare(date, current) > 0) {
|
|
166
|
+
return { start: next, date: date.toString() };
|
|
167
|
+
}
|
|
168
|
+
cursor = next;
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Walk the terminal's real local days from the clock start and lay out free time and charges.
|
|
174
|
+
*
|
|
175
|
+
* Each day is a bucket `zonedUnitStart` / `nextZonedBucketStart` returns for `"day"`, the same
|
|
176
|
+
* boundaries `floorToZone` and `bucketRange` use, so a 23- or 25-hour day is one day, a date the
|
|
177
|
+
* zone deleted is never visited, and a date the clock falls back into is one day. Free days and
|
|
178
|
+
* charged days are counted against their own terms: on a working basis a weekend day or holiday is
|
|
179
|
+
* visited but not counted; on a calendar basis every day counts. The day of the event is neither
|
|
180
|
+
* free nor charged under `"nextDay"`.
|
|
181
|
+
*
|
|
182
|
+
* - Free days are the first `freeDays` days counted on `calendar`. `expiresAt` is the start of the
|
|
183
|
+
* day after the last of them, whether or not that day counts; with `freeDays` of `0` it is the
|
|
184
|
+
* start of the first counted day.
|
|
185
|
+
* - With a `clockEnd`, the dwell `[clockStart, clockEnd)` is half-open: a day is touched when it
|
|
186
|
+
* starts before `clockEnd`, and a zero-length dwell touches the day it sits on, as `dwellTime`
|
|
187
|
+
* counts. `used` is the free days touched; `charged` the days from `expiresAt` touched that count
|
|
188
|
+
* on `chargeCalendar`.
|
|
189
|
+
* - An event day that began before the first representable instant is still walked from the
|
|
190
|
+
* clock start; only an expiry that would be that unrepresentable start is refused.
|
|
191
|
+
* - Returns `null` when the walk would visit more than `MAX_WALKED_DAYS` local days, when a day
|
|
192
|
+
* boundary cannot be found, or when the expiry lies outside the representable range.
|
|
193
|
+
*/
|
|
194
|
+
export function walkFreeTime(clockStart, freeDays, terms, clockEnd) {
|
|
195
|
+
// The dwell's last instant, one nanosecond before the exit; a zero-length dwell is its own point.
|
|
196
|
+
const last = clockEnd === undefined
|
|
197
|
+
? undefined
|
|
198
|
+
: Temporal.ZonedDateTime.compare(clockStart, clockEnd) < 0
|
|
199
|
+
? clockEnd.subtract({ nanoseconds: 1 })
|
|
200
|
+
: clockEnd;
|
|
201
|
+
const touched = (day) => last !== undefined && Temporal.ZonedDateTime.compare(day.start, last) <= 0;
|
|
202
|
+
const counts = (day) => terms.calendar === null ||
|
|
203
|
+
isBusinessDate(day.start.toPlainDate(), terms.calendar);
|
|
204
|
+
const charges = (day) => terms.chargeCalendar === null ||
|
|
205
|
+
isBusinessDate(day.start.toPlainDate(), terms.chargeCalendar);
|
|
206
|
+
const free = [];
|
|
207
|
+
const charged = [];
|
|
208
|
+
let used = 0;
|
|
209
|
+
let expiresAt = null;
|
|
210
|
+
let expiryPending = false;
|
|
211
|
+
let skipEventDay = terms.firstDay === "nextDay";
|
|
212
|
+
let day = localDayOf(clockStart);
|
|
213
|
+
if (day === null) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
// One more visit than the cap: the day after the last touched one is what ends the walk.
|
|
217
|
+
for (let i = 0; i <= MAX_WALKED_DAYS; i++) {
|
|
218
|
+
const eventDaySkipped = skipEventDay;
|
|
219
|
+
const counted = !skipEventDay && counts(day);
|
|
220
|
+
skipEventDay = false;
|
|
221
|
+
if (expiryPending) {
|
|
222
|
+
expiresAt = day.start;
|
|
223
|
+
expiryPending = false;
|
|
224
|
+
}
|
|
225
|
+
else if (expiresAt === null && counted) {
|
|
226
|
+
if (freeDays === 0) {
|
|
227
|
+
// With no free time the expiry is day one's start, which must be a real instant.
|
|
228
|
+
if (day.clamped)
|
|
229
|
+
return null;
|
|
230
|
+
expiresAt = day.start;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
free.push(day);
|
|
234
|
+
if (touched(day))
|
|
235
|
+
used++;
|
|
236
|
+
expiryPending = free.length === freeDays;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (expiresAt !== null) {
|
|
240
|
+
// Free time has ended; with no clock end there is nothing more to lay out.
|
|
241
|
+
if (last === undefined) {
|
|
242
|
+
return { free, expiresAt, used, charged };
|
|
243
|
+
}
|
|
244
|
+
if (Temporal.ZonedDateTime.compare(day.start, last) > 0) {
|
|
245
|
+
return { free, expiresAt, used, charged };
|
|
246
|
+
}
|
|
247
|
+
// The day of the event under `nextDay` is never charged: free time has not started on it.
|
|
248
|
+
if (!eventDaySkipped && charges(day))
|
|
249
|
+
charged.push(day);
|
|
250
|
+
}
|
|
251
|
+
const next = nextLocalDay(day);
|
|
252
|
+
if (next === undefined) {
|
|
253
|
+
// No representable day follows: free time can still be laid out only if it has ended.
|
|
254
|
+
return expiresAt === null ? null : { free, expiresAt, used, charged };
|
|
255
|
+
}
|
|
256
|
+
if (next === null) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
day = next;
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { calendarOfAllDateValues, calendarSystemOfDateValue, } from "./calendarV
|
|
|
7
7
|
export { calendarOfAllZonedValues, calendarSystemOfZonedValue, } from "./calendarValueOfZoned.js";
|
|
8
8
|
export { formatZonedInCalendar, parseCalendarZonedValue, } from "./calendarZonedString.js";
|
|
9
9
|
export { cycleFieldValue } from "./cycleFieldValue.js";
|
|
10
|
+
export { isInDaylightTime, observesDaylightTime } from "./daylightTime.js";
|
|
10
11
|
export { fiscalPeriodOfWeek, fiscalYearOf } from "./fiscalCalendar.js";
|
|
11
12
|
export { floorDivide } from "./floorDivide.js";
|
|
12
13
|
export { DOT_NET_TICKS_EPOCH_OFFSET, EXCEL_1900_EPOCH_NANOSECONDS, EXCEL_1900_PHANTOM_END_NANOSECONDS, EXCEL_1900_PRE_PHANTOM_EPOCH_NANOSECONDS, EXCEL_1904_EPOCH_NANOSECONDS, EXCEL_PHANTOM_SERIAL, FILE_TIME_EPOCH_OFFSET_TICKS, MAX_DOT_NET_TICKS, MAX_EXCEL_1900_SERIAL_EXCLUSIVE, MAX_EXCEL_1904_SERIAL_EXCLUSIVE, MAX_FILE_TIME, MILLISECONDS_PER_DAY, MIN_DOT_NET_TICKS, MIN_EXCEL_1900_SERIAL, MIN_EXCEL_1904_SERIAL, MIN_FILE_TIME, MIN_PG_MICROSECONDS, NANOSECONDS_PER_DAY, NANOSECONDS_PER_DAY_NUMBER, NANOSECONDS_PER_MICROSECOND, NANOSECONDS_PER_MILLISECOND, NANOSECONDS_PER_SECOND, NANOSECONDS_PER_TICK, NTP_EPOCH_OFFSET_NANOSECONDS, NTP_ERA_UNITS, NTP_UNITS_PER_SECOND, PG_EPOCH_OFFSET_MICROSECONDS, } from "./foreignEpochs.js";
|
|
@@ -14,12 +15,15 @@ export { isValidEpochNanoseconds, MAX_EPOCH_NANOSECOND_DIGITS, } from "./epochNa
|
|
|
14
15
|
export { dateCycleFieldBounds } from "./dateCycleFieldBounds.js";
|
|
15
16
|
export { timeCycleFieldBounds } from "./timeCycleFieldBounds.js";
|
|
16
17
|
export { durationUntilString } from "./durationUntilString.js";
|
|
18
|
+
export { exactDurationNanoseconds, nonNegativeExactDurationNanoseconds, } from "./exactDuration.js";
|
|
19
|
+
export { type ExactMoment, readExactMoment, writeExactMoment, } from "./exactMoment.js";
|
|
17
20
|
export { formatDateInCalendar } from "./formatDateInCalendar.js";
|
|
21
|
+
export { bandsByTier, parseFreeDays, parseFreeTimeTerms, parseTiers, walkFreeTime, } from "./freeTimeLedger.js";
|
|
18
22
|
export { halfOpenAbuts, halfOpenContainsPoint, halfOpenContainsSpan, halfOpenDifference, halfOpenIntersection, halfOpenMerge, halfOpenOverlap, halfOpenUnion, halfOpenXor, } from "./halfOpenIntervals.js";
|
|
19
|
-
export { isoStringBody } from "./isoStringBody.js";
|
|
23
|
+
export { isoStringBody, TIME_ZONE_ANNOTATION } from "./isoStringBody.js";
|
|
20
24
|
export { formatHourDuration } from "./hourDurationString.js";
|
|
21
25
|
export { canonicalInstantIntervals } from "./instantIntervalText.js";
|
|
22
|
-
export { parseInstantNanoseconds } from "./instantNanoseconds.js";
|
|
26
|
+
export { instantFrom, parseInstantNanoseconds } from "./instantNanoseconds.js";
|
|
23
27
|
export { coalesceIntervalNanoseconds, parseIntervalNanoseconds, parseIntervalNanosecondsList, } from "./intervalNanoseconds.js";
|
|
24
28
|
export { resolveDurationRelativeTo } from "./resolveDurationRelativeTo.js";
|
|
25
29
|
export { formatUtcOffset, parseUtcOffsetNanoseconds } from "./utcOffsetString.js";
|
|
@@ -38,6 +42,7 @@ export { monthGridWeekRow } from "./monthGridWeekRow.js";
|
|
|
38
42
|
export { normalizeDateTime } from "./normalizeDateTime.js";
|
|
39
43
|
export { DATE_PATTERN_FIELDS, DATE_TIME_PATTERN_FIELDS, parseValueWithPattern, TIME_PATTERN_FIELDS, } from "./patternToken.js";
|
|
40
44
|
export { plainDateAdd } from "./plainDateAdd.js";
|
|
45
|
+
export { parsePunctualityTolerance, punctualityOf } from "./punctuality.js";
|
|
41
46
|
export { plainDateUntil } from "./plainDateUntil.js";
|
|
42
47
|
export { resolveDateTimeUnit } from "./resolveDateTimeUnit.js";
|
|
43
48
|
export { resolveDurationUnit } from "./resolveDurationUnit.js";
|
|
@@ -45,9 +50,11 @@ export { resolveOverflow } from "./resolveOverflow.js";
|
|
|
45
50
|
export { resolveRelativeRounding } from "./resolveRelativeRounding.js";
|
|
46
51
|
export { parseUnixEpochInterval, parseUnixEpochIntervalList, parseUnixEpochIntervalPair, parseUnixEpochValue, } from "./unixEpochValue.js";
|
|
47
52
|
export { tileByUnit } from "./splitStep.js";
|
|
53
|
+
export { parseTimestampEvents } from "./timestampEvents.js";
|
|
48
54
|
export { countZonedBuckets, nextZonedBucketStart, type WeekStartDay, zonedUnitEnd, zonedUnitStart, } from "./zonedBucket.js";
|
|
49
55
|
export { countZonedLocalDates } from "./zonedLocalDates.js";
|
|
50
56
|
export { zonedDateTimeFrom } from "./zonedWallClock.js";
|
|
57
|
+
export { wallClockAtOffset } from "./wallClockAtOffset.js";
|
|
51
58
|
export { durationCompare, durationRound, durationTotal, isCalendarDifferenceAcrossZones, plainUntilWithRounding, zonedUntil, } from "./zonedWallClockDifference.js";
|
|
52
|
-
export { addToZoned, addToZonedDisambiguated, plainToZoned, roundZonedDateTime, subtractFromZoned, withZonedFields, zonedHoursInDay, zonedNextTransition, zonedStartOfDay, } from "./zonedWallClockOperations.js";
|
|
59
|
+
export { addToZoned, addToZonedDisambiguated, plainToZoned, roundZonedDateTime, subtractFromZoned, withZonedFields, zonedHoursInDay, zonedNextTransition, zonedPreviousTransition, zonedStartOfDay, } from "./zonedWallClockOperations.js";
|
|
53
60
|
export { zonelessCalendarDate } from "./zonelessCalendarDate.js";
|
package/dist/internal/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { calendarOfAllDateValues, calendarSystemOfDateValue, } from "./calendarV
|
|
|
7
7
|
export { calendarOfAllZonedValues, calendarSystemOfZonedValue, } from "./calendarValueOfZoned.js";
|
|
8
8
|
export { formatZonedInCalendar, parseCalendarZonedValue, } from "./calendarZonedString.js";
|
|
9
9
|
export { cycleFieldValue } from "./cycleFieldValue.js";
|
|
10
|
+
export { isInDaylightTime, observesDaylightTime } from "./daylightTime.js";
|
|
10
11
|
export { fiscalPeriodOfWeek, fiscalYearOf } from "./fiscalCalendar.js";
|
|
11
12
|
export { floorDivide } from "./floorDivide.js";
|
|
12
13
|
export { DOT_NET_TICKS_EPOCH_OFFSET, EXCEL_1900_EPOCH_NANOSECONDS, EXCEL_1900_PHANTOM_END_NANOSECONDS, EXCEL_1900_PRE_PHANTOM_EPOCH_NANOSECONDS, EXCEL_1904_EPOCH_NANOSECONDS, EXCEL_PHANTOM_SERIAL, FILE_TIME_EPOCH_OFFSET_TICKS, MAX_DOT_NET_TICKS, MAX_EXCEL_1900_SERIAL_EXCLUSIVE, MAX_EXCEL_1904_SERIAL_EXCLUSIVE, MAX_FILE_TIME, MILLISECONDS_PER_DAY, MIN_DOT_NET_TICKS, MIN_EXCEL_1900_SERIAL, MIN_EXCEL_1904_SERIAL, MIN_FILE_TIME, MIN_PG_MICROSECONDS, NANOSECONDS_PER_DAY, NANOSECONDS_PER_DAY_NUMBER, NANOSECONDS_PER_MICROSECOND, NANOSECONDS_PER_MILLISECOND, NANOSECONDS_PER_SECOND, NANOSECONDS_PER_TICK, NTP_EPOCH_OFFSET_NANOSECONDS, NTP_ERA_UNITS, NTP_UNITS_PER_SECOND, PG_EPOCH_OFFSET_MICROSECONDS, } from "./foreignEpochs.js";
|
|
@@ -14,12 +15,15 @@ export { isValidEpochNanoseconds, MAX_EPOCH_NANOSECOND_DIGITS, } from "./epochNa
|
|
|
14
15
|
export { dateCycleFieldBounds } from "./dateCycleFieldBounds.js";
|
|
15
16
|
export { timeCycleFieldBounds } from "./timeCycleFieldBounds.js";
|
|
16
17
|
export { durationUntilString } from "./durationUntilString.js";
|
|
18
|
+
export { exactDurationNanoseconds, nonNegativeExactDurationNanoseconds, } from "./exactDuration.js";
|
|
19
|
+
export { readExactMoment, writeExactMoment, } from "./exactMoment.js";
|
|
17
20
|
export { formatDateInCalendar } from "./formatDateInCalendar.js";
|
|
21
|
+
export { bandsByTier, parseFreeDays, parseFreeTimeTerms, parseTiers, walkFreeTime, } from "./freeTimeLedger.js";
|
|
18
22
|
export { halfOpenAbuts, halfOpenContainsPoint, halfOpenContainsSpan, halfOpenDifference, halfOpenIntersection, halfOpenMerge, halfOpenOverlap, halfOpenUnion, halfOpenXor, } from "./halfOpenIntervals.js";
|
|
19
|
-
export { isoStringBody } from "./isoStringBody.js";
|
|
23
|
+
export { isoStringBody, TIME_ZONE_ANNOTATION } from "./isoStringBody.js";
|
|
20
24
|
export { formatHourDuration } from "./hourDurationString.js";
|
|
21
25
|
export { canonicalInstantIntervals } from "./instantIntervalText.js";
|
|
22
|
-
export { parseInstantNanoseconds } from "./instantNanoseconds.js";
|
|
26
|
+
export { instantFrom, parseInstantNanoseconds } from "./instantNanoseconds.js";
|
|
23
27
|
export { coalesceIntervalNanoseconds, parseIntervalNanoseconds, parseIntervalNanosecondsList, } from "./intervalNanoseconds.js";
|
|
24
28
|
export { resolveDurationRelativeTo } from "./resolveDurationRelativeTo.js";
|
|
25
29
|
export { formatUtcOffset, parseUtcOffsetNanoseconds } from "./utcOffsetString.js";
|
|
@@ -38,6 +42,7 @@ export { monthGridWeekRow } from "./monthGridWeekRow.js";
|
|
|
38
42
|
export { normalizeDateTime } from "./normalizeDateTime.js";
|
|
39
43
|
export { DATE_PATTERN_FIELDS, DATE_TIME_PATTERN_FIELDS, parseValueWithPattern, TIME_PATTERN_FIELDS, } from "./patternToken.js";
|
|
40
44
|
export { plainDateAdd } from "./plainDateAdd.js";
|
|
45
|
+
export { parsePunctualityTolerance, punctualityOf } from "./punctuality.js";
|
|
41
46
|
export { plainDateUntil } from "./plainDateUntil.js";
|
|
42
47
|
export { resolveDateTimeUnit } from "./resolveDateTimeUnit.js";
|
|
43
48
|
export { resolveDurationUnit } from "./resolveDurationUnit.js";
|
|
@@ -45,9 +50,11 @@ export { resolveOverflow } from "./resolveOverflow.js";
|
|
|
45
50
|
export { resolveRelativeRounding } from "./resolveRelativeRounding.js";
|
|
46
51
|
export { parseUnixEpochInterval, parseUnixEpochIntervalList, parseUnixEpochIntervalPair, parseUnixEpochValue, } from "./unixEpochValue.js";
|
|
47
52
|
export { tileByUnit } from "./splitStep.js";
|
|
53
|
+
export { parseTimestampEvents } from "./timestampEvents.js";
|
|
48
54
|
export { countZonedBuckets, nextZonedBucketStart, zonedUnitEnd, zonedUnitStart, } from "./zonedBucket.js";
|
|
49
55
|
export { countZonedLocalDates } from "./zonedLocalDates.js";
|
|
50
56
|
export { zonedDateTimeFrom } from "./zonedWallClock.js";
|
|
57
|
+
export { wallClockAtOffset } from "./wallClockAtOffset.js";
|
|
51
58
|
export { durationCompare, durationRound, durationTotal, isCalendarDifferenceAcrossZones, plainUntilWithRounding, zonedUntil, } from "./zonedWallClockDifference.js";
|
|
52
|
-
export { addToZoned, addToZonedDisambiguated, plainToZoned, roundZonedDateTime, subtractFromZoned, withZonedFields, zonedHoursInDay, zonedNextTransition, zonedStartOfDay, } from "./zonedWallClockOperations.js";
|
|
59
|
+
export { addToZoned, addToZonedDisambiguated, plainToZoned, roundZonedDateTime, subtractFromZoned, withZonedFields, zonedHoursInDay, zonedNextTransition, zonedPreviousTransition, zonedStartOfDay, } from "./zonedWallClockOperations.js";
|
|
53
60
|
export { zonelessCalendarDate } from "./zonelessCalendarDate.js";
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// and GetDateTimeFormat with required ~any~ and inherit ~all~, so every caller
|
|
5
5
|
// field, including `era` and `timeZoneName`, is passed on unchanged.
|
|
6
6
|
import { plainDateTimeFormatOptions } from "./plainFormatOptions.js";
|
|
7
|
+
import { optionOrDefault } from "./optionOrDefault.js";
|
|
7
8
|
// GetDateTimeFormat requiredOptions for ~any~. `era` and `timeZoneName` are
|
|
8
9
|
// deliberately absent: neither suppresses the defaults.
|
|
9
10
|
const REQUIRED_FIELDS = [
|
|
@@ -58,7 +59,7 @@ export function instantFormatOptions(options, timeZone, defaults) {
|
|
|
58
59
|
...DEFAULT_FIELDS,
|
|
59
60
|
...(defaults === "zoned-date-time"
|
|
60
61
|
? {
|
|
61
|
-
timeZoneName: options.timeZoneName
|
|
62
|
+
timeZoneName: optionOrDefault(options.timeZoneName, "short"),
|
|
62
63
|
}
|
|
63
64
|
: {}),
|
|
64
65
|
timeZone,
|
|
@@ -1,16 +1,62 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
1
2
|
/**
|
|
2
3
|
* Parse an ISO 8601 instant string to epoch nanoseconds, or `null` when it is not one.
|
|
3
4
|
*
|
|
4
|
-
* The single definition of "an instant string GMT accepts"
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* The single definition of "an instant string GMT accepts", and of the instant it names. Every
|
|
6
|
+
* GMT function that reads a moment without keeping its zone reads through here.
|
|
7
|
+
*
|
|
8
|
+
* **Which strings.** The RFC 9557 instant grammar `Temporal.Instant.from` parses, restricted to
|
|
9
|
+
* ISO 8601 extended format before the first `[` (`instantBody`: `<date>T<time>`, then `Z` or
|
|
10
|
+
* `±HH:MM[:SS[.fraction]]`), minus leap seconds (which Temporal clamps rather than rejects).
|
|
11
|
+
* Basic format, a space or lower-case `t` separator, a lower-case `z` and an hour-only time or
|
|
12
|
+
* offset are rejected. Annotations are read as Temporal reads them (proposal-temporal
|
|
9
13
|
* `ParseISODateTime`, RFC 9557 §3.3): a time zone, calendar (`[u-ca=hebrew]`) or elective
|
|
10
|
-
* (`[foo=bar]`) annotation
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
+
* (`[foo=bar]`) annotation never makes a string invalid, and an unknown critical one
|
|
15
|
+
* (`[!foo=bar]`) is rejected.
|
|
16
|
+
*
|
|
17
|
+
* **Which instant.** The written offset fixes it, as in `Temporal.Instant.from`, with one
|
|
18
|
+
* exception:
|
|
19
|
+
*
|
|
20
|
+
* - **A minute-rounded offset is read as its zone's real offset.** When the string has a
|
|
21
|
+
* bracketed zone and an offset written to the minute, and that offset is the zone's actual
|
|
22
|
+
* offset at that wall time rounded to the minute, the instant is the one the zone gives. This
|
|
23
|
+
* is TC39 `ToTemporalZonedDateTime`'s match-minutes rule (`InterpretISODateTimeOffset`),
|
|
24
|
+
* applied to the zone and the offset alone. It exists because
|
|
25
|
+
* `Temporal.ZonedDateTime.prototype.toString` writes the offset rounded to the minute: in a
|
|
26
|
+
* zone with a sub-minute offset (`Africa/Monrovia` before 1972, at −00:44:30, written
|
|
27
|
+
* `-00:45`), the string a zoned function writes would otherwise be read up to 30 seconds off.
|
|
28
|
+
* - **The instant range is the only range.** The match has no `CheckISODaysRange` on the local
|
|
29
|
+
* date, which `Temporal.ZonedDateTime.from` has, and does not need the written offset's own
|
|
30
|
+
* reading to be in range. So every string Temporal writes for an instant in range is read
|
|
31
|
+
* back, the first and last instants included: `-271821-04-19T23:58:45-00:01[Europe/London]`
|
|
32
|
+
* (London's local mean time, −00:01:15) is the first instant, although its local date is
|
|
33
|
+
* outside Temporal's date range and its reading at −00:01 is 15 seconds before the range.
|
|
34
|
+
* - **A repeated wall time inside a sub-minute offset change reads as its first pass.** The
|
|
35
|
+
* match is against each candidate instant in order, so when a wall time happened twice and
|
|
36
|
+
* the rounded offset fits the first pass, the first pass is the answer, even if the string
|
|
37
|
+
* was written for the second. This is a class of strings, not one zone: it arises wherever a
|
|
38
|
+
* zone's history has a fall-back of under a minute at a sub-minute offset. The example
|
|
39
|
+
* test262 uses: Pacific/Niue moved from −11:19:40 to −11:20:00 at the end of
|
|
40
|
+
* 15 October 1952, so 23:59:40 to 23:59:59 happened twice, 20 seconds apart, and both passes
|
|
41
|
+
* are written `-11:20`: `1952-10-15T23:59:59-11:20[Pacific/Niue]` reads as the pass at
|
|
42
|
+
* −11:19:40. This is `Temporal.ZonedDateTime.from`'s own reading (test262
|
|
43
|
+
* `intl402/Temporal/ZonedDateTime/from/zoneddatetime-sub-minute-offset.js`), and the one kind
|
|
44
|
+
* of string Temporal writes that an instant reader does not read as the instant it was
|
|
45
|
+
* written for. The exact offset, `-11:20:00`, names the second pass.
|
|
46
|
+
* - **Everything else keeps the written offset.** The complete list: a string without a
|
|
47
|
+
* bracket; a `Z` instant; an offset written with seconds, which TC39 matches exactly
|
|
48
|
+
* (`-00:45:00[Africa/Monrovia]` is −00:45:00); a bracket whose zone does not exist; and a
|
|
49
|
+
* bracket whose zone has no instant in range with that wall time at the written offset or at
|
|
50
|
+
* an offset that rounds to it (`-00:44[Africa/Monrovia]`, `-05:00[America/New_York]` in
|
|
51
|
+
* June). Such a bracket is not validated here; a function that keeps the zone
|
|
52
|
+
* (`transitTime`, `toOffsetInstant`) rejects it instead. Calendar and elective annotations
|
|
53
|
+
* never change the reading. A string whose written reading is outside the instant range, and
|
|
54
|
+
* which the zone does not bring inside it, is `null`.
|
|
55
|
+
*
|
|
56
|
+
* The zone's offset comes from Temporal's time-zone data; nothing here holds an offset or a
|
|
57
|
+
* zone name. A string in a whole-minute zone costs two offset lookups more than
|
|
58
|
+
* `Temporal.Instant.from`. Callers layer their own sentinel on top — `toNanoseconds` returns
|
|
59
|
+
* `0n`, `spanNs` returns `null` — so the parse result stays unambiguous here.
|
|
14
60
|
*
|
|
15
61
|
* @param value candidate ISO 8601 instant string
|
|
16
62
|
* @returns nanoseconds since the Unix epoch, or null when `value` is not a valid instant
|
|
@@ -21,5 +67,25 @@
|
|
|
21
67
|
* @example parseInstantNanoseconds("20240310T120000Z") // null — basic format
|
|
22
68
|
* @example parseInstantNanoseconds("2024-03-10T12:00:00z") // null — lower-case z
|
|
23
69
|
* @example parseInstantNanoseconds("1970-01-01T00:00:00Z[u-ca=hebrew]") // 0n — calendar annotation ignored
|
|
70
|
+
* @example parseInstantNanoseconds("1960-01-01T00:20:00-00:45[Africa/Monrovia]") // -315615330000000000n — 01:04:30Z: Monrovia stood at -00:44:30
|
|
71
|
+
* @example parseInstantNanoseconds("1960-01-01T00:20:00-00:45") // -315615300000000000n — 01:05:00Z: no zone, so the offset is exact
|
|
72
|
+
* @example parseInstantNanoseconds("1952-10-15T23:59:59-11:20[Pacific/Niue]") // -543069621000000000n — the first pass of a repeated second, at -11:19:40
|
|
73
|
+
* @example parseInstantNanoseconds("-271821-04-19T23:58:45-00:01[Europe/London]") // -8640000000000000000000n — the first instant, at London's -00:01:15
|
|
74
|
+
* @example parseInstantNanoseconds("2024-06-15T10:00:00Z[Not/AZone]") // 1718445600000000000n — the bracket is not validated
|
|
24
75
|
*/
|
|
25
76
|
export declare function parseInstantNanoseconds(value: string): bigint | null;
|
|
77
|
+
/**
|
|
78
|
+
* `parseInstantNanoseconds` as a `Temporal.Instant`, for callers that already hold a validated
|
|
79
|
+
* string and go on to Temporal arithmetic. Use it wherever a caller's instant string would
|
|
80
|
+
* otherwise go to `Temporal.Instant.from`, so a minute-rounded offset is read the same way
|
|
81
|
+
* everywhere. Throws where `Temporal.Instant.from` throws, so it sits inside the caller's `try`
|
|
82
|
+
* like any other Temporal parse.
|
|
83
|
+
*
|
|
84
|
+
* @param value ISO 8601 instant or zoned datetime string
|
|
85
|
+
* @returns the instant the string names
|
|
86
|
+
* @throws RangeError when `value` is not a valid instant
|
|
87
|
+
*
|
|
88
|
+
* @example instantFrom("1960-01-01T00:20:00-00:45[Africa/Monrovia]").toString() // "1960-01-01T01:04:30Z"
|
|
89
|
+
* @example instantFrom("2024-06-15T10:00:00") // throws RangeError
|
|
90
|
+
*/
|
|
91
|
+
export declare function instantFrom(value: string): Temporal.Instant;
|