UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

19 lines (18 loc) 1.23 kB
/** * Return the candidate zoned datetime nearest to `target` by temporal distance. * * - Distance is measured in total days using `Temporal.Instant` epoch milliseconds. * - Returns `null` if the candidates array is empty or contains no valid dates. * - Returns `null` if `target` is invalid. * - On a tie (two equidistant candidates), returns the first one in array order. * * @param target ISO ZonedDateTime string to measure distance from * @param candidates Array of ISO ZonedDateTime strings to choose from * @returns The nearest candidate zoned datetime string, or null on invalid input * * @example closestZonedTo("2024-03-15T12:00:00+00:00[UTC]", ["2024-03-01T00:00:00+00:00[UTC]", "2024-03-20T00:00:00+00:00[UTC]", "2024-03-18T00:00:00+00:00[UTC]"]) // "2024-03-18T00:00:00+00:00[UTC]" * @example closestZonedTo("2024-03-15T12:00:00+00:00[UTC]", ["2024-03-01T00:00:00+00:00[UTC]", "2024-03-29T00:00:00+00:00[UTC]"]) // "2024-03-29T00:00:00+00:00[UTC]" * @example closestZonedTo("2024-03-15T12:00:00+00:00[UTC]", []) // null * @example closestZonedTo("invalid", ["2024-03-01T00:00:00+00:00[UTC]"]) // null */ export declare function closestZonedTo(target: string, candidates: string[]): string | null;