endOfDateTime
Signature
Section titled “Signature”endOfDateTime(value: string, unit: SmallestUnit<DateTimeUnit>, optionsArg?: { weekStartsOn?: "monday" | "sunday"; fractionalSecondDigits?: FractionalDigit; }): stringReturn the end of the specified date-time unit for a given ISO 8601 datetime 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.
- Compatibility: before 1.16.0 the default printed only the digits the unit names — none for
secondand coarser, 3 formillisecond, 6 formicrosecond— which wrote a moment earlier than the end. Pass thatfractionalSecondDigitsto keep the previous string.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO 8601 datetime string |
unit | SmallestUnit<DateTimeUnit> | date or time unit, singular or plural, to specify the unit for the end |
Options
Section titled “Options”optionsArg
How the week is defined and how the result is written
| 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. |
fractionalSecondDigits? | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | "auto" | 8 | 9 (FractionalDigit) | 9 | The number of fractional-second digits the result is written with, 0 to 9, or "auto" to drop trailing zeros. Fewer than 9 digits truncate the string, as Temporal’s toString does, so it names a moment before the end. |
Returns
Section titled “Returns”ISO 8601 string representing the end of the specified unit, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { endOfDateTime } from "@northguild/gmt/plain/calculate";
endOfDateTime("2024-02-29T12:34:56", "month") // "2024-02-29T23:59:59.999999999"