parseX12DateAndTime
Signature
Section titled “Signature”parseX12DateAndTime(date: string, time: string): stringRead the date and the time of an X12 segment, sent as two elements, as one ISO 8601 local date-time.
-
X12 freight segments carry a moment as separate elements, and this function takes the two as they are transmitted:
AT7-05andAT7-06(in a 214 shipment status),G62-02andG62-04(a 204 load tender) andDTM-02andDTM-03. Definitions are release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### The two elements -
The result is local, never UTC. It has no
Zand no offset.AT7says what a blank time code means: “If AT707 is not present then AT706 represents local time of the status”. Reading the value as UTC is the most common EDI timestamp bug. -
The time code beside them (data element 623) says where the clock was. For a code that states an offset, resolve the result at that offset:
resolveLocal(parseX12DateAndTime("20240615", "1430"), x12TimeCodeOffset("20"))is"2024-06-15T19:30:00Z". For a code that names a zone (x12TimeCodeZone), pass the result and the IANA zone you map the name to, toresolveLocal. -
Both elements are required. A missing or empty date or time returns
"": read a date alone withparseX12Date(value, "D8")and a time alone withparseX12Time. -
The time is one of the four element 337 forms, 4, 6, 7 or 8 digits. Seconds are always written,
00forHHMM. Tenths and hundredths become the fraction of the second exactly:14300012is14:30:00.12. A zero fraction is not written. -
To write the two elements back, write the date with
formatX12Date(date, "D8")and the time withformatX12TimeElement, naming the element 337 form by its mask:formatX12TimeElement("14:30:00.12", "HHMMSSDD")is14300012. -
Fields are checked, not clamped: 29 February 2023, 31 June, hour 24, minute or second 60 and a time of 5 or 9 digits return
"". -
The date has a four-digit year. Before release 004010, element 373 was
YYMMDD: read such a date withparseDateWithPattern("240615", "yyMMdd", undefined, { yearWindow: 2000 }). -
Returns
""for a non-string argument.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
date | string | The data element 373 date as transmitted, CCYYMMDD (e.g. “20240615”) |
time | string | The data element 337 time as transmitted (e.g. “1430”) |
Returns
Section titled “Returns”the local date-time as YYYY-MM-DDTHH:MM:SS, with a fraction when the time has one, or "" on invalid input
Examples
Section titled “Examples”import { parseX12DateAndTime } from "@northguild/gmt/intermodal/parse";
parseX12DateAndTime("20240615", "1430") // "2024-06-15T14:30:00"