Skip to content

classifyEdifactDtmFormat

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

Name the kind of value a UN/EDIFACT data element 2379 format code 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 DTM reader holds the code 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. ### Kinds

    kindCodesRead by
    "date"102parseEdifactDate
    "time"401, 402parseEdifactTime
    "dateTime"203, 204parseEdifactDateTime
    "offsetDateTime"205, 208, 303, 304parseEdifactOffsetDateTime
    "datePeriod"718parseEdifactDatePeriod
    "dateTimePeriod"719parseEdifactDateTimePeriod
  • The narrowing pattern. With const classified = classifyEdifactDtmFormat(code), the line if (classified?.kind === "date") parseEdifactDate(value, classified.format) compiles with no cast: inside the test, classified.format is EdifactDateFormat.

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

  • Returns null for every code no function reads: the two-digit-year codes (101, 201, 202, 206, 207, 301, 302, 713, 717), 209, 404, 406 and every other 2379 code.

  • Matching is exact: " 203", "0203" and the number 203 are not codes.

  • Returns a result exactly when isValidEdifactDtmFormat is true.

ParameterTypeDescription
formatstringThe data element 2379 format code, as it arrives (e.g. “203”)

{ kind, format }, or null on invalid input

A UN/EDIFACT data element 2379 format code with the kind of value it states: the result of classifyEdifactDtmFormat.

import type { EdifactDtmFormatClass } from "@northguild/gmt";
type EdifactDtmFormatClass =
| {
/** The kind of value the code states: a calendar date, read by `parseEdifactDate`. */
kind: "date";
/** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */
format: EdifactDateFormat;
}
| {
/** The kind of value the code states: a time of day, read by `parseEdifactTime`. */
kind: "time";
/** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */
format: EdifactTimeFormat;
}
| {
/** The kind of value the code states: a local date and time, read by `parseEdifactDateTime`. */
kind: "dateTime";
/** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */
format: EdifactDateTimeFormat;
}
| {
/** The kind of value the code states: a date and time with an offset from UTC, read by `parseEdifactOffsetDateTime`. */
kind: "offsetDateTime";
/** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */
format: EdifactOffsetDateTimeFormat;
}
| {
/** The kind of value the code states: a period between two dates, read by `parseEdifactDatePeriod`. */
kind: "datePeriod";
/** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */
format: EdifactDatePeriodFormat;
}
| {
/** The kind of value the code states: a period between two local date-times, read by `parseEdifactDateTimePeriod`. */
kind: "dateTimePeriod";
/** The code itself, narrowed to the codes of that kind, so it fits the kind's functions. */
format: EdifactDateTimePeriodFormat;
};
import { classifyEdifactDtmFormat } from "@northguild/gmt/intermodal/parse";
classifyEdifactDtmFormat("102") // { kind: "date", format: "102" }
output 

intermodal/parse/classifyEdifactDtmFormat.ts