UNPKG

luxon

Version:
1,800 lines (1,727 loc) 294 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } // these aren't really private, but nor are they really useful to document /** * @private */ var LuxonError = /*#__PURE__*/function (_Error) { _inheritsLoose(LuxonError, _Error); function LuxonError() { return _Error.apply(this, arguments) || this; } return LuxonError; }( /*#__PURE__*/_wrapNativeSuper(Error)); /** * @private */ var InvalidDateTimeError = /*#__PURE__*/function (_LuxonError) { _inheritsLoose(InvalidDateTimeError, _LuxonError); function InvalidDateTimeError(reason) { return _LuxonError.call(this, "Invalid DateTime: " + reason.toMessage()) || this; } return InvalidDateTimeError; }(LuxonError); /** * @private */ var InvalidIntervalError = /*#__PURE__*/function (_LuxonError2) { _inheritsLoose(InvalidIntervalError, _LuxonError2); function InvalidIntervalError(reason) { return _LuxonError2.call(this, "Invalid Interval: " + reason.toMessage()) || this; } return InvalidIntervalError; }(LuxonError); /** * @private */ var InvalidDurationError = /*#__PURE__*/function (_LuxonError3) { _inheritsLoose(InvalidDurationError, _LuxonError3); function InvalidDurationError(reason) { return _LuxonError3.call(this, "Invalid Duration: " + reason.toMessage()) || this; } return InvalidDurationError; }(LuxonError); /** * @private */ var ConflictingSpecificationError = /*#__PURE__*/function (_LuxonError4) { _inheritsLoose(ConflictingSpecificationError, _LuxonError4); function ConflictingSpecificationError() { return _LuxonError4.apply(this, arguments) || this; } return ConflictingSpecificationError; }(LuxonError); /** * @private */ var InvalidUnitError = /*#__PURE__*/function (_LuxonError5) { _inheritsLoose(InvalidUnitError, _LuxonError5); function InvalidUnitError(unit) { return _LuxonError5.call(this, "Invalid unit " + unit) || this; } return InvalidUnitError; }(LuxonError); /** * @private */ var InvalidArgumentError = /*#__PURE__*/function (_LuxonError6) { _inheritsLoose(InvalidArgumentError, _LuxonError6); function InvalidArgumentError() { return _LuxonError6.apply(this, arguments) || this; } return InvalidArgumentError; }(LuxonError); /** * @private */ var ZoneIsAbstractError = /*#__PURE__*/function (_LuxonError7) { _inheritsLoose(ZoneIsAbstractError, _LuxonError7); function ZoneIsAbstractError() { return _LuxonError7.call(this, "Zone is an abstract class") || this; } return ZoneIsAbstractError; }(LuxonError); /** * @private */ var n = "numeric", s = "short", l = "long"; var DATE_SHORT = { year: n, month: n, day: n }; var DATE_MED = { year: n, month: s, day: n }; var DATE_MED_WITH_WEEKDAY = { year: n, month: s, day: n, weekday: s }; var DATE_FULL = { year: n, month: l, day: n }; var DATE_HUGE = { year: n, month: l, day: n, weekday: l }; var TIME_SIMPLE = { hour: n, minute: n }; var TIME_WITH_SECONDS = { hour: n, minute: n, second: n }; var TIME_WITH_SHORT_OFFSET = { hour: n, minute: n, second: n, timeZoneName: s }; var TIME_WITH_LONG_OFFSET = { hour: n, minute: n, second: n, timeZoneName: l }; var TIME_24_SIMPLE = { hour: n, minute: n, hourCycle: "h23" }; var TIME_24_WITH_SECONDS = { hour: n, minute: n, second: n, hourCycle: "h23" }; var TIME_24_WITH_SHORT_OFFSET = { hour: n, minute: n, second: n, hourCycle: "h23", timeZoneName: s }; var TIME_24_WITH_LONG_OFFSET = { hour: n, minute: n, second: n, hourCycle: "h23", timeZoneName: l }; var DATETIME_SHORT = { year: n, month: n, day: n, hour: n, minute: n }; var DATETIME_SHORT_WITH_SECONDS = { year: n, month: n, day: n, hour: n, minute: n, second: n }; var DATETIME_MED = { year: n, month: s, day: n, hour: n, minute: n }; var DATETIME_MED_WITH_SECONDS = { year: n, month: s, day: n, hour: n, minute: n, second: n }; var DATETIME_MED_WITH_WEEKDAY = { year: n, month: s, day: n, weekday: s, hour: n, minute: n }; var DATETIME_FULL = { year: n, month: l, day: n, hour: n, minute: n, timeZoneName: s }; var DATETIME_FULL_WITH_SECONDS = { year: n, month: l, day: n, hour: n, minute: n, second: n, timeZoneName: s }; var DATETIME_HUGE = { year: n, month: l, day: n, weekday: l, hour: n, minute: n, timeZoneName: l }; var DATETIME_HUGE_WITH_SECONDS = { year: n, month: l, day: n, weekday: l, hour: n, minute: n, second: n, timeZoneName: l }; /** * @interface */ var Zone = /*#__PURE__*/function () { function Zone() {} var _proto = Zone.prototype; /** * Returns the offset's common name (such as EST) at the specified timestamp * @abstract * @param {number} ts - Epoch milliseconds for which to get the name * @param {Object} opts - Options to affect the format * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'. * @param {string} opts.locale - What locale to return the offset name in. * @return {string} */ _proto.offsetName = function offsetName(ts, opts) { throw new ZoneIsAbstractError(); } /** * Returns the offset's value as a string * @abstract * @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} */; _proto.formatOffset = function formatOffset(ts, format) { throw new ZoneIsAbstractError(); } /** * Return the offset in minutes for this zone at the specified timestamp. * @abstract * @param {number} ts - Epoch milliseconds for which to compute the offset * @return {number} */; _proto.offset = function offset(ts) { throw new ZoneIsAbstractError(); } /** * Return whether this Zone is equal to another zone * @abstract * @param {Zone} otherZone - the zone to compare * @return {boolean} */; _proto.equals = function equals(otherZone) { throw new ZoneIsAbstractError(); } /** * Return whether this Zone is valid. * @abstract * @type {boolean} */; _createClass(Zone, [{ key: "type", get: /** * The type of zone * @abstract * @type {string} */ function get() { throw new ZoneIsAbstractError(); } /** * The name of this zone. * @abstract * @type {string} */ }, { key: "name", get: function get() { throw new ZoneIsAbstractError(); } /** * The IANA name of this zone. * Defaults to `name` if not overwritten by a subclass. * @abstract * @type {string} */ }, { key: "ianaName", get: function get() { return this.name; } /** * Returns whether the offset is known to be fixed for the whole year. * @abstract * @type {boolean} */ }, { key: "isUniversal", get: function get() { throw new ZoneIsAbstractError(); } }, { key: "isValid", get: function get() { throw new ZoneIsAbstractError(); } }]); return Zone; }(); var singleton$1 = null; /** * Represents the local zone for this JavaScript environment. * @implements {Zone} */ var SystemZone = /*#__PURE__*/function (_Zone) { _inheritsLoose(SystemZone, _Zone); function SystemZone() { return _Zone.apply(this, arguments) || this; } var _proto = SystemZone.prototype; /** @override **/ _proto.offsetName = function offsetName(ts, _ref) { var format = _ref.format, locale = _ref.locale; return parseZoneInfo(ts, format, locale); } /** @override **/; _proto.formatOffset = function formatOffset$1(ts, format) { return formatOffset(this.offset(ts), format); } /** @override **/; _proto.offset = function offset(ts) { return -new Date(ts).getTimezoneOffset(); } /** @override **/; _proto.equals = function equals(otherZone) { return otherZone.type === "system"; } /** @override **/; _createClass(SystemZone, [{ key: "type", get: /** @override **/ function get() { return "system"; } /** @override **/ }, { key: "name", get: function get() { return new Intl.DateTimeFormat().resolvedOptions().timeZone; } /** @override **/ }, { key: "isUniversal", get: function get() { return false; } }, { key: "isValid", get: function get() { return true; } }], [{ key: "instance", get: /** * Get a singleton instance of the local zone * @return {SystemZone} */ function get() { if (singleton$1 === null) { singleton$1 = new SystemZone(); } return singleton$1; } }]); return SystemZone; }(Zone); var 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", era: "short" }); } return dtfCache[zone]; } var typeToPos = { year: 0, month: 1, day: 2, era: 3, hour: 4, minute: 5, second: 6 }; function hackyOffset(dtf, date) { var formatted = dtf.format(date).replace(/\u200E/g, ""), parsed = /(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(formatted), fMonth = parsed[1], fDay = parsed[2], fYear = parsed[3], fadOrBc = parsed[4], fHour = parsed[5], fMinute = parsed[6], fSecond = parsed[7]; return [fYear, fMonth, fDay, fadOrBc, fHour, fMinute, fSecond]; } function partsOffset(dtf, date) { var formatted = dtf.formatToParts(date); var filled = []; for (var i = 0; i < formatted.length; i++) { var _formatted$i = formatted[i], type = _formatted$i.type, value = _formatted$i.value; var pos = typeToPos[type]; if (type === "era") { filled[pos] = value; } else if (!isUndefined(pos)) { filled[pos] = parseInt(value, 10); } } return filled; } var ianaZoneCache = {}; /** * A zone identified by an IANA identifier, like America/New_York * @implements {Zone} */ var IANAZone = /*#__PURE__*/function (_Zone) { _inheritsLoose(IANAZone, _Zone); /** * @param {string} name - Zone name * @return {IANAZone} */ IANAZone.create = function 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} */; IANAZone.resetCache = function 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("Sport~~blorp") //=> false * @deprecated For backward compatibility, this forwards to isValidZone, better use `isValidZone()` directly instead. * @return {boolean} */; IANAZone.isValidSpecifier = function isValidSpecifier(s) { return this.isValidZone(s); } /** * 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} */; IANAZone.isValidZone = function isValidZone(zone) { if (!zone) { return false; } try { new Intl.DateTimeFormat("en-US", { timeZone: zone }).format(); return true; } catch (e) { return false; } }; function IANAZone(name) { var _this; _this = _Zone.call(this) || this; /** @private **/ _this.zoneName = name; /** @private **/ _this.valid = IANAZone.isValidZone(name); return _this; } /** * The type of zone. `iana` for all instances of `IANAZone`. * @override * @type {string} */ var _proto = IANAZone.prototype; /** * Returns the offset's common name (such as EST) at the specified timestamp * @override * @param {number} ts - Epoch milliseconds for which to get the name * @param {Object} opts - Options to affect the format * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'. * @param {string} opts.locale - What locale to return the offset name in. * @return {string} */ _proto.offsetName = function offsetName(ts, _ref) { var format = _ref.format, locale = _ref.locale; return parseZoneInfo(ts, format, locale, 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} */; _proto.formatOffset = function formatOffset$1(ts, format) { return formatOffset(this.offset(ts), format); } /** * Return the offset in minutes for this zone at the specified timestamp. * @override * @param {number} ts - Epoch milliseconds for which to compute the offset * @return {number} */; _proto.offset = function offset(ts) { var date = new Date(ts); if (isNaN(date)) return NaN; var dtf = makeDTF(this.name); var _ref2 = dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date), year = _ref2[0], month = _ref2[1], day = _ref2[2], adOrBc = _ref2[3], hour = _ref2[4], minute = _ref2[5], second = _ref2[6]; if (adOrBc === "BC") { year = -Math.abs(year) + 1; } // because we're using hour12 and https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat var adjustedHour = hour === 24 ? 0 : hour; var asUTC = objToLocalTS({ year: year, month: month, day: day, hour: adjustedHour, minute: minute, second: second, millisecond: 0 }); var asTS = +date; var over = asTS % 1000; asTS -= over >= 0 ? over : 1000 + over; return (asUTC - asTS) / (60 * 1000); } /** * Return whether this Zone is equal to another zone * @override * @param {Zone} otherZone - the zone to compare * @return {boolean} */; _proto.equals = function equals(otherZone) { return otherZone.type === "iana" && otherZone.name === this.name; } /** * Return whether this Zone is valid. * @override * @type {boolean} */; _createClass(IANAZone, [{ key: "type", get: function get() { return "iana"; } /** * The name of this zone (i.e. the IANA zone name). * @override * @type {string} */ }, { key: "name", get: function get() { return this.zoneName; } /** * Returns whether the offset is known to be fixed for the whole year: * Always returns false for all IANA zones. * @override * @type {boolean} */ }, { key: "isUniversal", get: function get() { return false; } }, { key: "isValid", get: function get() { return this.valid; } }]); return IANAZone; }(Zone); var _excluded = ["base"], _excluded2 = ["padTo", "floor"]; // todo - remap caching var intlLFCache = {}; function getCachedLF(locString, opts) { if (opts === void 0) { opts = {}; } var key = JSON.stringify([locString, opts]); var dtf = intlLFCache[key]; if (!dtf) { dtf = new Intl.ListFormat(locString, opts); intlLFCache[key] = dtf; } return dtf; } var intlDTCache = {}; function getCachedDTF(locString, opts) { if (opts === void 0) { opts = {}; } var key = JSON.stringify([locString, opts]); var dtf = intlDTCache[key]; if (!dtf) { dtf = new Intl.DateTimeFormat(locString, opts); intlDTCache[key] = dtf; } return dtf; } var intlNumCache = {}; function getCachedINF(locString, opts) { if (opts === void 0) { opts = {}; } var key = JSON.stringify([locString, opts]); var inf = intlNumCache[key]; if (!inf) { inf = new Intl.NumberFormat(locString, opts); intlNumCache[key] = inf; } return inf; } var intlRelCache = {}; function getCachedRTF(locString, opts) { if (opts === void 0) { opts = {}; } var _opts = opts; _opts.base; var cacheKeyOpts = _objectWithoutPropertiesLoose(_opts, _excluded); // exclude `base` from the options var key = JSON.stringify([locString, cacheKeyOpts]); var inf = intlRelCache[key]; if (!inf) { inf = new Intl.RelativeTimeFormat(locString, opts); intlRelCache[key] = inf; } return inf; } var sysLocaleCache = null; function systemLocale() { if (sysLocaleCache) { return sysLocaleCache; } else { sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale; return sysLocaleCache; } } var weekInfoCache = {}; function getCachedWeekInfo(locString) { var data = weekInfoCache[locString]; if (!data) { var locale = new Intl.Locale(locString); // browsers currently implement this as a property, but spec says it should be a getter function data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo; weekInfoCache[locString] = data; } return data; } function parseLocaleString(localeStr) { // I really want to avoid writing a BCP 47 parser // see, e.g. https://github.com/wooorm/bcp-47 // Instead, we'll do this: // a) if the string has no -u extensions, just leave it alone // b) if it does, use Intl to resolve everything // c) if Intl fails, try again without the -u // private subtags and unicode subtags have ordering requirements, // and we're not properly parsing this, so just strip out the // private ones if they exist. var xIndex = localeStr.indexOf("-x-"); if (xIndex !== -1) { localeStr = localeStr.substring(0, xIndex); } var uIndex = localeStr.indexOf("-u-"); if (uIndex === -1) { return [localeStr]; } else { var options; var selectedStr; try { options = getCachedDTF(localeStr).resolvedOptions(); selectedStr = localeStr; } catch (e) { var smaller = localeStr.substring(0, uIndex); options = getCachedDTF(smaller).resolvedOptions(); selectedStr = smaller; } var _options = options, numberingSystem = _options.numberingSystem, calendar = _options.calendar; return [selectedStr, numberingSystem, calendar]; } } function intlConfigString(localeStr, numberingSystem, outputCalendar) { if (outputCalendar || numberingSystem) { if (!localeStr.includes("-u-")) { localeStr += "-u"; } if (outputCalendar) { localeStr += "-ca-" + outputCalendar; } if (numberingSystem) { localeStr += "-nu-" + numberingSystem; } return localeStr; } else { return localeStr; } } function mapMonths(f) { var ms = []; for (var i = 1; i <= 12; i++) { var dt = DateTime.utc(2009, i, 1); ms.push(f(dt)); } return ms; } function mapWeekdays(f) { var ms = []; for (var i = 1; i <= 7; i++) { var dt = DateTime.utc(2016, 11, 13 + i); ms.push(f(dt)); } return ms; } function listStuff(loc, length, englishFn, intlFn) { var mode = loc.listingMode(); if (mode === "error") { return null; } else if (mode === "en") { return englishFn(length); } else { return intlFn(length); } } function supportsFastNumbers(loc) { if (loc.numberingSystem && loc.numberingSystem !== "latn") { return false; } else { return loc.numberingSystem === "latn" || !loc.locale || loc.locale.startsWith("en") || new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn"; } } /** * @private */ var PolyNumberFormatter = /*#__PURE__*/function () { function PolyNumberFormatter(intl, forceSimple, opts) { this.padTo = opts.padTo || 0; this.floor = opts.floor || false; opts.padTo; opts.floor; var otherOpts = _objectWithoutPropertiesLoose(opts, _excluded2); if (!forceSimple || Object.keys(otherOpts).length > 0) { var intlOpts = _extends({ useGrouping: false }, opts); if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo; this.inf = getCachedINF(intl, intlOpts); } } var _proto = PolyNumberFormatter.prototype; _proto.format = function format(i) { if (this.inf) { var fixed = this.floor ? Math.floor(i) : i; return this.inf.format(fixed); } else { // to match the browser's numberformatter defaults var _fixed = this.floor ? Math.floor(i) : roundTo(i, 3); return padStart(_fixed, this.padTo); } }; return PolyNumberFormatter; }(); /** * @private */ var PolyDateFormatter = /*#__PURE__*/function () { function PolyDateFormatter(dt, intl, opts) { this.opts = opts; this.originalZone = undefined; var z = undefined; if (this.opts.timeZone) { // Don't apply any workarounds if a timeZone is explicitly provided in opts this.dt = dt; } else if (dt.zone.type === "fixed") { // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like. // That is why fixed-offset TZ is set to that unless it is: // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT. // 2. Unsupported by the browser: // - some do not support Etc/ // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata var gmtOffset = -1 * (dt.offset / 60); var offsetZ = gmtOffset >= 0 ? "Etc/GMT+" + gmtOffset : "Etc/GMT" + gmtOffset; if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) { z = offsetZ; this.dt = dt; } else { // Not all fixed-offset zones like Etc/+4:30 are present in tzdata so // we manually apply the offset and substitute the zone as needed. z = "UTC"; this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset }); this.originalZone = dt.zone; } } else if (dt.zone.type === "system") { this.dt = dt; } else if (dt.zone.type === "iana") { this.dt = dt; z = dt.zone.name; } else { // Custom zones can have any offset / offsetName so we just manually // apply the offset and substitute the zone as needed. z = "UTC"; this.dt = dt.setZone("UTC").plus({ minutes: dt.offset }); this.originalZone = dt.zone; } var intlOpts = _extends({}, this.opts); intlOpts.timeZone = intlOpts.timeZone || z; this.dtf = getCachedDTF(intl, intlOpts); } var _proto2 = PolyDateFormatter.prototype; _proto2.format = function format() { if (this.originalZone) { // If we have to substitute in the actual zone name, we have to use // formatToParts so that the timezone can be replaced. return this.formatToParts().map(function (_ref) { var value = _ref.value; return value; }).join(""); } return this.dtf.format(this.dt.toJSDate()); }; _proto2.formatToParts = function formatToParts() { var _this = this; var parts = this.dtf.formatToParts(this.dt.toJSDate()); if (this.originalZone) { return parts.map(function (part) { if (part.type === "timeZoneName") { var offsetName = _this.originalZone.offsetName(_this.dt.ts, { locale: _this.dt.locale, format: _this.opts.timeZoneName }); return _extends({}, part, { value: offsetName }); } else { return part; } }); } return parts; }; _proto2.resolvedOptions = function resolvedOptions() { return this.dtf.resolvedOptions(); }; return PolyDateFormatter; }(); /** * @private */ var PolyRelFormatter = /*#__PURE__*/function () { function PolyRelFormatter(intl, isEnglish, opts) { this.opts = _extends({ style: "long" }, opts); if (!isEnglish && hasRelative()) { this.rtf = getCachedRTF(intl, opts); } } var _proto3 = PolyRelFormatter.prototype; _proto3.format = function format(count, unit) { if (this.rtf) { return this.rtf.format(count, unit); } else { return formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long"); } }; _proto3.formatToParts = function formatToParts(count, unit) { if (this.rtf) { return this.rtf.formatToParts(count, unit); } else { return []; } }; return PolyRelFormatter; }(); var fallbackWeekSettings = { firstDay: 1, minimalDays: 4, weekend: [6, 7] }; /** * @private */ var Locale = /*#__PURE__*/function () { Locale.fromOpts = function fromOpts(opts) { return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.weekSettings, opts.defaultToEN); }; Locale.create = function create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN) { if (defaultToEN === void 0) { defaultToEN = false; } var specifiedLocale = locale || Settings.defaultLocale; // the system locale is useful for human-readable strings but annoying for parsing/formatting known formats var localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale()); var numberingSystemR = numberingSystem || Settings.defaultNumberingSystem; var outputCalendarR = outputCalendar || Settings.defaultOutputCalendar; var weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings; return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale); }; Locale.resetCache = function resetCache() { sysLocaleCache = null; intlDTCache = {}; intlNumCache = {}; intlRelCache = {}; }; Locale.fromObject = function fromObject(_temp) { var _ref2 = _temp === void 0 ? {} : _temp, locale = _ref2.locale, numberingSystem = _ref2.numberingSystem, outputCalendar = _ref2.outputCalendar, weekSettings = _ref2.weekSettings; return Locale.create(locale, numberingSystem, outputCalendar, weekSettings); }; function Locale(locale, numbering, outputCalendar, weekSettings, specifiedLocale) { var _parseLocaleString = parseLocaleString(locale), parsedLocale = _parseLocaleString[0], parsedNumberingSystem = _parseLocaleString[1], parsedOutputCalendar = _parseLocaleString[2]; this.locale = parsedLocale; this.numberingSystem = numbering || parsedNumberingSystem || null; this.outputCalendar = outputCalendar || parsedOutputCalendar || null; this.weekSettings = weekSettings; this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar); this.weekdaysCache = { format: {}, standalone: {} }; this.monthsCache = { format: {}, standalone: {} }; this.meridiemCache = null; this.eraCache = {}; this.specifiedLocale = specifiedLocale; this.fastNumbersCached = null; } var _proto4 = Locale.prototype; _proto4.listingMode = function listingMode() { var isActuallyEn = this.isEnglish(); var hasNoWeirdness = (this.numberingSystem === null || this.numberingSystem === "latn") && (this.outputCalendar === null || this.outputCalendar === "gregory"); return isActuallyEn && hasNoWeirdness ? "en" : "intl"; }; _proto4.clone = function clone(alts) { if (!alts || Object.getOwnPropertyNames(alts).length === 0) { return this; } else { return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, validateWeekSettings(alts.weekSettings) || this.weekSettings, alts.defaultToEN || false); } }; _proto4.redefaultToEN = function redefaultToEN(alts) { if (alts === void 0) { alts = {}; } return this.clone(_extends({}, alts, { defaultToEN: true })); }; _proto4.redefaultToSystem = function redefaultToSystem(alts) { if (alts === void 0) { alts = {}; } return this.clone(_extends({}, alts, { defaultToEN: false })); }; _proto4.months = function months$1(length, format) { var _this2 = this; if (format === void 0) { format = false; } return listStuff(this, length, months, function () { var intl = format ? { month: length, day: "numeric" } : { month: length }, formatStr = format ? "format" : "standalone"; if (!_this2.monthsCache[formatStr][length]) { _this2.monthsCache[formatStr][length] = mapMonths(function (dt) { return _this2.extract(dt, intl, "month"); }); } return _this2.monthsCache[formatStr][length]; }); }; _proto4.weekdays = function weekdays$1(length, format) { var _this3 = this; if (format === void 0) { format = false; } return listStuff(this, length, weekdays, function () { var intl = format ? { weekday: length, year: "numeric", month: "long", day: "numeric" } : { weekday: length }, formatStr = format ? "format" : "standalone"; if (!_this3.weekdaysCache[formatStr][length]) { _this3.weekdaysCache[formatStr][length] = mapWeekdays(function (dt) { return _this3.extract(dt, intl, "weekday"); }); } return _this3.weekdaysCache[formatStr][length]; }); }; _proto4.meridiems = function meridiems$1() { var _this4 = this; return listStuff(this, undefined, function () { return meridiems; }, function () { // In theory there could be aribitrary day periods. We're gonna assume there are exactly two // for AM and PM. This is probably wrong, but it's makes parsing way easier. if (!_this4.meridiemCache) { var intl = { hour: "numeric", hourCycle: "h12" }; _this4.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map(function (dt) { return _this4.extract(dt, intl, "dayperiod"); }); } return _this4.meridiemCache; }); }; _proto4.eras = function eras$1(length) { var _this5 = this; return listStuff(this, length, eras, function () { var intl = { era: length }; // This is problematic. Different calendars are going to define eras totally differently. What I need is the minimum set of dates // to definitely enumerate them. if (!_this5.eraCache[length]) { _this5.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map(function (dt) { return _this5.extract(dt, intl, "era"); }); } return _this5.eraCache[length]; }); }; _proto4.extract = function extract(dt, intlOpts, field) { var df = this.dtFormatter(dt, intlOpts), results = df.formatToParts(), matching = results.find(function (m) { return m.type.toLowerCase() === field; }); return matching ? matching.value : null; }; _proto4.numberFormatter = function numberFormatter(opts) { if (opts === void 0) { opts = {}; } // this forcesimple option is never used (the only caller short-circuits on it, but it seems safer to leave) // (in contrast, the rest of the condition is used heavily) return new PolyNumberFormatter(this.intl, opts.forceSimple || this.fastNumbers, opts); }; _proto4.dtFormatter = function dtFormatter(dt, intlOpts) { if (intlOpts === void 0) { intlOpts = {}; } return new PolyDateFormatter(dt, this.intl, intlOpts); }; _proto4.relFormatter = function relFormatter(opts) { if (opts === void 0) { opts = {}; } return new PolyRelFormatter(this.intl, this.isEnglish(), opts); }; _proto4.listFormatter = function listFormatter(opts) { if (opts === void 0) { opts = {}; } return getCachedLF(this.intl, opts); }; _proto4.isEnglish = function isEnglish() { return this.locale === "en" || this.locale.toLowerCase() === "en-us" || new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us"); }; _proto4.getWeekSettings = function getWeekSettings() { if (this.weekSettings) { return this.weekSettings; } else if (!hasLocaleWeekInfo()) { return fallbackWeekSettings; } else { return getCachedWeekInfo(this.locale); } }; _proto4.getStartOfWeek = function getStartOfWeek() { return this.getWeekSettings().firstDay; }; _proto4.getMinDaysInFirstWeek = function getMinDaysInFirstWeek() { return this.getWeekSettings().minimalDays; }; _proto4.getWeekendDays = function getWeekendDays() { return this.getWeekSettings().weekend; }; _proto4.equals = function equals(other) { return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar; }; _proto4.toString = function toString() { return "Locale(" + this.locale + ", " + this.numberingSystem + ", " + this.outputCalendar + ")"; }; _createClass(Locale, [{ key: "fastNumbers", get: function get() { if (this.fastNumbersCached == null) { this.fastNumbersCached = supportsFastNumbers(this); } return this.fastNumbersCached; } }]); return Locale; }(); var singleton = null; /** * A zone with a fixed offset (meaning no DST) * @implements {Zone} */ var FixedOffsetZone = /*#__PURE__*/function (_Zone) { _inheritsLoose(FixedOffsetZone, _Zone); /** * Get an instance with a specified offset * @param {number} offset - The offset in minutes * @return {FixedOffsetZone} */ FixedOffsetZone.instance = function 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} */; FixedOffsetZone.parseSpecifier = function parseSpecifier(s) { if (s) { var r = s.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i); if (r) { return new FixedOffsetZone(signedOffset(r[1], r[2])); } } return null; }; function FixedOffsetZone(offset) { var _this; _this = _Zone.call(this) || this; /** @private **/ _this.fixed = offset; return _this; } /** * The type of zone. `fixed` for all instances of `FixedOffsetZone`. * @override * @type {string} */ var _proto = FixedOffsetZone.prototype; /** * Returns the offset's common name at the specified timestamp. * * For fixed offset zones this equals to the zone name. * @override */ _proto.offsetName = function 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} */; _proto.formatOffset = function formatOffset$1(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} */; /** * 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} */ _proto.offset = function 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} */; _proto.equals = function 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} */; _createClass(FixedOffsetZone, [{ key: "type", get: function get() { return "fixed"; } /** * The name of this zone. * All fixed zones' names always start with "UTC" (plus optional offset) * @override * @type {string} */ }, { key: "name", get: function get() { 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} */ }, { key: "ianaName", get: function get() { if (this.fixed === 0) { return "Etc/UTC"; } else { return "Etc/GMT" + formatOffset(-this.fixed, "narrow"); } } }, { key: "isUniversal", get: function get() { return true; } }, { key: "isValid", get: function get() { return true; } }], [{ key: "utcInstance", get: /** * Get a singleton instance of UTC * @return {FixedOffsetZone} */ function get() { if (singleton === null) { singleton = new FixedOffsetZone(0); } return singleton; } }]); return FixedOffsetZone; }(Zone); /** * A zone that failed to parse. You should never need to instantiate this. * @implements {Zone} */ var InvalidZone = /*#__PURE__*/function (_Zone) { _inheritsLoose(InvalidZone, _Zone); function InvalidZone(zoneName) { var _this; _this = _Zone.call(this) || this; /** @private */ _this.zoneName = zoneName; return _this; } /** @override **/ var _proto = InvalidZone.prototype; /** @override **/ _proto.offsetName = function offsetName() { return null; } /** @override **/; _proto.formatOffset = function formatOffset() { return ""; } /** @override **/; _proto.offset = function offset() { return NaN; } /** @override **/; _proto.equals = function equals() { return false; } /** @override **/; _createClass(InvalidZone, [{ key: "type", get: function get() { return "invalid"; } /** @override **/ }, { key: "name", get: function get() { return this.zoneName; } /** @override **/ }, { key: "isUniversal", get: function get() { return false; } }, { key: "isValid", get: function get() { return false; } }]); return InvalidZone; }(Zone); /** * @private */ function normalizeZone(input, defaultZone) { if (isUndefined(input) || input === null) { return defaultZone; } else if (input instanceof Zone) { return input; } else if (isString(input)) { var lowered = input.toLowerCase(); if (lowered === "default") return defaultZone;else if (lowered === "local" || lowered === "system") return SystemZone.instance;else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;else return FixedOffsetZone.parseSpecifier(lowered) || IANAZone.create(input); } else if (isNumber(input)) { return FixedOffsetZone.instance(input); } else if (typeof input === "object" && "offset" in input && typeof input.offset === "function") { // This is dumb, but the instanceof check above doesn't seem to really work // so we're duck checking it return input; } else { return new InvalidZone(input); } } var numberingSystems = { arab: "[\u0660-\u0669]", arabext: "[\u06F0-\u06F9]", bali: "[\u1B50-\u1B59]", beng: "[\u09E6-\u09EF]", deva: "[\u0966-\u096F]", fullwide: "[\uFF10-\uFF19]", gujr: "[\u0AE6-\u0AEF]", hanidec: "[〇|一|二|三|四|五|六|七|八|九]", khmr: "[\u17E0-\u17E9]", knda: "[\u0CE6-\u0CEF]", laoo: "[\u0ED0-\u0ED9]", limb: "[\u1946-\u194F]", mlym: "[\u0D66-\u0D6F]", mong: "[\u1810-\u1819]", mymr: "[\u1040-\u1049]", orya: "[\u0B66-\u0B6F]", tamldec: "[\u0BE6-\u0BEF]", telu: "[\u0C66-\u0C6F]", thai: "[\u0E50-\u0E59]", tibt: "[\u0F20-\u0F29]", latn: "\\d" }; var numberingSystemsUTF16 = { arab: [1632, 1641], arabext: [1776, 1785], bali: [6992, 7001], beng: [2534, 2543], deva: [2406, 2415], fullwide: [65296, 65303], gujr: [2790, 2799], khmr: [6112, 6121], knda: [3302, 3311], laoo: [3792, 3801], limb: [6470, 6479], mlym: [3430, 3439], mong: [6160, 6169], mymr: [4160, 4169], orya: [2918, 2927], tamldec: [3046, 3055], telu: [3174, 3183], thai: [3664, 3673], tibt: [3872, 3881] }; var hanidecChars = numberingSystems.hanidec.replace(/[\[|\]]/g, "").split(""); function parseDigits(str) { var value = parseInt(str, 10); if (isNaN(value)) { value = ""; for (var i = 0; i < str.length; i++) { var code = str.charCodeAt(i); if (str[i].search(numberingSystems.hanidec) !== -1) { value += hanidecChars.indexOf(str[i]); } else { for (var key in numberingSystemsUTF16) { var _numberingSystemsUTF = numberingSystemsUTF16[key], min = _numberingSystemsUTF[0], max = _numberingSystemsUTF[1]; if (code >= min && code <= max) { value += code - min; } } } } return parseInt(value, 10); } else { return value; } } // cache of {numberingSystem: {append: regex}} var digitRegexCache = {}; function resetDigitRegexCache() { digitRegexCache = {}; } function digitRegex(_ref, append) { var numberingSystem = _ref.numberingSystem; if (append === void 0) { append = ""; } var ns = numberingSystem || "latn"; if (!digitRegexCache[ns]) { digitRegexCache[ns] = {}; } if (!digitRegexCache[ns][append]) { digitRegexCache[ns][append] = new RegExp("" + numberingSystems[ns] + append); } return digitRegexCache[ns][append]; } var now = function now() { return Date.now(); }, defaultZone = "system", defaultLocale = null, defaultNumberingSystem = null, defaultOutputCalendar = null, twoDigitCutoffYear = 60, throwOnInvalid, defaultWeekSettings = null; /** * Settings contains static getters and setters that control Luxon's overall behavior. Luxon is a simple library with few options, but the ones it does have live here. */ var Settings = /*#__PURE__*/function () { function Settings() {} /** * Reset Luxon's global caches. Should only be necessary in testing scenarios. * @return {void} */ Settings.resetCaches = function resetCaches() { Locale.resetCache(); IANAZone.resetCache(); DateTime.resetCache(); resetDigitRegexCache(); }; _createClass(Settings, null, [{ key: "now", get: /** * Get the callback for returning the current timestamp. * @type {function} */ function get() { return now; } /** * Set the callback for returning the current timestamp. * The function should return a number, which will be interpreted as an Epoch millisecond count * @type {function} * @example Settings.now = () => Date.now() + 3000 // pretend it is 3 seconds in the future * @example Settings.now = () => 0 // always pretend it's Jan 1, 1970 at midnight in UTC time */, set: function set(n) { now = n; } /** * Set the default time zone to create DateTimes in. Does not affect existing instances. * Use the value "system" to reset this value to the system's time zone. * @type {string} */ }, { key: "defaultZone", get: /** * Get the default time zone object currently used to create DateTimes. Does not affect existing instances.