endOfZoned
Signature
Section titled “Signature”endOfZoned(value: string, unit: SmallestUnit<DateTimeUnit>, optionsArg?: { weekStartsOn?: "monday" | "sunday"; fractionalSecondDigits?: FractionalDigit; }): stringReturn the end of the specified date-time unit for a given zoned ISO 8601 datetime string.
- Supports: “year”, “month”, “week”, “day”, “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”, each also in its plural form (
"days"), as Temporal accepts. - Returns the last instant of the real local
unitcontainingvaluein its own zone — one nanosecond before the next bucketfloorToZonewould return — so the result is never beforevalue. The second pass of New York’s repeated fall-back hour ends at 01:59:59.999999999 −05:00, andAustralia/Lord_Howe’s 90-minute fall-back hour ends in its new offset. - A transition that reopens the previous local date makes that stretch its own bucket:
America/Goose_Bay’s 00:01 fall-back on 7 November 2010 re-entered 6 November for 59 minutes, so the day holding2010-11-06T23:30:00-04:00ends at 23:59:59.999999999 −04:00. - A midnight repeated on the same date stays one day:
America/Havana’s 25-hour 2024-11-03 ends at 23:59:59.999999999 −05:00 from either pass of its repeated first hour. - Takes no
disambiguationoroffset: a boundary is always a real instant, as TC39’sstartOfDay()takes neither. Those ignored options were removed in 1.16.0. - The end is written at nanosecond precision by default, so the string names the end itself.
- Returns "" for invalid input.
- 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 | zoned 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
optional settings for the week’s first day and the precision of the output string
| 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”zoned 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 { endOfZoned } from "@northguild/gmt/zoned/calculate";
endOfZoned("2024-02-29T12:34:56+00:00[UTC]", "month") // "2024-02-29T23:59:59.999999999+00:00[UTC]"