@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.
37 lines • 2.02 kB
TypeScript
/**
* An ISO 8601 duration as exact elapsed nanoseconds, signed, or `null` when it is not one.
*
* The transport rule for a span of exact time (`transitTime`, `classifyPunctuality`,
* `nextDeparture`, …):
*
* - Hours, minutes, seconds and fractions are elapsed time, and a day is 24 hours exactly. That
* is how TC39 Temporal's `Duration.prototype.round` and `total` read a day when no
* `relativeTo` is given.
* - Years, months and weeks return `null`: `round` and `total` require a `relativeTo` for them,
* so they have no exact length on their own. A zero calendar component (`P0Y1D`) changes
* nothing. (`Temporal.Instant#add` accepts no date unit at all, days included; callers add the
* nanoseconds this returns instead.)
* - The result keeps the duration's sign, so a caller that needs a non-negative amount checks
* `< 0n` itself. `-PT0S` is `0n`.
* - Summed in bigint, so it stays exact past 2^53 ns and across the whole instant range.
*
* @param value candidate ISO 8601 duration string
* @returns the duration in nanoseconds, negative for a negative duration, or null on invalid input
*
* @example exactDurationNanoseconds("PT1H") // 3600000000000n
* @example exactDurationNanoseconds("-PT5M") // -300000000000n
* @example exactDurationNanoseconds("P1D") // 86400000000000n
* @example exactDurationNanoseconds("P1W") // null
*/
export declare function exactDurationNanoseconds(value: unknown): bigint | null;
/**
* `exactDurationNanoseconds` for an amount that may not be negative — a tolerance, a minimum
* connection — or `null`. Zero is allowed, and `-PT0S` is zero.
*
* @param value candidate ISO 8601 duration string
* @returns the duration in nanoseconds, zero or more, or null on invalid input or a negative duration
*
* @example nonNegativeExactDurationNanoseconds("PT15M") // 900000000000n
* @example nonNegativeExactDurationNanoseconds("-PT15M") // null
*/
export declare function nonNegativeExactDurationNanoseconds(value: unknown): bigint | null;