endOfDate
Signature
Section titled “Signature”endOfDate(value: string, unit: SmallestUnit<DateUnit>, optionsArg?: { weekStartsOn?: "monday" | "sunday"; }): stringReturn 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). unitaccepts the singular or plural name ("month"or"months"), as Temporal does.- Returns "" for invalid inputs.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO 8601 date string |
unit | SmallestUnit<DateUnit> | date unit, singular or plural, to specify the unit for the end |
Options
Section titled “Options”optionsArg
How the week is defined
| Option | Type | Default | Description |
|---|---|---|---|
weekStartsOn? | "monday" | "sunday" | "monday" | 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. |
Returns
Section titled “Returns”ISO 8601 string representing the end of the specified unit, or "" on invalid input
Examples
Section titled “Examples”import { endOfDate } from "@northguild/gmt/plain/calculate";
endOfDate("2024-02-29", "month") // "2024-02-29"