@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
20 lines (18 loc) • 775 B
JavaScript
import { Temporal } from "./temporal.js";
// src/internal/instantStringFromEpochNanoseconds.ts
/**
* The core of every reader that turns an epoch-nanosecond count into a UTC instant string
* (`fromNanoseconds` without a zone, the identifier and foreign-epoch readers). Returns "" for
* `null`, for a value that is not a `bigint` (the polyfill would coerce a number or a string,
* so the type is checked first) and for a count outside the range `Temporal.Instant` holds
* (`fromEpochNanoseconds` throws there).
*/
function instantStringFromEpochNanoseconds(nanoseconds) {
if (typeof nanoseconds !== "bigint") return "";
try {
return Temporal.Instant.fromEpochNanoseconds(nanoseconds).toString();
} catch {
return "";
}
}
export { instantStringFromEpochNanoseconds };