UNPKG

@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.

34 lines (33 loc) • 1.57 kB
// src/internal/epochNanoseconds.ts /** * Smallest epoch-nanosecond value `Temporal.Instant` can represent: * -10^8 days from the Unix epoch, i.e. `-271821-04-20T00:00:00Z`. */ const MIN_EPOCH_NANOSECONDS = -8640000000000000000000n; /** * Largest epoch-nanosecond value `Temporal.Instant` can represent: * +10^8 days from the Unix epoch, i.e. `+275760-09-13T00:00:00Z`. */ const MAX_EPOCH_NANOSECONDS = 8640000000000000000000n; /** TC39 `CheckISODaysRange`: a date may sit at most 10^8 days from the Unix epoch. */ const MAX_ISO_EPOCH_DAYS = 1e8; /** * Digits in `MAX_EPOCH_NANOSECONDS` (22) — the longest a decimal form of an in-range * epoch-nanosecond value can be, sign excluded. */ const MAX_EPOCH_NANOSECOND_DIGITS = MAX_EPOCH_NANOSECONDS.toString().length; /** * Type guard for an epoch-nanosecond value the `precision/` namespace accepts: a `bigint` * inside the range `Temporal.Instant` can represent. * * Every `precision/` function gates on this, so anything one of them accepts is renderable * by `fromNanoseconds` — a value outside the range has no instant to convert back to. * * @example isValidEpochNanoseconds(0n) // true * @example isValidEpochNanoseconds(8_640_000_000_000_000_000_001n) // false * @example isValidEpochNanoseconds(0) // false — number, not bigint */ function isValidEpochNanoseconds(value) { return typeof value === "bigint" && value >= -8640000000000000000000n && value <= 8640000000000000000000n; } export { MAX_EPOCH_NANOSECONDS, MAX_EPOCH_NANOSECOND_DIGITS, MAX_ISO_EPOCH_DAYS, MIN_EPOCH_NANOSECONDS, isValidEpochNanoseconds };