Skip to content

parseEdifactDateTime

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

Parse a UN/EDIFACT DTM value that states a date and a time with no offset, as an ISO 8601 local date-time.

  • 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 codes whose value is a wall clock at a place the value does not name. Masks and descriptions are the UNTDID directory’s, read from UNECE’s D.21B page as archived. ### Format codes

    CodeMaskThe directory’s description
    203CCYYMMDDHHMM“Calendar date including time with minutes”
    204CCYYMMDDHHMMSS“Calendar date including time with seconds”
  • The result is local, never UTC. It carries no Z and no offset: reading a 203 value as UTC is the most common EDI timestamp bug. Pass the result and the place’s IANA zone to resolveLocal to get the instant.

  • The value must be the digits of its code’s mask: "202406151430" is a 203 value and not a 204 one.

  • Seconds are always written in the result, 00 for 203.

  • Fields are checked, not clamped: hour 24, second 60, 31 June and 29 February 2023 return "".

  • A two-digit year (201, 202) is not read: UN/EDIFACT does not say which century it belongs to. Read one with parseDateTimeWithPattern("2406151430", "yyMMddHHmm", undefined, { yearWindow: 2000 }).

  • Returns "" for any other code, a code of another kind included (205 is read by parseEdifactOffsetDateTime), and for a non-string argument.

ParameterTypeDescription
valuestringThe data element 2380 value (e.g. “202406151430”)
formatEdifactDateTimeFormatThe data element 2379 format code

the local date-time as YYYY-MM-DDTHH:MM:SS, or "" on invalid input

import { parseEdifactDateTime } from "@northguild/gmt/intermodal/parse";
parseEdifactDateTime("202406151430", "203") // "2024-06-15T14:30:00"
output 

intermodal/parse/parseEdifactDateTime.ts