UNPKG

@anoki/fse-ui

Version:

FSE UI components library

127 lines (126 loc) 3.27 kB
import { signedOffset as s, formatOffset as i } from "./index.es231.js"; import u from "./index.es240.js"; let n = null; class r extends u { /** * Get a singleton instance of UTC * @return {FixedOffsetZone} */ static get utcInstance() { return n === null && (n = new r(0)), n; } /** * Get an instance with a specified offset * @param {number} offset - The offset in minutes * @return {FixedOffsetZone} */ static instance(t) { return t === 0 ? r.utcInstance : new r(t); } /** * Get an instance of FixedOffsetZone from a UTC offset string, like "UTC+6" * @param {string} s - The offset string to parse * @example FixedOffsetZone.parseSpecifier("UTC+6") * @example FixedOffsetZone.parseSpecifier("UTC+06") * @example FixedOffsetZone.parseSpecifier("UTC-6:00") * @return {FixedOffsetZone} */ static parseSpecifier(t) { if (t) { const e = t.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i); if (e) return new r(s(e[1], e[2])); } return null; } constructor(t) { super(), this.fixed = t; } /** * The type of zone. `fixed` for all instances of `FixedOffsetZone`. * @override * @type {string} */ get type() { return "fixed"; } /** * The name of this zone. * All fixed zones' names always start with "UTC" (plus optional offset) * @override * @type {string} */ get name() { return this.fixed === 0 ? "UTC" : `UTC${i(this.fixed, "narrow")}`; } /** * The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn` * * @override * @type {string} */ get ianaName() { return this.fixed === 0 ? "Etc/UTC" : `Etc/GMT${i(-this.fixed, "narrow")}`; } /** * Returns the offset's common name at the specified timestamp. * * For fixed offset zones this equals to the zone name. * @override */ offsetName() { return this.name; } /** * Returns the offset's value as a string * @override * @param {number} ts - Epoch milliseconds for which to get the offset * @param {string} format - What style of offset to return. * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively * @return {string} */ formatOffset(t, e) { return i(this.fixed, e); } /** * Returns whether the offset is known to be fixed for the whole year: * Always returns true for all fixed offset zones. * @override * @type {boolean} */ get isUniversal() { return !0; } /** * Return the offset in minutes for this zone at the specified timestamp. * * For fixed offset zones, this is constant and does not depend on a timestamp. * @override * @return {number} */ offset() { return this.fixed; } /** * Return whether this Zone is equal to another zone (i.e. also fixed and same offset) * @override * @param {Zone} otherZone - the zone to compare * @return {boolean} */ equals(t) { return t.type === "fixed" && t.fixed === this.fixed; } /** * Return whether this Zone is valid: * All fixed offset zones are valid. * @override * @type {boolean} */ get isValid() { return !0; } } export { r as default }; //# sourceMappingURL=index.es229.js.map