Skip to content

parseX12DateRange

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

Parse an X12 Date Time Period value that states a range between two calendar dates, as its start and end.

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

    CodeMaskThe dictionary’s definition
    RD8CCYYMMDD-CCYYMMDD“Range of Dates Expressed in Format CCYYMMDD-CCYYMMDD”
    RDMMDDCCYY-MMDDCCYY“Range of Dates Expressed in Format MMDDCCYY-MMDDCCYY”
  • A range is transmitted with exactly one hyphen. Each definition gives the format with its hyphen: "20240615-20240620" reads, and "2024061520240620" returns null.

  • start and end are the two dates as transmitted, each YYYY-MM-DD. X12 does not say here whether the end date is inside the range: that is the segment’s to define, so no day is added or removed. Pass the pair to the plain interval functions as (start, end), for example intervalLengthDate(range.start, range.end, "days"); they leave end outside the interval.

  • An end before its start returns null: a reversed range names no span of time. An end equal to its start is a valid range.

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

  • A two-digit year (RD6, YYMMDD-YYMMDD) is not read. Split such a value at its hyphen 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 (RDT is read by parseX12DateTimeRange), and for a non-string argument.

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

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

import { parseX12DateRange } from "@northguild/gmt/intermodal/parse";
parseX12DateRange("20240615-20240620", "RD8") // { start: "2024-06-15", end: "2024-06-20" }
output 

intermodal/parse/parseX12DateRange.ts