Skip to content

parseX12DateTimeRange

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

Parse an X12 Date Time Period value that states a range between two local date-times, 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
    RDTCCYYMMDDHHMM-CCYYMMDDHHMM“Range of Date and Time, Expressed in Format CCYYMMDDHHMM-CCYYMMDDHHMM”
    DTSCCYYMMDDHHMMSS-CCYYMMDDHHMMSS“Range of Date and Time Expressed in Format CCYYMMDDHHMMSS-CCYYMMDDHHMMSS”
  • A range is transmitted with exactly one hyphen: "202406151430-202406201600" reads, and the same digits run together return null.

  • start and end are local date-times as transmitted, each YYYY-MM-DDTHH:MM:SS, with seconds 00 for RDT. No 1250 code carries an offset, so neither names an instant: pass each and the place’s IANA zone to resolveLocal.

  • X12 does not say here whether the end is inside the range. Pass the pair to the plain interval functions as (start, end), for example intervalLengthDateTime(range.start, range.end, "hours"); they leave end outside the interval.

  • DTS is a range, despite having no R.

  • 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: hour 24, second 60 and 29 February 2023 return null.

  • A range with a date on one side and a date-time on the other (DDT, DTD) is not read, and neither is a range of times with no date (RTM).

  • Returns null for any other code, a code of another kind included (RD8 is read by parseX12DateRange), and for a non-string argument.

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

{ start, end }, two ISO 8601 local date-times, or null on invalid input

import { parseX12DateTimeRange } from "@northguild/gmt/intermodal/parse";
parseX12DateTimeRange("202406151430-202406201600", "RDT") // { start: "2024-06-15T14:30:00", end: "2024-06-20T16:00:00" }
output 

intermodal/parse/parseX12DateTimeRange.ts