toNanoseconds
Signature
Section titled “Signature”toNanoseconds(isoString: string): bigintConvert an ISO 8601 instant string to nanoseconds since the Unix epoch.
- Requires an offset designator (
Z,±HH:MM), asTemporal.Instantdoes — date-only and offset-less strings are rejected. - Accepts no annotation: a time zone, a
[u-ca=...]calendar or any other bracket returns0n. The offset alone fixes the instant, and one written with seconds is read exactly (-00:44:30and-00:45are different instants). - ISO 8601 extended format over the whole string:
<date>T<time>, thenZor±HH:MM[:SS[.fraction]]. Basic format, a space or lower-casetseparator, a lower-casezand an hour-only time or offset return0n, althoughTemporal.Instant.fromreads them. The offsets make this wider thanisValidUtc, which requiresZ. - Rejects leap seconds (
"2016-12-31T23:59:60Z"), which Temporal would silently clamp — in every separator and format variant it accepts,"20161231 235960Z"included. - Returns
bigint, notnumber: nanoseconds since the epoch passedNumber.MAX_SAFE_INTEGERin April 1970, so anumbercannot hold them. - Returns
0non invalid input.0nis also the epoch itself — useisValidInstant, which accepts exactly this grammar, when the two must be told apart. NotisValidUtc: it gates on GMT’s stricter<date>T<time>Zshape and returnsfalsefor the offsets this function accepts, so validating with it discards valid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
isoString | string | ISO 8601 instant string (e.g. “2024-03-10T12:00:00.123456789Z”) |
Returns
Section titled “Returns”nanoseconds since the Unix epoch as a bigint, or 0n on invalid input
Examples
Section titled “Examples”import { toNanoseconds } from "@northguild/gmt/precision/convert";
toNanoseconds("1970-01-01T00:00:00Z") // 0nSource
Section titled “Source”Accessibility
© 2026 NorthGuild · Licences
Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.