UNPKG

@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.

58 lines • 3.84 kB
import { Hl7Precision } from "../types/hl7.js"; import { OffsetInstant } from "../instant/convert/toOffsetInstant.js"; /** * The pair for an instant string: `Z` or an extended offset after `<date>T<time>`, nothing after * it (GMT's instant shape, `hasInstantShape`). One of the two exact readers, with * `readZonedOffsetInstant`; a string with any annotation is `null` here. Never throws. * * @param value ISO 8601 extended instant string, `…Z` or `…±HH:MM[:SS[.fraction]]` * @param timeZone the zone to read the offset in, instead of the written one * @returns the pair, or null when `value` is not an instant or `timeZone` is not a zone * * @example readInstantOffsetInstant("2024-07-15T16:00:00+05:30") // { instant: "2024-07-15T10:30:00Z", offset: "+05:30" } * @example readInstantOffsetInstant("2024-07-15T16:00:00+05:30[Asia/Kolkata]") // null (a zoned string; see `readZonedOffsetInstant`) * @example readInstantOffsetInstant("2024-06-15T10Z") // null (an hour-only time; see `readFormOffsetInstant`) */ export declare function readInstantOffsetInstant(value: string, timeZone?: string): OffsetInstant | null; /** * The pair for a zoned string that writes its offset: `<date>T<time>` then `Z` or an extended * offset, then exactly one time zone bracket (`hasZonedInstantShape`), nothing after it. The other * exact reader, with `readInstantOffsetInstant`; a string with no bracket is `null` here, and * so is one whose offset contradicts its zone. Never throws. * * @param value zoned string that writes its offset, `2024-07-15T16:00:00+05:30[Asia/Kolkata]` * @param timeZone the zone to read the offset in, instead of the bracketed one * @returns the pair, or null when `value` is not such a string or `timeZone` is not a zone * * @example readZonedOffsetInstant("2024-07-15T16:00:00+05:30[Asia/Kolkata]") // { instant: "2024-07-15T10:30:00Z", offset: "+05:30", timeZone: "Asia/Kolkata" } * @example readZonedOffsetInstant("2024-07-15T16:00:00+05:30") // null (an instant; see `readInstantOffsetInstant`) */ export declare function readZonedOffsetInstant(value: string, timeZone?: string): OffsetInstant | null; /** * The pair for a string `isoHl7Form` matched, at the precision `isoHl7Precision` read from it. * Never throws. * * An hour-only time (`2024-06-15T10Z`, `…T23-05:00`) is ISO 8601-1 §5.3.1.3 reduced precision. * `readInstantOffsetInstant` refuses it, as `isValidInstant` does, because GMT's instant shape needs * a minute. Here the caller has already matched the form, and the string must match the exact * hour-only instant shape (`hourInstant`) over the whole string, so Temporal reads the hour * directly (`Temporal.Instant.from("2024-06-15T10Z")` is `2024-06-15T10:00:00Z`). Every finer form * goes through `readInstantOffsetInstant`. * * @param value a string `isoHl7Form` matched, with its offset * @param written the precision `isoHl7Precision` read * @returns the pair, or null when the value is not an instant * * @example readFormOffsetInstant("2024-06-15T23-05:00", "hour") // { instant: "2024-06-16T04:00:00Z", offset: "-05:00" } */ export declare function readFormOffsetInstant(value: string, written: Hl7Precision): OffsetInstant | null; /** * The core of `fromOffsetInstant`: the local time an instant-plus-offset pair describes, with the * pair's own offset, or the bracketed zoned string when the pair names a zone. Never throws. * * @param value `{ instant, offset, timeZone? }` pair, as `readInstantOffsetInstant` and `readZonedOffsetInstant` return * @returns the local ISO 8601 string, or `""` on invalid input or a zone that contradicts the offset * * @example writeOffsetInstant({ instant: "2024-07-15T16:00:00Z", offset: "-04:00" }) // "2024-07-15T12:00:00-04:00" */ export declare function writeOffsetInstant(value: OffsetInstant): string;