classifyX12TimeCode
Signature
Section titled “Signature”classifyX12TimeCode(timeCode: string): X12TimeCodeClass | nullSay 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,G62orDTMsegment. 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, testskind, and passestimeCodeon. TestingkindnarrowstimeCodeto 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. ### KindskindCodes Read 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 lineif (classified?.kind === "offset") x12TimeCodeOffset(classified.timeCode)compiles with no cast: inside the test,classified.timeCodeisX12OffsetTimeCode. The"zone"branch passesclassified.timeCodetox12TimeCodeZonethe 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, asx12TimeCodeOffsetexplains. -
25–29were added in release 006010. The function takes no release, so it reads them. -
This is a time code, not a format qualifier:
TShere is Atlantic Standard Time. Classify a data element 1250 code withclassifyX12DateTimePeriodFormat. -
Matching is exact: two characters, upper case, no padding.
-
Returns
nullfor a code that is not one of the 56 and for a non-string. It returns a result exactly whenisValidX12TimeCodeis true.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
timeCode | string | X12 data element 623 time code, as it arrives (e.g. “20”) |
Returns
Section titled “Returns”{ kind, timeCode }, or null on invalid input
X12TimeCodeClass
Section titled “X12TimeCodeClass”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; };Related types
Section titled “Related types”Examples
Section titled “Examples”import { classifyX12TimeCode } from "@northguild/gmt/intermodal/parse";
classifyX12TimeCode("20") // { kind: "offset", timeCode: "20" }