# convertPlainDateTimeToZoned

Industry: Core

## Signature

```ts
convertPlainDateTimeToZoned(value: string, timeZone: string, optionsArg?: { smallestUnit?: PluralizeUnit<"minute" | "second" | "millisecond" | "microsecond" | "nanosecond"> | undefined; disambiguation?: "compatible" | "earlier" | "later" | "reject" | undefined; }): string
```

Attach 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 `offset` option (removed in 1.16.0): Temporal `PlainDateTime#toZonedDateTime` reads only `disambiguation`, and a plain datetime has no UTC offset for `offset` to act on.
- **Output is cut to milliseconds by default**, so microseconds and nanoseconds in `value` are 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 call `resolveLocal` for the instant the wall time names at that offset.

## 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

**optionsArg**

optional settings for the precision of the output string and for resolving a DST gap or overlap

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `smallestUnit?` | `PluralizeUnit<"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`](/gmt/reference/types/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

zoned ISO 8601 datetime string or "" when invalid

## Related types

- [`Disambiguation`](/gmt/reference/types/Disambiguation/)

## Examples

```ts
import { convertPlainDateTimeToZoned } from "@northguild/gmt/zoned/convert";

convertPlainDateTimeToZoned("2024-02-29T14:30:45", "Asia/Tokyo") // "2024-02-29T14:30:45.000+09:00[Asia/Tokyo]"
```

## Source

[zoned/convert/convertPlainDateTimeToZoned.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/zoned/convert/convertPlainDateTimeToZoned.ts)
