formatDateTimeRange
Signature
Section titled “Signature”formatDateTimeRange(start: string, end: string, locale?: string | string[], options?: DateTimeFormatOptions): stringFormat a plain datetime range using the Temporal Intl.DateTimeFormat formatRange API.
- Plain counterpart of
formatZonedRange— same parameter order and option shape. - Uses Temporal.PlainDateTime.from for both endpoints; no timezone is involved.
- Formats as Temporal’s ECMA-402 PlainDateTime format does, through the runtime’s
Intl.DateTimeFormat#formatRange: the requested fields and style widths are kept,eraalone still gets the date and time defaults, andtimeZoneNameis ignored. - Compatibility: before 1.16.0 some locales lost a requested width (zh-CN with
{ year: "numeric", month: "long" }gave"2024/2"),eraalone dropped the time, andtimeZoneNamealone returned"". Pass the fields the old text showed to keep it. - Locale elides shared fields between
startandend(e.g. same day/month/year). - Returns "" for invalid input on either endpoint.
- Output is normalized: dash separators become ASCII ”-” (unspaced between digits, spaced otherwise), and no-break, narrow and thin spaces become U+0020.
optionsnull returns"", as ECMA-402’s CoerceOptionsToObject rejects it. Any other non-object — a string, a number, a boolean — formats with the defaults, asIntl.DateTimeFormatdoes: CoerceOptionsToObject calls ToObject on it and the wrapper carries no recognised option. Onlynullandundefinedare special-cased.- A
chineseordangidate follows the observatory the standard names: Purple Mountain Observatory forchinese, KASI fordangi. A runtime that prints a different date for one of them returns""for any format with a year, month, day or era in that calendar. A runtime that prints the observatory’s date keeps its own text. A format with only a time or weekday field always returns its text.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start | string | ISO PlainDateTime string (range start) |
end | string | ISO PlainDateTime string (range end) |
locale | string | string[] | optional locale tag (default: runtime default), or a preference list of tags (ECMA-402) |
Options
Section titled “Options”options
optional Intl.DateTimeFormatOptions
Type: DateTimeFormatOptions.
| Option | Type | Default | Description |
|---|---|---|---|
…Intl.DateTimeFormatOptions | — | — | Every field of DateTimeFormatOptions, as ECMA-402 defines it. |
Returns
Section titled “Returns”localized range string or "" when invalid
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatDateTimeRange } from "@northguild/gmt/plain/format";
formatDateTimeRange("2024-02-03T09:00:00", "2024-02-03T17:00:00", "en-GB", { dateStyle: "long", timeStyle: "short" }) // "3 February 2024, 09:00-17:00"Source
Section titled “Source”Accessibility
© 2026 NorthGuild · Licences
Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.