parseEdifactDatePeriod
Signature
Section titled “Signature”parseEdifactDatePeriod(value: string, format: "718"): EdiDatePeriod | nullParse a UN/EDIFACT DTM value that states a period between two calendar dates, as its start and end.
-
A
DTMsegment carries its value in data element 2380 and, in data element 2379, the format code that says how to read it. 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 718CCYYMMDD-CCYYMMDD“A period of time specified by giving the start date followed by the end date (both including century). Data is to be transmitted as consecutive characters without hyphen.” -
A period is transmitted without a hyphen, and a hyphen is rejected. Every directory read (twelve, from D.93A to D.22B) says so; the hyphen in the mask is notation.
"2024061520240620"reads and"20240615-20240620"returnsnull. -
startandendare the two dates as transmitted, eachYYYY-MM-DD. The directory does not say whether the end date is inside the period: that is the message’s to define, so no day is added or removed. Pass the pair to the plain interval functions as(start, end), for exampleintervalLengthDate(period.start, period.end, "days"); they leaveendoutside the interval. -
An end before its start returns
null: a reversed period names no span of time. An end equal to its start is a valid period. -
Fields are checked, not clamped: month 13, 31 June and 29 February 2023 return
null. -
A two-digit year (
717,YYMMDD-YYMMDD) is not read. Split such a value in two and read each half withparseDateWithPattern, ayypattern and itsyearWindowoption. -
Returns
nullfor any other code, a code of another kind included (719is read byparseEdifactDateTimePeriod), and for a non-string argument.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | The data element 2380 value (e.g. “2024061520240620”) |
format | "718" | The data element 2379 format code |
Returns
Section titled “Returns”{ start, end }, two ISO 8601 dates, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { parseEdifactDatePeriod } from "@northguild/gmt/intermodal/parse";
parseEdifactDatePeriod("2024061520240620", "718") // { start: "2024-06-15", end: "2024-06-20" }