@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
40 lines • 2.99 kB
TypeScript
/**
* Render an arrival instant as local time in the zone where it will be read.
*
* Schedules are computed in UTC and displayed where the cargo lands. The zone is the caller's
* fact: GMT does not resolve a port, airport, terminal or station code to a timezone, and
* takes an IANA identifier instead.
*
* - `arrivalUtc` is any instant `isValidInstant` accepts — `Z` or an offset, with no annotation of
* any kind. `targetZone` is the zone the result is rendered in.
* - **No disambiguation arises.** The input is a moment, and a moment has exactly one wall
* time in any zone, so the `disambiguation` vocabulary of `resolveLocal` does not apply here.
* On a fall-back night two moments an hour apart print the same wall time with different
* offsets, and the offset in the result is what tells them apart; on a spring-forward night
* the skipped hour simply never appears. That is also why the result carries its offset and
* zone rather than a bare wall time.
* - Returns a zoned ISO 8601 string, `Temporal.ZonedDateTime.prototype.toString()`'s form:
* wall time, offset, bracketed zone.
* - `targetZone` is whatever `isValidTimeZone` accepts, which is what Temporal accepts: an IANA
* identifier, or a fixed offset such as `"+09:00"`, which renders with the offset as its zone.
* A fixed offset is a legitimate rendering choice for a ship's log; it is not a place.
* - Returns `""` when the instant or the zone is invalid.
* - An offset with seconds (`-00:44:30`) returns `""`. A written zone cannot carry seconds (RFC
* 9557 §4.1), so the result could not name it. Pass the IANA name, or call
* `fromOffsetInstant({ instant, offset })` for the local time with its full offset and no
* bracket.
*
* @param arrivalUtc ISO 8601 instant string of the arrival
* @param targetZone IANA name or a UTC offset to the minute (what `isValidTimeZone` accepts), for
* the place the arrival is read in
* @returns zoned ISO 8601 string of the local arrival, or "" on invalid input
*
* @example etaAtZone("2024-06-15T12:30:00Z", "Asia/Tokyo") // "2024-06-15T21:30:00+09:00[Asia/Tokyo]"
* @example etaAtZone("2024-06-15T12:30:00Z", "America/Los_Angeles") // "2024-06-15T05:30:00-07:00[America/Los_Angeles]"
* @example etaAtZone("2024-06-15T12:30:00+02:00", "Pacific/Apia") // "2024-06-15T23:30:00+13:00[Pacific/Apia]" (the offset fixes the instant; the zone renders it)
* @example etaAtZone("2024-04-06T15:30:00Z", "Australia/Sydney") // "2024-04-07T02:30:00+11:00[Australia/Sydney]" (the first 02:30 of the fall-back night)
* @example etaAtZone("2024-04-06T16:30:00Z", "Australia/Sydney") // "2024-04-07T02:30:00+10:00[Australia/Sydney]" (the second; the offset tells them apart)
* @example etaAtZone("2024-06-15T12:30:00", "Asia/Tokyo") // "" (no offset designator: not a moment)
* @example etaAtZone("2024-06-15T12:30:00Z", "Asia/Tokio") // ""
*/
export declare function etaAtZone(arrivalUtc: string, targetZone: string): string;