Skip to content

parseEdifactDate

  • Container free time, demurrage, billing deadlines, bill of lading dates and EDI timestamps.
parseEdifactDate(value: string, format: "102"): string

Parse a UN/EDIFACT DTM value that states a calendar date, as an ISO 8601 date.

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

    CodeMaskThe 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, 0000 to 9999.

  • A two-digit year (101, YYMMDD) is not read: UN/EDIFACT does not say which century it belongs to. Read one with parseDateWithPattern("240615", "yyMMdd", undefined, { yearWindow: 2000 }).

  • Returns "" for any other code, a code of another kind included (203 is read by parseEdifactDateTime); classifyEdifactDtmFormat names the kind of a code. Returns "" for a non-string argument.

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

the date as YYYY-MM-DD, or "" on invalid input

import { parseEdifactDate } from "@northguild/gmt/intermodal/parse";
parseEdifactDate("20240615", "102") // "2024-06-15"
output 

intermodal/parse/parseEdifactDate.ts