Skip to content

classifyX12DateTimePeriodFormat

  • Container free time, demurrage, billing deadlines, bill of lading dates and EDI timestamps.
classifyX12DateTimePeriodFormat(format: string): X12DateTimePeriodFormatClass | null

Name 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 DTP reader holds DTP-02 as a plain string: it calls this function, tests kind, and passes format on. Testing kind narrows format to 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. ### Kinds

    kindCodesRead 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 line if (classified?.kind === "date") parseX12Date(value, classified.format) compiles with no cast: inside the test, classified.format is X12DateFormat.

  • Both members are always present, and each call returns a new object.

  • RTS is one date-time despite its R, and DTS is a range despite having none.

  • Returns null for every code no function reads: the two-digit-year codes (D6, TT, TR, RD6, TU), TC, EH, DDT, DTD, RTM, UN and every other 1250 code.

  • This is a format qualifier, not a time code: TS here is the format HHMMSS. Classify a data element 623 time code with classifyX12TimeCode.

  • Matching is exact: "d8" and " D8" are not codes.

  • Returns a result exactly when isValidX12DateTimePeriodFormat is true.

ParameterTypeDescription
formatstringX12 data element 1250 format qualifier, as it arrives (e.g. “D8”)

{ kind, format }, or null on invalid input

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;
};
import { classifyX12DateTimePeriodFormat } from "@northguild/gmt/intermodal/parse";
classifyX12DateTimePeriodFormat("D8") // { kind: "date", format: "D8" }
output 

intermodal/parse/classifyX12DateTimePeriodFormat.ts