parseX12Date
Signature
Section titled “Signature”parseX12Date(value: string, format: X12DateFormat): stringParse an X12 Date Time Period value that states a calendar date, as an ISO 8601 date.
-
A
DTPsegment carries a format qualifier inDTP-02(data element 1250) and its value inDTP-03(data element 1251);DTM-05andDTM-06carry the same pair. This function reads the codes whose value is a date. Codes are release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### Format codesCode Mask The dictionary’s definition D8CCYYMMDD“Date Expressed in Format CCYYMMDD” DBMMDDCCYY“Date Expressed in Format MMDDCCYY” -
The value must be the eight digits of its code’s mask. The same digits can read two ways, so the code decides:
"12112010"is 11 December 2010 underDBand not a date underD8. -
D8also reads data element 373 (Date), theCCYYMMDDdate element ofAT7,G62andDTM-02. To read that date and its time element together, useparseX12DateAndTime. -
Fields are checked, not clamped: month 13, 31 June and 29 February 2023 return
"". -
A two-digit year (
D6YYMMDD,TTMMDDYY) is not read: X12 does not say which century it belongs to. Read one withparseDateWithPattern("240615", "yyMMdd", undefined, { yearWindow: 2000 }). -
Returns
""for any other code, a code of another kind included (DTis read byparseX12DateTime), and for a non-string argument.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | The data element 1251 value (e.g. “20240615”) |
format | X12DateFormat | X12 data element 1250 format qualifier |
Returns
Section titled “Returns”the date as YYYY-MM-DD, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { parseX12Date } from "@northguild/gmt/intermodal/parse";
parseX12Date("20240615", "D8") // "2024-06-15"