# formatEdifactOffsetDateTime

Industry: Intermodal

## Signature

```ts
formatEdifactOffsetDateTime(value: string, format: EdifactOffsetDateTimeFormat): string
```

Write an ISO 8601 date-time with an offset as a UN/EDIFACT `DTM` value (data element 2380) in a format code that carries an offset (data element 2379). The inverse of `parseEdifactOffsetDateTime`.

- Masks and descriptions are the UNTDID directory's, read from [UNECE's D.21B page as archived](http://web.archive.org/web/20240303123657/https://service.unece.org/trade/untdid/d21b/tred/tred2379.htm). ### Format codes

  | Code | Mask | The directory's description |
  |---|---|---|
  | `205` | `CCYYMMDDHHMMZHHMM` | "Calendar date including time and time zone expressed in hours and minutes." |
  | `208` | `CCYYMMDDHHMMSSZHHMM` | "Calendar date including time with seconds, with Time Zone" (D.12A and later) |
  | `303` | `CCYYMMDDHHMMZZZ` | "See 203 plus Z=Time zone." |
  | `304` | `CCYYMMDDHHMMSSZZZ` | "See 204 plus Z=Time zone." |

- `value` is an ISO 8601 date-time with an offset (`2024-06-15T14:30:00+02:00`) or a `Z` instant, as `toOffsetInstant` reads it: the string `parseEdifactOffsetDateTime` returns and `fromOffsetInstant` writes. A local date-time, a date and a time return `""`: there is no offset to write.
- **The digits are the value's own wall clock**, never the UTC clock: `2024-01-01T00:30:00+02:00` under `303` is `202401010030+02`. A `Z` instant is written on the UTC clock with `+0000` or `+00`.
- **`ZZZ` (`303`, `304`) is always written `±HH`**, the hours-only form of UN/ECE Recommendation 7 ¶12, never `UTC` or `GMT`. **It holds whole hours only**: an offset such as `+05:30` returns `""` under `303` and `304`. Write it under `205` or `208`, whose `ZHHMM` holds hours and minutes.
- **An offset with a non-zero seconds part returns `""` under every code**, `205` and `208` included. A seconds part of zero (`+02:00:00`) is the offset `+02:00` and is written. `ZHHMM` holds hours and minutes and `ZZZ` hours, so no mask holds the seconds of an offset such as `-00:44:30`, the offset `Africa/Monrovia` kept until 1972. An offset is never rounded: the value would name another instant. Write the same instant in `Z` form instead.
- Precision is cut to the mask, never rounded: a fraction of a second is always dropped, and `205` and `303` drop the seconds too.
- **The output is the element value, not segment text.** `+` is the EDIFACT data element separator, so a value that holds one must be released when it is placed in a segment: write `?+`. The function does not add the release character.
- The value is an instant string: `Z` or an offset, and nothing after it. A zone bracket (`[Europe/Berlin]`) or any other annotation returns `""`; this function writes the offset it is given and takes no zone, so a zoned string is a different kind.
- A wall clock whose year is outside 0000–9999 returns `""`.
- Returns `""` for any other code, a code of another kind included, and for a non-string argument.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | ISO 8601 date-time with an offset or `Z` (e.g. "2024-06-15T14:30:00+02:00") |
| `format` | `EdifactOffsetDateTimeFormat` | The data element 2379 format code |

## Returns

the data element 2380 value, unescaped, or "" on invalid input

## Related types

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

## Examples

```ts
import { formatEdifactOffsetDateTime } from "@northguild/gmt/intermodal/format";

formatEdifactOffsetDateTime("2024-06-15T14:30:00+02:00", "205") // "202406151430+0200"
```

## Source

[intermodal/format/formatEdifactOffsetDateTime.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/intermodal/format/formatEdifactOffsetDateTime.ts)
