parseEdifactDate
Signature
Section titled “Signature”parseEdifactDate(value: string, format: "102"): stringParse a UN/EDIFACT DTM value that states a calendar date, as an ISO 8601 date.
-
A
DTMsegment carries its value in data element 2380 and, in data element 2379, the format code that says how to read it. This function reads the code whose value is a date. The mask and description are the UNTDID directory’s, read from UNECE’s D.21B page as archived. ### Format codeCode Mask The directory’s description 102CCYYMMDD“Calendar date: C = Century ; Y = Year ; M = Month ; D = Day.” -
The value must be the eight digits of the mask and nothing else: a hyphen, a space or a ninth digit returns
"". -
Fields are checked, not clamped: month 13, 31 June and 29 February 2023 return
"". -
The year is the four digits as written,
0000to9999. -
A two-digit year (
101,YYMMDD) is not read: UN/EDIFACT 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 (203is read byparseEdifactDateTime);classifyEdifactDtmFormatnames the kind of a code. Returns""for a non-string argument.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | The data element 2380 value (e.g. “20240615”) |
format | "102" | The data element 2379 format code |
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 { parseEdifactDate } from "@northguild/gmt/intermodal/parse";
parseEdifactDate("20240615", "102") // "2024-06-15"