@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.
30 lines • 1.5 kB
TypeScript
import { Temporal } from "../../internal/temporal.js";
/**
* Return the end of the specified date `unit` for a given ISO 8601 date string.
*
* - The end is computed forward from `value`, so it is returned even when the unit began before
* the first representable date (`-271821-04-19`).
* - `unit` accepts the singular or plural name (`"month"` or `"months"`), as Temporal does.
* - Returns "" for invalid inputs.
*
* @param value ISO 8601 date string
* @param unit date unit, singular or plural, to specify the unit for the end
* @param optionsArg How the week is defined
* @returns ISO 8601 string representing the end of the specified unit, or "" on invalid input
*
* @example endOfDate("2024-02-29", "month") // "2024-02-29"
* @example endOfDate("2024-03-03", "week", { weekStartsOn: "sunday" }) // "2024-03-09"
* @example endOfDate("-271821-04-19", "month") // "-271821-04-30" (the month began before the range; its end did not)
* @example endOfDate("2024-02-29", "years") // "2024-12-31"
* @example endOfDate("invalid-date", "month") // ""
*/
export declare function endOfDate(value: string, unit: Temporal.SmallestUnit<Temporal.DateUnit>, optionsArg?: {
/**
* The first day of the week, which sets where a `"week"` unit starts. `"monday"` is the ISO
* 8601 week, Monday to Sunday; `"sunday"` runs Sunday to Saturday. Any other value returns
* `""`, whatever the unit.
*
* @defaultValue `"monday"`
*/
weekStartsOn?: "monday" | "sunday";
}): string;