summaryrefslogtreecommitdiffstats
path: root/npm_assets/node_modules/luxon/src/zones
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-02-03 19:17:00 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-02-03 19:17:00 -0500
commit3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 (patch)
treea7cf56282e54f05785243bc1e903d6594f2c06ba /npm_assets/node_modules/luxon/src/zones
parent787b97a4cb24330b36f11297c6d3a7a473a907d0 (diff)
New upstream version 8.1.2.upstream/8.1.2
Diffstat (limited to 'npm_assets/node_modules/luxon/src/zones')
-rw-r--r--npm_assets/node_modules/luxon/src/zones/IANAZone.js188
-rw-r--r--npm_assets/node_modules/luxon/src/zones/fixedOffsetZone.js94
-rw-r--r--npm_assets/node_modules/luxon/src/zones/invalidZone.js53
-rw-r--r--npm_assets/node_modules/luxon/src/zones/localZone.js63
4 files changed, 398 insertions, 0 deletions
diff --git a/npm_assets/node_modules/luxon/src/zones/IANAZone.js b/npm_assets/node_modules/luxon/src/zones/IANAZone.js
new file mode 100644
index 0000000..e2ad296
--- /dev/null
+++ b/npm_assets/node_modules/luxon/src/zones/IANAZone.js
@@ -0,0 +1,188 @@
+import { formatOffset, parseZoneInfo, isUndefined, ianaRegex, objToLocalTS } from "../impl/util.js";
+import Zone from "../zone.js";
+
+const matchingRegex = RegExp(`^${ianaRegex.source}$`);
+
+let dtfCache = {};
+function makeDTF(zone) {
+ if (!dtfCache[zone]) {
+ dtfCache[zone] = new Intl.DateTimeFormat("en-US", {
+ hour12: false,
+ timeZone: zone,
+ year: "numeric",
+ month: "2-digit",
+ day: "2-digit",
+ hour: "2-digit",
+ minute: "2-digit",
+ second: "2-digit"
+ });
+ }
+ return dtfCache[zone];
+}
+
+const typeToPos = {
+ year: 0,
+ month: 1,
+ day: 2,
+ hour: 3,
+ minute: 4,
+ second: 5
+};
+
+function hackyOffset(dtf, date) {
+ const formatted = dtf.format(date).replace(/\u200E/g, ""),
+ parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted),
+ [, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed;
+ return [fYear, fMonth, fDay, fHour, fMinute, fSecond];
+}
+
+function partsOffset(dtf, date) {
+ const formatted = dtf.formatToParts(date),
+ filled = [];
+ for (let i = 0; i < formatted.length; i++) {
+ const { type, value } = formatted[i],
+ pos = typeToPos[type];
+
+ if (!isUndefined(pos)) {
+ filled[pos] = parseInt(value, 10);
+ }
+ }
+ return filled;
+}
+
+let ianaZoneCache = {};
+/**
+ * A zone identified by an IANA identifier, like America/New_York
+ * @implements {Zone}
+ */
+export default class IANAZone extends Zone {
+ /**
+ * @param {string} name - Zone name
+ * @return {IANAZone}
+ */
+ static create(name) {
+ if (!ianaZoneCache[name]) {
+ ianaZoneCache[name] = new IANAZone(name);
+ }
+ return ianaZoneCache[name];
+ }
+
+ /**
+ * Reset local caches. Should only be necessary in testing scenarios.
+ * @return {void}
+ */
+ static resetCache() {
+ ianaZoneCache = {};
+ dtfCache = {};
+ }
+
+ /**
+ * Returns whether the provided string is a valid specifier. This only checks the string's format, not that the specifier identifies a known zone; see isValidZone for that.
+ * @param {string} s - The string to check validity on
+ * @example IANAZone.isValidSpecifier("America/New_York") //=> true
+ * @example IANAZone.isValidSpecifier("Fantasia/Castle") //=> true
+ * @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false
+ * @return {boolean}
+ */
+ static isValidSpecifier(s) {
+ return !!(s && s.match(matchingRegex));
+ }
+
+ /**
+ * Returns whether the provided string identifies a real zone
+ * @param {string} zone - The string to check
+ * @example IANAZone.isValidZone("America/New_York") //=> true
+ * @example IANAZone.isValidZone("Fantasia/Castle") //=> false
+ * @example IANAZone.isValidZone("Sport~~blorp") //=> false
+ * @return {boolean}
+ */
+ static isValidZone(zone) {
+ try {
+ new Intl.DateTimeFormat("en-US", { timeZone: zone }).format();
+ return true;
+ } catch (e) {
+ return false;
+ }
+ }
+
+ // Etc/GMT+8 -> -480
+ /** @ignore */
+ static parseGMTOffset(specifier) {
+ if (specifier) {
+ const match = specifier.match(/^Etc\/GMT([+-]\d{1,2})$/i);
+ if (match) {
+ return -60 * parseInt(match[1]);
+ }
+ }
+ return null;
+ }
+
+ constructor(name) {
+ super();
+ /** @private **/
+ this.zoneName = name;
+ /** @private **/
+ this.valid = IANAZone.isValidZone(name);
+ }
+
+ /** @override **/
+ get type() {
+ return "iana";
+ }
+
+ /** @override **/
+ get name() {
+ return this.zoneName;
+ }
+
+ /** @override **/
+ get universal() {
+ return false;
+ }
+
+ /** @override **/
+ offsetName(ts, { format, locale }) {
+ return parseZoneInfo(ts, format, locale, this.name);
+ }
+
+ /** @override **/
+ formatOffset(ts, format) {
+ return formatOffset(this.offset(ts), format);
+ }
+
+ /** @override **/
+ offset(ts) {
+ const date = new Date(ts),
+ dtf = makeDTF(this.name),
+ [year, month, day, hour, minute, second] = dtf.formatToParts
+ ? partsOffset(dtf, date)
+ : hackyOffset(dtf, date),
+ // work around https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat
+ adjustedHour = hour === 24 ? 0 : hour;
+
+ const asUTC = objToLocalTS({
+ year,
+ month,
+ day,
+ hour: adjustedHour,
+ minute,
+ second,
+ millisecond: 0
+ });
+
+ let asTS = +date;
+ const over = asTS % 1000;
+ asTS -= over >= 0 ? over : 1000 + over;
+ return (asUTC - asTS) / (60 * 1000);
+ }
+
+ /** @override **/
+ equals(otherZone) {
+ return otherZone.type === "iana" && otherZone.name === this.name;
+ }
+
+ /** @override **/
+ get isValid() {
+ return this.valid;
+ }
+}
diff --git a/npm_assets/node_modules/luxon/src/zones/fixedOffsetZone.js b/npm_assets/node_modules/luxon/src/zones/fixedOffsetZone.js
new file mode 100644
index 0000000..364e065
--- /dev/null
+++ b/npm_assets/node_modules/luxon/src/zones/fixedOffsetZone.js
@@ -0,0 +1,94 @@
+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;
+ }
+
+ /** @override **/
+ get type() {
+ return "fixed";
+ }
+
+ /** @override **/
+ get name() {
+ return this.fixed === 0 ? "UTC" : `UTC${formatOffset(this.fixed, "narrow")}`;
+ }
+
+ /** @override **/
+ offsetName() {
+ return this.name;
+ }
+
+ /** @override **/
+ formatOffset(ts, format) {
+ return formatOffset(this.fixed, format);
+ }
+
+ /** @override **/
+ get universal() {
+ return true;
+ }
+
+ /** @override **/
+ offset() {
+ return this.fixed;
+ }
+
+ /** @override **/
+ equals(otherZone) {
+ return otherZone.type === "fixed" && otherZone.fixed === this.fixed;
+ }
+
+ /** @override **/
+ get isValid() {
+ return true;
+ }
+}
diff --git a/npm_assets/node_modules/luxon/src/zones/invalidZone.js b/npm_assets/node_modules/luxon/src/zones/invalidZone.js
new file mode 100644
index 0000000..d7b7104
--- /dev/null
+++ b/npm_assets/node_modules/luxon/src/zones/invalidZone.js
@@ -0,0 +1,53 @@
+import Zone from "../zone.js";
+
+/**
+ * A zone that failed to parse. You should never need to instantiate this.
+ * @implements {Zone}
+ */
+export default class InvalidZone extends Zone {
+ constructor(zoneName) {
+ super();
+ /** @private */
+ this.zoneName = zoneName;
+ }
+
+ /** @override **/
+ get type() {
+ return "invalid";
+ }
+
+ /** @override **/
+ get name() {
+ return this.zoneName;
+ }
+
+ /** @override **/
+ get universal() {
+ return false;
+ }
+
+ /** @override **/
+ offsetName() {
+ return null;
+ }
+
+ /** @override **/
+ formatOffset() {
+ return "";
+ }
+
+ /** @override **/
+ offset() {
+ return NaN;
+ }
+
+ /** @override **/
+ equals() {
+ return false;
+ }
+
+ /** @override **/
+ get isValid() {
+ return false;
+ }
+}
diff --git a/npm_assets/node_modules/luxon/src/zones/localZone.js b/npm_assets/node_modules/luxon/src/zones/localZone.js
new file mode 100644
index 0000000..b8cbcdc
--- /dev/null
+++ b/npm_assets/node_modules/luxon/src/zones/localZone.js
@@ -0,0 +1,63 @@
+import { formatOffset, parseZoneInfo, hasIntl } from "../impl/util.js";
+import Zone from "../zone.js";
+
+let singleton = null;
+
+/**
+ * Represents the local zone for this Javascript environment.
+ * @implements {Zone}
+ */
+export default class LocalZone extends Zone {
+ /**
+ * Get a singleton instance of the local zone
+ * @return {LocalZone}
+ */
+ static get instance() {
+ if (singleton === null) {
+ singleton = new LocalZone();
+ }
+ return singleton;
+ }
+
+ /** @override **/
+ get type() {
+ return "local";
+ }
+
+ /** @override **/
+ get name() {
+ if (hasIntl()) {
+ return new Intl.DateTimeFormat().resolvedOptions().timeZone;
+ } else return "local";
+ }
+
+ /** @override **/
+ get universal() {
+ return false;
+ }
+
+ /** @override **/
+ offsetName(ts, { format, locale }) {
+ return parseZoneInfo(ts, format, locale);
+ }
+
+ /** @override **/
+ formatOffset(ts, format) {
+ return formatOffset(this.offset(ts), format);
+ }
+
+ /** @override **/
+ offset(ts) {
+ return -new Date(ts).getTimezoneOffset();
+ }
+
+ /** @override **/
+ equals(otherZone) {
+ return otherZone.type === "local";
+ }
+
+ /** @override **/
+ get isValid() {
+ return true;
+ }
+}