# formatEdifactTime

Industry: Intermodal

## Signature

```ts
formatEdifactTime(value: string, format: EdifactTimeFormat): string
```

Write an ISO 8601 time as a UN/EDIFACT `DTM` value (data element 2380) in a time format code (data element 2379). The inverse of `parseEdifactTime`.

- 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 |
  |---|---|---|
  | `401` | `HHMM` | "Time without seconds: H = Hour; m = Minute." |
  | `402` | `HHMMSS` | "Time with seconds: H = Hour; m = Minute; s = Seconds." |

- `value` is a time, as `isValidTime` accepts it: `HH:MM`, with seconds and a fraction of a second if it has them. A date-time, a date or a time with an offset returns `""`.
- Precision is cut to the mask, never rounded: a fraction of a second is always dropped, and `401` drops the seconds too. `14:30:59.9` is `1430` under `401` and `143059` under `402`, and `parseEdifactTime` reads back the time the mask holds.
- 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 time (e.g. "14:30:00") |
| `format` | `EdifactTimeFormat` | The data element 2379 format code |

## Returns

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

## Related types

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

## Examples

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

formatEdifactTime("14:30:00", "401") // "1430"
```

## Source

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