@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.
35 lines • 2.19 kB
TypeScript
/**
* Return true when `value` is a GS1 EPCIS 2.0 `eventTimeZoneOffset`: the UTC offset the local
* clock ran at where a supply-chain event happened, written `±HH:MM`.
*
* EPCIS (ISO/IEC 19987) is GS1's event standard for supply-chain visibility. This is the check
* `isValidEpcisEvent` applies to the event's `eventTimeZoneOffset` field: that validator calls
* this one.
*
* - The value must match `epcisTimeZoneOffset`, the pattern the EPCIS JSON schema gives: `±HH:MM`
* from `-14:00` to `+14:00`, the rule of EPCIS Standard Release 2.0 §7.4.1
* (https://ref.gs1.org/standards/epcis/).
* - **The pattern is the whole rule for a string.** Every value it matches is an offset Temporal
* reads, so this validator and `epcisTimeZoneOffset.test` agree on every string; the validator
* adds only the answer false for a non-string.
* - A value that is not a string, a `String` object included, returns false. A true result
* narrows an `unknown` value to `string`.
* - `Z`, `+0200`, `+02`, an offset with seconds and an offset past `14:00` are false.
* - `-00:00` is true: the GS1 pattern matches it. `parseEpcisEvent` returns it as `+00:00`.
* - It need not agree with an offset written in the event's `eventTime`. Check that field with
* `isValidEpcisEventTime`, or both with `isValidEpcisEvent`.
*
* @param value any value; a string is checked as an EPCIS `eventTimeZoneOffset`
* @returns boolean indicating validity
*
* @example isValidEpcisTimeZoneOffset("-05:00") // true
* @example isValidEpcisTimeZoneOffset("+14:00") // true
* @example isValidEpcisTimeZoneOffset("+14:01") // false (past the range GS1 allows)
* @example isValidEpcisTimeZoneOffset("Z") // false (a designator, not an offset)
* @example isValidEpcisTimeZoneOffset("+0200") // false (no colon)
* @example isValidEpcisTimeZoneOffset("+05:30:00") // false (seconds)
* @example isValidEpcisTimeZoneOffset(null) // false
*/
export declare function isValidEpcisTimeZoneOffset(value: string): boolean;
export declare function isValidEpcisTimeZoneOffset(value: {} | null | undefined | void): boolean;
export declare function isValidEpcisTimeZoneOffset(value: unknown): value is string;