summaryrefslogtreecommitdiff
path: root/node_modules/luxon/src/zones/fixedOffsetZone.js
diff options
context:
space:
mode:
authorShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
committerShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
commit7a52ddeba2a68388b544f529d2d92104420f77b0 (patch)
tree15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/luxon/src/zones/fixedOffsetZone.js
parent53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff)
Changed from static to 11ty!
Diffstat (limited to 'node_modules/luxon/src/zones/fixedOffsetZone.js')
-rw-r--r--node_modules/luxon/src/zones/fixedOffsetZone.js150
1 files changed, 150 insertions, 0 deletions
diff --git a/node_modules/luxon/src/zones/fixedOffsetZone.js b/node_modules/luxon/src/zones/fixedOffsetZone.js
new file mode 100644
index 0000000..b1ab4ab
--- /dev/null
+++ b/node_modules/luxon/src/zones/fixedOffsetZone.js
@@ -0,0 +1,150 @@
+import { formatOffset, signedOffset } from "../impl/util.js";
+import Zone from "../zone.js";
+
+let singleton = null;
+
+/**
+ * A zone with a fixed offset (meaning no DST)
+ * @implements {Zone}
+ */
+export default class FixedOffsetZone extends Zone {
+ /**
+ * Get a singleton instance of UTC
+ * @return {FixedOffsetZone}
+ */
+ static get utcInstance() {
+ if (singleton === null) {
+ singleton = new FixedOffsetZone(0);
+ }
+ return singleton;
+ }
+
+ /**
+ * Get an instance with a specified offset
+ * @param {number} offset - The offset in minutes
+ * @return {FixedOffsetZone}
+ */
+ static instance(offset) {
+ return offset === 0 ? FixedOffsetZone.utcInstance : new FixedOffsetZone(offset);
+ }
+
+ /**
+ * 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(s) {
+ if (s) {
+ const r = s.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);
+ if (r) {
+ return new FixedOffsetZone(signedOffset(r[1], r[2]));
+ }
+ }
+ return null;
+ }
+
+ constructor(offset) {
+ super();
+ /** @private **/
+ this.fixed = offset;
+ }
+
+ /**
+ * 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${formatOffset(this.fixed, "narrow")}`;
+ }
+
+ /**
+ * The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
+ *
+ * @override
+ * @type {string}
+ */
+ get ianaName() {
+ if (this.fixed === 0) {
+ return "Etc/UTC";
+ } else {
+ return `Etc/GMT${formatOffset(-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(ts, format) {
+ return formatOffset(this.fixed, format);
+ }
+
+ /**
+ * 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 true;
+ }
+
+ /**
+ * 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(otherZone) {
+ return otherZone.type === "fixed" && otherZone.fixed === this.fixed;
+ }
+
+ /**
+ * Return whether this Zone is valid:
+ * All fixed offset zones are valid.
+ * @override
+ * @type {boolean}
+ */
+ get isValid() {
+ return true;
+ }
+}