parseNanoseconds
Signature
Section titled “Signature”parseNanoseconds(value: string): bigintParse a decimal string produced by formatNanoseconds — typically one field of a JSON payload — back to nanoseconds since the Unix epoch.
- Takes the string value, not JSON text: pass
JSON.parse(payload).observedAt, not the payload itself. A quoted"\"123\""is rejected, because the quotes are not part of a decimal integer. - Accepts only a canonical decimal integer — an optional
-then digits with no leading zeros. Exponents, fractions, hex, separators, a+sign and surrounding whitespace are rejected rather than coerced, so a payload written by another language’s serialiser either reads back exactly or fails loudly. - Rejects values outside the range
Temporal.Instantcan represent (±8_640_000_000_000_000_000_000n). - Returns
0non invalid input.0nis also the epoch itself —isValidNanoPatterntells the two apart, and accepts exactly what this parses.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | decimal string form of a nanosecond timestamp (e.g. “1710072000123456789”) |
Returns
Section titled “Returns”nanoseconds since the Unix epoch as a bigint, or 0n on invalid input
Examples
Section titled “Examples”import { parseNanoseconds } from "@northguild/gmt/precision/parse";
parseNanoseconds("1710072000123456789") // 1710072000123456789n