classifyX12DateTimePeriodFormat
Signature
Section titled “Signature”classifyX12DateTimePeriodFormat(format: string): X12DateTimePeriodFormatClass | nullName the kind of value an X12 data element 1250 format qualifier states, and return the code narrowed to that kind, so a code that arrives as data reaches the function that reads it.
-
Each kind has its own parser, formatter and validator, and each takes only its own codes. A generic
DTPreader holdsDTP-02as a plain string: it calls this function, testskind, and passesformaton. Testingkindnarrowsformatto that kind’s union, so the call needs no cast. Codes are release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### KindskindCodes Read by "date"D8,DBparseX12Date"time"TM,TSparseX12Time(value, format)"dateTime"DT,RTSparseX12DateTime"dateRange"RD8,RDparseX12DateRange"dateTimeRange"RDT,DTSparseX12DateTimeRange -
The narrowing pattern. With
const classified = classifyX12DateTimePeriodFormat(code), the lineif (classified?.kind === "date") parseX12Date(value, classified.format)compiles with no cast: inside the test,classified.formatisX12DateFormat. -
Both members are always present, and each call returns a new object.
-
RTSis one date-time despite itsR, andDTSis a range despite having none. -
Returns
nullfor every code no function reads: the two-digit-year codes (D6,TT,TR,RD6,TU),TC,EH,DDT,DTD,RTM,UNand every other 1250 code. -
This is a format qualifier, not a time code:
TShere is the formatHHMMSS. Classify a data element 623 time code withclassifyX12TimeCode. -
Matching is exact:
"d8"and" D8"are not codes. -
Returns a result exactly when
isValidX12DateTimePeriodFormatis true.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
format | string | X12 data element 1250 format qualifier, as it arrives (e.g. “D8”) |
Returns
Section titled “Returns”{ kind, format }, or null on invalid input
X12DateTimePeriodFormatClass
Section titled “X12DateTimePeriodFormatClass”An X12 data element 1250 format qualifier with the kind of value it states: the result of classifyX12DateTimePeriodFormat.
import type { X12DateTimePeriodFormatClass } from "@northguild/gmt";type X12DateTimePeriodFormatClass = | { /** The kind of value the code states: a calendar date, read by `parseX12Date`. */ kind: "date"; /** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */ format: X12DateFormat; } | { /** The kind of value the code states: a time of day, read by `parseX12Time(value, format)`. */ kind: "time"; /** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */ format: X12TimeFormat; } | { /** The kind of value the code states: a local date and time, read by `parseX12DateTime`. */ kind: "dateTime"; /** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */ format: X12DateTimeFormat; } | { /** The kind of value the code states: a range between two dates, read by `parseX12DateRange`. */ kind: "dateRange"; /** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */ format: X12DateRangeFormat; } | { /** The kind of value the code states: a range between two local date-times, read by `parseX12DateTimeRange`. */ kind: "dateTimeRange"; /** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */ format: X12DateTimeRangeFormat; };Related types
Section titled “Related types”Examples
Section titled “Examples”import { classifyX12DateTimePeriodFormat } from "@northguild/gmt/intermodal/parse";
classifyX12DateTimePeriodFormat("D8") // { kind: "date", format: "D8" }