formatX12TimeElement
Signature
Section titled “Signature”formatX12TimeElement(value: string, form: X12TimeElementForm): stringWrite an ISO 8601 time as an X12 data element 337 (Time) value, in the form the caller names by the element’s own mask. parseX12Time reads the result back when it is given no qualifier.
-
Element 337 is the time element of many X12 segments: in freight,
AT7-06,G62-04andDTM-03. No format qualifier travels with it, so nothing in the segment says which of its four forms a value is in. The definition is release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### FormsForm Digits The dictionary’s definition HHMM4 “H = hours (00-23), M = minutes (00-59)” HHMMSS6 “S = integer seconds (00-59)” HHMMSSD7 “D = tenths (0-9)” HHMMSSDD8 “DD = hundredths (00-99)” -
valueis a time, asisValidTimeaccepts 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"". -
The form alone fixes the digits written. It is never read off the value, so the width of the field does not depend on the data: a time with no fraction is
14300000underHHMMSSDD, and a time with one is1430underHHMM. -
Precision is cut to the mask, never rounded.
Dis the whole tenths of the second andDDits whole hundredths, so14:30:45.999is1430459underHHMMSSDand14304599underHHMMSSDD. A written value never names a later second than its input. -
The form is a mask, not a data element 1250 code.
TMandTSreturn""here. To write a time that travels with a 1250 qualifier (DTP-03,DTM-06), useformatX12Time. -
Returns
""for any other form and for a non-string argument.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO 8601 time (e.g. “14:30:00.12”) |
form | X12TimeElementForm | The element 337 mask to write: HHMM, HHMMSS, HHMMSSD or HHMMSSDD |
Returns
Section titled “Returns”the X12 time value, or "" on invalid input
X12TimeElementForm
Section titled “X12TimeElementForm”The four forms of X12 data element 337 (Time), each named by the element’s own mask. Release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. The dictionary’s definition: “Time expressed in 24-hour clock time as follows: HHMM, or HHMMSS, or HHMMSSD, or HHMMSSDD, where H = hours (00-23), M = minutes (00-59), S = integer seconds (00-59) and DD = decimal seconds; decimal seconds are expressed as follows: D = tenths (0-9) and DD = hundredths (00-99)”.
import type { X12TimeElementForm } from "@northguild/gmt";"HHMM" | "HHMMSS" | "HHMMSSD" | "HHMMSSDD"Examples
Section titled “Examples”import { formatX12TimeElement } from "@northguild/gmt/intermodal/format";
formatX12TimeElement("14:30:00.12", "HHMMSSDD") // "14300012"