@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
119 lines (118 loc) • 1.98 kB
JavaScript
// src/intermodal/parse/x12TimeCodeZone.ts
/**
* X12 data element 623 code → the zone its definition names, release 008010, read from Stedi's
* X12-licensed dictionary (https://www.stedi.com/edi/x12-008010/element/623); the X12 text was
* not reached. Each comment quotes the definition. Typed by `X12ZoneTimeCode`, so a missing code
* fails typecheck.
*/
const X12_TIME_CODE_ZONE = {
AD: {
zone: "Alaska",
daylight: true
},
AS: {
zone: "Alaska",
daylight: false
},
AT: {
zone: "Alaska",
daylight: null
},
CD: {
zone: "Central",
daylight: true
},
CS: {
zone: "Central",
daylight: false
},
CT: {
zone: "Central",
daylight: null
},
ED: {
zone: "Eastern",
daylight: true
},
ES: {
zone: "Eastern",
daylight: false
},
ET: {
zone: "Eastern",
daylight: null
},
HD: {
zone: "Hawaii-Aleutian",
daylight: true
},
HS: {
zone: "Hawaii-Aleutian",
daylight: false
},
HT: {
zone: "Hawaii-Aleutian",
daylight: null
},
LT: {
zone: "Local",
daylight: null
},
MD: {
zone: "Mountain",
daylight: true
},
MS: {
zone: "Mountain",
daylight: false
},
MT: {
zone: "Mountain",
daylight: null
},
ND: {
zone: "Newfoundland",
daylight: true
},
NS: {
zone: "Newfoundland",
daylight: false
},
NT: {
zone: "Newfoundland",
daylight: null
},
PD: {
zone: "Pacific",
daylight: true
},
PS: {
zone: "Pacific",
daylight: false
},
PT: {
zone: "Pacific",
daylight: null
},
TD: {
zone: "Atlantic",
daylight: true
},
TS: {
zone: "Atlantic",
daylight: false
},
TT: {
zone: "Atlantic",
daylight: null
}
};
/** Whether `code` is an own key of the table: `"toString"` and `"__proto__"` are not codes. */
function isZoneTimeCode(code) {
return typeof code === "string" && Object.hasOwn(X12_TIME_CODE_ZONE, code);
}
function x12TimeCodeZone(timeCode) {
if (!isZoneTimeCode(timeCode)) return null;
return { ...X12_TIME_CODE_ZONE[timeCode] };
}
export { x12TimeCodeZone };