parseX12DateRange
Signature
Section titled “Signature”parseX12DateRange(value: string, format: X12DateRangeFormat): EdiDatePeriod | nullParse an X12 Date Time Period value that states a range between two calendar dates, as its start and end.
-
A
DTPsegment carries a format qualifier inDTP-02(data element 1250) and its value inDTP-03(data element 1251);DTM-05andDTM-06carry the same pair. Codes are release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### Format codesCode Mask The 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"returnsnull. -
startandendare the two dates as transmitted, eachYYYY-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 exampleintervalLengthDate(range.start, range.end, "days"); they leaveendoutside 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 withparseDateWithPattern, ayypattern and itsyearWindowoption. -
Returns
nullfor any other code, a code of another kind included (RDTis read byparseX12DateTimeRange), and for a non-string argument.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | The data element 1251 value (e.g. “20240615-20240620”) |
format | X12DateRangeFormat | X12 data element 1250 format qualifier |
Returns
Section titled “Returns”{ start, end }, two ISO 8601 dates, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { parseX12DateRange } from "@northguild/gmt/intermodal/parse";
parseX12DateRange("20240615-20240620", "RD8") // { start: "2024-06-15", end: "2024-06-20" }