Skip to content

fromPgMicroseconds

fromPgMicroseconds(value: bigint): string

Convert PostgreSQL’s internal timestamptz value back to an ISO 8601 instant string.

  • value is a signed count of microseconds since 2000-01-01T00:00:00Z, the number PostgreSQL stores and the binary wire format carries. It is not a Unix timestamp.
  • Accepted range is the narrower of PostgreSQL’s and Temporal.Instant’s, one binding at each end: -211813488000000000n (MIN_TIMESTAMP, -004713-11-24T00:00:00Z — the manual’s “4713 BC”, counted in the Julian calendar) up to 8639053315200000000n (+275760-09-13, where Temporal stops, well before PostgreSQL’s 294276 AD). Anything outside returns "".
  • Exact in this direction — a microsecond is coarser than the nanoseconds an ISO string carries, so nothing is rounded. The loss, if any, happened in toPgMicroseconds.
  • Returns "" on invalid input.
ParameterTypeDescription
valuebigintmicroseconds since 2000-01-01 (bigint)

ISO 8601 instant string (UTC), or "" on invalid input

import { fromPgMicroseconds } from "@northguild/gmt/precision/convert";
fromPgMicroseconds(0n) // "2000-01-01T00:00:00Z" — the PostgreSQL epoch
output 

precision/convert/fromPgMicroseconds.ts