isValidInstant
Signature
Section titled “Signature”isValidInstant(value: string): booleanValidate whether a string is an ISO 8601 instant string the precision/ namespace accepts.
- The predicate
toNanosecondswas missing.toNanosecondsreturns0nfor both the epoch and a rejected string, and the only public validator close enough to reach for —isValidUtc— is narrower than this grammar: it gates on GMT’s stricter<date>T<time>Zshape and rejects the offsets and bracketed zonestoNanosecondsparses. Validating with it discards valid input. This accepts exactly whattoNanosecondsdoes, so the two never disagree. - Requires an offset designator (
Z,±HH:MM); a bracketed IANA zone may follow, but a bracket alone is not enough. - The offset fixes the instant; a bracketed zone only resolves a rounded one. An offset written to the minute that is the bracketed zone’s sub-minute offset rounded (
-00:45[Africa/Monrovia], for −00:44:30) names the instant the zone gives, asTemporal.ZonedDateTime.fromreads it, so a zoned string Temporal wrote is read back as the instant it was written for, at the first and last instants of the range too, where the written offset’s own reading can fall just outside it (-271821-04-19T23:58:45-00:01[Europe/London]is the first instant). One exception, which is Temporal’s own: a wall time repeated inside a sub-minute offset change, written with a minute-rounded offset, reads as its first pass (for example1952-10-15T23:59:59-11:20[Pacific/Niue], where the zone moved from −11:19:40 to −11:20:00, is the pass at −11:19:40). Otherwise the bracket is not checked: a zone that does not exist, or that disagrees with the offset, changes nothing. Validity never depends on the bracket. - ISO 8601 extended format before any annotation:
<date>T<time>, thenZor±HH:MM[:SS[.fraction]]. Basic format, a space or lower-casetseparator, a lower-casezand an hour-only time or offset returnfalse, althoughTemporal.Instant.fromreads them. - Rejects leap seconds in every separator and format variant.
- Reads RFC 9557 annotations as
Temporal.Instant.fromdoes: a calendar or elective annotation is ignored, and an unknown critical one ([!foo=bar]) is rejected. - Returns
falsefor non-strings and empty strings.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | candidate ISO 8601 instant string |
Returns
Section titled “Returns”boolean indicating whether toNanoseconds will parse it
Examples
Section titled “Examples”import { isValidInstant } from "@northguild/gmt/precision/validate";
isValidInstant("2024-03-10T12:00:00Z") // true