@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.
92 lines • 4.34 kB
TypeScript
import { GnssSystem, GnssWeek, GnssWeekCounter } from "../types/gnss.js";
/** The scale a week counter counts on, and after how many weeks it wraps. */
export interface GnssWeekCounterSpec {
/** The satellite time scale whose epoch is week 0 of era 0. */
readonly system: GnssSystem;
/** The number of week values the counter can show: it wraps to 0 after `modulus − 1`. */
readonly modulus: bigint;
}
/**
* The broadcast week counters, each with exactly one width. GLONASS broadcasts no week number,
* so it has none.
*/
export declare const GNSS_WEEK_COUNTERS: Readonly<Record<GnssWeekCounter, GnssWeekCounterSpec>>;
/**
* Whether a value names one of the eight broadcast week counters.
*
* @param value candidate counter
* @returns true for a `GnssWeekCounter` member
*/
export declare function isGnssWeekCounter(value: unknown): value is GnssWeekCounter;
/**
* A week number as a bigint: any safe integer from 0. The caller checks a counter's modulus.
*
* @param week candidate week number
* @returns the week, or null when it is not a safe integer ≥ 0
*/
export declare function weekNumber(week: unknown): bigint | null;
/**
* Seconds of week as nanoseconds, rounded to the nearest nanosecond (TC39 Temporal's resolution;
* a GMT rule). Valid from 0 up to but not including one week, 604 800 s (IS-GPS-200N §3.3.4).
*
* @param timeOfWeekSeconds candidate seconds of week
* @returns the time of week in nanoseconds, or null when it is not a finite number in range or
* rounds to a whole week
*/
export declare function timeOfWeekNanoseconds(timeOfWeekSeconds: unknown): bigint | null;
/**
* The label `fullWeek` weeks and `timeOfWeek` nanoseconds after an epoch label.
*
* @param epochLabel week 0's first label, label nanoseconds
* @param fullWeek weeks since the epoch, never wrapped
* @param timeOfWeek nanoseconds into that week
* @returns the label, label nanoseconds
*/
export declare function labelOfFullWeek(epochLabel: bigint, fullWeek: bigint, timeOfWeek: bigint): bigint;
/**
* Split a label into whole weeks since an epoch label and seconds into the week. The seconds are
* a `number`: the nearest double to the exact nanosecond count.
*
* @param epochLabel week 0's first label, label nanoseconds
* @param labelNanoseconds the label to split
* @returns the full week and seconds of week, or null before the epoch
*/
export declare function weeksSince(epochLabel: bigint, labelNanoseconds: bigint): {
fullWeek: bigint;
timeOfWeekSeconds: number;
} | null;
/**
* The era a week number belongs to.
*
* - An integer from 0 is the era itself.
* - `"rolling"` reads `nowInstant()` once and picks the era within half a counter
* period of the current week, clamped at era 0. Call it inside `try`: the clock read can throw.
* - `{ notBefore }` reads `notBefore` once and picks the earliest occurrence at or after it, so a
* pivot before the counter's epoch gives era 0; other keys are ignored. It never reads the clock.
*
* @param counter the week counter
* @param week the week number the counter shows
* @param timeOfWeek nanoseconds into the week
* @param rolloverEra an integer era from 0, "rolling", or `{ notBefore }`
* @returns the era, or null for any other value, when the clock reads before the counter's epoch,
* or for a pivot that is not an instant string or is an unlisted second 60
*/
export declare function resolveRolloverEra(counter: GnssWeekCounter, week: bigint, timeOfWeek: bigint, rolloverEra: unknown): bigint | null;
/**
* The label of a week time on a counter: epoch + (era × modulus + week) weeks + time of week.
*
* @param counter the week counter
* @param week the week number the counter shows
* @param timeOfWeek nanoseconds into the week
* @param era how many times the counter has wrapped
* @returns the label on the counter's scale, label nanoseconds
*/
export declare function labelOfWeek(counter: GnssWeekCounter, week: bigint, timeOfWeek: bigint, era: bigint): bigint;
/**
* The week, time of week and era of a label on a counter's scale.
*
* @param counter the week counter
* @param labelNanoseconds a label on the counter's scale
* @returns a new `GnssWeek`, or null before the counter's epoch
*/
export declare function weekOfLabel(counter: GnssWeekCounter, labelNanoseconds: bigint): GnssWeek | null;