Skip to content

parseX12DateTime

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

Parse an X12 Date Time Period value that states a date and a time, as an ISO 8601 local date-time.

  • 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 one date-time. Codes are release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### Format codes

    CodeMaskThe dictionary’s definition
    DTCCYYMMDDHHMM“Date and Time Expressed in Format CCYYMMDDHHMM”
    RTSCCYYMMDDHHMMSS“Date and Time Expressed in Format CCYYMMDDHHMMSS”
  • The result is local, never UTC. No 1250 code carries an offset, so the result has no Z and no offset. Pass it and the place’s IANA zone to resolveLocal to get the instant.

  • RTS is one date-time, despite the R that marks a range in other codes.

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

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

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

  • A freight segment sends the date and the time as two elements (373 and 337 in AT7, G62 and DTM-02/03), not as one 1250 value: read those with parseX12DateAndTime.

  • A two-digit year (TR, DDMMYYHHMM) is not read: X12 does not say which century it belongs to. Read one with parseDateTimeWithPattern("1506241430", "ddMMyyHHmm", undefined, { yearWindow: 2000 }).

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

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

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

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

intermodal/parse/parseX12DateTime.ts