transitTime
Signature
Section titled “Signature”transitTime(departure: string, duration: string): stringAdd a transit duration to a departure and return the arrival, in the departure’s own zone.
- The first of the three shared transport operations: a leg is a departure plus how long it takes. Every mode publishes it that way, and every mode gets the same thing wrong — a leg that crosses a DST transition is a fixed number of elapsed hours, not a wall-clock interval, so the local arrival time reflects the shift.
- Transit time is exact time. Hours, minutes, seconds and fractions are added as elapsed time, and a day component means 24 hours, exactly. That is TC39 Temporal’s rule:
Duration.prototype.roundandtotalwithout arelativeTotreat a day as 24 hours and require arelativeTofor weeks, months and years. A 26-hour leg that starts the evening before a spring-forward arrives at a wall time one hour later than a wall-clock reading would suggest, because that is when the vessel, train or aircraft actually gets there. - Calendar units are refused. A
durationwith years, months or weeks returns"": no leg takes “a month” in a sense that time arithmetic can fix without a reference point, and Temporal’sroundandtotalrequire arelativeTofor them. Scheduled connections that are dated rather than timed belong toscheduleDelivery. - The departure’s zone is preserved. A bracketed IANA zone (
…-05:00[America/New_York]) stays that zone, so the arrival’s offset is whatever is in force there at arrival. AZinstant returns aZinstant; an offset-only instant keeps its offset, written exactly as the departure wrote it, sub-minute offsets such as+05:30:15included (an offset is not a zone, so nothing else can be inferred from it — seetoOffsetInstant). A bracketed zone that does not exist, or that contradicts its offset, is rejected asisValidZonedDateTimerejects it; it does not fall back to the offset. An offset written to the minute that is the zone’s sub-minute offset rounded (-00:45[Africa/Monrovia], for −00:44:30) agrees with the zone, as Temporal writes and reads it, and names the instant the zone gives. - One zoned departure in range is refused. A zoned departure is read as
Temporal.ZonedDateTime.fromreads it, which rejects a local date of −271821-04-19. A zone west of Greenwich shows that date for the first hours of the instant range, so a departure written there (-271821-04-19T23:59:00-00:01[Europe/London]) returns"", althoughetaAtZonewrites it andscheduleDeviationreads it. Pass the instant inZform. - Local-time resolution policy (
"compatible"). A departure written as a wall time with a bracketed zone and no offset is resolved in that zone with the"compatible"policy, Temporal’s default andresolveLocal’s. An ambiguous wall time — a fall-back hour the clock ran through twice — resolves to the earlier instant:2024-11-03T01:30:00[America/New_York]is01:30-04:00. A nonexistent one — a spring-forward hour the clock skipped — resolves to the later instant:2024-03-10T02:30:00[America/New_York]is03:30-04:00. Write the offset to name the other pass of a repeated hour; a departure that carries its offset is never re-resolved. - RFC 9557 annotations are read as
Temporal.Instant.fromreads them: a bracket without=is a time zone, and akey=valuebracket with an unknown key is ignored when elective and rejected when critical ([!…]). A calendar on a departure without a zone is accepted and changes nothing, since an instant has no calendar; a zoned departure’s calendar must be ISO, asisValidZonedDateTimerequires. - A negative duration is allowed and moves backwards; that is how a departure is recovered from an arrival.
- Returns
""whendepartureis not a zoned datetime or instant string, ordurationis not an ISO 8601 duration.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
departure | string | ISO 8601 zoned datetime (bracketed zone) or instant string (Z or offset) |
duration | string | ISO 8601 duration of the leg; time units and 24-hour days only |
Returns
Section titled “Returns”the arrival in the departure’s zone or offset form, or "" on invalid input
Examples
Section titled “Examples”import { transitTime } from "@northguild/gmt/transport/calculate";
transitTime("2024-06-15T10:00:00-04:00[America/New_York]", "PT2H30M") // "2024-06-15T12:30:00-04:00[America/New_York]"