convertPlainDateTimeToZoned
Signature
Section titled “Signature”convertPlainDateTimeToZoned(value: string, timeZone: string, optionsArg?: { smallestUnit?: SmallestUnit<"minute" | "second" | "millisecond" | "microsecond" | "nanosecond"> | undefined; disambiguation?: "compatible" | "earlier" | "later" | "reject" | undefined; }): stringAttach the specified timeZone to a plain datetime string and return a zoned ISO 8601 datetime string.
- Combines plain datetime with timezone to create ZonedDateTime.
- There is no
offsetoption (removed in 1.16.0): TemporalPlainDateTime#toZonedDateTimereads onlydisambiguation, and a plain datetime has no UTC offset foroffsetto act on. - Output is cut to milliseconds by default, so microseconds and nanoseconds in
valueare dropped. Pass{ smallestUnit: "nanoseconds" }to keep every digit. - Returns "" for invalid input.
- An offset with seconds (
-00:44:30) returns"". A written zone cannot carry seconds (RFC 9557 §4.1), so the result could not name it. Pass the IANA name, or callresolveLocalfor the instant the wall time names at that offset.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | plain datetime string (e.g. “2024-02-29T14:30:45”) |
timeZone | string | IANA name or a UTC offset to the minute (what isValidTimeZone accepts) |
Options
Section titled “Options”optionsArg
optional settings for the precision of the output string and for resolving a DST gap or overlap
| Option | Type | Default | Description |
|---|---|---|---|
smallestUnit? | SmallestUnit<"minute" | "second" | "millisecond" | "microsecond" | "nanosecond"> | "milliseconds" | The smallest unit written in the output string, from "minute" to "nanosecond", singular or plural. Anything smaller is truncated, as Temporal’s toString does with its "trunc" rounding mode. |
disambiguation? | "compatible" | "earlier" | "later" | "reject" (Disambiguation) | "compatible", Temporal’s default. | How value resolves when its wall-clock time falls in a DST gap or overlap in timeZone. In a fall-back overlap "compatible" and "earlier" take the earlier instant and "later" the later one; in a spring-forward gap "compatible" and "later" move the wall clock forward by the gap length and "earlier" back by it. "reject" returns "" for both. |
Returns
Section titled “Returns”zoned ISO 8601 datetime string or "" when invalid
Related types
Section titled “Related types”Examples
Section titled “Examples”import { convertPlainDateTimeToZoned } from "@northguild/gmt/zoned/convert";
convertPlainDateTimeToZoned("2024-02-29T14:30:45", "America/New_York") // "2024-02-29T14:30:45.000-05:00[America/New_York]"