formatEpcisEvent
Signature
Section titled “Signature”formatEpcisEvent(value: OffsetInstant): EpcisEventTime | nullWrite an instant-plus-offset pair as the two required time fields of a GS1 EPCIS 2.0 event.
- EPCIS (ISO/IEC 19987) is GS1’s event standard for supply-chain visibility. Every event must carry
eventTime, the instant, andeventTimeZoneOffset, the offset the local clock ran at where the event happened. The inverse ofparseEpcisEvent, whose result it takes as it is. eventTimeis the instant in UTC, ending inZ, asTemporal.Instant.prototype.toStringwrites it: seconds always present, and a fraction kept to the nanosecond with no trailing zeros and no padding. It always matchesepcisEventTime, theDateTimeStamppattern of the EPCIS XSD, and so is valid in the XML binding and in the JSON one (format: date-time).eventTimeZoneOffsetisoffset, which must matchepcisTimeZoneOffset, the pattern of the EPCIS JSON schema and the rule of EPCIS Standard Release 2.0 §7.4.1 (https://ref.gs1.org/standards/epcis/):±HH:MMfrom-14:00to+14:00. That is narrower than the offsets a pair can hold, so an offset with seconds (+05:30:00,-00:44:30), one past 14 hours (+14:30) andZreturn null, althoughfromOffsetInstantaccepts some of them. Nothing is rounded to fit.-00:00matches the GS1 pattern and is written as+00:00, the spellingparseEpcisEventreturns.instantis any instantisValidInstantaccepts:Z, an offset, or an offset with a bracketed zone. Only the instant is read, so an offset written ininstantdoes not have to equaloffset.timeZoneis not read. EPCIS has no field for a zone, so a pair’s zone is dropped, and one that is invalid or disagrees withoffsetchanges nothing.fromOffsetInstantis the function that checks a zone against its offset.eventTimehas a four-digit year, so an instant whose UTC year is outside 0000–9999 returns null.parseEpcisEventcan return one, from aneventTimewhose own offset carries it across either end of that range, and such a result cannot be written back.- Returns null when
valueis not an object, wheninstantis not a valid instant, and whenoffsetis missing, not a string, or outside the GS1 pattern.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | OffsetInstant | { instant, offset } pair, as parseEpcisEvent or toOffsetInstant returns it |
Returns
Section titled “Returns”{ eventTime, eventTimeZoneOffset }, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatEpcisEvent } from "@northguild/gmt/intermodal/format";
formatEpcisEvent({ instant: "2024-06-15T14:30:00Z", offset: "-05:00" }) // { eventTime: "2024-06-15T14:30:00Z", eventTimeZoneOffset: "-05:00" }