# formatX12Time

Industry: Intermodal

## Signature

```ts
formatX12Time(value: string, format: X12TimeFormat): string
```

Write an ISO 8601 time as an X12 time in a time format qualifier (data element 1250). The result is also a data element 337 (Time) value: `parseX12Time` reads it back with the same qualifier, and with none.

- Codes are release 005010, read from [Stedi's X12-licensed dictionary](https://www.stedi.com/edi/x12-005010/element/1250); the X12 text itself was not reached. ### Format codes

  | Code | Mask | The dictionary's definition |
  |---|---|---|
  | `TM` | `HHMM` | "Time Expressed in Format HHMM" |
  | `TS` | `HHMMSS` | "Time Expressed in Format HHMMSS" |

- `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 `TM` drops the seconds too. `14:30:45.123` is `1430` under `TM` and `143045` under `TS`.
- **To write the time element of a freight segment** (`AT7-06`, `G62-04`, `DTM-03`), use `formatX12TimeElement`: it writes all four forms of data element 337, named by the element's own masks, tenths and hundredths of a second included. `TM` and `TS` give the same digits as that element's `HHMM` and `HHMMSS` forms, and no 1250 code holds decimal seconds.
- `TS` here is the format `HHMMSS`. As a data element 623 time code, `TS` is Atlantic Standard Time: read that with `x12TimeCodeZone`.
- 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` | `X12TimeFormat` | X12 data element 1250 format qualifier |

## Returns

the X12 time value, or "" on invalid input

## Related types

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

## Examples

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

formatX12Time("14:30:00", "TM") // "1430"
```

## Source

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