Skip to content

parseX12Date

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

Parse an X12 Date Time Period value that states a calendar date, as an ISO 8601 date.

  • A DTP segment carries a format qualifier in DTP-02 (data element 1250) and its value in DTP-03 (data element 1251); DTM-05 and DTM-06 carry the same pair. This function reads the codes whose value is a date. Codes are release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### Format codes

    CodeMaskThe dictionary’s definition
    D8CCYYMMDD“Date Expressed in Format CCYYMMDD”
    DBMMDDCCYY“Date Expressed in Format MMDDCCYY”
  • The value must be the eight digits of its code’s mask. The same digits can read two ways, so the code decides: "12112010" is 11 December 2010 under DB and not a date under D8.

  • D8 also reads data element 373 (Date), the CCYYMMDD date element of AT7, G62 and DTM-02. To read that date and its time element together, use parseX12DateAndTime.

  • Fields are checked, not clamped: month 13, 31 June and 29 February 2023 return "".

  • A two-digit year (D6 YYMMDD, TT MMDDYY) is not read: X12 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 (DT is read by parseX12DateTime), and for a non-string argument.

ParameterTypeDescription
valuestringThe data element 1251 value (e.g. “20240615”)
formatX12DateFormatX12 data element 1250 format qualifier

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

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

intermodal/parse/parseX12Date.ts