@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
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { zonedNextTransition, zonedPreviousTransition, } from "./zonedWallClockOperations.js";
|
|
2
|
+
/**
|
|
3
|
+
* The longest a daylight period can last: a forward change and the backward change that undoes it
|
|
4
|
+
* are less than 365 days apart. Daylight time is seasonal, so it recurs within every year, and
|
|
5
|
+
* 365 days is the shortest year. A longer advance is a change of standard time.
|
|
6
|
+
*/
|
|
7
|
+
const DAYLIGHT_PERIOD_LIMIT_NANOSECONDS = 365n * 86400000000000n;
|
|
8
|
+
/**
|
|
9
|
+
* Offset changes read in each direction before the walk gives up and answers `false`, the
|
|
10
|
+
* sentinel: a bounded loop that runs out never returns a partial answer. Every walk here is also
|
|
11
|
+
* limited to 365 days, and a year of `Africa/Casablanca` holds four changes, so no real zone
|
|
12
|
+
* reaches the bound; `daylightTime.test.ts` reaches it with a made-up zone.
|
|
13
|
+
*/
|
|
14
|
+
const MAX_WALKED_CHANGES = 64;
|
|
15
|
+
function offsetChangeAt(transition) {
|
|
16
|
+
return {
|
|
17
|
+
at: transition.epochNanoseconds,
|
|
18
|
+
step: transition.offsetNanoseconds -
|
|
19
|
+
transition.subtract({ nanoseconds: 1 }).offsetNanoseconds,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Apply one change to the list of advances not yet undone. A forward change joins the list. A
|
|
24
|
+
* backward change undoes the most recent advance of the same size, if that advance is less than
|
|
25
|
+
* 365 days old, and returns it; otherwise it undoes nothing.
|
|
26
|
+
*/
|
|
27
|
+
function applyChange(open, change) {
|
|
28
|
+
if (change.step > 0) {
|
|
29
|
+
open.push(change);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
for (let i = open.length - 1; i >= 0; i--) {
|
|
33
|
+
if (open[i].step !== -change.step) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (change.at - open[i].at >= DAYLIGHT_PERIOD_LIMIT_NANOSECONDS) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return open.splice(i, 1)[0];
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/** Whether `to` is less than the daylight period limit after `from`. */
|
|
44
|
+
function isWithinLimit(from, to) {
|
|
45
|
+
return to - from < DAYLIGHT_PERIOD_LIMIT_NANOSECONDS;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The advances still open just before `next`: made in the 365 days before it and not yet undone.
|
|
49
|
+
* An older advance cannot be undone at or after `next`. Null past `MAX_WALKED_CHANGES` changes.
|
|
50
|
+
*
|
|
51
|
+
* @param next the first change after the instant being judged
|
|
52
|
+
* @param latest the change before `next`, already known to be within the limit
|
|
53
|
+
*/
|
|
54
|
+
function openAdvancesBefore(next, latest) {
|
|
55
|
+
const changes = [offsetChangeAt(latest)];
|
|
56
|
+
let cursor = latest;
|
|
57
|
+
for (let i = 0; i <= MAX_WALKED_CHANGES; i++) {
|
|
58
|
+
const previous = zonedPreviousTransition(cursor, next.epochNanoseconds - DAYLIGHT_PERIOD_LIMIT_NANOSECONDS);
|
|
59
|
+
if (previous === null ||
|
|
60
|
+
!isWithinLimit(previous.epochNanoseconds, next.epochNanoseconds)) {
|
|
61
|
+
const open = [];
|
|
62
|
+
for (const change of changes) {
|
|
63
|
+
applyChange(open, change);
|
|
64
|
+
}
|
|
65
|
+
return open;
|
|
66
|
+
}
|
|
67
|
+
changes.unshift(offsetChangeAt(previous));
|
|
68
|
+
cursor = previous;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Whether a change from `next` onwards undoes one of the `open` advances made at or before `at`.
|
|
74
|
+
* It has to come less than 365 days after `at`, since the advance is no later than `at`.
|
|
75
|
+
*/
|
|
76
|
+
function isUndoneFrom(next, open, at) {
|
|
77
|
+
let cursor = next;
|
|
78
|
+
for (let i = 0; i <= MAX_WALKED_CHANGES; i++) {
|
|
79
|
+
if (cursor === null || !isWithinLimit(at, cursor.epochNanoseconds)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const undone = applyChange(open, offsetChangeAt(cursor));
|
|
83
|
+
if (undone !== null && undone.at <= at) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
cursor = zonedNextTransition(cursor, at + DAYLIGHT_PERIOD_LIMIT_NANOSECONDS);
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether an instant is in daylight saving time, read from the zone's offset changes alone.
|
|
92
|
+
*
|
|
93
|
+
* The rule: daylight time runs from a forward change of the clocks to the backward change that
|
|
94
|
+
* undoes it. A backward change undoes the most recent forward change of the same size that is not
|
|
95
|
+
* yet undone, and only if it comes less than 365 days after it. An instant is in daylight time when
|
|
96
|
+
* it is at or after such a forward change and before the backward change paired with it.
|
|
97
|
+
*
|
|
98
|
+
* A forward change that is never undone, or undone a year or more later, is a change of standard
|
|
99
|
+
* time (`Europe/Istanbul` 2016, `Europe/Moscow` 2011 to 2014), as is any backward change with no
|
|
100
|
+
* forward change to undo (`Asia/Almaty` 2024).
|
|
101
|
+
*
|
|
102
|
+
* This is GMT's own definition, not the tz database's daylight flag, which no JavaScript API
|
|
103
|
+
* exposes and offsets do not determine.
|
|
104
|
+
*
|
|
105
|
+
* Cost: one transition lookup forward, then one back, and more only outside the ordinary summer
|
|
106
|
+
* case. A paired change is less than 365 days away, so every lookup is given that limit and reads
|
|
107
|
+
* no further: with GMT's own search (temporalCompat D13) at most 74 offset samples and 51 reads to
|
|
108
|
+
* pin a change, for any zone and any instant.
|
|
109
|
+
*
|
|
110
|
+
* @param zoned the instant, in the zone to read
|
|
111
|
+
* @returns true in daylight time, false in standard time or when the walk exceeds its bound
|
|
112
|
+
*/
|
|
113
|
+
export function isInDaylightTime(zoned) {
|
|
114
|
+
const at = zoned.epochNanoseconds;
|
|
115
|
+
// Daylight time ends with a clock change. No change ahead, or none within the limit: standard.
|
|
116
|
+
const next = zonedNextTransition(zoned, at + DAYLIGHT_PERIOD_LIMIT_NANOSECONDS);
|
|
117
|
+
if (next === null || !isWithinLimit(at, next.epochNanoseconds)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
// It begins with one too, and no change in the 365 days before `next` leaves nothing to undo.
|
|
121
|
+
const latest = zonedPreviousTransition(next, next.epochNanoseconds - DAYLIGHT_PERIOD_LIMIT_NANOSECONDS);
|
|
122
|
+
if (latest === null ||
|
|
123
|
+
!isWithinLimit(latest.epochNanoseconds, next.epochNanoseconds)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
// The ordinary summer: the clocks last went forward, and next go back by as much. The latest
|
|
127
|
+
// advance is the most recent one open, so `next` undoes it whatever came before.
|
|
128
|
+
const latestStep = offsetChangeAt(latest).step;
|
|
129
|
+
const nextStep = next.offsetNanoseconds - zoned.offsetNanoseconds;
|
|
130
|
+
if (latestStep > 0 && nextStep === -latestStep) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
const open = openAdvancesBefore(next, latest);
|
|
134
|
+
if (open === null || open.length === 0) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return isUndoneFrom(next, open, at);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Whether a zone observes daylight saving time as of an instant: the instant is in daylight time,
|
|
141
|
+
* or a daylight period begins within the 365 days after it. Same rule as `isInDaylightTime`.
|
|
142
|
+
*
|
|
143
|
+
* @param zoned the instant to judge from, in the zone to read
|
|
144
|
+
* @returns true when the zone observes daylight time then, false otherwise or past the walk bound
|
|
145
|
+
*/
|
|
146
|
+
export function observesDaylightTime(zoned) {
|
|
147
|
+
if (isInDaylightTime(zoned)) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
let cursor = zoned;
|
|
151
|
+
for (let i = 0; i <= MAX_WALKED_CHANGES; i++) {
|
|
152
|
+
const next = zonedNextTransition(cursor, zoned.epochNanoseconds + DAYLIGHT_PERIOD_LIMIT_NANOSECONDS);
|
|
153
|
+
if (next === null ||
|
|
154
|
+
next.epochNanoseconds - zoned.epochNanoseconds >=
|
|
155
|
+
DAYLIGHT_PERIOD_LIMIT_NANOSECONDS) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (isInDaylightTime(next)) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
cursor = next;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
@@ -2,16 +2,17 @@ import { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import { plainDateUntil } from "./plainDateUntil.js";
|
|
3
3
|
import { zonedUntil } from "./zonedWallClockDifference.js";
|
|
4
4
|
export function durationUntilString(start, end, largestUnit, options) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// Each option is read once (GetOption); the difference below works on these values.
|
|
6
|
+
const roundingOptions = {
|
|
7
7
|
smallestUnit: options?.smallestUnit,
|
|
8
8
|
roundingIncrement: options?.roundingIncrement,
|
|
9
9
|
roundingMode: options?.roundingMode,
|
|
10
10
|
};
|
|
11
|
+
const untilOptions = { largestUnit, ...roundingOptions };
|
|
11
12
|
const duration = start instanceof Temporal.ZonedDateTime
|
|
12
13
|
? zonedUntil(start, end, untilOptions)
|
|
13
14
|
: start instanceof Temporal.PlainDate
|
|
14
|
-
? plainDateUntil(start, end, largestUnit,
|
|
15
|
+
? plainDateUntil(start, end, largestUnit, roundingOptions)
|
|
15
16
|
: start.until(end, untilOptions);
|
|
16
17
|
return duration.toString({
|
|
17
18
|
smallestUnit: options?.toStringSmallestUnit,
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
// RFC 7231) mandate English weekday/month
|
|
3
3
|
// abbreviations regardless of the caller's locale — these are fixed,
|
|
4
4
|
// non-locale-adaptive grammars, not a display format, so hardcoding the
|
|
5
|
-
// English names here is not the i18n bug it would be in a formatter
|
|
6
|
-
// roadmap Decision 1 / J13's "Why this survives Decision 1").
|
|
5
|
+
// English names here is not the i18n bug it would be in a formatter.
|
|
7
6
|
// Index 0 = Monday, aligned with Temporal's 1-7 `dayOfWeek` via `[dayOfWeek - 1]`.
|
|
8
7
|
export const ENGLISH_WEEKDAY_NAMES = [
|
|
9
8
|
"Mon",
|
|
@@ -8,6 +8,8 @@ export declare const MIN_EPOCH_NANOSECONDS = -8640000000000000000000n;
|
|
|
8
8
|
* +10^8 days from the Unix epoch, i.e. `+275760-09-13T00:00:00Z`.
|
|
9
9
|
*/
|
|
10
10
|
export declare const MAX_EPOCH_NANOSECONDS = 8640000000000000000000n;
|
|
11
|
+
/** TC39 `CheckISODaysRange`: a date may sit at most 10^8 days from the Unix epoch. */
|
|
12
|
+
export declare const MAX_ISO_EPOCH_DAYS = 100000000;
|
|
11
13
|
/**
|
|
12
14
|
* Digits in `MAX_EPOCH_NANOSECONDS` (22) — the longest a decimal form of an in-range
|
|
13
15
|
* epoch-nanosecond value can be, sign excluded.
|
|
@@ -8,6 +8,8 @@ export const MIN_EPOCH_NANOSECONDS = -8640000000000000000000n;
|
|
|
8
8
|
* +10^8 days from the Unix epoch, i.e. `+275760-09-13T00:00:00Z`.
|
|
9
9
|
*/
|
|
10
10
|
export const MAX_EPOCH_NANOSECONDS = 8640000000000000000000n;
|
|
11
|
+
/** TC39 `CheckISODaysRange`: a date may sit at most 10^8 days from the Unix epoch. */
|
|
12
|
+
export const MAX_ISO_EPOCH_DAYS = 100_000_000;
|
|
11
13
|
/**
|
|
12
14
|
* Digits in `MAX_EPOCH_NANOSECONDS` (22) — the longest a decimal form of an in-range
|
|
13
15
|
* epoch-nanosecond value can be, sign excluded.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An ISO 8601 duration as exact elapsed nanoseconds, signed, or `null` when it is not one.
|
|
3
|
+
*
|
|
4
|
+
* The transport rule for a span of exact time (`transitTime`, `classifyPunctuality`,
|
|
5
|
+
* `nextDeparture`, …):
|
|
6
|
+
*
|
|
7
|
+
* - Hours, minutes, seconds and fractions are elapsed time, and a day is 24 hours exactly. That
|
|
8
|
+
* is how TC39 Temporal's `Duration.prototype.round` and `total` read a day when no
|
|
9
|
+
* `relativeTo` is given.
|
|
10
|
+
* - Years, months and weeks return `null`: `round` and `total` require a `relativeTo` for them,
|
|
11
|
+
* so they have no exact length on their own. A zero calendar component (`P0Y1D`) changes
|
|
12
|
+
* nothing. (`Temporal.Instant#add` accepts no date unit at all, days included; callers add the
|
|
13
|
+
* nanoseconds this returns instead.)
|
|
14
|
+
* - The result keeps the duration's sign, so a caller that needs a non-negative amount checks
|
|
15
|
+
* `< 0n` itself. `-PT0S` is `0n`.
|
|
16
|
+
* - Summed in bigint, so it stays exact past 2^53 ns and across the whole instant range.
|
|
17
|
+
*
|
|
18
|
+
* @param value candidate ISO 8601 duration string
|
|
19
|
+
* @returns the duration in nanoseconds, negative for a negative duration, or null on invalid input
|
|
20
|
+
*
|
|
21
|
+
* @example exactDurationNanoseconds("PT1H") // 3600000000000n
|
|
22
|
+
* @example exactDurationNanoseconds("-PT5M") // -300000000000n
|
|
23
|
+
* @example exactDurationNanoseconds("P1D") // 86400000000000n
|
|
24
|
+
* @example exactDurationNanoseconds("P1W") // null
|
|
25
|
+
*/
|
|
26
|
+
export declare function exactDurationNanoseconds(value: unknown): bigint | null;
|
|
27
|
+
/**
|
|
28
|
+
* `exactDurationNanoseconds` for an amount that may not be negative — a tolerance, a minimum
|
|
29
|
+
* connection — or `null`. Zero is allowed, and `-PT0S` is zero.
|
|
30
|
+
*
|
|
31
|
+
* @param value candidate ISO 8601 duration string
|
|
32
|
+
* @returns the duration in nanoseconds, zero or more, or null on invalid input or a negative duration
|
|
33
|
+
*
|
|
34
|
+
* @example nonNegativeExactDurationNanoseconds("PT15M") // 900000000000n
|
|
35
|
+
* @example nonNegativeExactDurationNanoseconds("-PT15M") // null
|
|
36
|
+
*/
|
|
37
|
+
export declare function nonNegativeExactDurationNanoseconds(value: unknown): bigint | null;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { NANOSECONDS_PER_DAY, NANOSECONDS_PER_MICROSECOND, NANOSECONDS_PER_MILLISECOND, NANOSECONDS_PER_SECOND, } from "./foreignEpochs.js";
|
|
3
|
+
const NANOSECONDS_PER_HOUR = 3600000000000n;
|
|
4
|
+
const NANOSECONDS_PER_MINUTE = 60000000000n;
|
|
5
|
+
/**
|
|
6
|
+
* An ISO 8601 duration as exact elapsed nanoseconds, signed, or `null` when it is not one.
|
|
7
|
+
*
|
|
8
|
+
* The transport rule for a span of exact time (`transitTime`, `classifyPunctuality`,
|
|
9
|
+
* `nextDeparture`, …):
|
|
10
|
+
*
|
|
11
|
+
* - Hours, minutes, seconds and fractions are elapsed time, and a day is 24 hours exactly. That
|
|
12
|
+
* is how TC39 Temporal's `Duration.prototype.round` and `total` read a day when no
|
|
13
|
+
* `relativeTo` is given.
|
|
14
|
+
* - Years, months and weeks return `null`: `round` and `total` require a `relativeTo` for them,
|
|
15
|
+
* so they have no exact length on their own. A zero calendar component (`P0Y1D`) changes
|
|
16
|
+
* nothing. (`Temporal.Instant#add` accepts no date unit at all, days included; callers add the
|
|
17
|
+
* nanoseconds this returns instead.)
|
|
18
|
+
* - The result keeps the duration's sign, so a caller that needs a non-negative amount checks
|
|
19
|
+
* `< 0n` itself. `-PT0S` is `0n`.
|
|
20
|
+
* - Summed in bigint, so it stays exact past 2^53 ns and across the whole instant range.
|
|
21
|
+
*
|
|
22
|
+
* @param value candidate ISO 8601 duration string
|
|
23
|
+
* @returns the duration in nanoseconds, negative for a negative duration, or null on invalid input
|
|
24
|
+
*
|
|
25
|
+
* @example exactDurationNanoseconds("PT1H") // 3600000000000n
|
|
26
|
+
* @example exactDurationNanoseconds("-PT5M") // -300000000000n
|
|
27
|
+
* @example exactDurationNanoseconds("P1D") // 86400000000000n
|
|
28
|
+
* @example exactDurationNanoseconds("P1W") // null
|
|
29
|
+
*/
|
|
30
|
+
export function exactDurationNanoseconds(value) {
|
|
31
|
+
if (typeof value !== "string") {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const duration = Temporal.Duration.from(value);
|
|
36
|
+
if (duration.years !== 0 || duration.months !== 0 || duration.weeks !== 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return (BigInt(duration.days) * NANOSECONDS_PER_DAY +
|
|
40
|
+
BigInt(duration.hours) * NANOSECONDS_PER_HOUR +
|
|
41
|
+
BigInt(duration.minutes) * NANOSECONDS_PER_MINUTE +
|
|
42
|
+
BigInt(duration.seconds) * NANOSECONDS_PER_SECOND +
|
|
43
|
+
BigInt(duration.milliseconds) * NANOSECONDS_PER_MILLISECOND +
|
|
44
|
+
BigInt(duration.microseconds) * NANOSECONDS_PER_MICROSECOND +
|
|
45
|
+
BigInt(duration.nanoseconds));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `exactDurationNanoseconds` for an amount that may not be negative — a tolerance, a minimum
|
|
53
|
+
* connection — or `null`. Zero is allowed, and `-PT0S` is zero.
|
|
54
|
+
*
|
|
55
|
+
* @param value candidate ISO 8601 duration string
|
|
56
|
+
* @returns the duration in nanoseconds, zero or more, or null on invalid input or a negative duration
|
|
57
|
+
*
|
|
58
|
+
* @example nonNegativeExactDurationNanoseconds("PT15M") // 900000000000n
|
|
59
|
+
* @example nonNegativeExactDurationNanoseconds("-PT15M") // null
|
|
60
|
+
*/
|
|
61
|
+
export function nonNegativeExactDurationNanoseconds(value) {
|
|
62
|
+
const nanoseconds = exactDurationNanoseconds(value);
|
|
63
|
+
return nanoseconds === null || nanoseconds < 0n ? null : nanoseconds;
|
|
64
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How an exact moment was written, so a result can be written the same way: in a named zone
|
|
3
|
+
* (the bracket), at a UTC offset (its text exactly as written), or as a `Z` instant.
|
|
4
|
+
*/
|
|
5
|
+
export type MomentNotation = {
|
|
6
|
+
kind: "zone";
|
|
7
|
+
timeZone: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "offset";
|
|
10
|
+
offset: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "utc";
|
|
13
|
+
};
|
|
14
|
+
/** An exact moment: its epoch nanoseconds and how it was written. */
|
|
15
|
+
export type ExactMoment = {
|
|
16
|
+
nanoseconds: bigint;
|
|
17
|
+
notation: MomentNotation;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Read an exact moment the way `transitTime` reads a departure, or `null`.
|
|
21
|
+
*
|
|
22
|
+
* - A zoned string (`…-04:00[America/New_York]`) is read through its bracket, which must name a
|
|
23
|
+
* real zone that agrees with the offset, as `isValidZonedDateTime` requires. An offset written
|
|
24
|
+
* to the minute agrees when it is the zone's sub-minute offset rounded (TC39
|
|
25
|
+
* `ToTemporalZonedDateTime`, match-minutes), which is how `writeExactMoment` writes one.
|
|
26
|
+
* - A wall time with a bracket and no offset is read in that zone with the `"compatible"`
|
|
27
|
+
* disambiguation policy (`context/reference/LOCAL_TIME_RESOLUTION.md`): an **ambiguous** wall
|
|
28
|
+
* time, a fall-back hour the clock ran through twice, resolves to the **earlier** instant
|
|
29
|
+
* (`2024-11-03T01:30:00[America/New_York]` is `01:30-04:00`), and a **nonexistent** one, a
|
|
30
|
+
* spring-forward hour the clock skipped, to the **later** instant
|
|
31
|
+
* (`2024-03-10T02:30:00[America/New_York]` is `03:30-04:00`). A caller that must not guess
|
|
32
|
+
* refuses the offset-less form before calling, as `nextDeparture` does.
|
|
33
|
+
* - A string that names a zone the zoned read rejects is `null`; it never falls back to its
|
|
34
|
+
* offset. That includes a zoned string whose local date is −271821-04-19, which
|
|
35
|
+
* `Temporal.ZonedDateTime.from` refuses although its instant is in range.
|
|
36
|
+
* - Otherwise an instant (`Z` or an offset) as `parseInstantNanoseconds` reads it: calendar and
|
|
37
|
+
* elective annotations are ignored and a critical unknown one is rejected. Its offset text is
|
|
38
|
+
* kept exactly as written, sub-minute and `,` fractions included.
|
|
39
|
+
*
|
|
40
|
+
* @param value candidate zoned datetime or instant string
|
|
41
|
+
* @returns the moment's epoch nanoseconds and notation, or null on invalid input
|
|
42
|
+
*
|
|
43
|
+
* @example readExactMoment("2024-06-15T10:00:00+09:00") // { nanoseconds: 1718413200000000000n, notation: { kind: "offset", offset: "+09:00" } }
|
|
44
|
+
* @example readExactMoment("2024-06-15T10:00:00Z[Not/AZone]") // null
|
|
45
|
+
* @example readExactMoment("2024-03-10T02:30:00[America/New_York]") // { nanoseconds: 1710055800000000000n, notation: { kind: "zone", timeZone: "America/New_York" } } (nonexistent: the later instant, 03:30-04:00)
|
|
46
|
+
*/
|
|
47
|
+
export declare function readExactMoment(value: unknown): ExactMoment | null;
|
|
48
|
+
/**
|
|
49
|
+
* Write epoch nanoseconds the way a moment was written: in its zone, at its offset text, or as a
|
|
50
|
+
* `Z` instant. `""` when the nanoseconds leave the instant range (±8.64e21 ns).
|
|
51
|
+
*
|
|
52
|
+
* - A zone notation is written as Temporal writes a `ZonedDateTime`: the offset in force at that
|
|
53
|
+
* instant, rounded to the minute (`-00:45` for Monrovia's −00:44:30), then the bracket.
|
|
54
|
+
* `readExactMoment` and `parseInstantNanoseconds` read that string back as the same instant,
|
|
55
|
+
* with two exceptions, both Temporal's own. A wall time repeated inside a sub-minute offset
|
|
56
|
+
* change reads as its first pass, in both readers (`parseInstantNanoseconds` states the
|
|
57
|
+
* rule). And `readExactMoment`, a zoned read, refuses a string whose local date is
|
|
58
|
+
* −271821-04-19 (`CheckISODaysRange` in `Temporal.ZonedDateTime.from`): the string written
|
|
59
|
+
* for the first hours of the instant range in a zone west of Greenwich reads as `null` there,
|
|
60
|
+
* and as its instant in `parseInstantNanoseconds`
|
|
61
|
+
* (`context/domination/js-temporal-polyfill-bugs.md` § J).
|
|
62
|
+
* - An offset notation keeps its text as written. The wall clock is shifted, never the instant
|
|
63
|
+
* (`wallClockAtOffset`), so the last hours of the range still write at a positive offset.
|
|
64
|
+
*
|
|
65
|
+
* @param nanoseconds epoch nanoseconds of the moment to write
|
|
66
|
+
* @param notation how to write it, from `readExactMoment`
|
|
67
|
+
* @returns the moment as a zoned, offset or `Z` string, or "" when it is out of range
|
|
68
|
+
*
|
|
69
|
+
* @example writeExactMoment(0n, { kind: "offset", offset: "+09:00" }) // "1970-01-01T09:00:00+09:00"
|
|
70
|
+
* @example writeExactMoment(0n, { kind: "zone", timeZone: "UTC" }) // "1970-01-01T00:00:00+00:00[UTC]"
|
|
71
|
+
*/
|
|
72
|
+
export declare function writeExactMoment(nanoseconds: bigint, notation: MomentNotation): string;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { isValidZonedDateTime } from "../zoned/validate/isValidZonedDateTime.js";
|
|
3
|
+
import { parseInstantNanoseconds } from "./instantNanoseconds.js";
|
|
4
|
+
import { EXTENDED_UTC_OFFSET, TIME_ZONE_ANNOTATION } from "./isoStringBody.js";
|
|
5
|
+
import { wallClockAtOffset } from "./wallClockAtOffset.js";
|
|
6
|
+
import { utcOffsetStringNanoseconds, zonedDateTimeFrom, } from "./zonedWallClock.js";
|
|
7
|
+
/**
|
|
8
|
+
* Trailing `Z` or extended offset of an instant string, before any annotation. The offset grammar
|
|
9
|
+
* is `isValidInstant`'s own (`EXTENDED_UTC_OFFSET`), so every offset it accepts, `,` fractions
|
|
10
|
+
* included, is captured as written.
|
|
11
|
+
*/
|
|
12
|
+
const trailingOffset = new RegExp(`(Z|${EXTENDED_UTC_OFFSET})(?:\\[[^\\]]*\\])*$`);
|
|
13
|
+
/**
|
|
14
|
+
* A time-zone annotation anywhere in the string (`TIME_ZONE_ANNOTATION`). Every `key=value`
|
|
15
|
+
* bracket is a tagged annotation, which the instant parse already decides.
|
|
16
|
+
*/
|
|
17
|
+
const zoneAnnotation = new RegExp(TIME_ZONE_ANNOTATION);
|
|
18
|
+
/**
|
|
19
|
+
* Read an exact moment the way `transitTime` reads a departure, or `null`.
|
|
20
|
+
*
|
|
21
|
+
* - A zoned string (`…-04:00[America/New_York]`) is read through its bracket, which must name a
|
|
22
|
+
* real zone that agrees with the offset, as `isValidZonedDateTime` requires. An offset written
|
|
23
|
+
* to the minute agrees when it is the zone's sub-minute offset rounded (TC39
|
|
24
|
+
* `ToTemporalZonedDateTime`, match-minutes), which is how `writeExactMoment` writes one.
|
|
25
|
+
* - A wall time with a bracket and no offset is read in that zone with the `"compatible"`
|
|
26
|
+
* disambiguation policy (`context/reference/LOCAL_TIME_RESOLUTION.md`): an **ambiguous** wall
|
|
27
|
+
* time, a fall-back hour the clock ran through twice, resolves to the **earlier** instant
|
|
28
|
+
* (`2024-11-03T01:30:00[America/New_York]` is `01:30-04:00`), and a **nonexistent** one, a
|
|
29
|
+
* spring-forward hour the clock skipped, to the **later** instant
|
|
30
|
+
* (`2024-03-10T02:30:00[America/New_York]` is `03:30-04:00`). A caller that must not guess
|
|
31
|
+
* refuses the offset-less form before calling, as `nextDeparture` does.
|
|
32
|
+
* - A string that names a zone the zoned read rejects is `null`; it never falls back to its
|
|
33
|
+
* offset. That includes a zoned string whose local date is −271821-04-19, which
|
|
34
|
+
* `Temporal.ZonedDateTime.from` refuses although its instant is in range.
|
|
35
|
+
* - Otherwise an instant (`Z` or an offset) as `parseInstantNanoseconds` reads it: calendar and
|
|
36
|
+
* elective annotations are ignored and a critical unknown one is rejected. Its offset text is
|
|
37
|
+
* kept exactly as written, sub-minute and `,` fractions included.
|
|
38
|
+
*
|
|
39
|
+
* @param value candidate zoned datetime or instant string
|
|
40
|
+
* @returns the moment's epoch nanoseconds and notation, or null on invalid input
|
|
41
|
+
*
|
|
42
|
+
* @example readExactMoment("2024-06-15T10:00:00+09:00") // { nanoseconds: 1718413200000000000n, notation: { kind: "offset", offset: "+09:00" } }
|
|
43
|
+
* @example readExactMoment("2024-06-15T10:00:00Z[Not/AZone]") // null
|
|
44
|
+
* @example readExactMoment("2024-03-10T02:30:00[America/New_York]") // { nanoseconds: 1710055800000000000n, notation: { kind: "zone", timeZone: "America/New_York" } } (nonexistent: the later instant, 03:30-04:00)
|
|
45
|
+
*/
|
|
46
|
+
export function readExactMoment(value) {
|
|
47
|
+
if (typeof value !== "string") {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
if (isValidZonedDateTime(value)) {
|
|
52
|
+
const zoned = zonedDateTimeFrom(value);
|
|
53
|
+
return {
|
|
54
|
+
nanoseconds: zoned.epochNanoseconds,
|
|
55
|
+
notation: { kind: "zone", timeZone: zoned.timeZoneId },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (zoneAnnotation.test(value)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const nanoseconds = parseInstantNanoseconds(value);
|
|
62
|
+
if (nanoseconds === null) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const offset = trailingOffset.exec(value)?.[1] ?? "Z";
|
|
66
|
+
return {
|
|
67
|
+
nanoseconds,
|
|
68
|
+
notation: offset === "Z" ? { kind: "utc" } : { kind: "offset", offset },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Write epoch nanoseconds the way a moment was written: in its zone, at its offset text, or as a
|
|
77
|
+
* `Z` instant. `""` when the nanoseconds leave the instant range (±8.64e21 ns).
|
|
78
|
+
*
|
|
79
|
+
* - A zone notation is written as Temporal writes a `ZonedDateTime`: the offset in force at that
|
|
80
|
+
* instant, rounded to the minute (`-00:45` for Monrovia's −00:44:30), then the bracket.
|
|
81
|
+
* `readExactMoment` and `parseInstantNanoseconds` read that string back as the same instant,
|
|
82
|
+
* with two exceptions, both Temporal's own. A wall time repeated inside a sub-minute offset
|
|
83
|
+
* change reads as its first pass, in both readers (`parseInstantNanoseconds` states the
|
|
84
|
+
* rule). And `readExactMoment`, a zoned read, refuses a string whose local date is
|
|
85
|
+
* −271821-04-19 (`CheckISODaysRange` in `Temporal.ZonedDateTime.from`): the string written
|
|
86
|
+
* for the first hours of the instant range in a zone west of Greenwich reads as `null` there,
|
|
87
|
+
* and as its instant in `parseInstantNanoseconds`
|
|
88
|
+
* (`context/domination/js-temporal-polyfill-bugs.md` § J).
|
|
89
|
+
* - An offset notation keeps its text as written. The wall clock is shifted, never the instant
|
|
90
|
+
* (`wallClockAtOffset`), so the last hours of the range still write at a positive offset.
|
|
91
|
+
*
|
|
92
|
+
* @param nanoseconds epoch nanoseconds of the moment to write
|
|
93
|
+
* @param notation how to write it, from `readExactMoment`
|
|
94
|
+
* @returns the moment as a zoned, offset or `Z` string, or "" when it is out of range
|
|
95
|
+
*
|
|
96
|
+
* @example writeExactMoment(0n, { kind: "offset", offset: "+09:00" }) // "1970-01-01T09:00:00+09:00"
|
|
97
|
+
* @example writeExactMoment(0n, { kind: "zone", timeZone: "UTC" }) // "1970-01-01T00:00:00+00:00[UTC]"
|
|
98
|
+
*/
|
|
99
|
+
export function writeExactMoment(nanoseconds, notation) {
|
|
100
|
+
try {
|
|
101
|
+
const instant = Temporal.Instant.fromEpochNanoseconds(nanoseconds);
|
|
102
|
+
if (notation.kind === "zone") {
|
|
103
|
+
return instant.toZonedDateTimeISO(notation.timeZone).toString();
|
|
104
|
+
}
|
|
105
|
+
if (notation.kind === "utc") {
|
|
106
|
+
return instant.toString();
|
|
107
|
+
}
|
|
108
|
+
const wall = wallClockAtOffset(instant, utcOffsetStringNanoseconds(notation.offset));
|
|
109
|
+
return `${wall.toString()}${notation.offset}`;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return "";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -10,9 +10,10 @@ import type { FiscalPattern } from "../types/index.js";
|
|
|
10
10
|
* off the result.
|
|
11
11
|
*
|
|
12
12
|
* - The month-day is moved into `year` with Temporal's `overflow: "constrain"`, so a
|
|
13
|
-
* February 29 anchor targets February 28 in a common year before the weekday shift. A
|
|
14
|
-
*
|
|
15
|
-
* instead put a February 28 anchor on February 29 in a leap year;
|
|
13
|
+
* February 29 anchor targets February 28 in a common year before the weekday shift. A rule
|
|
14
|
+
* tied to the end of a month ("the last Saturday of February", or the Saturday nearest the
|
|
15
|
+
* month's last day) would instead put a February 28 anchor on February 29 in a leap year;
|
|
16
|
+
* this does not.
|
|
16
17
|
*/
|
|
17
18
|
export declare function fiscalYearEndIn(anchor: Temporal.PlainDate, year: number): Temporal.PlainDate;
|
|
18
19
|
/**
|
|
@@ -32,9 +32,10 @@ const NEAREST_WEEKDAY_RADIUS = 3;
|
|
|
32
32
|
* off the result.
|
|
33
33
|
*
|
|
34
34
|
* - The month-day is moved into `year` with Temporal's `overflow: "constrain"`, so a
|
|
35
|
-
* February 29 anchor targets February 28 in a common year before the weekday shift. A
|
|
36
|
-
*
|
|
37
|
-
* instead put a February 28 anchor on February 29 in a leap year;
|
|
35
|
+
* February 29 anchor targets February 28 in a common year before the weekday shift. A rule
|
|
36
|
+
* tied to the end of a month ("the last Saturday of February", or the Saturday nearest the
|
|
37
|
+
* month's last day) would instead put a February 28 anchor on February 29 in a leap year;
|
|
38
|
+
* this does not.
|
|
38
39
|
*/
|
|
39
40
|
export function fiscalYearEndIn(anchor, year) {
|
|
40
41
|
const target = anchor.with({ year }, { overflow: "constrain" });
|
|
@@ -13,7 +13,7 @@ import type { Temporal } from "@js-temporal/polyfill";
|
|
|
13
13
|
* @example formatCalendarDays(1, 1710685800000, "UTC", "en-US", "short") // "tomorrow at 2:30 PM"
|
|
14
14
|
* @example formatCalendarDays(-9, 1710685800000, "UTC", "en-US", "short") // "March 17, 2024 at 2:30 PM"
|
|
15
15
|
*/
|
|
16
|
-
export declare function formatCalendarDays(diffDays: number, epochMilliseconds: number, timeZone: string, locale: string | string[] | undefined, timeStyle: "short" | "medium" | "full"): string;
|
|
16
|
+
export declare function formatCalendarDays(diffDays: number, epochMilliseconds: number, timeZone: string, locale: string | string[] | undefined, timeStyle: "short" | "medium" | "long" | "full"): string;
|
|
17
17
|
/**
|
|
18
18
|
* `formatCalendarDays` for two instants, counting calendar days between their dates in `timeZone`.
|
|
19
19
|
*
|
|
@@ -25,4 +25,4 @@ export declare function formatCalendarDays(diffDays: number, epochMilliseconds:
|
|
|
25
25
|
* @returns the phrase; throws where Temporal or `Intl` throws
|
|
26
26
|
* @example formatCalendarInstants(Temporal.Instant.from("2024-03-17T14:30:00Z"), Temporal.Instant.from("2024-03-16T09:00:00Z"), "UTC", "en-US", "short") // "tomorrow at 2:30 PM"
|
|
27
27
|
*/
|
|
28
|
-
export declare function formatCalendarInstants(target: Temporal.Instant, reference: Temporal.Instant, timeZone: string, locale: string | string[] | undefined, timeStyle: "short" | "medium" | "full"): string;
|
|
28
|
+
export declare function formatCalendarInstants(target: Temporal.Instant, reference: Temporal.Instant, timeZone: string, locale: string | string[] | undefined, timeStyle: "short" | "medium" | "long" | "full"): string;
|
|
@@ -23,5 +23,25 @@ export interface RelativeDurationFormatOptions {
|
|
|
23
23
|
* @example formatRelativeDuration(Temporal.Duration.from({ hours: 36 }), "en-US", { largestUnit: "hour" }, () => 0) // "in 36 hours"
|
|
24
24
|
* @example formatRelativeDuration(Temporal.Duration.from({ days: 400 }), "en-US", {}, () => 1) // "next year" (month/year totals come from calendarTotal)
|
|
25
25
|
*/
|
|
26
|
-
export declare function formatRelativeDuration(diff: Temporal.Duration, locale: string | string[] | undefined, options: RelativeDurationFormatOptions, calendarTotal: (unit:
|
|
26
|
+
export declare function formatRelativeDuration(diff: Temporal.Duration, locale: string | string[] | undefined, options: RelativeDurationFormatOptions, calendarTotal: (unit: RelativeUnit) => number): string;
|
|
27
|
+
/**
|
|
28
|
+
* Round a distance to a whole number of `unit` and render it with `Intl.RelativeTimeFormat`. The
|
|
29
|
+
* shared last step of every `formatRelative*` function.
|
|
30
|
+
*
|
|
31
|
+
* - `numeric` and `style` are read here, once each (GetOption); `roundingMethod` is passed in
|
|
32
|
+
* because the caller has already read it.
|
|
33
|
+
*
|
|
34
|
+
* @param total the signed fractional distance in `unit`
|
|
35
|
+
* @param unit the singular unit the distance is written in
|
|
36
|
+
* @param locale BCP 47 locale(s) passed through to `Intl.RelativeTimeFormat`
|
|
37
|
+
* @param options the caller's options, read for `numeric` (default `"auto"`) and `style`
|
|
38
|
+
* (default `"long"`)
|
|
39
|
+
* @param roundingMethod the caller's `roundingMethod`, `undefined` for the default `"round"`
|
|
40
|
+
* @returns the formatted phrase; throws where `Intl` throws or the rounding method is invalid, for
|
|
41
|
+
* the caller's sentinel
|
|
42
|
+
* @example formatRelativeAmount(-1.5, "hour", "en-US", {}, "floor") // "2 hours ago"
|
|
43
|
+
* @example formatRelativeAmount(1, "day", "en-US", { numeric: "always" }, undefined) // "in 1 day"
|
|
44
|
+
* @example formatRelativeAmount(1, "day", "en-US", { style: "wide" as never }, undefined) // throws RangeError
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatRelativeAmount(total: number, unit: RelativeUnit, locale: string | string[] | undefined, options: Pick<RelativeDurationFormatOptions, "numeric" | "style">, roundingMethod: RelativeRoundingMethod | undefined): string;
|
|
27
47
|
export {};
|