formatEdifactDate
Signature
Section titled “Signature”formatEdifactDate(value: string, format: "102"): stringWrite an ISO 8601 date as a UN/EDIFACT DTM value (data element 2380) in a date format code (data element 2379). The inverse of parseEdifactDate: what one writes, the other reads back.
-
The mask and description are the UNTDID directory’s, read from UNECE’s D.21B page as archived. ### Format code
Code Mask The directory’s description 102CCYYMMDD“Calendar date: C = Century ; Y = Year ; M = Month ; D = Day.” -
valueis a date, asisValidDateaccepts it. A date-time, an instant or a time returns"", asformatDatereturns""for them: pass the date alone. -
Each field is zero-padded to the width the mask gives it.
-
A year outside 0000–9999 returns
"":CCYYis four digits and no sign. -
No function writes a two-digit year (
101,YYMMDD): the one date code that is written holds the whole year. -
Returns
""for any other code, a code of another kind included, and for a non-string argument.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO 8601 date (e.g. “2024-06-15”) |
format | "102" | The data element 2379 format code |
Returns
Section titled “Returns”the data element 2380 value, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatEdifactDate } from "@northguild/gmt/intermodal/format";
formatEdifactDate("2024-06-15", "102") // "20240615"