Skip to content

classifyX12TimeCode

  • Container free time, demurrage, billing deadlines, bill of lading dates and EDI timestamps.
classifyX12TimeCode(timeCode: string): X12TimeCodeClass | null

Say whether an X12 time code (data element 623) states an offset or names a zone, and return the code narrowed to the function that reads it.

  • Data element 623 is the code beside the date and time of an X12 AT7, G62 or DTM segment. 31 of its 56 codes state an offset from UTC and 25 name a zone, and each group has its own reader. A segment reader holds the code as a plain string: it calls this function, tests kind, and passes timeCode on. Testing kind narrows timeCode to that reader’s union, so the call needs no cast. Codes are release 008010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### Kinds

    kindCodesRead by
    "offset"01–29, UT, GMx12TimeCodeOffset
    "zone"AD, AS, AT, CD, CS, CT, ED, ES, ET, HD, HS, HT, MD, MS, MT, ND, NS, NT, PD, PS, PT, TD, TS, TT, LTx12TimeCodeZone
  • The narrowing pattern. With const classified = classifyX12TimeCode(code), the line if (classified?.kind === "offset") x12TimeCodeOffset(classified.timeCode) compiles with no cast: inside the test, classified.timeCode is X12OffsetTimeCode. The "zone" branch passes classified.timeCode to x12TimeCodeZone the same way.

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

  • GM (“Greenwich Mean Time”) is an offset code: GMT reads it as +00:00, as x12TimeCodeOffset explains.

  • 25–29 were added in release 006010. The function takes no release, so it reads them.

  • This is a time code, not a format qualifier: TS here is Atlantic Standard Time. Classify a data element 1250 code with classifyX12DateTimePeriodFormat.

  • Matching is exact: two characters, upper case, no padding.

  • Returns null for a code that is not one of the 56 and for a non-string. It returns a result exactly when isValidX12TimeCode is true.

ParameterTypeDescription
timeCodestringX12 data element 623 time code, as it arrives (e.g. “20”)

{ kind, timeCode }, or null on invalid input

An X12 data element 623 time code with what it states: the result of classifyX12TimeCode.

import type { X12TimeCodeClass } from "@northguild/gmt";
type X12TimeCodeClass =
| {
/** The code states an offset from UTC: read it with `x12TimeCodeOffset`. */
kind: "offset";
/** The code itself, narrowed to the 31 codes that state an offset. */
timeCode: X12OffsetTimeCode;
}
| {
/** The code names a zone and states no offset: read it with `x12TimeCodeZone`. */
kind: "zone";
/** The code itself, narrowed to the 25 codes that name a zone. */
timeCode: X12ZoneTimeCode;
};
import { classifyX12TimeCode } from "@northguild/gmt/intermodal/parse";
classifyX12TimeCode("20") // { kind: "offset", timeCode: "20" }
output 

intermodal/parse/classifyX12TimeCode.ts