Skip to content

parseX12Time

  • Container free time, demurrage, billing deadlines, bill of lading dates and EDI timestamps.
parseX12Time(value: string, format?: X12TimeFormat): string

Parse an X12 time as an ISO 8601 time: a data element 337 value with no qualifier, or a time that arrives with a data element 1250 format qualifier.

  • X12 sends a time two ways, and format says which the caller holds:

  • With no qualifier: the time element of a freight segment (AT7-06, G62-04, DTM-03) is data element 337, which fixes its own four forms. Omit format.

  • With a qualifier: a DTP segment (DTP-02 and DTP-03), and DTM-05 and DTM-06, send a data element 1250 format qualifier beside the value. Pass it as format, and the value is read against that qualifier’s mask alone. Definitions are release 005010, read from Stedi’s X12-licensed dictionary (337, 1250); the X12 text itself was not reached. ### Forms

    formatDigitsMaskThe dictionary’s definition
    omitted4, 6, 7 or 8HHMM, HHMMSS, HHMMSSD, HHMMSSDDElement 337: “H = hours (00-23), M = minutes (00-59), S = integer seconds (00-59) … D = tenths (0-9) and DD = hundredths (00-99)”
    TM4HHMM“Time Expressed in Format HHMM”
    TS6HHMMSS“Time Expressed in Format HHMMSS”
  • A qualifier is strict. "143045" is a TS value and returns "" under TM, and no 1250 code holds decimal seconds, so a 7- or 8-digit value returns "" under either qualifier. The same values read when format is omitted.

  • A format that is present and is not TM or TS returns "", never the unqualified read: a code of another kind (D8), a code that is not read (RTM, TT), an empty string and a non-string. Only an omitted or undefined format means “no qualifier”.

  • Seconds are always written in the result, 00 for HHMM.

  • With no qualifier, tenths and hundredths become the fraction of the second exactly: 1430001 is 14:30:00.1 and 14300012 is 14:30:00.12. A zero fraction is not written (14300000 is 14:30:00).

  • To write the value back, use formatX12TimeElement for an element 337 time and name the form by its mask: formatX12TimeElement("14:30:00.12", "HHMMSSDD") is 14300012. Use formatX12Time for a time that travels with a TM or TS qualifier.

  • Fields are checked, not clamped: hour 24, minute 60, second 60 and a value of 5 or 9 digits return "".

  • The time is local to a place the value does not name. In a freight segment the time code beside it (data element 623) says where the clock was: classify it with classifyX12TimeCode. To read the date and time elements together, use parseX12DateAndTime.

  • A range of times (RTM, HHMM-HHMM) is not read.

  • Returns "" for a non-string value.

ParameterTypeDescription
valuestringThe time as transmitted (e.g. “1430”)
formatX12TimeFormatX12 data element 1250 format qualifier the time arrived with; omit it for a data element 337 value

the time as HH:MM:SS, with a fraction of one or two digits when a 337 value has one, or "" on invalid input

import { parseX12Time } from "@northguild/gmt/intermodal/parse";
parseX12Time("1430") // "14:30:00"
output 

intermodal/parse/parseX12Time.ts