parseX12Time
Signature
Section titled “Signature”parseX12Time(value: string, format?: X12TimeFormat): stringParse an X12 time as an ISO 8601 time: a data element 337 value with no qualifier, or a time that arrives with a data element 1250 format qualifier.
-
X12 sends a time two ways, and
formatsays which the caller holds: -
With no qualifier: the time element of a freight segment (
AT7-06,G62-04,DTM-03) is data element 337, which fixes its own four forms. Omitformat. -
With a qualifier: a
DTPsegment (DTP-02andDTP-03), andDTM-05andDTM-06, send a data element 1250 format qualifier beside the value. Pass it asformat, and the value is read against that qualifier’s mask alone. Definitions are release 005010, read from Stedi’s X12-licensed dictionary (337, 1250); the X12 text itself was not reached. ### FormsformatDigits Mask The dictionary’s definition omitted 4, 6, 7 or 8 HHMM,HHMMSS,HHMMSSD,HHMMSSDDElement 337: “H = hours (00-23), M = minutes (00-59), S = integer seconds (00-59) … D = tenths (0-9) and DD = hundredths (00-99)” TM4 HHMM“Time Expressed in Format HHMM” TS6 HHMMSS“Time Expressed in Format HHMMSS” -
A qualifier is strict.
"143045"is aTSvalue and returns""underTM, and no 1250 code holds decimal seconds, so a 7- or 8-digit value returns""under either qualifier. The same values read whenformatis omitted. -
A
formatthat is present and is notTMorTSreturns"", never the unqualified read: a code of another kind (D8), a code that is not read (RTM,TT), an empty string and a non-string. Only an omitted orundefinedformat means “no qualifier”. -
Seconds are always written in the result,
00forHHMM. -
With no qualifier, tenths and hundredths become the fraction of the second exactly:
1430001is14:30:00.1and14300012is14:30:00.12. A zero fraction is not written (14300000is14:30:00). -
To write the value back, use
formatX12TimeElementfor an element 337 time and name the form by its mask:formatX12TimeElement("14:30:00.12", "HHMMSSDD")is14300012. UseformatX12Timefor a time that travels with aTMorTSqualifier. -
Fields are checked, not clamped: hour 24, minute 60, second 60 and a value of 5 or 9 digits return
"". -
The time is local to a place the value does not name. In a freight segment the time code beside it (data element 623) says where the clock was: classify it with
classifyX12TimeCode. To read the date and time elements together, useparseX12DateAndTime. -
A range of times (
RTM,HHMM-HHMM) is not read. -
Returns
""for a non-string value.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | The time as transmitted (e.g. “1430”) |
format | X12TimeFormat | X12 data element 1250 format qualifier the time arrived with; omit it for a data element 337 value |
Returns
Section titled “Returns”the time as HH:MM:SS, with a fraction of one or two digits when a 337 value has one, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { parseX12Time } from "@northguild/gmt/intermodal/parse";
parseX12Time("1430") // "14:30:00"