parseEdifactOffsetDateTime
Signature
Section titled “Signature”parseEdifactOffsetDateTime(value: string, format: EdifactOffsetDateTimeFormat): stringParse a UN/EDIFACT DTM value that states a date and a time with an offset from UTC, as an ISO 8601 date-time with its offset.
-
A
DTMsegment carries its value in data element 2380 and, in data element 2379, the format code that says how to read it. This function reads the codes whose value names an instant. Masks and descriptions are the UNTDID directory’s, read from UNECE’s D.21B page as archived. ### Format codesCode Mask The directory’s description 205CCYYMMDDHHMMZHHMM“Calendar date including time and time zone expressed in hours and minutes.” 208CCYYMMDDHHMMSSZHHMM“Calendar date including time with seconds, with Time Zone” (D.12A and later) 303CCYYMMDDHHMMZZZ“See 203 plus Z=Time zone.” 304CCYYMMDDHHMMSSZZZ“See 204 plus Z=Time zone.” -
The result is the wall clock as written, with its offset:
YYYY-MM-DDTHH:MM:SS±HH:MM, on its own day and never moved to UTC. It is the stringfromOffsetInstantwrites, sotoOffsetInstantreads it as the instant and the offset, and every function that takes an instant takes it. -
ZHHMM(205,208) is a sign, hours and minutes (+0200,-0330).-0000is read as+00:00. -
ZZZ(303,304) is read as an offset only. A signed hour from00to23(+02,-05) is that offset: UN/ECE Recommendation 7 ¶12 appends the difference from UTC “in hours and minutes, or hours only, with a leading ”+” or ”-” sign”. The literalsUTCandGMTare+00:00: the SMDG container-shipping guides writeUTCin a303value, and Recommendation 7 ¶12 names one scale by both names, “Co-ordinated Universal Time (formerly known as Greenwich Mean Time)”. -
Any other three characters return
"", letters such asCETincluded: the directory says only “Z = Time zone”, no standard defines an abbreviation, and GMT does not guess what one means. Where a partner sends one, read the wall clock withparseEdifactDateTimeafter removing the three letters, and resolve it in the IANA zone you map them to withresolveLocal. -
Pass the unescaped element value.
+is the EDIFACT data element separator, so an interchange transmits+02as?+02. Remove the release character first:"202406151430?+02"returns"". -
Seconds are always written in the result,
00for205and303. Fields are checked, not clamped: hour 24, second 60 and 29 February 2023 return"". -
A two-digit year (
206,207,301,302) is not read. -
Returns
""for any other code, a code of another kind included (203is read byparseEdifactDateTime), and for a non-string argument.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | The data element 2380 value, unescaped (e.g. “202406151430+0200”) |
format | EdifactOffsetDateTimeFormat | The data element 2379 format code |
Returns
Section titled “Returns”the date-time with its offset as YYYY-MM-DDTHH:MM:SS±HH:MM, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { parseEdifactOffsetDateTime } from "@northguild/gmt/intermodal/parse";
parseEdifactOffsetDateTime("202406151430+0200", "205") // "2024-06-15T14:30:00+02:00"