fromNtpTimestamp
Signature
Section titled “Signature”fromNtpTimestamp(value: bigint, eraArg?: number): stringConvert a 64-bit NTP timestamp (RFC 5905) back to an ISO 8601 instant string.
valueis unsigned: the whole 64-bit timestamp, seconds since 1900-01-01 in the high 32 bits and 2^-32 s units in the low 32. Values outside0n–2^64 − 1are rejected.erais required information the value does not carry. The seconds field wraps every 2^32 seconds (~136.19 years), so one timestamp names one instant per era: era 0 is 1900-01-01 to 2036-02-07T06:28:15Z, era 1 starts at 2036-02-07T06:28:16Z, era -1 starts at 1763-11-24T17:31:44Z. It defaults to 0;undefinedis the same as omitting it, as TC39 treats an undefined argument as absent.- Rounds to the nearest nanosecond. One NTP unit is ~233 ps, finer than an ISO string can express, so rounding — not truncation — is what makes
fromNtpTimestamp(toNtpTimestamp(iso))returnisoexactly rather than one nanosecond early. - The top two values of an era round onto the next era’s first instant.
2^64 − 1and2^64 − 2in era 0 both render as"2036-02-07T06:28:16Z", which is where era 1 starts: the last 0.47 ns of an era has no nanosecond of its own, and the nearest one is the era boundary.toNtpTimestampcannot produce either value from a nanosecond-precision instant — its largest era-0 output is18446744073709551611n— so this does not affect the round trip. 0nis two things on the wire. RFC 5905 §6 defines the prime epoch as the instant “when all bits are zero”, and also says “a value of zero is a special case representing unknown or unsynchronized time” — for example a reference timestamp sent before the first sync. This function decodes0nas the era’s first instant; a caller reading packet fields should test for0nfirst when “unsynchronized” must not become a 1900 date.- Returns "" when the resulting instant is outside the range
Temporal.Instantcan represent, which a largeerawill reach. - Returns "" on invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | bigint | 64-bit NTP timestamp (bigint, 0n to 2^64 − 1) |
eraArg | number | optional 136-year era selector; omitted or undefined is era 0 |
Returns
Section titled “Returns”ISO 8601 instant string (UTC), or "" on invalid input
Examples
Section titled “Examples”import { fromNtpTimestamp } from "@northguild/gmt/precision/convert";
fromNtpTimestamp(0n) // "1900-01-01T00:00:00Z" — the NTP epoch, and also RFC 5905's unknown or unsynchronized marker