@shopify/dates
Advanced tools
Comparing version 0.5.0-sk-next-beta.0 to 0.5.0-sk-next-beta.1
@@ -14,42 +14,24 @@ "use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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 _decorate(decorators, factory, superClass, mixins) { var api = _getDecoratorsApi(); if (mixins) { for (var i = 0; i < mixins.length; i++) { api = mixins[i](api); } } var r = factory(function initialize(O) { api.initializeInstanceElements(O, decorated.elements); }, superClass); var decorated = api.decorateClass(_coalesceClassElements(r.d.map(_createElementDescriptor)), decorators); api.initializeClassElements(r.F, decorated.elements); return api.runClassFinishers(r.F, decorated.finishers); } | ||
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 _getDecoratorsApi() { _getDecoratorsApi = function _getDecoratorsApi() { return api; }; var api = { elementsDefinitionOrder: [["method"], ["field"]], initializeInstanceElements: function initializeInstanceElements(O, elements) { ["method", "field"].forEach(function (kind) { elements.forEach(function (element) { if (element.kind === kind && element.placement === "own") { this.defineClassElement(O, element); } }, this); }, this); }, initializeClassElements: function initializeClassElements(F, elements) { var proto = F.prototype; ["method", "field"].forEach(function (kind) { elements.forEach(function (element) { var placement = element.placement; if (element.kind === kind && (placement === "static" || placement === "prototype")) { var receiver = placement === "static" ? F : proto; this.defineClassElement(receiver, element); } }, this); }, this); }, defineClassElement: function defineClassElement(receiver, element) { var descriptor = element.descriptor; if (element.kind === "field") { var initializer = element.initializer; descriptor = { enumerable: descriptor.enumerable, writable: descriptor.writable, configurable: descriptor.configurable, value: initializer === void 0 ? void 0 : initializer.call(receiver) }; } Object.defineProperty(receiver, element.key, descriptor); }, decorateClass: function decorateClass(elements, decorators) { var newElements = []; var finishers = []; var placements = { "static": [], prototype: [], own: [] }; elements.forEach(function (element) { this.addElementPlacement(element, placements); }, this); elements.forEach(function (element) { if (!_hasDecorators(element)) return newElements.push(element); var elementFinishersExtras = this.decorateElement(element, placements); newElements.push(elementFinishersExtras.element); newElements.push.apply(newElements, elementFinishersExtras.extras); finishers.push.apply(finishers, elementFinishersExtras.finishers); }, this); if (!decorators) { return { elements: newElements, finishers: finishers }; } var result = this.decorateConstructor(newElements, decorators); finishers.push.apply(finishers, result.finishers); result.finishers = finishers; return result; }, addElementPlacement: function addElementPlacement(element, placements, silent) { var keys = placements[element.placement]; if (!silent && keys.indexOf(element.key) !== -1) { throw new TypeError("Duplicated element (" + element.key + ")"); } keys.push(element.key); }, decorateElement: function decorateElement(element, placements) { var extras = []; var finishers = []; for (var decorators = element.decorators, i = decorators.length - 1; i >= 0; i--) { var keys = placements[element.placement]; keys.splice(keys.indexOf(element.key), 1); var elementObject = this.fromElementDescriptor(element); var elementFinisherExtras = this.toElementFinisherExtras((0, decorators[i])(elementObject) || elementObject); element = elementFinisherExtras.element; this.addElementPlacement(element, placements); if (elementFinisherExtras.finisher) { finishers.push(elementFinisherExtras.finisher); } var newExtras = elementFinisherExtras.extras; if (newExtras) { for (var j = 0; j < newExtras.length; j++) { this.addElementPlacement(newExtras[j], placements); } extras.push.apply(extras, newExtras); } } return { element: element, finishers: finishers, extras: extras }; }, decorateConstructor: function decorateConstructor(elements, decorators) { var finishers = []; for (var i = decorators.length - 1; i >= 0; i--) { var obj = this.fromClassDescriptor(elements); var elementsAndFinisher = this.toClassDescriptor((0, decorators[i])(obj) || obj); if (elementsAndFinisher.finisher !== undefined) { finishers.push(elementsAndFinisher.finisher); } if (elementsAndFinisher.elements !== undefined) { elements = elementsAndFinisher.elements; for (var j = 0; j < elements.length - 1; j++) { for (var k = j + 1; k < elements.length; k++) { if (elements[j].key === elements[k].key && elements[j].placement === elements[k].placement) { throw new TypeError("Duplicated element (" + elements[j].key + ")"); } } } } } return { elements: elements, finishers: finishers }; }, fromElementDescriptor: function fromElementDescriptor(element) { var obj = { kind: element.kind, key: element.key, placement: element.placement, descriptor: element.descriptor }; var desc = { value: "Descriptor", configurable: true }; Object.defineProperty(obj, Symbol.toStringTag, desc); if (element.kind === "field") obj.initializer = element.initializer; return obj; }, toElementDescriptors: function toElementDescriptors(elementObjects) { if (elementObjects === undefined) return; return _toArray(elementObjects).map(function (elementObject) { var element = this.toElementDescriptor(elementObject); this.disallowProperty(elementObject, "finisher", "An element descriptor"); this.disallowProperty(elementObject, "extras", "An element descriptor"); return element; }, this); }, toElementDescriptor: function toElementDescriptor(elementObject) { var kind = String(elementObject.kind); if (kind !== "method" && kind !== "field") { throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"'); } var key = _toPropertyKey(elementObject.key); var placement = String(elementObject.placement); if (placement !== "static" && placement !== "prototype" && placement !== "own") { throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"'); } var descriptor = elementObject.descriptor; this.disallowProperty(elementObject, "elements", "An element descriptor"); var element = { kind: kind, key: key, placement: placement, descriptor: Object.assign({}, descriptor) }; if (kind !== "field") { this.disallowProperty(elementObject, "initializer", "A method descriptor"); } else { this.disallowProperty(descriptor, "get", "The property descriptor of a field descriptor"); this.disallowProperty(descriptor, "set", "The property descriptor of a field descriptor"); this.disallowProperty(descriptor, "value", "The property descriptor of a field descriptor"); element.initializer = elementObject.initializer; } return element; }, toElementFinisherExtras: function toElementFinisherExtras(elementObject) { var element = this.toElementDescriptor(elementObject); var finisher = _optionalCallableProperty(elementObject, "finisher"); var extras = this.toElementDescriptors(elementObject.extras); return { element: element, finisher: finisher, extras: extras }; }, fromClassDescriptor: function fromClassDescriptor(elements) { var obj = { kind: "class", elements: elements.map(this.fromElementDescriptor, this) }; var desc = { value: "Descriptor", configurable: true }; Object.defineProperty(obj, Symbol.toStringTag, desc); return obj; }, toClassDescriptor: function toClassDescriptor(obj) { var kind = String(obj.kind); if (kind !== "class") { throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"'); } this.disallowProperty(obj, "key", "A class descriptor"); this.disallowProperty(obj, "placement", "A class descriptor"); this.disallowProperty(obj, "descriptor", "A class descriptor"); this.disallowProperty(obj, "initializer", "A class descriptor"); this.disallowProperty(obj, "extras", "A class descriptor"); var finisher = _optionalCallableProperty(obj, "finisher"); var elements = this.toElementDescriptors(obj.elements); return { elements: elements, finisher: finisher }; }, runClassFinishers: function runClassFinishers(constructor, finishers) { for (var i = 0; i < finishers.length; i++) { var newConstructor = (0, finishers[i])(constructor); if (newConstructor !== undefined) { if (typeof newConstructor !== "function") { throw new TypeError("Finishers must return a constructor."); } constructor = newConstructor; } } return constructor; }, disallowProperty: function disallowProperty(obj, name, objectType) { if (obj[name] !== undefined) { throw new TypeError(objectType + " can't have a ." + name + " property."); } } }; return api; } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _createElementDescriptor(def) { var key = _toPropertyKey(def.key); var descriptor; if (def.kind === "method") { descriptor = { value: def.value, writable: true, configurable: true, enumerable: false }; } else if (def.kind === "get") { descriptor = { get: def.value, configurable: true, enumerable: false }; } else if (def.kind === "set") { descriptor = { set: def.value, configurable: true, enumerable: false }; } else if (def.kind === "field") { descriptor = { configurable: true, writable: true, enumerable: true }; } var element = { kind: def.kind === "field" ? "field" : "method", key: key, placement: def["static"] ? "static" : def.kind === "field" ? "own" : "prototype", descriptor: descriptor }; if (def.decorators) element.decorators = def.decorators; if (def.kind === "field") element.initializer = def.value; return element; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _coalesceGetterSetter(element, other) { if (element.descriptor.get !== undefined) { other.descriptor.get = element.descriptor.get; } else { other.descriptor.set = element.descriptor.set; } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _coalesceClassElements(elements) { var newElements = []; var isSameElement = function isSameElement(other) { return other.kind === "method" && other.key === element.key && other.placement === element.placement; }; for (var i = 0; i < elements.length; i++) { var element = elements[i]; var other; if (element.kind === "method" && (other = newElements.find(isSameElement))) { if (_isDataDescriptor(element.descriptor) || _isDataDescriptor(other.descriptor)) { if (_hasDecorators(element) || _hasDecorators(other)) { throw new ReferenceError("Duplicated methods (" + element.key + ") can't be decorated."); } other.descriptor = element.descriptor; } else { if (_hasDecorators(element)) { if (_hasDecorators(other)) { throw new ReferenceError("Decorators can't be placed on different accessors with for " + "the same property (" + element.key + ")."); } other.decorators = element.decorators; } _coalesceGetterSetter(element, other); } } else { newElements.push(element); } } return newElements; } | ||
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, descriptor.key, descriptor); } } | ||
function _hasDecorators(element) { return element.decorators && element.decorators.length; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _isDataDescriptor(desc) { return desc !== undefined && !(desc.value === undefined && desc.writable === undefined); } | ||
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; } | ||
function _optionalCallableProperty(obj, name) { var value = obj[name]; if (value !== undefined && typeof value !== "function") { throw new TypeError("Expected '" + name + "' to be a function"); } return value; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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 _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var TWO_DIGIT_REGEX = /(\d{2})/; | ||
@@ -130,179 +112,152 @@ | ||
var DateTimeParts = _decorate(null, function (_initialize) { | ||
var DateTimeParts = function DateTimeParts() { | ||
var DateTimeParts = (_dec = (0, _decorators.memoize)(dateTimeCacheKey('year')), _dec2 = (0, _decorators.memoize)(dateTimeCacheKey('month')), _dec3 = (0, _decorators.memoize)(dateTimeCacheKey('day')), _dec4 = (0, _decorators.memoize)(dateTimeCacheKey('weekday')), _dec5 = (0, _decorators.memoize)(dateTimeCacheKey('hour')), _dec6 = (0, _decorators.memoize)(dateTimeCacheKey('minute')), _dec7 = (0, _decorators.memoize)(dateTimeCacheKey('second')), _dec8 = (0, _decorators.memoize)(dateTimeCacheKey('timePartsFallback')), (_class = /*#__PURE__*/function () { | ||
function DateTimeParts() { | ||
_classCallCheck(this, DateTimeParts); | ||
} | ||
_initialize(this); | ||
}; | ||
_createClass(DateTimeParts, null, [{ | ||
key: "getYear", | ||
value: function getYear(date, timeZone) { | ||
if (isNaN(date.valueOf())) { | ||
throw new Error("Unable to parse date: ".concat(date, " for timezone: ").concat(timeZone)); | ||
} | ||
return { | ||
F: DateTimeParts, | ||
d: [{ | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('year'))], | ||
"static": true, | ||
key: "getYear", | ||
value: function getYear(date, timeZone) { | ||
if (isNaN(date.valueOf())) { | ||
throw new Error("Unable to parse date: ".concat(date, " for timezone: ").concat(timeZone)); | ||
} | ||
var yearString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
year: 'numeric' | ||
}); | ||
var sanitisedYearString = (0, _sanitiseDateString.sanitiseDateString)(yearString); | ||
var year = parseInt(sanitisedYearString, 10); | ||
var yearString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
year: 'numeric' | ||
}); | ||
var sanitisedYearString = (0, _sanitiseDateString.sanitiseDateString)(yearString); | ||
var year = parseInt(sanitisedYearString, 10); | ||
if (isNaN(year)) { | ||
throw new Error("Unable to parse year: '".concat(yearString, "'")); | ||
} | ||
if (isNaN(year)) { | ||
throw new Error("Unable to parse year: '".concat(yearString, "'")); | ||
} | ||
return year; | ||
} | ||
}, { | ||
key: "getMonth", | ||
value: function getMonth(date, timeZone) { | ||
var monthString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
month: 'numeric' | ||
}); | ||
var sanitisedMonthString = (0, _sanitiseDateString.sanitiseDateString)(monthString); | ||
var month = parseInt(sanitisedMonthString, 10); | ||
return year; | ||
if (isNaN(month)) { | ||
throw new Error("Unable to parse month: '".concat(monthString, "'")); | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('month'))], | ||
"static": true, | ||
key: "getMonth", | ||
value: function getMonth(date, timeZone) { | ||
var monthString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
month: 'numeric' | ||
}); | ||
var sanitisedMonthString = (0, _sanitiseDateString.sanitiseDateString)(monthString); | ||
var month = parseInt(sanitisedMonthString, 10); | ||
if (isNaN(month)) { | ||
throw new Error("Unable to parse month: '".concat(monthString, "'")); | ||
} | ||
return month; | ||
} | ||
}, { | ||
key: "getDay", | ||
value: function getDay(date, timeZone) { | ||
var dayString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
day: 'numeric' | ||
}); | ||
var sanitisedDayString = (0, _sanitiseDateString.sanitiseDateString)(dayString); | ||
var day = parseInt(sanitisedDayString, 10); | ||
return month; | ||
if (isNaN(day)) { | ||
throw new Error("Unable to parse day: '".concat(dayString, "'")); | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('day'))], | ||
"static": true, | ||
key: "getDay", | ||
value: function getDay(date, timeZone) { | ||
var dayString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
day: 'numeric' | ||
}); | ||
var sanitisedDayString = (0, _sanitiseDateString.sanitiseDateString)(dayString); | ||
var day = parseInt(sanitisedDayString, 10); | ||
if (isNaN(day)) { | ||
throw new Error("Unable to parse day: '".concat(dayString, "'")); | ||
} | ||
return day; | ||
} | ||
}, { | ||
key: "getWeekday", | ||
value: function getWeekday(date, timeZone) { | ||
var weekdayString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
weekday: 'long' | ||
}); | ||
var sanitisedWeekdayString = (0, _sanitiseDateString.sanitiseDateString)(weekdayString); | ||
return getWeekdayValue(sanitisedWeekdayString); | ||
} | ||
}, { | ||
key: "getHour", | ||
value: function getHour(date, timeZone) { | ||
var hourString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
hour12: false, | ||
hour: 'numeric' | ||
}); | ||
var hour = parseInt(hourString, 10); | ||
return day; | ||
if (isNaN(hour)) { | ||
hour = DateTimeParts.getTimePartsFallback(date, timeZone).hour; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('weekday'))], | ||
"static": true, | ||
key: "getWeekday", | ||
value: function getWeekday(date, timeZone) { | ||
var weekdayString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
weekday: 'long' | ||
}); | ||
var sanitisedWeekdayString = (0, _sanitiseDateString.sanitiseDateString)(weekdayString); | ||
return getWeekdayValue(sanitisedWeekdayString); | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('hour'))], | ||
"static": true, | ||
key: "getHour", | ||
value: function getHour(date, timeZone) { | ||
var hourString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
hour12: false, | ||
hour: 'numeric' | ||
}); | ||
var hour = parseInt(hourString, 10); | ||
if (isNaN(hour)) { | ||
hour = DateTimeParts.getTimePartsFallback(date, timeZone).hour; | ||
} | ||
return hour; | ||
} | ||
}, { | ||
key: "getMinute", | ||
value: function getMinute(date, timeZone) { | ||
var minuteString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
minute: 'numeric' | ||
}); | ||
var minute = parseInt(minuteString, 10); | ||
return hour; | ||
if (isNaN(minute)) { | ||
minute = DateTimeParts.getTimePartsFallback(date, timeZone).minute; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('minute'))], | ||
"static": true, | ||
key: "getMinute", | ||
value: function getMinute(date, timeZone) { | ||
var minuteString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
minute: 'numeric' | ||
}); | ||
var minute = parseInt(minuteString, 10); | ||
if (isNaN(minute)) { | ||
minute = DateTimeParts.getTimePartsFallback(date, timeZone).minute; | ||
} | ||
return minute; | ||
} | ||
}, { | ||
key: "getSecond", | ||
value: function getSecond(date, timeZone) { | ||
var secondString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
second: 'numeric' | ||
}); | ||
var second = parseInt(secondString, 10); | ||
return minute; | ||
if (isNaN(second)) { | ||
second = DateTimeParts.getTimePartsFallback(date, timeZone).second; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('second'))], | ||
"static": true, | ||
key: "getSecond", | ||
value: function getSecond(date, timeZone) { | ||
var secondString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
second: 'numeric' | ||
}); | ||
var second = parseInt(secondString, 10); | ||
if (isNaN(second)) { | ||
second = DateTimeParts.getTimePartsFallback(date, timeZone).second; | ||
} | ||
return second; | ||
} | ||
}, { | ||
key: "getTimePartsFallback", | ||
value: function getTimePartsFallback(date, timeZone) { | ||
var timeString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
hour12: false, | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit' | ||
}); // In Microsoft Edge, Intl.DateTimeFormat returns invisible characters around the individual numbers | ||
return second; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('timePartsFallback'))], | ||
"static": true, | ||
key: "getTimePartsFallback", | ||
value: function getTimePartsFallback(date, timeZone) { | ||
var timeString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone: timeZone, | ||
hour12: false, | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit' | ||
}); // In Microsoft Edge, Intl.DateTimeFormat returns invisible characters around the individual numbers | ||
var _timeString$split = timeString.split(':'), | ||
_timeString$split2 = _slicedToArray(_timeString$split, 3), | ||
dirtyHour = _timeString$split2[0], | ||
dirtyMinute = _timeString$split2[1], | ||
dirtySecond = _timeString$split2[2]; | ||
var _timeString$split = timeString.split(':'), | ||
_timeString$split2 = _slicedToArray(_timeString$split, 3), | ||
dirtyHour = _timeString$split2[0], | ||
dirtyMinute = _timeString$split2[1], | ||
dirtySecond = _timeString$split2[2]; | ||
var rawHour = new RegExp(TWO_DIGIT_REGEX).exec(dirtyHour); | ||
var rawMinute = new RegExp(TWO_DIGIT_REGEX).exec(dirtyMinute); | ||
var rawSecond = new RegExp(TWO_DIGIT_REGEX).exec(dirtySecond); | ||
var rawHour = new RegExp(TWO_DIGIT_REGEX).exec(dirtyHour); | ||
var rawMinute = new RegExp(TWO_DIGIT_REGEX).exec(dirtyMinute); | ||
var rawSecond = new RegExp(TWO_DIGIT_REGEX).exec(dirtySecond); | ||
if (rawHour != null && rawMinute != null && rawSecond != null) { | ||
var hour = parseInt(rawHour[1], 10); | ||
var minute = parseInt(rawMinute[1], 10); | ||
var second = parseInt(rawSecond[1], 10); | ||
return { | ||
hour: hour, | ||
minute: minute, | ||
second: second | ||
}; | ||
} | ||
if (rawHour != null && rawMinute != null && rawSecond != null) { | ||
var hour = parseInt(rawHour[1], 10); | ||
var minute = parseInt(rawMinute[1], 10); | ||
var second = parseInt(rawSecond[1], 10); | ||
return { | ||
hour: hour, | ||
minute: minute, | ||
second: second | ||
}; | ||
} | ||
throw new Error("Unable to parse timeString: '".concat(timeString, "'")); | ||
} | ||
}]); | ||
throw new Error("Unable to parse timeString: '".concat(timeString, "'")); | ||
} | ||
}] | ||
}; | ||
}); | ||
return DateTimeParts; | ||
}(), (_applyDecoratedDescriptor(_class, "getYear", [_dec], Object.getOwnPropertyDescriptor(_class, "getYear"), _class), _applyDecoratedDescriptor(_class, "getMonth", [_dec2], Object.getOwnPropertyDescriptor(_class, "getMonth"), _class), _applyDecoratedDescriptor(_class, "getDay", [_dec3], Object.getOwnPropertyDescriptor(_class, "getDay"), _class), _applyDecoratedDescriptor(_class, "getWeekday", [_dec4], Object.getOwnPropertyDescriptor(_class, "getWeekday"), _class), _applyDecoratedDescriptor(_class, "getHour", [_dec5], Object.getOwnPropertyDescriptor(_class, "getHour"), _class), _applyDecoratedDescriptor(_class, "getMinute", [_dec6], Object.getOwnPropertyDescriptor(_class, "getMinute"), _class), _applyDecoratedDescriptor(_class, "getSecond", [_dec7], Object.getOwnPropertyDescriptor(_class, "getSecond"), _class), _applyDecoratedDescriptor(_class, "getTimePartsFallback", [_dec8], Object.getOwnPropertyDescriptor(_class, "getTimePartsFallback"), _class)), _class)); |
@@ -14,34 +14,6 @@ "use strict"; | ||
function _decorate(decorators, factory, superClass, mixins) { var api = _getDecoratorsApi(); if (mixins) { for (var i = 0; i < mixins.length; i++) { api = mixins[i](api); } } var r = factory(function initialize(O) { api.initializeInstanceElements(O, decorated.elements); }, superClass); var decorated = api.decorateClass(_coalesceClassElements(r.d.map(_createElementDescriptor)), decorators); api.initializeClassElements(r.F, decorated.elements); return api.runClassFinishers(r.F, decorated.finishers); } | ||
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class; | ||
function _getDecoratorsApi() { _getDecoratorsApi = function () { return api; }; var api = { elementsDefinitionOrder: [["method"], ["field"]], initializeInstanceElements: function (O, elements) { ["method", "field"].forEach(function (kind) { elements.forEach(function (element) { if (element.kind === kind && element.placement === "own") { this.defineClassElement(O, element); } }, this); }, this); }, initializeClassElements: function (F, elements) { var proto = F.prototype; ["method", "field"].forEach(function (kind) { elements.forEach(function (element) { var placement = element.placement; if (element.kind === kind && (placement === "static" || placement === "prototype")) { var receiver = placement === "static" ? F : proto; this.defineClassElement(receiver, element); } }, this); }, this); }, defineClassElement: function (receiver, element) { var descriptor = element.descriptor; if (element.kind === "field") { var initializer = element.initializer; descriptor = { enumerable: descriptor.enumerable, writable: descriptor.writable, configurable: descriptor.configurable, value: initializer === void 0 ? void 0 : initializer.call(receiver) }; } Object.defineProperty(receiver, element.key, descriptor); }, decorateClass: function (elements, decorators) { var newElements = []; var finishers = []; var placements = { static: [], prototype: [], own: [] }; elements.forEach(function (element) { this.addElementPlacement(element, placements); }, this); elements.forEach(function (element) { if (!_hasDecorators(element)) return newElements.push(element); var elementFinishersExtras = this.decorateElement(element, placements); newElements.push(elementFinishersExtras.element); newElements.push.apply(newElements, elementFinishersExtras.extras); finishers.push.apply(finishers, elementFinishersExtras.finishers); }, this); if (!decorators) { return { elements: newElements, finishers: finishers }; } var result = this.decorateConstructor(newElements, decorators); finishers.push.apply(finishers, result.finishers); result.finishers = finishers; return result; }, addElementPlacement: function (element, placements, silent) { var keys = placements[element.placement]; if (!silent && keys.indexOf(element.key) !== -1) { throw new TypeError("Duplicated element (" + element.key + ")"); } keys.push(element.key); }, decorateElement: function (element, placements) { var extras = []; var finishers = []; for (var decorators = element.decorators, i = decorators.length - 1; i >= 0; i--) { var keys = placements[element.placement]; keys.splice(keys.indexOf(element.key), 1); var elementObject = this.fromElementDescriptor(element); var elementFinisherExtras = this.toElementFinisherExtras((0, decorators[i])(elementObject) || elementObject); element = elementFinisherExtras.element; this.addElementPlacement(element, placements); if (elementFinisherExtras.finisher) { finishers.push(elementFinisherExtras.finisher); } var newExtras = elementFinisherExtras.extras; if (newExtras) { for (var j = 0; j < newExtras.length; j++) { this.addElementPlacement(newExtras[j], placements); } extras.push.apply(extras, newExtras); } } return { element: element, finishers: finishers, extras: extras }; }, decorateConstructor: function (elements, decorators) { var finishers = []; for (var i = decorators.length - 1; i >= 0; i--) { var obj = this.fromClassDescriptor(elements); var elementsAndFinisher = this.toClassDescriptor((0, decorators[i])(obj) || obj); if (elementsAndFinisher.finisher !== undefined) { finishers.push(elementsAndFinisher.finisher); } if (elementsAndFinisher.elements !== undefined) { elements = elementsAndFinisher.elements; for (var j = 0; j < elements.length - 1; j++) { for (var k = j + 1; k < elements.length; k++) { if (elements[j].key === elements[k].key && elements[j].placement === elements[k].placement) { throw new TypeError("Duplicated element (" + elements[j].key + ")"); } } } } } return { elements: elements, finishers: finishers }; }, fromElementDescriptor: function (element) { var obj = { kind: element.kind, key: element.key, placement: element.placement, descriptor: element.descriptor }; var desc = { value: "Descriptor", configurable: true }; Object.defineProperty(obj, Symbol.toStringTag, desc); if (element.kind === "field") obj.initializer = element.initializer; return obj; }, toElementDescriptors: function (elementObjects) { if (elementObjects === undefined) return; return _toArray(elementObjects).map(function (elementObject) { var element = this.toElementDescriptor(elementObject); this.disallowProperty(elementObject, "finisher", "An element descriptor"); this.disallowProperty(elementObject, "extras", "An element descriptor"); return element; }, this); }, toElementDescriptor: function (elementObject) { var kind = String(elementObject.kind); if (kind !== "method" && kind !== "field") { throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"'); } var key = _toPropertyKey(elementObject.key); var placement = String(elementObject.placement); if (placement !== "static" && placement !== "prototype" && placement !== "own") { throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"'); } var descriptor = elementObject.descriptor; this.disallowProperty(elementObject, "elements", "An element descriptor"); var element = { kind: kind, key: key, placement: placement, descriptor: Object.assign({}, descriptor) }; if (kind !== "field") { this.disallowProperty(elementObject, "initializer", "A method descriptor"); } else { this.disallowProperty(descriptor, "get", "The property descriptor of a field descriptor"); this.disallowProperty(descriptor, "set", "The property descriptor of a field descriptor"); this.disallowProperty(descriptor, "value", "The property descriptor of a field descriptor"); element.initializer = elementObject.initializer; } return element; }, toElementFinisherExtras: function (elementObject) { var element = this.toElementDescriptor(elementObject); var finisher = _optionalCallableProperty(elementObject, "finisher"); var extras = this.toElementDescriptors(elementObject.extras); return { element: element, finisher: finisher, extras: extras }; }, fromClassDescriptor: function (elements) { var obj = { kind: "class", elements: elements.map(this.fromElementDescriptor, this) }; var desc = { value: "Descriptor", configurable: true }; Object.defineProperty(obj, Symbol.toStringTag, desc); return obj; }, toClassDescriptor: function (obj) { var kind = String(obj.kind); if (kind !== "class") { throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"'); } this.disallowProperty(obj, "key", "A class descriptor"); this.disallowProperty(obj, "placement", "A class descriptor"); this.disallowProperty(obj, "descriptor", "A class descriptor"); this.disallowProperty(obj, "initializer", "A class descriptor"); this.disallowProperty(obj, "extras", "A class descriptor"); var finisher = _optionalCallableProperty(obj, "finisher"); var elements = this.toElementDescriptors(obj.elements); return { elements: elements, finisher: finisher }; }, runClassFinishers: function (constructor, finishers) { for (var i = 0; i < finishers.length; i++) { var newConstructor = (0, finishers[i])(constructor); if (newConstructor !== undefined) { if (typeof newConstructor !== "function") { throw new TypeError("Finishers must return a constructor."); } constructor = newConstructor; } } return constructor; }, disallowProperty: function (obj, name, objectType) { if (obj[name] !== undefined) { throw new TypeError(objectType + " can't have a ." + name + " property."); } } }; return api; } | ||
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; } | ||
function _createElementDescriptor(def) { var key = _toPropertyKey(def.key); var descriptor; if (def.kind === "method") { descriptor = { value: def.value, writable: true, configurable: true, enumerable: false }; } else if (def.kind === "get") { descriptor = { get: def.value, configurable: true, enumerable: false }; } else if (def.kind === "set") { descriptor = { set: def.value, configurable: true, enumerable: false }; } else if (def.kind === "field") { descriptor = { configurable: true, writable: true, enumerable: true }; } var element = { kind: def.kind === "field" ? "field" : "method", key: key, placement: def.static ? "static" : def.kind === "field" ? "own" : "prototype", descriptor: descriptor }; if (def.decorators) element.decorators = def.decorators; if (def.kind === "field") element.initializer = def.value; return element; } | ||
function _coalesceGetterSetter(element, other) { if (element.descriptor.get !== undefined) { other.descriptor.get = element.descriptor.get; } else { other.descriptor.set = element.descriptor.set; } } | ||
function _coalesceClassElements(elements) { var newElements = []; var isSameElement = function (other) { return other.kind === "method" && other.key === element.key && other.placement === element.placement; }; for (var i = 0; i < elements.length; i++) { var element = elements[i]; var other; if (element.kind === "method" && (other = newElements.find(isSameElement))) { if (_isDataDescriptor(element.descriptor) || _isDataDescriptor(other.descriptor)) { if (_hasDecorators(element) || _hasDecorators(other)) { throw new ReferenceError("Duplicated methods (" + element.key + ") can't be decorated."); } other.descriptor = element.descriptor; } else { if (_hasDecorators(element)) { if (_hasDecorators(other)) { throw new ReferenceError("Decorators can't be placed on different accessors with for " + "the same property (" + element.key + ")."); } other.decorators = element.decorators; } _coalesceGetterSetter(element, other); } } else { newElements.push(element); } } return newElements; } | ||
function _hasDecorators(element) { return element.decorators && element.decorators.length; } | ||
function _isDataDescriptor(desc) { return desc !== undefined && !(desc.value === undefined && desc.writable === undefined); } | ||
function _optionalCallableProperty(obj, name) { var value = obj[name]; if (value !== undefined && typeof value !== "function") { throw new TypeError("Expected '" + name + "' to be a function"); } return value; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
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 _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
const TWO_DIGIT_REGEX = /(\d{2})/; | ||
@@ -104,175 +76,132 @@ | ||
let DateTimeParts = _decorate(null, function (_initialize) { | ||
class DateTimeParts { | ||
constructor() { | ||
_initialize(this); | ||
let DateTimeParts = (_dec = (0, _decorators.memoize)(dateTimeCacheKey('year')), _dec2 = (0, _decorators.memoize)(dateTimeCacheKey('month')), _dec3 = (0, _decorators.memoize)(dateTimeCacheKey('day')), _dec4 = (0, _decorators.memoize)(dateTimeCacheKey('weekday')), _dec5 = (0, _decorators.memoize)(dateTimeCacheKey('hour')), _dec6 = (0, _decorators.memoize)(dateTimeCacheKey('minute')), _dec7 = (0, _decorators.memoize)(dateTimeCacheKey('second')), _dec8 = (0, _decorators.memoize)(dateTimeCacheKey('timePartsFallback')), (_class = class DateTimeParts { | ||
static getYear(date, timeZone) { | ||
if (isNaN(date.valueOf())) { | ||
throw new Error(`Unable to parse date: ${date} for timezone: ${timeZone}`); | ||
} | ||
const yearString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
year: 'numeric' | ||
}); | ||
const sanitisedYearString = (0, _sanitiseDateString.sanitiseDateString)(yearString); | ||
const year = parseInt(sanitisedYearString, 10); | ||
if (isNaN(year)) { | ||
throw new Error(`Unable to parse year: '${yearString}'`); | ||
} | ||
return year; | ||
} | ||
return { | ||
F: DateTimeParts, | ||
d: [{ | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('year'))], | ||
static: true, | ||
key: "getYear", | ||
value: function getYear(date, timeZone) { | ||
if (isNaN(date.valueOf())) { | ||
throw new Error(`Unable to parse date: ${date} for timezone: ${timeZone}`); | ||
} | ||
static getMonth(date, timeZone) { | ||
const monthString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
month: 'numeric' | ||
}); | ||
const sanitisedMonthString = (0, _sanitiseDateString.sanitiseDateString)(monthString); | ||
const month = parseInt(sanitisedMonthString, 10); | ||
const yearString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
year: 'numeric' | ||
}); | ||
const sanitisedYearString = (0, _sanitiseDateString.sanitiseDateString)(yearString); | ||
const year = parseInt(sanitisedYearString, 10); | ||
if (isNaN(month)) { | ||
throw new Error(`Unable to parse month: '${monthString}'`); | ||
} | ||
if (isNaN(year)) { | ||
throw new Error(`Unable to parse year: '${yearString}'`); | ||
} | ||
return month; | ||
} | ||
return year; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('month'))], | ||
static: true, | ||
key: "getMonth", | ||
value: function getMonth(date, timeZone) { | ||
const monthString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
month: 'numeric' | ||
}); | ||
const sanitisedMonthString = (0, _sanitiseDateString.sanitiseDateString)(monthString); | ||
const month = parseInt(sanitisedMonthString, 10); | ||
static getDay(date, timeZone) { | ||
const dayString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
day: 'numeric' | ||
}); | ||
const sanitisedDayString = (0, _sanitiseDateString.sanitiseDateString)(dayString); | ||
const day = parseInt(sanitisedDayString, 10); | ||
if (isNaN(month)) { | ||
throw new Error(`Unable to parse month: '${monthString}'`); | ||
} | ||
if (isNaN(day)) { | ||
throw new Error(`Unable to parse day: '${dayString}'`); | ||
} | ||
return month; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('day'))], | ||
static: true, | ||
key: "getDay", | ||
value: function getDay(date, timeZone) { | ||
const dayString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
day: 'numeric' | ||
}); | ||
const sanitisedDayString = (0, _sanitiseDateString.sanitiseDateString)(dayString); | ||
const day = parseInt(sanitisedDayString, 10); | ||
return day; | ||
} | ||
if (isNaN(day)) { | ||
throw new Error(`Unable to parse day: '${dayString}'`); | ||
} | ||
static getWeekday(date, timeZone) { | ||
const weekdayString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
weekday: 'long' | ||
}); | ||
const sanitisedWeekdayString = (0, _sanitiseDateString.sanitiseDateString)(weekdayString); | ||
return getWeekdayValue(sanitisedWeekdayString); | ||
} | ||
return day; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('weekday'))], | ||
static: true, | ||
key: "getWeekday", | ||
value: function getWeekday(date, timeZone) { | ||
const weekdayString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
weekday: 'long' | ||
}); | ||
const sanitisedWeekdayString = (0, _sanitiseDateString.sanitiseDateString)(weekdayString); | ||
return getWeekdayValue(sanitisedWeekdayString); | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('hour'))], | ||
static: true, | ||
key: "getHour", | ||
value: function getHour(date, timeZone) { | ||
const hourString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
hour12: false, | ||
hour: 'numeric' | ||
}); | ||
let hour = parseInt(hourString, 10); | ||
static getHour(date, timeZone) { | ||
const hourString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
hour12: false, | ||
hour: 'numeric' | ||
}); | ||
let hour = parseInt(hourString, 10); | ||
if (isNaN(hour)) { | ||
hour = DateTimeParts.getTimePartsFallback(date, timeZone).hour; | ||
} | ||
if (isNaN(hour)) { | ||
hour = DateTimeParts.getTimePartsFallback(date, timeZone).hour; | ||
} | ||
return hour; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('minute'))], | ||
static: true, | ||
key: "getMinute", | ||
value: function getMinute(date, timeZone) { | ||
const minuteString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
minute: 'numeric' | ||
}); | ||
let minute = parseInt(minuteString, 10); | ||
return hour; | ||
} | ||
if (isNaN(minute)) { | ||
minute = DateTimeParts.getTimePartsFallback(date, timeZone).minute; | ||
} | ||
static getMinute(date, timeZone) { | ||
const minuteString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
minute: 'numeric' | ||
}); | ||
let minute = parseInt(minuteString, 10); | ||
return minute; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('second'))], | ||
static: true, | ||
key: "getSecond", | ||
value: function getSecond(date, timeZone) { | ||
const secondString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
second: 'numeric' | ||
}); | ||
let second = parseInt(secondString, 10); | ||
if (isNaN(minute)) { | ||
minute = DateTimeParts.getTimePartsFallback(date, timeZone).minute; | ||
} | ||
if (isNaN(second)) { | ||
second = DateTimeParts.getTimePartsFallback(date, timeZone).second; | ||
} | ||
return minute; | ||
} | ||
return second; | ||
} | ||
}, { | ||
kind: "method", | ||
decorators: [(0, _decorators.memoize)(dateTimeCacheKey('timePartsFallback'))], | ||
static: true, | ||
key: "getTimePartsFallback", | ||
value: function getTimePartsFallback(date, timeZone) { | ||
const timeString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
hour12: false, | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit' | ||
}); // In Microsoft Edge, Intl.DateTimeFormat returns invisible characters around the individual numbers | ||
static getSecond(date, timeZone) { | ||
const secondString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
second: 'numeric' | ||
}); | ||
let second = parseInt(secondString, 10); | ||
const [dirtyHour, dirtyMinute, dirtySecond] = timeString.split(':'); | ||
const rawHour = new RegExp(TWO_DIGIT_REGEX).exec(dirtyHour); | ||
const rawMinute = new RegExp(TWO_DIGIT_REGEX).exec(dirtyMinute); | ||
const rawSecond = new RegExp(TWO_DIGIT_REGEX).exec(dirtySecond); | ||
if (isNaN(second)) { | ||
second = DateTimeParts.getTimePartsFallback(date, timeZone).second; | ||
} | ||
if (rawHour != null && rawMinute != null && rawSecond != null) { | ||
const hour = parseInt(rawHour[1], 10); | ||
const minute = parseInt(rawMinute[1], 10); | ||
const second = parseInt(rawSecond[1], 10); | ||
return { | ||
hour, | ||
minute, | ||
second | ||
}; | ||
} | ||
return second; | ||
} | ||
throw new Error(`Unable to parse timeString: '${timeString}'`); | ||
} | ||
}] | ||
}; | ||
}); | ||
static getTimePartsFallback(date, timeZone) { | ||
const timeString = (0, _utilities.formatDate)(date, 'en', { | ||
timeZone, | ||
hour12: false, | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit' | ||
}); // In Microsoft Edge, Intl.DateTimeFormat returns invisible characters around the individual numbers | ||
const [dirtyHour, dirtyMinute, dirtySecond] = timeString.split(':'); | ||
const rawHour = new RegExp(TWO_DIGIT_REGEX).exec(dirtyHour); | ||
const rawMinute = new RegExp(TWO_DIGIT_REGEX).exec(dirtyMinute); | ||
const rawSecond = new RegExp(TWO_DIGIT_REGEX).exec(dirtySecond); | ||
if (rawHour != null && rawMinute != null && rawSecond != null) { | ||
const hour = parseInt(rawHour[1], 10); | ||
const minute = parseInt(rawMinute[1], 10); | ||
const second = parseInt(rawSecond[1], 10); | ||
return { | ||
hour, | ||
minute, | ||
second | ||
}; | ||
} | ||
throw new Error(`Unable to parse timeString: '${timeString}'`); | ||
} | ||
}, (_applyDecoratedDescriptor(_class, "getYear", [_dec], Object.getOwnPropertyDescriptor(_class, "getYear"), _class), _applyDecoratedDescriptor(_class, "getMonth", [_dec2], Object.getOwnPropertyDescriptor(_class, "getMonth"), _class), _applyDecoratedDescriptor(_class, "getDay", [_dec3], Object.getOwnPropertyDescriptor(_class, "getDay"), _class), _applyDecoratedDescriptor(_class, "getWeekday", [_dec4], Object.getOwnPropertyDescriptor(_class, "getWeekday"), _class), _applyDecoratedDescriptor(_class, "getHour", [_dec5], Object.getOwnPropertyDescriptor(_class, "getHour"), _class), _applyDecoratedDescriptor(_class, "getMinute", [_dec6], Object.getOwnPropertyDescriptor(_class, "getMinute"), _class), _applyDecoratedDescriptor(_class, "getSecond", [_dec7], Object.getOwnPropertyDescriptor(_class, "getSecond"), _class), _applyDecoratedDescriptor(_class, "getTimePartsFallback", [_dec8], Object.getOwnPropertyDescriptor(_class, "getTimePartsFallback"), _class)), _class)); |
{ | ||
"name": "@shopify/dates", | ||
"version": "0.5.0-sk-next-beta.0", | ||
"version": "0.5.0-sk-next-beta.1", | ||
"license": "MIT", | ||
@@ -27,7 +27,7 @@ "description": "Lightweight date operations library", | ||
"dependencies": { | ||
"@shopify/decorators": "^1.2.0-sk-next-beta.0", | ||
"@shopify/decorators": "^1.2.0-sk-next-beta.1", | ||
"tslib": "^1.14.1" | ||
}, | ||
"devDependencies": { | ||
"@shopify/jest-dom-mocks": "^2.10.0-sk-next-beta.0" | ||
"@shopify/jest-dom-mocks": "^2.10.0-sk-next-beta.1" | ||
}, | ||
@@ -34,0 +34,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
175448
3143