/** One second in milliseconds. */ export declare const ONE_SECOND = 1000; /** One minute in milliseconds. */ export declare const ONE_MINUTE: number; /** One hour in milliseconds. */ export declare const ONE_HOUR: number; /** One day in milliseconds. */ export declare const ONE_DAY: number; /** One year in milliseconds. */ export declare const ONE_YEAR: number; /** Duration in milliseconds. */ export type Duration = number & { d: 'Duration in ms'; }; /** Duration in nanoseconds (used by the server-side event format). */ export type ServerDuration = number & { s: 'Duration in ns'; }; /** Unix epoch timestamp in milliseconds. */ export type TimeStamp = number & { t: 'Epoch time'; }; /** * Time relative to the navigation start, in milliseconds. Used for timing events relative to * when the page was loaded (sourced from `performance.now()`). */ export type RelativeTime = number & { r: 'Time relative to navigation start'; } & { d: 'Duration in ms'; }; /** Pair of a relative time and its corresponding absolute timestamp. */ export interface ClocksState { relative: RelativeTime; timeStamp: TimeStamp; } /** * Returns the current time as a Unix timestamp in milliseconds. * * Prefer this over `Date.now()` because some environments incorrectly polyfill `Date.now` — * for example, old versions of `datejs` patched it to return a `Date` instance instead of a * number, which silently breaks arithmetic. `new Date().getTime()` is unaffected by such patches. * * @returns Current Unix timestamp in milliseconds. */ export declare function dateNow(): number; /** * Returns the current time as a {@link TimeStamp}. * * @returns Current Unix timestamp in milliseconds, typed as {@link TimeStamp}. */ export declare function timeStampNow(): TimeStamp; /** * Computes the elapsed duration between two timestamps or relative times. * * @param start - The start time. * @param end - The end time. * @returns The elapsed duration in milliseconds. */ export declare function elapsed(start: TimeStamp, end: TimeStamp): Duration; export declare function elapsed(start: RelativeTime, end: RelativeTime): Duration; /** * Converts a {@link Duration} (milliseconds) to a {@link ServerDuration} (nanoseconds). * * @param duration - The duration in milliseconds to convert. * @returns The duration in nanoseconds, or `undefined` if the input is `undefined`. */ export declare function toServerDuration(duration: Duration): ServerDuration; export declare function toServerDuration(duration: Duration | undefined): ServerDuration | undefined; /** * Adds two numeric time values, preserving the branded type of the result. * * @returns `a + b` typed as `TimeStamp`, `RelativeTime`, or `Duration` depending on the overload. */ export declare function addDuration(a: TimeStamp, b: Duration): TimeStamp; export declare function addDuration(a: RelativeTime, b: Duration): RelativeTime; export declare function addDuration(a: Duration, b: Duration): Duration; /** * Returns the current relative time in milliseconds since navigation start, sourced from * `performance.now()`. In Node.js (≥16), this is relative to the process start time. * * @returns Current relative time as a {@link RelativeTime}. */ export declare function relativeNow(): RelativeTime; /** * Returns the current time as both a relative time and an absolute timestamp. * * @returns A {@link ClocksState} with the current relative and absolute times. */ export declare function clocksNow(): ClocksState; /** * Returns the clocks state at the navigation/process origin (relative = 0). * * @returns A {@link ClocksState} with `relative = 0` and the navigation start timestamp. */ export declare function clocksOrigin(): ClocksState; /** * Converts a relative time to a {@link ClocksState} with a corrected absolute timestamp. * Applies a drift correction when the system clock moved forward relative to `performance.now()`. * * @param relative - The relative time to convert. * @returns A {@link ClocksState} with the relative time and its corrected absolute timestamp. */ export declare function relativeToClocks(relative: RelativeTime): ClocksState; /** * Converts an absolute timestamp to a {@link ClocksState} with its corresponding relative time. * * @param timeStamp - The absolute timestamp to convert. * @returns A {@link ClocksState} with the timestamp and its relative time since navigation start. */ export declare function timeStampToClocks(timeStamp: TimeStamp): ClocksState; /** * Converts an absolute timestamp to a relative time since navigation start. * * @param timestamp - An absolute Unix timestamp. * @returns The corresponding {@link RelativeTime} since navigation start. */ export declare function toRelativeTime(timestamp: TimeStamp): RelativeTime; /** * Converts a relative time since navigation start to an absolute timestamp. * * @param relativeTime - Time in milliseconds since navigation start. * @returns The corresponding absolute {@link TimeStamp}. */ export declare function toTimeStamp(relativeTime: RelativeTime): TimeStamp; /** * Returns `true` if the given value is more likely a relative time than an absolute timestamp. * Heuristic: values smaller than one year are treated as relative. * * @param time - A value that may be either a {@link RelativeTime} or a {@link TimeStamp}. */ export declare function isRelativeTime(time: RelativeTime | TimeStamp): time is RelativeTime; /** * Returns the drift in milliseconds between `Date.now()` and `performance.now()` relative to * navigation start. A positive value means the system clock ran ahead of the performance timer. * * @returns Clock drift in milliseconds. */ export declare function clockDrift(): number; /** * Returns the time origin — the start of the current navigation in browsers, or the process * start time in Node.js. * * Prefers `performance.timing.navigationStart` over `performance.timeOrigin` because * `timeOrigin` can be much farther in the past than the actual navigation start (Firefox 71, * https://bugzilla.mozilla.org/show_bug.cgi?id=1429926) and is not supported in Safari <15. * Falls back to `performance.timeOrigin` in environments without `performance.timing` * (Service Workers, Node.js) * * @returns The time origin as a {@link TimeStamp}. */ export declare function getTimeOrigin(): TimeStamp;