Skip to content

parseEdifactDatePeriod

  • Container free time, demurrage, billing deadlines, bill of lading dates and EDI timestamps.
parseEdifactDatePeriod(value: string, format: "718"): EdiDatePeriod | null

Parse a UN/EDIFACT DTM value that states a period between two calendar dates, as its start and end.

  • A DTM segment 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 code

    CodeMaskThe 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" returns null.

  • start and end are the two dates as transmitted, each YYYY-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 example intervalLengthDate(period.start, period.end, "days"); they leave end outside 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 with parseDateWithPattern, a yy pattern and its yearWindow option.

  • Returns null for any other code, a code of another kind included (719 is read by parseEdifactDateTimePeriod), and for a non-string argument.

ParameterTypeDescription
valuestringThe data element 2380 value (e.g. “2024061520240620”)
format"718"The data element 2379 format code

{ start, end }, two ISO 8601 dates, or null on invalid input

import { parseEdifactDatePeriod } from "@northguild/gmt/intermodal/parse";
parseEdifactDatePeriod("2024061520240620", "718") // { start: "2024-06-15", end: "2024-06-20" }
output 

intermodal/parse/parseEdifactDatePeriod.ts