UNPKG

@burglekitt/gmt

Version:

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

22 lines (21 loc) 1.07 kB
import { Temporal } from "@js-temporal/polyfill"; import { startOrEndOfUtc } from "./startOrEndOfUtc.js"; /** * Return the end of the specified date-time `unit` for a given UTC datetime string. * * - Converts to ZonedDateTime, sets to end of unit, converts back to Instant. * - Supports: "year", "month", "week", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond". * - Returns "" for invalid input. * * @param value ISO UTC datetime string * @param unit Temporal.DateUnit | Temporal.TimeUnit to specify the end * @param options optional: weekStartsOn ("monday" | "sunday"), fractionalSecondDigits (number) * @returns UTC Instant string representing the end of the unit, or "" on invalid input * * @example endOfUtc("2024-03-15T14:30:45Z", "year") // "2024-12-31T23:59:59.999999999Z" * @example endOfUtc("2024-03-15T14:30:45Z", "month") // "2024-03-31T23:59:59.999999999Z" * @example endOfUtc("invalid", "year") // "" */ export function endOfUtc(value, unit, options) { return startOrEndOfUtc(value, unit, options ?? {}, true); }