Skip to content

endOfDate

endOfDate(value: string, unit: SmallestUnit<DateUnit>, optionsArg?: { weekStartsOn?: "monday" | "sunday"; }): string

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.
ParameterTypeDescription
valuestringISO 8601 date string
unitSmallestUnit<DateUnit>date unit, singular or plural, to specify the unit for the end

optionsArg

How the week is defined

OptionTypeDefaultDescription
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.

ISO 8601 string representing the end of the specified unit, or "" on invalid input

import { endOfDate } from "@northguild/gmt/plain/calculate";
endOfDate("2024-02-29", "month") // "2024-02-29"
output 

plain/calculate/endOfDate.ts