@rededor/cura 1.6.0 → 1.6.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cura-calendar.cjs.entry.js +2997 -198
- package/dist/cjs/cura-calendar.cjs.entry.js.map +1 -1
- package/dist/cjs/cura.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/accordion/cura-accordion-item/cura-accordion-item.css +6 -2
- package/dist/collection/components/cura-calendar/cura-calendar.css +35 -4
- package/dist/collection/components/cura-calendar/cura-calendar.js +17 -9
- package/dist/collection/components/cura-calendar/cura-calendar.js.map +1 -1
- package/dist/collection/components/cura-calendar/cura-calendar.stories.js +0 -1
- package/dist/collection/components/cura-calendar/cura-calendar.stories.js.map +1 -1
- package/dist/collection/components/cura-modal/cura-modal.css +6 -2
- package/dist/collection/components/cura-page-template/cura-page-template.css +6 -2
- package/dist/collection/components/cura-toast/cura-toast.css +6 -2
- package/dist/collection/components/cura-tooltip/cura-tooltip.css +6 -2
- package/dist/collection/components/forms/cura-label/cura-label.css +6 -2
- package/dist/collection/components/text/cura-display/cura-display.css +6 -2
- package/dist/collection/components/text/cura-heading/cura-heading.css +6 -2
- package/dist/collection/components/text/cura-paragraph/cura-paragraph.css +6 -2
- package/dist/components/cura-calendar2.js +2999 -200
- package/dist/components/cura-calendar2.js.map +1 -1
- package/dist/cura/cura.esm.js +1 -1
- package/dist/cura/cura.esm.js.map +1 -1
- package/dist/cura/p-2090e71a.entry.js +2 -0
- package/dist/cura/p-2090e71a.entry.js.map +1 -0
- package/dist/esm/cura-calendar.entry.js +2997 -198
- package/dist/esm/cura-calendar.entry.js.map +1 -1
- package/dist/esm/cura.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/types/components/cura-calendar/cura-calendar.stories.d.ts +0 -1
- package/package.json +2 -2
- package/dist/cura/p-62c1b0f4.entry.js +0 -2
- package/dist/cura/p-62c1b0f4.entry.js.map +0 -1
|
@@ -275,6 +275,16 @@ var millisecondsInMinute = 60000;
|
|
|
275
275
|
*/
|
|
276
276
|
var millisecondsInHour = 3600000;
|
|
277
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Milliseconds in 1 second
|
|
280
|
+
*
|
|
281
|
+
* @name millisecondsInSecond
|
|
282
|
+
* @constant
|
|
283
|
+
* @type {number}
|
|
284
|
+
* @default
|
|
285
|
+
*/
|
|
286
|
+
var millisecondsInSecond = 1000;
|
|
287
|
+
|
|
278
288
|
/**
|
|
279
289
|
* @name isSameDay
|
|
280
290
|
* @category Day Helpers
|
|
@@ -2232,14 +2242,14 @@ const defaultLocale = locale$2;
|
|
|
2232
2242
|
// If there is no matching single quote
|
|
2233
2243
|
// then the sequence will continue until the end of the string.
|
|
2234
2244
|
// - . matches any single character unmatched by previous parts of the RegExps
|
|
2235
|
-
var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
|
|
2245
|
+
var formattingTokensRegExp$1 = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
|
|
2236
2246
|
|
|
2237
2247
|
// This RegExp catches symbols escaped by quotes, and also
|
|
2238
2248
|
// sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
|
|
2239
|
-
var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
2240
|
-
var escapedStringRegExp = /^'([^]*?)'?$/;
|
|
2241
|
-
var doubleQuoteRegExp = /''/g;
|
|
2242
|
-
var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
|
|
2249
|
+
var longFormattingTokensRegExp$1 = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
2250
|
+
var escapedStringRegExp$1 = /^'([^]*?)'?$/;
|
|
2251
|
+
var doubleQuoteRegExp$1 = /''/g;
|
|
2252
|
+
var unescapedLatinCharacterRegExp$1 = /[a-zA-Z]/;
|
|
2243
2253
|
|
|
2244
2254
|
/**
|
|
2245
2255
|
* @name format
|
|
@@ -2573,21 +2583,21 @@ function format(dirtyDate, dirtyFormatStr, options) {
|
|
|
2573
2583
|
locale: locale,
|
|
2574
2584
|
_originalDate: originalDate
|
|
2575
2585
|
};
|
|
2576
|
-
var result = formatStr.match(longFormattingTokensRegExp).map(function (substring) {
|
|
2586
|
+
var result = formatStr.match(longFormattingTokensRegExp$1).map(function (substring) {
|
|
2577
2587
|
var firstCharacter = substring[0];
|
|
2578
2588
|
if (firstCharacter === 'p' || firstCharacter === 'P') {
|
|
2579
2589
|
var longFormatter = longFormatters$1[firstCharacter];
|
|
2580
2590
|
return longFormatter(substring, locale.formatLong);
|
|
2581
2591
|
}
|
|
2582
2592
|
return substring;
|
|
2583
|
-
}).join('').match(formattingTokensRegExp).map(function (substring) {
|
|
2593
|
+
}).join('').match(formattingTokensRegExp$1).map(function (substring) {
|
|
2584
2594
|
// Replace two single quote characters with one single quote character
|
|
2585
2595
|
if (substring === "''") {
|
|
2586
2596
|
return "'";
|
|
2587
2597
|
}
|
|
2588
2598
|
var firstCharacter = substring[0];
|
|
2589
2599
|
if (firstCharacter === "'") {
|
|
2590
|
-
return cleanEscapedString(substring);
|
|
2600
|
+
return cleanEscapedString$1(substring);
|
|
2591
2601
|
}
|
|
2592
2602
|
var formatter = formatters$1[firstCharacter];
|
|
2593
2603
|
if (formatter) {
|
|
@@ -2599,19 +2609,31 @@ function format(dirtyDate, dirtyFormatStr, options) {
|
|
|
2599
2609
|
}
|
|
2600
2610
|
return formatter(utcDate, substring, locale.localize, formatterOptions);
|
|
2601
2611
|
}
|
|
2602
|
-
if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
|
|
2612
|
+
if (firstCharacter.match(unescapedLatinCharacterRegExp$1)) {
|
|
2603
2613
|
throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`');
|
|
2604
2614
|
}
|
|
2605
2615
|
return substring;
|
|
2606
2616
|
}).join('');
|
|
2607
2617
|
return result;
|
|
2608
2618
|
}
|
|
2609
|
-
function cleanEscapedString(input) {
|
|
2610
|
-
var matched = input.match(escapedStringRegExp);
|
|
2619
|
+
function cleanEscapedString$1(input) {
|
|
2620
|
+
var matched = input.match(escapedStringRegExp$1);
|
|
2611
2621
|
if (!matched) {
|
|
2612
2622
|
return input;
|
|
2613
2623
|
}
|
|
2614
|
-
return matched[1].replace(doubleQuoteRegExp, "'");
|
|
2624
|
+
return matched[1].replace(doubleQuoteRegExp$1, "'");
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
function assign(target, object) {
|
|
2628
|
+
if (target == null) {
|
|
2629
|
+
throw new TypeError('assign requires that input parameter not be null or undefined');
|
|
2630
|
+
}
|
|
2631
|
+
for (var property in object) {
|
|
2632
|
+
if (Object.prototype.hasOwnProperty.call(object, property)) {
|
|
2633
|
+
target[property] = object[property];
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
return target;
|
|
2615
2637
|
}
|
|
2616
2638
|
|
|
2617
2639
|
/**
|
|
@@ -2684,205 +2706,2977 @@ function getYear(dirtyDate) {
|
|
|
2684
2706
|
return toDate(dirtyDate).getFullYear();
|
|
2685
2707
|
}
|
|
2686
2708
|
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
* @pure false
|
|
2692
|
-
*
|
|
2693
|
-
* @description
|
|
2694
|
-
* Is the given date today?
|
|
2695
|
-
*
|
|
2696
|
-
* > ⚠️ Please note that this function is not present in the FP submodule as
|
|
2697
|
-
* > it uses `Date.now()` internally hence impure and can't be safely curried.
|
|
2698
|
-
*
|
|
2699
|
-
* @param {Date|Number} date - the date to check
|
|
2700
|
-
* @returns {Boolean} the date is today
|
|
2701
|
-
* @throws {TypeError} 1 argument required
|
|
2702
|
-
*
|
|
2703
|
-
* @example
|
|
2704
|
-
* // If today is 6 October 2014, is 6 October 14:00:00 today?
|
|
2705
|
-
* const result = isToday(new Date(2014, 9, 6, 14, 0))
|
|
2706
|
-
* //=> true
|
|
2707
|
-
*/
|
|
2708
|
-
function isToday(dirtyDate) {
|
|
2709
|
-
requiredArgs(1, arguments);
|
|
2710
|
-
return isSameDay(dirtyDate, Date.now());
|
|
2709
|
+
function _arrayLikeToArray(r, a) {
|
|
2710
|
+
(null == a || a > r.length) && (a = r.length);
|
|
2711
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
2712
|
+
return n;
|
|
2711
2713
|
}
|
|
2712
2714
|
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
* Subtract the specified number of days from the given date.
|
|
2720
|
-
*
|
|
2721
|
-
* @param {Date|Number} date - the date to be changed
|
|
2722
|
-
* @param {Number} amount - the amount of days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
2723
|
-
* @returns {Date} the new date with the days subtracted
|
|
2724
|
-
* @throws {TypeError} 2 arguments required
|
|
2725
|
-
*
|
|
2726
|
-
* @example
|
|
2727
|
-
* // Subtract 10 days from 1 September 2014:
|
|
2728
|
-
* const result = subDays(new Date(2014, 8, 1), 10)
|
|
2729
|
-
* //=> Fri Aug 22 2014 00:00:00
|
|
2730
|
-
*/
|
|
2731
|
-
function subDays(dirtyDate, dirtyAmount) {
|
|
2732
|
-
requiredArgs(2, arguments);
|
|
2733
|
-
var amount = toInteger(dirtyAmount);
|
|
2734
|
-
return addDays(dirtyDate, -amount);
|
|
2715
|
+
function _unsupportedIterableToArray(r, a) {
|
|
2716
|
+
if (r) {
|
|
2717
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
2718
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
2719
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
2720
|
+
}
|
|
2735
2721
|
}
|
|
2736
2722
|
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
* //=> Tue Feb 11 2014 11:30:30
|
|
2762
|
-
*
|
|
2763
|
-
* @example
|
|
2764
|
-
* // Convert string '+02014101' to date,
|
|
2765
|
-
* // if the additional number of digits in the extended year format is 1:
|
|
2766
|
-
* const result = parseISO('+02014101', { additionalDigits: 1 })
|
|
2767
|
-
* //=> Fri Apr 11 2014 00:00:00
|
|
2768
|
-
*/
|
|
2769
|
-
function parseISO(argument, options) {
|
|
2770
|
-
var _options$additionalDi;
|
|
2771
|
-
requiredArgs(1, arguments);
|
|
2772
|
-
var additionalDigits = toInteger((_options$additionalDi = options === null || options === void 0 ? void 0 : options.additionalDigits) !== null && _options$additionalDi !== void 0 ? _options$additionalDi : 2);
|
|
2773
|
-
if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) {
|
|
2774
|
-
throw new RangeError('additionalDigits must be 0, 1 or 2');
|
|
2723
|
+
function _createForOfIteratorHelper(r, e) {
|
|
2724
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
2725
|
+
if (!t) {
|
|
2726
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
2727
|
+
t && (r = t);
|
|
2728
|
+
var _n = 0,
|
|
2729
|
+
F = function F() {};
|
|
2730
|
+
return {
|
|
2731
|
+
s: F,
|
|
2732
|
+
n: function n() {
|
|
2733
|
+
return _n >= r.length ? {
|
|
2734
|
+
done: !0
|
|
2735
|
+
} : {
|
|
2736
|
+
done: !1,
|
|
2737
|
+
value: r[_n++]
|
|
2738
|
+
};
|
|
2739
|
+
},
|
|
2740
|
+
e: function e(r) {
|
|
2741
|
+
throw r;
|
|
2742
|
+
},
|
|
2743
|
+
f: F
|
|
2744
|
+
};
|
|
2745
|
+
}
|
|
2746
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
2775
2747
|
}
|
|
2776
|
-
|
|
2777
|
-
|
|
2748
|
+
var o,
|
|
2749
|
+
a = !0,
|
|
2750
|
+
u = !1;
|
|
2751
|
+
return {
|
|
2752
|
+
s: function s() {
|
|
2753
|
+
t = t.call(r);
|
|
2754
|
+
},
|
|
2755
|
+
n: function n() {
|
|
2756
|
+
var r = t.next();
|
|
2757
|
+
return a = r.done, r;
|
|
2758
|
+
},
|
|
2759
|
+
e: function e(r) {
|
|
2760
|
+
u = !0, o = r;
|
|
2761
|
+
},
|
|
2762
|
+
f: function f() {
|
|
2763
|
+
try {
|
|
2764
|
+
a || null == t["return"] || t["return"]();
|
|
2765
|
+
} finally {
|
|
2766
|
+
if (u) throw o;
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
function _assertThisInitialized(e) {
|
|
2773
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
2774
|
+
return e;
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
function _setPrototypeOf(t, e) {
|
|
2778
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
2779
|
+
return t.__proto__ = e, t;
|
|
2780
|
+
}, _setPrototypeOf(t, e);
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
function _inherits(t, e) {
|
|
2784
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
2785
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
2786
|
+
constructor: {
|
|
2787
|
+
value: t,
|
|
2788
|
+
writable: !0,
|
|
2789
|
+
configurable: !0
|
|
2790
|
+
}
|
|
2791
|
+
}), Object.defineProperty(t, "prototype", {
|
|
2792
|
+
writable: !1
|
|
2793
|
+
}), e && _setPrototypeOf(t, e);
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
function _getPrototypeOf(t) {
|
|
2797
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
2798
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
2799
|
+
}, _getPrototypeOf(t);
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
function _isNativeReflectConstruct() {
|
|
2803
|
+
try {
|
|
2804
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
2805
|
+
} catch (t) {}
|
|
2806
|
+
return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
|
|
2807
|
+
return !!t;
|
|
2808
|
+
})();
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
function _possibleConstructorReturn(t, e) {
|
|
2812
|
+
if (e && ("object" == _typeof(e) || "function" == typeof e)) return e;
|
|
2813
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
2814
|
+
return _assertThisInitialized(t);
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
function _createSuper(t) {
|
|
2818
|
+
var r = _isNativeReflectConstruct();
|
|
2819
|
+
return function () {
|
|
2820
|
+
var e,
|
|
2821
|
+
o = _getPrototypeOf(t);
|
|
2822
|
+
if (r) {
|
|
2823
|
+
var s = _getPrototypeOf(this).constructor;
|
|
2824
|
+
e = Reflect.construct(o, arguments, s);
|
|
2825
|
+
} else e = o.apply(this, arguments);
|
|
2826
|
+
return _possibleConstructorReturn(this, e);
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
function _classCallCheck(a, n) {
|
|
2831
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
function toPrimitive(t, r) {
|
|
2835
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
2836
|
+
var e = t[Symbol.toPrimitive];
|
|
2837
|
+
if (void 0 !== e) {
|
|
2838
|
+
var i = e.call(t, r || "default");
|
|
2839
|
+
if ("object" != _typeof(i)) return i;
|
|
2840
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
2778
2841
|
}
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2842
|
+
return ("string" === r ? String : Number)(t);
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
function toPropertyKey(t) {
|
|
2846
|
+
var i = toPrimitive(t, "string");
|
|
2847
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
function _defineProperties(e, r) {
|
|
2851
|
+
for (var t = 0; t < r.length; t++) {
|
|
2852
|
+
var o = r[t];
|
|
2853
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, toPropertyKey(o.key), o);
|
|
2784
2854
|
}
|
|
2785
|
-
|
|
2786
|
-
|
|
2855
|
+
}
|
|
2856
|
+
function _createClass(e, r, t) {
|
|
2857
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
2858
|
+
writable: !1
|
|
2859
|
+
}), e;
|
|
2860
|
+
}
|
|
2861
|
+
|
|
2862
|
+
function _defineProperty(e, r, t) {
|
|
2863
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
2864
|
+
value: t,
|
|
2865
|
+
enumerable: !0,
|
|
2866
|
+
configurable: !0,
|
|
2867
|
+
writable: !0
|
|
2868
|
+
}) : e[r] = t, e;
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
var TIMEZONE_UNIT_PRIORITY = 10;
|
|
2872
|
+
var Setter = /*#__PURE__*/function () {
|
|
2873
|
+
function Setter() {
|
|
2874
|
+
_classCallCheck(this, Setter);
|
|
2875
|
+
_defineProperty(this, "priority", void 0);
|
|
2876
|
+
_defineProperty(this, "subPriority", 0);
|
|
2787
2877
|
}
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
time = parseTime(dateStrings.time);
|
|
2793
|
-
if (isNaN(time)) {
|
|
2794
|
-
return new Date(NaN);
|
|
2878
|
+
_createClass(Setter, [{
|
|
2879
|
+
key: "validate",
|
|
2880
|
+
value: function validate(_utcDate, _options) {
|
|
2881
|
+
return true;
|
|
2795
2882
|
}
|
|
2883
|
+
}]);
|
|
2884
|
+
return Setter;
|
|
2885
|
+
}();
|
|
2886
|
+
var ValueSetter = /*#__PURE__*/function (_Setter) {
|
|
2887
|
+
_inherits(ValueSetter, _Setter);
|
|
2888
|
+
var _super = _createSuper(ValueSetter);
|
|
2889
|
+
function ValueSetter(value, validateValue, setValue, priority, subPriority) {
|
|
2890
|
+
var _this;
|
|
2891
|
+
_classCallCheck(this, ValueSetter);
|
|
2892
|
+
_this = _super.call(this);
|
|
2893
|
+
_this.value = value;
|
|
2894
|
+
_this.validateValue = validateValue;
|
|
2895
|
+
_this.setValue = setValue;
|
|
2896
|
+
_this.priority = priority;
|
|
2897
|
+
if (subPriority) {
|
|
2898
|
+
_this.subPriority = subPriority;
|
|
2899
|
+
}
|
|
2900
|
+
return _this;
|
|
2796
2901
|
}
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
return
|
|
2902
|
+
_createClass(ValueSetter, [{
|
|
2903
|
+
key: "validate",
|
|
2904
|
+
value: function validate(utcDate, options) {
|
|
2905
|
+
return this.validateValue(utcDate, this.value, options);
|
|
2801
2906
|
}
|
|
2802
|
-
}
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2907
|
+
}, {
|
|
2908
|
+
key: "set",
|
|
2909
|
+
value: function set(utcDate, flags, options) {
|
|
2910
|
+
return this.setValue(utcDate, flags, this.value, options);
|
|
2911
|
+
}
|
|
2912
|
+
}]);
|
|
2913
|
+
return ValueSetter;
|
|
2914
|
+
}(Setter);
|
|
2915
|
+
var DateToSystemTimezoneSetter = /*#__PURE__*/function (_Setter2) {
|
|
2916
|
+
_inherits(DateToSystemTimezoneSetter, _Setter2);
|
|
2917
|
+
var _super2 = _createSuper(DateToSystemTimezoneSetter);
|
|
2918
|
+
function DateToSystemTimezoneSetter() {
|
|
2919
|
+
var _this2;
|
|
2920
|
+
_classCallCheck(this, DateToSystemTimezoneSetter);
|
|
2921
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2922
|
+
args[_key] = arguments[_key];
|
|
2923
|
+
}
|
|
2924
|
+
_this2 = _super2.call.apply(_super2, [this].concat(args));
|
|
2925
|
+
_defineProperty(_assertThisInitialized(_this2), "priority", TIMEZONE_UNIT_PRIORITY);
|
|
2926
|
+
_defineProperty(_assertThisInitialized(_this2), "subPriority", -1);
|
|
2927
|
+
return _this2;
|
|
2813
2928
|
}
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2929
|
+
_createClass(DateToSystemTimezoneSetter, [{
|
|
2930
|
+
key: "set",
|
|
2931
|
+
value: function set(date, flags) {
|
|
2932
|
+
if (flags.timestampIsSet) {
|
|
2933
|
+
return date;
|
|
2934
|
+
}
|
|
2935
|
+
var convertedDate = new Date(0);
|
|
2936
|
+
convertedDate.setFullYear(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
|
|
2937
|
+
convertedDate.setHours(date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());
|
|
2938
|
+
return convertedDate;
|
|
2939
|
+
}
|
|
2940
|
+
}]);
|
|
2941
|
+
return DateToSystemTimezoneSetter;
|
|
2942
|
+
}(Setter);
|
|
2828
2943
|
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2944
|
+
var Parser = /*#__PURE__*/function () {
|
|
2945
|
+
function Parser() {
|
|
2946
|
+
_classCallCheck(this, Parser);
|
|
2947
|
+
_defineProperty(this, "incompatibleTokens", void 0);
|
|
2948
|
+
_defineProperty(this, "priority", void 0);
|
|
2949
|
+
_defineProperty(this, "subPriority", void 0);
|
|
2833
2950
|
}
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2951
|
+
_createClass(Parser, [{
|
|
2952
|
+
key: "run",
|
|
2953
|
+
value: function run(dateString, token, match, options) {
|
|
2954
|
+
var result = this.parse(dateString, token, match, options);
|
|
2955
|
+
if (!result) {
|
|
2956
|
+
return null;
|
|
2957
|
+
}
|
|
2958
|
+
return {
|
|
2959
|
+
setter: new ValueSetter(result.value, this.validate, this.set, this.priority, this.subPriority),
|
|
2960
|
+
rest: result.rest
|
|
2961
|
+
};
|
|
2962
|
+
}
|
|
2963
|
+
}, {
|
|
2964
|
+
key: "validate",
|
|
2965
|
+
value: function validate(_utcDate, _value, _options) {
|
|
2966
|
+
return true;
|
|
2967
|
+
}
|
|
2968
|
+
}]);
|
|
2969
|
+
return Parser;
|
|
2970
|
+
}();
|
|
2971
|
+
|
|
2972
|
+
var EraParser = /*#__PURE__*/function (_Parser) {
|
|
2973
|
+
_inherits(EraParser, _Parser);
|
|
2974
|
+
var _super = _createSuper(EraParser);
|
|
2975
|
+
function EraParser() {
|
|
2976
|
+
var _this;
|
|
2977
|
+
_classCallCheck(this, EraParser);
|
|
2978
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2979
|
+
args[_key] = arguments[_key];
|
|
2842
2980
|
}
|
|
2981
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
2982
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 140);
|
|
2983
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['R', 'u', 't', 'T']);
|
|
2984
|
+
return _this;
|
|
2843
2985
|
}
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2986
|
+
_createClass(EraParser, [{
|
|
2987
|
+
key: "parse",
|
|
2988
|
+
value: function parse(dateString, token, match) {
|
|
2989
|
+
switch (token) {
|
|
2990
|
+
// AD, BC
|
|
2991
|
+
case 'G':
|
|
2992
|
+
case 'GG':
|
|
2993
|
+
case 'GGG':
|
|
2994
|
+
return match.era(dateString, {
|
|
2995
|
+
width: 'abbreviated'
|
|
2996
|
+
}) || match.era(dateString, {
|
|
2997
|
+
width: 'narrow'
|
|
2998
|
+
});
|
|
2999
|
+
// A, B
|
|
3000
|
+
case 'GGGGG':
|
|
3001
|
+
return match.era(dateString, {
|
|
3002
|
+
width: 'narrow'
|
|
3003
|
+
});
|
|
3004
|
+
// Anno Domini, Before Christ
|
|
3005
|
+
case 'GGGG':
|
|
3006
|
+
default:
|
|
3007
|
+
return match.era(dateString, {
|
|
3008
|
+
width: 'wide'
|
|
3009
|
+
}) || match.era(dateString, {
|
|
3010
|
+
width: 'abbreviated'
|
|
3011
|
+
}) || match.era(dateString, {
|
|
3012
|
+
width: 'narrow'
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
2851
3015
|
}
|
|
3016
|
+
}, {
|
|
3017
|
+
key: "set",
|
|
3018
|
+
value: function set(date, flags, value) {
|
|
3019
|
+
flags.era = value;
|
|
3020
|
+
date.setUTCFullYear(value, 0, 1);
|
|
3021
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3022
|
+
return date;
|
|
3023
|
+
}
|
|
3024
|
+
}]);
|
|
3025
|
+
return EraParser;
|
|
3026
|
+
}(Parser);
|
|
3027
|
+
|
|
3028
|
+
var numericPatterns = {
|
|
3029
|
+
month: /^(1[0-2]|0?\d)/,
|
|
3030
|
+
// 0 to 12
|
|
3031
|
+
date: /^(3[0-1]|[0-2]?\d)/,
|
|
3032
|
+
// 0 to 31
|
|
3033
|
+
dayOfYear: /^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,
|
|
3034
|
+
// 0 to 366
|
|
3035
|
+
week: /^(5[0-3]|[0-4]?\d)/,
|
|
3036
|
+
// 0 to 53
|
|
3037
|
+
hour23h: /^(2[0-3]|[0-1]?\d)/,
|
|
3038
|
+
// 0 to 23
|
|
3039
|
+
hour24h: /^(2[0-4]|[0-1]?\d)/,
|
|
3040
|
+
// 0 to 24
|
|
3041
|
+
hour11h: /^(1[0-1]|0?\d)/,
|
|
3042
|
+
// 0 to 11
|
|
3043
|
+
hour12h: /^(1[0-2]|0?\d)/,
|
|
3044
|
+
// 0 to 12
|
|
3045
|
+
minute: /^[0-5]?\d/,
|
|
3046
|
+
// 0 to 59
|
|
3047
|
+
second: /^[0-5]?\d/,
|
|
3048
|
+
// 0 to 59
|
|
3049
|
+
|
|
3050
|
+
singleDigit: /^\d/,
|
|
3051
|
+
// 0 to 9
|
|
3052
|
+
twoDigits: /^\d{1,2}/,
|
|
3053
|
+
// 0 to 99
|
|
3054
|
+
threeDigits: /^\d{1,3}/,
|
|
3055
|
+
// 0 to 999
|
|
3056
|
+
fourDigits: /^\d{1,4}/,
|
|
3057
|
+
// 0 to 9999
|
|
3058
|
+
|
|
3059
|
+
anyDigitsSigned: /^-?\d+/,
|
|
3060
|
+
singleDigitSigned: /^-?\d/,
|
|
3061
|
+
// 0 to 9, -0 to -9
|
|
3062
|
+
twoDigitsSigned: /^-?\d{1,2}/,
|
|
3063
|
+
// 0 to 99, -0 to -99
|
|
3064
|
+
threeDigitsSigned: /^-?\d{1,3}/,
|
|
3065
|
+
// 0 to 999, -0 to -999
|
|
3066
|
+
fourDigitsSigned: /^-?\d{1,4}/ // 0 to 9999, -0 to -9999
|
|
3067
|
+
};
|
|
3068
|
+
|
|
3069
|
+
var timezonePatterns = {
|
|
3070
|
+
basicOptionalMinutes: /^([+-])(\d{2})(\d{2})?|Z/,
|
|
3071
|
+
basic: /^([+-])(\d{2})(\d{2})|Z/,
|
|
3072
|
+
basicOptionalSeconds: /^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,
|
|
3073
|
+
extended: /^([+-])(\d{2}):(\d{2})|Z/,
|
|
3074
|
+
extendedOptionalSeconds: /^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/
|
|
3075
|
+
};
|
|
3076
|
+
|
|
3077
|
+
function mapValue(parseFnResult, mapFn) {
|
|
3078
|
+
if (!parseFnResult) {
|
|
3079
|
+
return parseFnResult;
|
|
2852
3080
|
}
|
|
2853
|
-
return
|
|
3081
|
+
return {
|
|
3082
|
+
value: mapFn(parseFnResult.value),
|
|
3083
|
+
rest: parseFnResult.rest
|
|
3084
|
+
};
|
|
2854
3085
|
}
|
|
2855
|
-
function
|
|
2856
|
-
var
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
3086
|
+
function parseNumericPattern(pattern, dateString) {
|
|
3087
|
+
var matchResult = dateString.match(pattern);
|
|
3088
|
+
if (!matchResult) {
|
|
3089
|
+
return null;
|
|
3090
|
+
}
|
|
3091
|
+
return {
|
|
3092
|
+
value: parseInt(matchResult[0], 10),
|
|
3093
|
+
rest: dateString.slice(matchResult[0].length)
|
|
2862
3094
|
};
|
|
2863
|
-
|
|
2864
|
-
|
|
3095
|
+
}
|
|
3096
|
+
function parseTimezonePattern(pattern, dateString) {
|
|
3097
|
+
var matchResult = dateString.match(pattern);
|
|
3098
|
+
if (!matchResult) {
|
|
3099
|
+
return null;
|
|
3100
|
+
}
|
|
2865
3101
|
|
|
2866
|
-
//
|
|
3102
|
+
// Input is 'Z'
|
|
3103
|
+
if (matchResult[0] === 'Z') {
|
|
3104
|
+
return {
|
|
3105
|
+
value: 0,
|
|
3106
|
+
rest: dateString.slice(1)
|
|
3107
|
+
};
|
|
3108
|
+
}
|
|
3109
|
+
var sign = matchResult[1] === '+' ? 1 : -1;
|
|
3110
|
+
var hours = matchResult[2] ? parseInt(matchResult[2], 10) : 0;
|
|
3111
|
+
var minutes = matchResult[3] ? parseInt(matchResult[3], 10) : 0;
|
|
3112
|
+
var seconds = matchResult[5] ? parseInt(matchResult[5], 10) : 0;
|
|
2867
3113
|
return {
|
|
2868
|
-
|
|
2869
|
-
|
|
3114
|
+
value: sign * (hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * millisecondsInSecond),
|
|
3115
|
+
rest: dateString.slice(matchResult[0].length)
|
|
2870
3116
|
};
|
|
2871
3117
|
}
|
|
2872
|
-
function
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
3118
|
+
function parseAnyDigitsSigned(dateString) {
|
|
3119
|
+
return parseNumericPattern(numericPatterns.anyDigitsSigned, dateString);
|
|
3120
|
+
}
|
|
3121
|
+
function parseNDigits(n, dateString) {
|
|
3122
|
+
switch (n) {
|
|
3123
|
+
case 1:
|
|
3124
|
+
return parseNumericPattern(numericPatterns.singleDigit, dateString);
|
|
3125
|
+
case 2:
|
|
3126
|
+
return parseNumericPattern(numericPatterns.twoDigits, dateString);
|
|
3127
|
+
case 3:
|
|
3128
|
+
return parseNumericPattern(numericPatterns.threeDigits, dateString);
|
|
3129
|
+
case 4:
|
|
3130
|
+
return parseNumericPattern(numericPatterns.fourDigits, dateString);
|
|
3131
|
+
default:
|
|
3132
|
+
return parseNumericPattern(new RegExp('^\\d{1,' + n + '}'), dateString);
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
function parseNDigitsSigned(n, dateString) {
|
|
3136
|
+
switch (n) {
|
|
3137
|
+
case 1:
|
|
3138
|
+
return parseNumericPattern(numericPatterns.singleDigitSigned, dateString);
|
|
3139
|
+
case 2:
|
|
3140
|
+
return parseNumericPattern(numericPatterns.twoDigitsSigned, dateString);
|
|
3141
|
+
case 3:
|
|
3142
|
+
return parseNumericPattern(numericPatterns.threeDigitsSigned, dateString);
|
|
3143
|
+
case 4:
|
|
3144
|
+
return parseNumericPattern(numericPatterns.fourDigitsSigned, dateString);
|
|
3145
|
+
default:
|
|
3146
|
+
return parseNumericPattern(new RegExp('^-?\\d{1,' + n + '}'), dateString);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
function dayPeriodEnumToHours(dayPeriod) {
|
|
3150
|
+
switch (dayPeriod) {
|
|
3151
|
+
case 'morning':
|
|
3152
|
+
return 4;
|
|
3153
|
+
case 'evening':
|
|
3154
|
+
return 17;
|
|
3155
|
+
case 'pm':
|
|
3156
|
+
case 'noon':
|
|
3157
|
+
case 'afternoon':
|
|
3158
|
+
return 12;
|
|
3159
|
+
case 'am':
|
|
3160
|
+
case 'midnight':
|
|
3161
|
+
case 'night':
|
|
3162
|
+
default:
|
|
3163
|
+
return 0;
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
function normalizeTwoDigitYear(twoDigitYear, currentYear) {
|
|
3167
|
+
var isCommonEra = currentYear > 0;
|
|
3168
|
+
// Absolute number of the current year:
|
|
3169
|
+
// 1 -> 1 AC
|
|
3170
|
+
// 0 -> 1 BC
|
|
3171
|
+
// -1 -> 2 BC
|
|
3172
|
+
var absCurrentYear = isCommonEra ? currentYear : 1 - currentYear;
|
|
3173
|
+
var result;
|
|
3174
|
+
if (absCurrentYear <= 50) {
|
|
3175
|
+
result = twoDigitYear || 100;
|
|
3176
|
+
} else {
|
|
3177
|
+
var rangeEnd = absCurrentYear + 50;
|
|
3178
|
+
var rangeEndCentury = Math.floor(rangeEnd / 100) * 100;
|
|
3179
|
+
var isPreviousCentury = twoDigitYear >= rangeEnd % 100;
|
|
3180
|
+
result = twoDigitYear + rangeEndCentury - (isPreviousCentury ? 100 : 0);
|
|
3181
|
+
}
|
|
3182
|
+
return isCommonEra ? result : 1 - result;
|
|
3183
|
+
}
|
|
3184
|
+
function isLeapYearIndex$1(year) {
|
|
3185
|
+
return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
|
|
3186
|
+
}
|
|
3187
|
+
|
|
3188
|
+
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
|
|
3189
|
+
// | Year | y | yy | yyy | yyyy | yyyyy |
|
|
3190
|
+
// |----------|-------|----|-------|-------|-------|
|
|
3191
|
+
// | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
|
|
3192
|
+
// | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
|
|
3193
|
+
// | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
|
|
3194
|
+
// | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
|
|
3195
|
+
// | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
|
|
3196
|
+
var YearParser = /*#__PURE__*/function (_Parser) {
|
|
3197
|
+
_inherits(YearParser, _Parser);
|
|
3198
|
+
var _super = _createSuper(YearParser);
|
|
3199
|
+
function YearParser() {
|
|
3200
|
+
var _this;
|
|
3201
|
+
_classCallCheck(this, YearParser);
|
|
3202
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3203
|
+
args[_key] = arguments[_key];
|
|
3204
|
+
}
|
|
3205
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3206
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 130);
|
|
3207
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['Y', 'R', 'u', 'w', 'I', 'i', 'e', 'c', 't', 'T']);
|
|
3208
|
+
return _this;
|
|
3209
|
+
}
|
|
3210
|
+
_createClass(YearParser, [{
|
|
3211
|
+
key: "parse",
|
|
3212
|
+
value: function parse(dateString, token, match) {
|
|
3213
|
+
var valueCallback = function valueCallback(year) {
|
|
3214
|
+
return {
|
|
3215
|
+
year: year,
|
|
3216
|
+
isTwoDigitYear: token === 'yy'
|
|
3217
|
+
};
|
|
3218
|
+
};
|
|
3219
|
+
switch (token) {
|
|
3220
|
+
case 'y':
|
|
3221
|
+
return mapValue(parseNDigits(4, dateString), valueCallback);
|
|
3222
|
+
case 'yo':
|
|
3223
|
+
return mapValue(match.ordinalNumber(dateString, {
|
|
3224
|
+
unit: 'year'
|
|
3225
|
+
}), valueCallback);
|
|
3226
|
+
default:
|
|
3227
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
}, {
|
|
3231
|
+
key: "validate",
|
|
3232
|
+
value: function validate(_date, value) {
|
|
3233
|
+
return value.isTwoDigitYear || value.year > 0;
|
|
3234
|
+
}
|
|
3235
|
+
}, {
|
|
3236
|
+
key: "set",
|
|
3237
|
+
value: function set(date, flags, value) {
|
|
3238
|
+
var currentYear = date.getUTCFullYear();
|
|
3239
|
+
if (value.isTwoDigitYear) {
|
|
3240
|
+
var normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear);
|
|
3241
|
+
date.setUTCFullYear(normalizedTwoDigitYear, 0, 1);
|
|
3242
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3243
|
+
return date;
|
|
3244
|
+
}
|
|
3245
|
+
var year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year;
|
|
3246
|
+
date.setUTCFullYear(year, 0, 1);
|
|
3247
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3248
|
+
return date;
|
|
3249
|
+
}
|
|
3250
|
+
}]);
|
|
3251
|
+
return YearParser;
|
|
3252
|
+
}(Parser);
|
|
3253
|
+
|
|
3254
|
+
// Local week-numbering year
|
|
3255
|
+
var LocalWeekYearParser = /*#__PURE__*/function (_Parser) {
|
|
3256
|
+
_inherits(LocalWeekYearParser, _Parser);
|
|
3257
|
+
var _super = _createSuper(LocalWeekYearParser);
|
|
3258
|
+
function LocalWeekYearParser() {
|
|
3259
|
+
var _this;
|
|
3260
|
+
_classCallCheck(this, LocalWeekYearParser);
|
|
3261
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3262
|
+
args[_key] = arguments[_key];
|
|
3263
|
+
}
|
|
3264
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3265
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 130);
|
|
3266
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['y', 'R', 'u', 'Q', 'q', 'M', 'L', 'I', 'd', 'D', 'i', 't', 'T']);
|
|
3267
|
+
return _this;
|
|
3268
|
+
}
|
|
3269
|
+
_createClass(LocalWeekYearParser, [{
|
|
3270
|
+
key: "parse",
|
|
3271
|
+
value: function parse(dateString, token, match) {
|
|
3272
|
+
var valueCallback = function valueCallback(year) {
|
|
3273
|
+
return {
|
|
3274
|
+
year: year,
|
|
3275
|
+
isTwoDigitYear: token === 'YY'
|
|
3276
|
+
};
|
|
3277
|
+
};
|
|
3278
|
+
switch (token) {
|
|
3279
|
+
case 'Y':
|
|
3280
|
+
return mapValue(parseNDigits(4, dateString), valueCallback);
|
|
3281
|
+
case 'Yo':
|
|
3282
|
+
return mapValue(match.ordinalNumber(dateString, {
|
|
3283
|
+
unit: 'year'
|
|
3284
|
+
}), valueCallback);
|
|
3285
|
+
default:
|
|
3286
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
}, {
|
|
3290
|
+
key: "validate",
|
|
3291
|
+
value: function validate(_date, value) {
|
|
3292
|
+
return value.isTwoDigitYear || value.year > 0;
|
|
3293
|
+
}
|
|
3294
|
+
}, {
|
|
3295
|
+
key: "set",
|
|
3296
|
+
value: function set(date, flags, value, options) {
|
|
3297
|
+
var currentYear = getUTCWeekYear(date, options);
|
|
3298
|
+
if (value.isTwoDigitYear) {
|
|
3299
|
+
var normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear);
|
|
3300
|
+
date.setUTCFullYear(normalizedTwoDigitYear, 0, options.firstWeekContainsDate);
|
|
3301
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3302
|
+
return startOfUTCWeek(date, options);
|
|
3303
|
+
}
|
|
3304
|
+
var year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year;
|
|
3305
|
+
date.setUTCFullYear(year, 0, options.firstWeekContainsDate);
|
|
3306
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3307
|
+
return startOfUTCWeek(date, options);
|
|
3308
|
+
}
|
|
3309
|
+
}]);
|
|
3310
|
+
return LocalWeekYearParser;
|
|
3311
|
+
}(Parser);
|
|
3312
|
+
|
|
3313
|
+
var ISOWeekYearParser = /*#__PURE__*/function (_Parser) {
|
|
3314
|
+
_inherits(ISOWeekYearParser, _Parser);
|
|
3315
|
+
var _super = _createSuper(ISOWeekYearParser);
|
|
3316
|
+
function ISOWeekYearParser() {
|
|
3317
|
+
var _this;
|
|
3318
|
+
_classCallCheck(this, ISOWeekYearParser);
|
|
3319
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3320
|
+
args[_key] = arguments[_key];
|
|
3321
|
+
}
|
|
3322
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3323
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 130);
|
|
3324
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['G', 'y', 'Y', 'u', 'Q', 'q', 'M', 'L', 'w', 'd', 'D', 'e', 'c', 't', 'T']);
|
|
3325
|
+
return _this;
|
|
3326
|
+
}
|
|
3327
|
+
_createClass(ISOWeekYearParser, [{
|
|
3328
|
+
key: "parse",
|
|
3329
|
+
value: function parse(dateString, token) {
|
|
3330
|
+
if (token === 'R') {
|
|
3331
|
+
return parseNDigitsSigned(4, dateString);
|
|
3332
|
+
}
|
|
3333
|
+
return parseNDigitsSigned(token.length, dateString);
|
|
3334
|
+
}
|
|
3335
|
+
}, {
|
|
3336
|
+
key: "set",
|
|
3337
|
+
value: function set(_date, _flags, value) {
|
|
3338
|
+
var firstWeekOfYear = new Date(0);
|
|
3339
|
+
firstWeekOfYear.setUTCFullYear(value, 0, 4);
|
|
3340
|
+
firstWeekOfYear.setUTCHours(0, 0, 0, 0);
|
|
3341
|
+
return startOfUTCISOWeek(firstWeekOfYear);
|
|
3342
|
+
}
|
|
3343
|
+
}]);
|
|
3344
|
+
return ISOWeekYearParser;
|
|
3345
|
+
}(Parser);
|
|
3346
|
+
|
|
3347
|
+
var ExtendedYearParser = /*#__PURE__*/function (_Parser) {
|
|
3348
|
+
_inherits(ExtendedYearParser, _Parser);
|
|
3349
|
+
var _super = _createSuper(ExtendedYearParser);
|
|
3350
|
+
function ExtendedYearParser() {
|
|
3351
|
+
var _this;
|
|
3352
|
+
_classCallCheck(this, ExtendedYearParser);
|
|
3353
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3354
|
+
args[_key] = arguments[_key];
|
|
3355
|
+
}
|
|
3356
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3357
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 130);
|
|
3358
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['G', 'y', 'Y', 'R', 'w', 'I', 'i', 'e', 'c', 't', 'T']);
|
|
3359
|
+
return _this;
|
|
3360
|
+
}
|
|
3361
|
+
_createClass(ExtendedYearParser, [{
|
|
3362
|
+
key: "parse",
|
|
3363
|
+
value: function parse(dateString, token) {
|
|
3364
|
+
if (token === 'u') {
|
|
3365
|
+
return parseNDigitsSigned(4, dateString);
|
|
3366
|
+
}
|
|
3367
|
+
return parseNDigitsSigned(token.length, dateString);
|
|
3368
|
+
}
|
|
3369
|
+
}, {
|
|
3370
|
+
key: "set",
|
|
3371
|
+
value: function set(date, _flags, value) {
|
|
3372
|
+
date.setUTCFullYear(value, 0, 1);
|
|
3373
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3374
|
+
return date;
|
|
3375
|
+
}
|
|
3376
|
+
}]);
|
|
3377
|
+
return ExtendedYearParser;
|
|
3378
|
+
}(Parser);
|
|
3379
|
+
|
|
3380
|
+
var QuarterParser = /*#__PURE__*/function (_Parser) {
|
|
3381
|
+
_inherits(QuarterParser, _Parser);
|
|
3382
|
+
var _super = _createSuper(QuarterParser);
|
|
3383
|
+
function QuarterParser() {
|
|
3384
|
+
var _this;
|
|
3385
|
+
_classCallCheck(this, QuarterParser);
|
|
3386
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3387
|
+
args[_key] = arguments[_key];
|
|
3388
|
+
}
|
|
3389
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3390
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 120);
|
|
3391
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['Y', 'R', 'q', 'M', 'L', 'w', 'I', 'd', 'D', 'i', 'e', 'c', 't', 'T']);
|
|
3392
|
+
return _this;
|
|
3393
|
+
}
|
|
3394
|
+
_createClass(QuarterParser, [{
|
|
3395
|
+
key: "parse",
|
|
3396
|
+
value: function parse(dateString, token, match) {
|
|
3397
|
+
switch (token) {
|
|
3398
|
+
// 1, 2, 3, 4
|
|
3399
|
+
case 'Q':
|
|
3400
|
+
case 'QQ':
|
|
3401
|
+
// 01, 02, 03, 04
|
|
3402
|
+
return parseNDigits(token.length, dateString);
|
|
3403
|
+
// 1st, 2nd, 3rd, 4th
|
|
3404
|
+
case 'Qo':
|
|
3405
|
+
return match.ordinalNumber(dateString, {
|
|
3406
|
+
unit: 'quarter'
|
|
3407
|
+
});
|
|
3408
|
+
// Q1, Q2, Q3, Q4
|
|
3409
|
+
case 'QQQ':
|
|
3410
|
+
return match.quarter(dateString, {
|
|
3411
|
+
width: 'abbreviated',
|
|
3412
|
+
context: 'formatting'
|
|
3413
|
+
}) || match.quarter(dateString, {
|
|
3414
|
+
width: 'narrow',
|
|
3415
|
+
context: 'formatting'
|
|
3416
|
+
});
|
|
3417
|
+
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
3418
|
+
case 'QQQQQ':
|
|
3419
|
+
return match.quarter(dateString, {
|
|
3420
|
+
width: 'narrow',
|
|
3421
|
+
context: 'formatting'
|
|
3422
|
+
});
|
|
3423
|
+
// 1st quarter, 2nd quarter, ...
|
|
3424
|
+
case 'QQQQ':
|
|
3425
|
+
default:
|
|
3426
|
+
return match.quarter(dateString, {
|
|
3427
|
+
width: 'wide',
|
|
3428
|
+
context: 'formatting'
|
|
3429
|
+
}) || match.quarter(dateString, {
|
|
3430
|
+
width: 'abbreviated',
|
|
3431
|
+
context: 'formatting'
|
|
3432
|
+
}) || match.quarter(dateString, {
|
|
3433
|
+
width: 'narrow',
|
|
3434
|
+
context: 'formatting'
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
}, {
|
|
3439
|
+
key: "validate",
|
|
3440
|
+
value: function validate(_date, value) {
|
|
3441
|
+
return value >= 1 && value <= 4;
|
|
3442
|
+
}
|
|
3443
|
+
}, {
|
|
3444
|
+
key: "set",
|
|
3445
|
+
value: function set(date, _flags, value) {
|
|
3446
|
+
date.setUTCMonth((value - 1) * 3, 1);
|
|
3447
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3448
|
+
return date;
|
|
3449
|
+
}
|
|
3450
|
+
}]);
|
|
3451
|
+
return QuarterParser;
|
|
3452
|
+
}(Parser);
|
|
3453
|
+
|
|
3454
|
+
var StandAloneQuarterParser = /*#__PURE__*/function (_Parser) {
|
|
3455
|
+
_inherits(StandAloneQuarterParser, _Parser);
|
|
3456
|
+
var _super = _createSuper(StandAloneQuarterParser);
|
|
3457
|
+
function StandAloneQuarterParser() {
|
|
3458
|
+
var _this;
|
|
3459
|
+
_classCallCheck(this, StandAloneQuarterParser);
|
|
3460
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3461
|
+
args[_key] = arguments[_key];
|
|
3462
|
+
}
|
|
3463
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3464
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 120);
|
|
3465
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['Y', 'R', 'Q', 'M', 'L', 'w', 'I', 'd', 'D', 'i', 'e', 'c', 't', 'T']);
|
|
3466
|
+
return _this;
|
|
3467
|
+
}
|
|
3468
|
+
_createClass(StandAloneQuarterParser, [{
|
|
3469
|
+
key: "parse",
|
|
3470
|
+
value: function parse(dateString, token, match) {
|
|
3471
|
+
switch (token) {
|
|
3472
|
+
// 1, 2, 3, 4
|
|
3473
|
+
case 'q':
|
|
3474
|
+
case 'qq':
|
|
3475
|
+
// 01, 02, 03, 04
|
|
3476
|
+
return parseNDigits(token.length, dateString);
|
|
3477
|
+
// 1st, 2nd, 3rd, 4th
|
|
3478
|
+
case 'qo':
|
|
3479
|
+
return match.ordinalNumber(dateString, {
|
|
3480
|
+
unit: 'quarter'
|
|
3481
|
+
});
|
|
3482
|
+
// Q1, Q2, Q3, Q4
|
|
3483
|
+
case 'qqq':
|
|
3484
|
+
return match.quarter(dateString, {
|
|
3485
|
+
width: 'abbreviated',
|
|
3486
|
+
context: 'standalone'
|
|
3487
|
+
}) || match.quarter(dateString, {
|
|
3488
|
+
width: 'narrow',
|
|
3489
|
+
context: 'standalone'
|
|
3490
|
+
});
|
|
3491
|
+
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
3492
|
+
case 'qqqqq':
|
|
3493
|
+
return match.quarter(dateString, {
|
|
3494
|
+
width: 'narrow',
|
|
3495
|
+
context: 'standalone'
|
|
3496
|
+
});
|
|
3497
|
+
// 1st quarter, 2nd quarter, ...
|
|
3498
|
+
case 'qqqq':
|
|
3499
|
+
default:
|
|
3500
|
+
return match.quarter(dateString, {
|
|
3501
|
+
width: 'wide',
|
|
3502
|
+
context: 'standalone'
|
|
3503
|
+
}) || match.quarter(dateString, {
|
|
3504
|
+
width: 'abbreviated',
|
|
3505
|
+
context: 'standalone'
|
|
3506
|
+
}) || match.quarter(dateString, {
|
|
3507
|
+
width: 'narrow',
|
|
3508
|
+
context: 'standalone'
|
|
3509
|
+
});
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
}, {
|
|
3513
|
+
key: "validate",
|
|
3514
|
+
value: function validate(_date, value) {
|
|
3515
|
+
return value >= 1 && value <= 4;
|
|
3516
|
+
}
|
|
3517
|
+
}, {
|
|
3518
|
+
key: "set",
|
|
3519
|
+
value: function set(date, _flags, value) {
|
|
3520
|
+
date.setUTCMonth((value - 1) * 3, 1);
|
|
3521
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3522
|
+
return date;
|
|
3523
|
+
}
|
|
3524
|
+
}]);
|
|
3525
|
+
return StandAloneQuarterParser;
|
|
3526
|
+
}(Parser);
|
|
3527
|
+
|
|
3528
|
+
var MonthParser = /*#__PURE__*/function (_Parser) {
|
|
3529
|
+
_inherits(MonthParser, _Parser);
|
|
3530
|
+
var _super = _createSuper(MonthParser);
|
|
3531
|
+
function MonthParser() {
|
|
3532
|
+
var _this;
|
|
3533
|
+
_classCallCheck(this, MonthParser);
|
|
3534
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3535
|
+
args[_key] = arguments[_key];
|
|
3536
|
+
}
|
|
3537
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3538
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['Y', 'R', 'q', 'Q', 'L', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T']);
|
|
3539
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 110);
|
|
3540
|
+
return _this;
|
|
3541
|
+
}
|
|
3542
|
+
_createClass(MonthParser, [{
|
|
3543
|
+
key: "parse",
|
|
3544
|
+
value: function parse(dateString, token, match) {
|
|
3545
|
+
var valueCallback = function valueCallback(value) {
|
|
3546
|
+
return value - 1;
|
|
3547
|
+
};
|
|
3548
|
+
switch (token) {
|
|
3549
|
+
// 1, 2, ..., 12
|
|
3550
|
+
case 'M':
|
|
3551
|
+
return mapValue(parseNumericPattern(numericPatterns.month, dateString), valueCallback);
|
|
3552
|
+
// 01, 02, ..., 12
|
|
3553
|
+
case 'MM':
|
|
3554
|
+
return mapValue(parseNDigits(2, dateString), valueCallback);
|
|
3555
|
+
// 1st, 2nd, ..., 12th
|
|
3556
|
+
case 'Mo':
|
|
3557
|
+
return mapValue(match.ordinalNumber(dateString, {
|
|
3558
|
+
unit: 'month'
|
|
3559
|
+
}), valueCallback);
|
|
3560
|
+
// Jan, Feb, ..., Dec
|
|
3561
|
+
case 'MMM':
|
|
3562
|
+
return match.month(dateString, {
|
|
3563
|
+
width: 'abbreviated',
|
|
3564
|
+
context: 'formatting'
|
|
3565
|
+
}) || match.month(dateString, {
|
|
3566
|
+
width: 'narrow',
|
|
3567
|
+
context: 'formatting'
|
|
3568
|
+
});
|
|
3569
|
+
// J, F, ..., D
|
|
3570
|
+
case 'MMMMM':
|
|
3571
|
+
return match.month(dateString, {
|
|
3572
|
+
width: 'narrow',
|
|
3573
|
+
context: 'formatting'
|
|
3574
|
+
});
|
|
3575
|
+
// January, February, ..., December
|
|
3576
|
+
case 'MMMM':
|
|
3577
|
+
default:
|
|
3578
|
+
return match.month(dateString, {
|
|
3579
|
+
width: 'wide',
|
|
3580
|
+
context: 'formatting'
|
|
3581
|
+
}) || match.month(dateString, {
|
|
3582
|
+
width: 'abbreviated',
|
|
3583
|
+
context: 'formatting'
|
|
3584
|
+
}) || match.month(dateString, {
|
|
3585
|
+
width: 'narrow',
|
|
3586
|
+
context: 'formatting'
|
|
3587
|
+
});
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
}, {
|
|
3591
|
+
key: "validate",
|
|
3592
|
+
value: function validate(_date, value) {
|
|
3593
|
+
return value >= 0 && value <= 11;
|
|
3594
|
+
}
|
|
3595
|
+
}, {
|
|
3596
|
+
key: "set",
|
|
3597
|
+
value: function set(date, _flags, value) {
|
|
3598
|
+
date.setUTCMonth(value, 1);
|
|
3599
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3600
|
+
return date;
|
|
3601
|
+
}
|
|
3602
|
+
}]);
|
|
3603
|
+
return MonthParser;
|
|
3604
|
+
}(Parser);
|
|
3605
|
+
|
|
3606
|
+
var StandAloneMonthParser = /*#__PURE__*/function (_Parser) {
|
|
3607
|
+
_inherits(StandAloneMonthParser, _Parser);
|
|
3608
|
+
var _super = _createSuper(StandAloneMonthParser);
|
|
3609
|
+
function StandAloneMonthParser() {
|
|
3610
|
+
var _this;
|
|
3611
|
+
_classCallCheck(this, StandAloneMonthParser);
|
|
3612
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3613
|
+
args[_key] = arguments[_key];
|
|
3614
|
+
}
|
|
3615
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3616
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 110);
|
|
3617
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['Y', 'R', 'q', 'Q', 'M', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T']);
|
|
3618
|
+
return _this;
|
|
3619
|
+
}
|
|
3620
|
+
_createClass(StandAloneMonthParser, [{
|
|
3621
|
+
key: "parse",
|
|
3622
|
+
value: function parse(dateString, token, match) {
|
|
3623
|
+
var valueCallback = function valueCallback(value) {
|
|
3624
|
+
return value - 1;
|
|
3625
|
+
};
|
|
3626
|
+
switch (token) {
|
|
3627
|
+
// 1, 2, ..., 12
|
|
3628
|
+
case 'L':
|
|
3629
|
+
return mapValue(parseNumericPattern(numericPatterns.month, dateString), valueCallback);
|
|
3630
|
+
// 01, 02, ..., 12
|
|
3631
|
+
case 'LL':
|
|
3632
|
+
return mapValue(parseNDigits(2, dateString), valueCallback);
|
|
3633
|
+
// 1st, 2nd, ..., 12th
|
|
3634
|
+
case 'Lo':
|
|
3635
|
+
return mapValue(match.ordinalNumber(dateString, {
|
|
3636
|
+
unit: 'month'
|
|
3637
|
+
}), valueCallback);
|
|
3638
|
+
// Jan, Feb, ..., Dec
|
|
3639
|
+
case 'LLL':
|
|
3640
|
+
return match.month(dateString, {
|
|
3641
|
+
width: 'abbreviated',
|
|
3642
|
+
context: 'standalone'
|
|
3643
|
+
}) || match.month(dateString, {
|
|
3644
|
+
width: 'narrow',
|
|
3645
|
+
context: 'standalone'
|
|
3646
|
+
});
|
|
3647
|
+
// J, F, ..., D
|
|
3648
|
+
case 'LLLLL':
|
|
3649
|
+
return match.month(dateString, {
|
|
3650
|
+
width: 'narrow',
|
|
3651
|
+
context: 'standalone'
|
|
3652
|
+
});
|
|
3653
|
+
// January, February, ..., December
|
|
3654
|
+
case 'LLLL':
|
|
3655
|
+
default:
|
|
3656
|
+
return match.month(dateString, {
|
|
3657
|
+
width: 'wide',
|
|
3658
|
+
context: 'standalone'
|
|
3659
|
+
}) || match.month(dateString, {
|
|
3660
|
+
width: 'abbreviated',
|
|
3661
|
+
context: 'standalone'
|
|
3662
|
+
}) || match.month(dateString, {
|
|
3663
|
+
width: 'narrow',
|
|
3664
|
+
context: 'standalone'
|
|
3665
|
+
});
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
}, {
|
|
3669
|
+
key: "validate",
|
|
3670
|
+
value: function validate(_date, value) {
|
|
3671
|
+
return value >= 0 && value <= 11;
|
|
3672
|
+
}
|
|
3673
|
+
}, {
|
|
3674
|
+
key: "set",
|
|
3675
|
+
value: function set(date, _flags, value) {
|
|
3676
|
+
date.setUTCMonth(value, 1);
|
|
3677
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3678
|
+
return date;
|
|
3679
|
+
}
|
|
3680
|
+
}]);
|
|
3681
|
+
return StandAloneMonthParser;
|
|
3682
|
+
}(Parser);
|
|
3683
|
+
|
|
3684
|
+
function setUTCWeek(dirtyDate, dirtyWeek, options) {
|
|
3685
|
+
requiredArgs(2, arguments);
|
|
3686
|
+
var date = toDate(dirtyDate);
|
|
3687
|
+
var week = toInteger(dirtyWeek);
|
|
3688
|
+
var diff = getUTCWeek(date, options) - week;
|
|
3689
|
+
date.setUTCDate(date.getUTCDate() - diff * 7);
|
|
3690
|
+
return date;
|
|
3691
|
+
}
|
|
3692
|
+
|
|
3693
|
+
var LocalWeekParser = /*#__PURE__*/function (_Parser) {
|
|
3694
|
+
_inherits(LocalWeekParser, _Parser);
|
|
3695
|
+
var _super = _createSuper(LocalWeekParser);
|
|
3696
|
+
function LocalWeekParser() {
|
|
3697
|
+
var _this;
|
|
3698
|
+
_classCallCheck(this, LocalWeekParser);
|
|
3699
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3700
|
+
args[_key] = arguments[_key];
|
|
3701
|
+
}
|
|
3702
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3703
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 100);
|
|
3704
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'i', 't', 'T']);
|
|
3705
|
+
return _this;
|
|
3706
|
+
}
|
|
3707
|
+
_createClass(LocalWeekParser, [{
|
|
3708
|
+
key: "parse",
|
|
3709
|
+
value: function parse(dateString, token, match) {
|
|
3710
|
+
switch (token) {
|
|
3711
|
+
case 'w':
|
|
3712
|
+
return parseNumericPattern(numericPatterns.week, dateString);
|
|
3713
|
+
case 'wo':
|
|
3714
|
+
return match.ordinalNumber(dateString, {
|
|
3715
|
+
unit: 'week'
|
|
3716
|
+
});
|
|
3717
|
+
default:
|
|
3718
|
+
return parseNDigits(token.length, dateString);
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
}, {
|
|
3722
|
+
key: "validate",
|
|
3723
|
+
value: function validate(_date, value) {
|
|
3724
|
+
return value >= 1 && value <= 53;
|
|
3725
|
+
}
|
|
3726
|
+
}, {
|
|
3727
|
+
key: "set",
|
|
3728
|
+
value: function set(date, _flags, value, options) {
|
|
3729
|
+
return startOfUTCWeek(setUTCWeek(date, value, options), options);
|
|
3730
|
+
}
|
|
3731
|
+
}]);
|
|
3732
|
+
return LocalWeekParser;
|
|
3733
|
+
}(Parser);
|
|
3734
|
+
|
|
3735
|
+
function setUTCISOWeek(dirtyDate, dirtyISOWeek) {
|
|
3736
|
+
requiredArgs(2, arguments);
|
|
3737
|
+
var date = toDate(dirtyDate);
|
|
3738
|
+
var isoWeek = toInteger(dirtyISOWeek);
|
|
3739
|
+
var diff = getUTCISOWeek(date) - isoWeek;
|
|
3740
|
+
date.setUTCDate(date.getUTCDate() - diff * 7);
|
|
3741
|
+
return date;
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
var ISOWeekParser = /*#__PURE__*/function (_Parser) {
|
|
3745
|
+
_inherits(ISOWeekParser, _Parser);
|
|
3746
|
+
var _super = _createSuper(ISOWeekParser);
|
|
3747
|
+
function ISOWeekParser() {
|
|
3748
|
+
var _this;
|
|
3749
|
+
_classCallCheck(this, ISOWeekParser);
|
|
3750
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3751
|
+
args[_key] = arguments[_key];
|
|
3752
|
+
}
|
|
3753
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3754
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 100);
|
|
3755
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['y', 'Y', 'u', 'q', 'Q', 'M', 'L', 'w', 'd', 'D', 'e', 'c', 't', 'T']);
|
|
3756
|
+
return _this;
|
|
3757
|
+
}
|
|
3758
|
+
_createClass(ISOWeekParser, [{
|
|
3759
|
+
key: "parse",
|
|
3760
|
+
value: function parse(dateString, token, match) {
|
|
3761
|
+
switch (token) {
|
|
3762
|
+
case 'I':
|
|
3763
|
+
return parseNumericPattern(numericPatterns.week, dateString);
|
|
3764
|
+
case 'Io':
|
|
3765
|
+
return match.ordinalNumber(dateString, {
|
|
3766
|
+
unit: 'week'
|
|
3767
|
+
});
|
|
3768
|
+
default:
|
|
3769
|
+
return parseNDigits(token.length, dateString);
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
}, {
|
|
3773
|
+
key: "validate",
|
|
3774
|
+
value: function validate(_date, value) {
|
|
3775
|
+
return value >= 1 && value <= 53;
|
|
3776
|
+
}
|
|
3777
|
+
}, {
|
|
3778
|
+
key: "set",
|
|
3779
|
+
value: function set(date, _flags, value) {
|
|
3780
|
+
return startOfUTCISOWeek(setUTCISOWeek(date, value));
|
|
3781
|
+
}
|
|
3782
|
+
}]);
|
|
3783
|
+
return ISOWeekParser;
|
|
3784
|
+
}(Parser);
|
|
3785
|
+
|
|
3786
|
+
var DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
3787
|
+
var DAYS_IN_MONTH_LEAP_YEAR = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
3788
|
+
|
|
3789
|
+
// Day of the month
|
|
3790
|
+
var DateParser = /*#__PURE__*/function (_Parser) {
|
|
3791
|
+
_inherits(DateParser, _Parser);
|
|
3792
|
+
var _super = _createSuper(DateParser);
|
|
3793
|
+
function DateParser() {
|
|
3794
|
+
var _this;
|
|
3795
|
+
_classCallCheck(this, DateParser);
|
|
3796
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3797
|
+
args[_key] = arguments[_key];
|
|
3798
|
+
}
|
|
3799
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3800
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 90);
|
|
3801
|
+
_defineProperty(_assertThisInitialized(_this), "subPriority", 1);
|
|
3802
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['Y', 'R', 'q', 'Q', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T']);
|
|
3803
|
+
return _this;
|
|
3804
|
+
}
|
|
3805
|
+
_createClass(DateParser, [{
|
|
3806
|
+
key: "parse",
|
|
3807
|
+
value: function parse(dateString, token, match) {
|
|
3808
|
+
switch (token) {
|
|
3809
|
+
case 'd':
|
|
3810
|
+
return parseNumericPattern(numericPatterns.date, dateString);
|
|
3811
|
+
case 'do':
|
|
3812
|
+
return match.ordinalNumber(dateString, {
|
|
3813
|
+
unit: 'date'
|
|
3814
|
+
});
|
|
3815
|
+
default:
|
|
3816
|
+
return parseNDigits(token.length, dateString);
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
}, {
|
|
3820
|
+
key: "validate",
|
|
3821
|
+
value: function validate(date, value) {
|
|
3822
|
+
var year = date.getUTCFullYear();
|
|
3823
|
+
var isLeapYear = isLeapYearIndex$1(year);
|
|
3824
|
+
var month = date.getUTCMonth();
|
|
3825
|
+
if (isLeapYear) {
|
|
3826
|
+
return value >= 1 && value <= DAYS_IN_MONTH_LEAP_YEAR[month];
|
|
3827
|
+
} else {
|
|
3828
|
+
return value >= 1 && value <= DAYS_IN_MONTH[month];
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
}, {
|
|
3832
|
+
key: "set",
|
|
3833
|
+
value: function set(date, _flags, value) {
|
|
3834
|
+
date.setUTCDate(value);
|
|
3835
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3836
|
+
return date;
|
|
3837
|
+
}
|
|
3838
|
+
}]);
|
|
3839
|
+
return DateParser;
|
|
3840
|
+
}(Parser);
|
|
3841
|
+
|
|
3842
|
+
var DayOfYearParser = /*#__PURE__*/function (_Parser) {
|
|
3843
|
+
_inherits(DayOfYearParser, _Parser);
|
|
3844
|
+
var _super = _createSuper(DayOfYearParser);
|
|
3845
|
+
function DayOfYearParser() {
|
|
3846
|
+
var _this;
|
|
3847
|
+
_classCallCheck(this, DayOfYearParser);
|
|
3848
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3849
|
+
args[_key] = arguments[_key];
|
|
3850
|
+
}
|
|
3851
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3852
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 90);
|
|
3853
|
+
_defineProperty(_assertThisInitialized(_this), "subpriority", 1);
|
|
3854
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['Y', 'R', 'q', 'Q', 'M', 'L', 'w', 'I', 'd', 'E', 'i', 'e', 'c', 't', 'T']);
|
|
3855
|
+
return _this;
|
|
3856
|
+
}
|
|
3857
|
+
_createClass(DayOfYearParser, [{
|
|
3858
|
+
key: "parse",
|
|
3859
|
+
value: function parse(dateString, token, match) {
|
|
3860
|
+
switch (token) {
|
|
3861
|
+
case 'D':
|
|
3862
|
+
case 'DD':
|
|
3863
|
+
return parseNumericPattern(numericPatterns.dayOfYear, dateString);
|
|
3864
|
+
case 'Do':
|
|
3865
|
+
return match.ordinalNumber(dateString, {
|
|
3866
|
+
unit: 'date'
|
|
3867
|
+
});
|
|
3868
|
+
default:
|
|
3869
|
+
return parseNDigits(token.length, dateString);
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
}, {
|
|
3873
|
+
key: "validate",
|
|
3874
|
+
value: function validate(date, value) {
|
|
3875
|
+
var year = date.getUTCFullYear();
|
|
3876
|
+
var isLeapYear = isLeapYearIndex$1(year);
|
|
3877
|
+
if (isLeapYear) {
|
|
3878
|
+
return value >= 1 && value <= 366;
|
|
3879
|
+
} else {
|
|
3880
|
+
return value >= 1 && value <= 365;
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
}, {
|
|
3884
|
+
key: "set",
|
|
3885
|
+
value: function set(date, _flags, value) {
|
|
3886
|
+
date.setUTCMonth(0, value);
|
|
3887
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3888
|
+
return date;
|
|
3889
|
+
}
|
|
3890
|
+
}]);
|
|
3891
|
+
return DayOfYearParser;
|
|
3892
|
+
}(Parser);
|
|
3893
|
+
|
|
3894
|
+
function setUTCDay(dirtyDate, dirtyDay, options) {
|
|
3895
|
+
var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
|
|
3896
|
+
requiredArgs(2, arguments);
|
|
3897
|
+
var defaultOptions = getDefaultOptions();
|
|
3898
|
+
var weekStartsOn = toInteger((_ref = (_ref2 = (_ref3 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.weekStartsOn) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.weekStartsOn) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.weekStartsOn) !== null && _ref !== void 0 ? _ref : 0);
|
|
3899
|
+
|
|
3900
|
+
// Test if weekStartsOn is between 0 and 6 _and_ is not NaN
|
|
3901
|
+
if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
|
|
3902
|
+
throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
|
|
3903
|
+
}
|
|
3904
|
+
var date = toDate(dirtyDate);
|
|
3905
|
+
var day = toInteger(dirtyDay);
|
|
3906
|
+
var currentDay = date.getUTCDay();
|
|
3907
|
+
var remainder = day % 7;
|
|
3908
|
+
var dayIndex = (remainder + 7) % 7;
|
|
3909
|
+
var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay;
|
|
3910
|
+
date.setUTCDate(date.getUTCDate() + diff);
|
|
3911
|
+
return date;
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
var DayParser = /*#__PURE__*/function (_Parser) {
|
|
3915
|
+
_inherits(DayParser, _Parser);
|
|
3916
|
+
var _super = _createSuper(DayParser);
|
|
3917
|
+
function DayParser() {
|
|
3918
|
+
var _this;
|
|
3919
|
+
_classCallCheck(this, DayParser);
|
|
3920
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3921
|
+
args[_key] = arguments[_key];
|
|
3922
|
+
}
|
|
3923
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3924
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 90);
|
|
3925
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['D', 'i', 'e', 'c', 't', 'T']);
|
|
3926
|
+
return _this;
|
|
3927
|
+
}
|
|
3928
|
+
_createClass(DayParser, [{
|
|
3929
|
+
key: "parse",
|
|
3930
|
+
value: function parse(dateString, token, match) {
|
|
3931
|
+
switch (token) {
|
|
3932
|
+
// Tue
|
|
3933
|
+
case 'E':
|
|
3934
|
+
case 'EE':
|
|
3935
|
+
case 'EEE':
|
|
3936
|
+
return match.day(dateString, {
|
|
3937
|
+
width: 'abbreviated',
|
|
3938
|
+
context: 'formatting'
|
|
3939
|
+
}) || match.day(dateString, {
|
|
3940
|
+
width: 'short',
|
|
3941
|
+
context: 'formatting'
|
|
3942
|
+
}) || match.day(dateString, {
|
|
3943
|
+
width: 'narrow',
|
|
3944
|
+
context: 'formatting'
|
|
3945
|
+
});
|
|
3946
|
+
// T
|
|
3947
|
+
case 'EEEEE':
|
|
3948
|
+
return match.day(dateString, {
|
|
3949
|
+
width: 'narrow',
|
|
3950
|
+
context: 'formatting'
|
|
3951
|
+
});
|
|
3952
|
+
// Tu
|
|
3953
|
+
case 'EEEEEE':
|
|
3954
|
+
return match.day(dateString, {
|
|
3955
|
+
width: 'short',
|
|
3956
|
+
context: 'formatting'
|
|
3957
|
+
}) || match.day(dateString, {
|
|
3958
|
+
width: 'narrow',
|
|
3959
|
+
context: 'formatting'
|
|
3960
|
+
});
|
|
3961
|
+
// Tuesday
|
|
3962
|
+
case 'EEEE':
|
|
3963
|
+
default:
|
|
3964
|
+
return match.day(dateString, {
|
|
3965
|
+
width: 'wide',
|
|
3966
|
+
context: 'formatting'
|
|
3967
|
+
}) || match.day(dateString, {
|
|
3968
|
+
width: 'abbreviated',
|
|
3969
|
+
context: 'formatting'
|
|
3970
|
+
}) || match.day(dateString, {
|
|
3971
|
+
width: 'short',
|
|
3972
|
+
context: 'formatting'
|
|
3973
|
+
}) || match.day(dateString, {
|
|
3974
|
+
width: 'narrow',
|
|
3975
|
+
context: 'formatting'
|
|
3976
|
+
});
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
}, {
|
|
3980
|
+
key: "validate",
|
|
3981
|
+
value: function validate(_date, value) {
|
|
3982
|
+
return value >= 0 && value <= 6;
|
|
3983
|
+
}
|
|
3984
|
+
}, {
|
|
3985
|
+
key: "set",
|
|
3986
|
+
value: function set(date, _flags, value, options) {
|
|
3987
|
+
date = setUTCDay(date, value, options);
|
|
3988
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
3989
|
+
return date;
|
|
3990
|
+
}
|
|
3991
|
+
}]);
|
|
3992
|
+
return DayParser;
|
|
3993
|
+
}(Parser);
|
|
3994
|
+
|
|
3995
|
+
var LocalDayParser = /*#__PURE__*/function (_Parser) {
|
|
3996
|
+
_inherits(LocalDayParser, _Parser);
|
|
3997
|
+
var _super = _createSuper(LocalDayParser);
|
|
3998
|
+
function LocalDayParser() {
|
|
3999
|
+
var _this;
|
|
4000
|
+
_classCallCheck(this, LocalDayParser);
|
|
4001
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4002
|
+
args[_key] = arguments[_key];
|
|
4003
|
+
}
|
|
4004
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4005
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 90);
|
|
4006
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'c', 't', 'T']);
|
|
4007
|
+
return _this;
|
|
4008
|
+
}
|
|
4009
|
+
_createClass(LocalDayParser, [{
|
|
4010
|
+
key: "parse",
|
|
4011
|
+
value: function parse(dateString, token, match, options) {
|
|
4012
|
+
var valueCallback = function valueCallback(value) {
|
|
4013
|
+
var wholeWeekDays = Math.floor((value - 1) / 7) * 7;
|
|
4014
|
+
return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
|
|
4015
|
+
};
|
|
4016
|
+
switch (token) {
|
|
4017
|
+
// 3
|
|
4018
|
+
case 'e':
|
|
4019
|
+
case 'ee':
|
|
4020
|
+
// 03
|
|
4021
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
4022
|
+
// 3rd
|
|
4023
|
+
case 'eo':
|
|
4024
|
+
return mapValue(match.ordinalNumber(dateString, {
|
|
4025
|
+
unit: 'day'
|
|
4026
|
+
}), valueCallback);
|
|
4027
|
+
// Tue
|
|
4028
|
+
case 'eee':
|
|
4029
|
+
return match.day(dateString, {
|
|
4030
|
+
width: 'abbreviated',
|
|
4031
|
+
context: 'formatting'
|
|
4032
|
+
}) || match.day(dateString, {
|
|
4033
|
+
width: 'short',
|
|
4034
|
+
context: 'formatting'
|
|
4035
|
+
}) || match.day(dateString, {
|
|
4036
|
+
width: 'narrow',
|
|
4037
|
+
context: 'formatting'
|
|
4038
|
+
});
|
|
4039
|
+
// T
|
|
4040
|
+
case 'eeeee':
|
|
4041
|
+
return match.day(dateString, {
|
|
4042
|
+
width: 'narrow',
|
|
4043
|
+
context: 'formatting'
|
|
4044
|
+
});
|
|
4045
|
+
// Tu
|
|
4046
|
+
case 'eeeeee':
|
|
4047
|
+
return match.day(dateString, {
|
|
4048
|
+
width: 'short',
|
|
4049
|
+
context: 'formatting'
|
|
4050
|
+
}) || match.day(dateString, {
|
|
4051
|
+
width: 'narrow',
|
|
4052
|
+
context: 'formatting'
|
|
4053
|
+
});
|
|
4054
|
+
// Tuesday
|
|
4055
|
+
case 'eeee':
|
|
4056
|
+
default:
|
|
4057
|
+
return match.day(dateString, {
|
|
4058
|
+
width: 'wide',
|
|
4059
|
+
context: 'formatting'
|
|
4060
|
+
}) || match.day(dateString, {
|
|
4061
|
+
width: 'abbreviated',
|
|
4062
|
+
context: 'formatting'
|
|
4063
|
+
}) || match.day(dateString, {
|
|
4064
|
+
width: 'short',
|
|
4065
|
+
context: 'formatting'
|
|
4066
|
+
}) || match.day(dateString, {
|
|
4067
|
+
width: 'narrow',
|
|
4068
|
+
context: 'formatting'
|
|
4069
|
+
});
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
4072
|
+
}, {
|
|
4073
|
+
key: "validate",
|
|
4074
|
+
value: function validate(_date, value) {
|
|
4075
|
+
return value >= 0 && value <= 6;
|
|
4076
|
+
}
|
|
4077
|
+
}, {
|
|
4078
|
+
key: "set",
|
|
4079
|
+
value: function set(date, _flags, value, options) {
|
|
4080
|
+
date = setUTCDay(date, value, options);
|
|
4081
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
4082
|
+
return date;
|
|
4083
|
+
}
|
|
4084
|
+
}]);
|
|
4085
|
+
return LocalDayParser;
|
|
4086
|
+
}(Parser);
|
|
4087
|
+
|
|
4088
|
+
var StandAloneLocalDayParser = /*#__PURE__*/function (_Parser) {
|
|
4089
|
+
_inherits(StandAloneLocalDayParser, _Parser);
|
|
4090
|
+
var _super = _createSuper(StandAloneLocalDayParser);
|
|
4091
|
+
function StandAloneLocalDayParser() {
|
|
4092
|
+
var _this;
|
|
4093
|
+
_classCallCheck(this, StandAloneLocalDayParser);
|
|
4094
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4095
|
+
args[_key] = arguments[_key];
|
|
4096
|
+
}
|
|
4097
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4098
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 90);
|
|
4099
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'e', 't', 'T']);
|
|
4100
|
+
return _this;
|
|
4101
|
+
}
|
|
4102
|
+
_createClass(StandAloneLocalDayParser, [{
|
|
4103
|
+
key: "parse",
|
|
4104
|
+
value: function parse(dateString, token, match, options) {
|
|
4105
|
+
var valueCallback = function valueCallback(value) {
|
|
4106
|
+
var wholeWeekDays = Math.floor((value - 1) / 7) * 7;
|
|
4107
|
+
return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
|
|
4108
|
+
};
|
|
4109
|
+
switch (token) {
|
|
4110
|
+
// 3
|
|
4111
|
+
case 'c':
|
|
4112
|
+
case 'cc':
|
|
4113
|
+
// 03
|
|
4114
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
4115
|
+
// 3rd
|
|
4116
|
+
case 'co':
|
|
4117
|
+
return mapValue(match.ordinalNumber(dateString, {
|
|
4118
|
+
unit: 'day'
|
|
4119
|
+
}), valueCallback);
|
|
4120
|
+
// Tue
|
|
4121
|
+
case 'ccc':
|
|
4122
|
+
return match.day(dateString, {
|
|
4123
|
+
width: 'abbreviated',
|
|
4124
|
+
context: 'standalone'
|
|
4125
|
+
}) || match.day(dateString, {
|
|
4126
|
+
width: 'short',
|
|
4127
|
+
context: 'standalone'
|
|
4128
|
+
}) || match.day(dateString, {
|
|
4129
|
+
width: 'narrow',
|
|
4130
|
+
context: 'standalone'
|
|
4131
|
+
});
|
|
4132
|
+
// T
|
|
4133
|
+
case 'ccccc':
|
|
4134
|
+
return match.day(dateString, {
|
|
4135
|
+
width: 'narrow',
|
|
4136
|
+
context: 'standalone'
|
|
4137
|
+
});
|
|
4138
|
+
// Tu
|
|
4139
|
+
case 'cccccc':
|
|
4140
|
+
return match.day(dateString, {
|
|
4141
|
+
width: 'short',
|
|
4142
|
+
context: 'standalone'
|
|
4143
|
+
}) || match.day(dateString, {
|
|
4144
|
+
width: 'narrow',
|
|
4145
|
+
context: 'standalone'
|
|
4146
|
+
});
|
|
4147
|
+
// Tuesday
|
|
4148
|
+
case 'cccc':
|
|
4149
|
+
default:
|
|
4150
|
+
return match.day(dateString, {
|
|
4151
|
+
width: 'wide',
|
|
4152
|
+
context: 'standalone'
|
|
4153
|
+
}) || match.day(dateString, {
|
|
4154
|
+
width: 'abbreviated',
|
|
4155
|
+
context: 'standalone'
|
|
4156
|
+
}) || match.day(dateString, {
|
|
4157
|
+
width: 'short',
|
|
4158
|
+
context: 'standalone'
|
|
4159
|
+
}) || match.day(dateString, {
|
|
4160
|
+
width: 'narrow',
|
|
4161
|
+
context: 'standalone'
|
|
4162
|
+
});
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
4165
|
+
}, {
|
|
4166
|
+
key: "validate",
|
|
4167
|
+
value: function validate(_date, value) {
|
|
4168
|
+
return value >= 0 && value <= 6;
|
|
4169
|
+
}
|
|
4170
|
+
}, {
|
|
4171
|
+
key: "set",
|
|
4172
|
+
value: function set(date, _flags, value, options) {
|
|
4173
|
+
date = setUTCDay(date, value, options);
|
|
4174
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
4175
|
+
return date;
|
|
4176
|
+
}
|
|
4177
|
+
}]);
|
|
4178
|
+
return StandAloneLocalDayParser;
|
|
4179
|
+
}(Parser);
|
|
4180
|
+
|
|
4181
|
+
function setUTCISODay(dirtyDate, dirtyDay) {
|
|
4182
|
+
requiredArgs(2, arguments);
|
|
4183
|
+
var day = toInteger(dirtyDay);
|
|
4184
|
+
if (day % 7 === 0) {
|
|
4185
|
+
day = day - 7;
|
|
4186
|
+
}
|
|
4187
|
+
var weekStartsOn = 1;
|
|
4188
|
+
var date = toDate(dirtyDate);
|
|
4189
|
+
var currentDay = date.getUTCDay();
|
|
4190
|
+
var remainder = day % 7;
|
|
4191
|
+
var dayIndex = (remainder + 7) % 7;
|
|
4192
|
+
var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay;
|
|
4193
|
+
date.setUTCDate(date.getUTCDate() + diff);
|
|
4194
|
+
return date;
|
|
4195
|
+
}
|
|
4196
|
+
|
|
4197
|
+
var ISODayParser = /*#__PURE__*/function (_Parser) {
|
|
4198
|
+
_inherits(ISODayParser, _Parser);
|
|
4199
|
+
var _super = _createSuper(ISODayParser);
|
|
4200
|
+
function ISODayParser() {
|
|
4201
|
+
var _this;
|
|
4202
|
+
_classCallCheck(this, ISODayParser);
|
|
4203
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4204
|
+
args[_key] = arguments[_key];
|
|
4205
|
+
}
|
|
4206
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4207
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 90);
|
|
4208
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['y', 'Y', 'u', 'q', 'Q', 'M', 'L', 'w', 'd', 'D', 'E', 'e', 'c', 't', 'T']);
|
|
4209
|
+
return _this;
|
|
4210
|
+
}
|
|
4211
|
+
_createClass(ISODayParser, [{
|
|
4212
|
+
key: "parse",
|
|
4213
|
+
value: function parse(dateString, token, match) {
|
|
4214
|
+
var valueCallback = function valueCallback(value) {
|
|
4215
|
+
if (value === 0) {
|
|
4216
|
+
return 7;
|
|
4217
|
+
}
|
|
4218
|
+
return value;
|
|
4219
|
+
};
|
|
4220
|
+
switch (token) {
|
|
4221
|
+
// 2
|
|
4222
|
+
case 'i':
|
|
4223
|
+
case 'ii':
|
|
4224
|
+
// 02
|
|
4225
|
+
return parseNDigits(token.length, dateString);
|
|
4226
|
+
// 2nd
|
|
4227
|
+
case 'io':
|
|
4228
|
+
return match.ordinalNumber(dateString, {
|
|
4229
|
+
unit: 'day'
|
|
4230
|
+
});
|
|
4231
|
+
// Tue
|
|
4232
|
+
case 'iii':
|
|
4233
|
+
return mapValue(match.day(dateString, {
|
|
4234
|
+
width: 'abbreviated',
|
|
4235
|
+
context: 'formatting'
|
|
4236
|
+
}) || match.day(dateString, {
|
|
4237
|
+
width: 'short',
|
|
4238
|
+
context: 'formatting'
|
|
4239
|
+
}) || match.day(dateString, {
|
|
4240
|
+
width: 'narrow',
|
|
4241
|
+
context: 'formatting'
|
|
4242
|
+
}), valueCallback);
|
|
4243
|
+
// T
|
|
4244
|
+
case 'iiiii':
|
|
4245
|
+
return mapValue(match.day(dateString, {
|
|
4246
|
+
width: 'narrow',
|
|
4247
|
+
context: 'formatting'
|
|
4248
|
+
}), valueCallback);
|
|
4249
|
+
// Tu
|
|
4250
|
+
case 'iiiiii':
|
|
4251
|
+
return mapValue(match.day(dateString, {
|
|
4252
|
+
width: 'short',
|
|
4253
|
+
context: 'formatting'
|
|
4254
|
+
}) || match.day(dateString, {
|
|
4255
|
+
width: 'narrow',
|
|
4256
|
+
context: 'formatting'
|
|
4257
|
+
}), valueCallback);
|
|
4258
|
+
// Tuesday
|
|
4259
|
+
case 'iiii':
|
|
4260
|
+
default:
|
|
4261
|
+
return mapValue(match.day(dateString, {
|
|
4262
|
+
width: 'wide',
|
|
4263
|
+
context: 'formatting'
|
|
4264
|
+
}) || match.day(dateString, {
|
|
4265
|
+
width: 'abbreviated',
|
|
4266
|
+
context: 'formatting'
|
|
4267
|
+
}) || match.day(dateString, {
|
|
4268
|
+
width: 'short',
|
|
4269
|
+
context: 'formatting'
|
|
4270
|
+
}) || match.day(dateString, {
|
|
4271
|
+
width: 'narrow',
|
|
4272
|
+
context: 'formatting'
|
|
4273
|
+
}), valueCallback);
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
}, {
|
|
4277
|
+
key: "validate",
|
|
4278
|
+
value: function validate(_date, value) {
|
|
4279
|
+
return value >= 1 && value <= 7;
|
|
4280
|
+
}
|
|
4281
|
+
}, {
|
|
4282
|
+
key: "set",
|
|
4283
|
+
value: function set(date, _flags, value) {
|
|
4284
|
+
date = setUTCISODay(date, value);
|
|
4285
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
4286
|
+
return date;
|
|
4287
|
+
}
|
|
4288
|
+
}]);
|
|
4289
|
+
return ISODayParser;
|
|
4290
|
+
}(Parser);
|
|
4291
|
+
|
|
4292
|
+
var AMPMParser = /*#__PURE__*/function (_Parser) {
|
|
4293
|
+
_inherits(AMPMParser, _Parser);
|
|
4294
|
+
var _super = _createSuper(AMPMParser);
|
|
4295
|
+
function AMPMParser() {
|
|
4296
|
+
var _this;
|
|
4297
|
+
_classCallCheck(this, AMPMParser);
|
|
4298
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4299
|
+
args[_key] = arguments[_key];
|
|
4300
|
+
}
|
|
4301
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4302
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 80);
|
|
4303
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['b', 'B', 'H', 'k', 't', 'T']);
|
|
4304
|
+
return _this;
|
|
4305
|
+
}
|
|
4306
|
+
_createClass(AMPMParser, [{
|
|
4307
|
+
key: "parse",
|
|
4308
|
+
value: function parse(dateString, token, match) {
|
|
4309
|
+
switch (token) {
|
|
4310
|
+
case 'a':
|
|
4311
|
+
case 'aa':
|
|
4312
|
+
case 'aaa':
|
|
4313
|
+
return match.dayPeriod(dateString, {
|
|
4314
|
+
width: 'abbreviated',
|
|
4315
|
+
context: 'formatting'
|
|
4316
|
+
}) || match.dayPeriod(dateString, {
|
|
4317
|
+
width: 'narrow',
|
|
4318
|
+
context: 'formatting'
|
|
4319
|
+
});
|
|
4320
|
+
case 'aaaaa':
|
|
4321
|
+
return match.dayPeriod(dateString, {
|
|
4322
|
+
width: 'narrow',
|
|
4323
|
+
context: 'formatting'
|
|
4324
|
+
});
|
|
4325
|
+
case 'aaaa':
|
|
4326
|
+
default:
|
|
4327
|
+
return match.dayPeriod(dateString, {
|
|
4328
|
+
width: 'wide',
|
|
4329
|
+
context: 'formatting'
|
|
4330
|
+
}) || match.dayPeriod(dateString, {
|
|
4331
|
+
width: 'abbreviated',
|
|
4332
|
+
context: 'formatting'
|
|
4333
|
+
}) || match.dayPeriod(dateString, {
|
|
4334
|
+
width: 'narrow',
|
|
4335
|
+
context: 'formatting'
|
|
4336
|
+
});
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
}, {
|
|
4340
|
+
key: "set",
|
|
4341
|
+
value: function set(date, _flags, value) {
|
|
4342
|
+
date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0);
|
|
4343
|
+
return date;
|
|
4344
|
+
}
|
|
4345
|
+
}]);
|
|
4346
|
+
return AMPMParser;
|
|
4347
|
+
}(Parser);
|
|
4348
|
+
|
|
4349
|
+
var AMPMMidnightParser = /*#__PURE__*/function (_Parser) {
|
|
4350
|
+
_inherits(AMPMMidnightParser, _Parser);
|
|
4351
|
+
var _super = _createSuper(AMPMMidnightParser);
|
|
4352
|
+
function AMPMMidnightParser() {
|
|
4353
|
+
var _this;
|
|
4354
|
+
_classCallCheck(this, AMPMMidnightParser);
|
|
4355
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4356
|
+
args[_key] = arguments[_key];
|
|
4357
|
+
}
|
|
4358
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4359
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 80);
|
|
4360
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['a', 'B', 'H', 'k', 't', 'T']);
|
|
4361
|
+
return _this;
|
|
4362
|
+
}
|
|
4363
|
+
_createClass(AMPMMidnightParser, [{
|
|
4364
|
+
key: "parse",
|
|
4365
|
+
value: function parse(dateString, token, match) {
|
|
4366
|
+
switch (token) {
|
|
4367
|
+
case 'b':
|
|
4368
|
+
case 'bb':
|
|
4369
|
+
case 'bbb':
|
|
4370
|
+
return match.dayPeriod(dateString, {
|
|
4371
|
+
width: 'abbreviated',
|
|
4372
|
+
context: 'formatting'
|
|
4373
|
+
}) || match.dayPeriod(dateString, {
|
|
4374
|
+
width: 'narrow',
|
|
4375
|
+
context: 'formatting'
|
|
4376
|
+
});
|
|
4377
|
+
case 'bbbbb':
|
|
4378
|
+
return match.dayPeriod(dateString, {
|
|
4379
|
+
width: 'narrow',
|
|
4380
|
+
context: 'formatting'
|
|
4381
|
+
});
|
|
4382
|
+
case 'bbbb':
|
|
4383
|
+
default:
|
|
4384
|
+
return match.dayPeriod(dateString, {
|
|
4385
|
+
width: 'wide',
|
|
4386
|
+
context: 'formatting'
|
|
4387
|
+
}) || match.dayPeriod(dateString, {
|
|
4388
|
+
width: 'abbreviated',
|
|
4389
|
+
context: 'formatting'
|
|
4390
|
+
}) || match.dayPeriod(dateString, {
|
|
4391
|
+
width: 'narrow',
|
|
4392
|
+
context: 'formatting'
|
|
4393
|
+
});
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
4396
|
+
}, {
|
|
4397
|
+
key: "set",
|
|
4398
|
+
value: function set(date, _flags, value) {
|
|
4399
|
+
date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0);
|
|
4400
|
+
return date;
|
|
4401
|
+
}
|
|
4402
|
+
}]);
|
|
4403
|
+
return AMPMMidnightParser;
|
|
4404
|
+
}(Parser);
|
|
4405
|
+
|
|
4406
|
+
var DayPeriodParser = /*#__PURE__*/function (_Parser) {
|
|
4407
|
+
_inherits(DayPeriodParser, _Parser);
|
|
4408
|
+
var _super = _createSuper(DayPeriodParser);
|
|
4409
|
+
function DayPeriodParser() {
|
|
4410
|
+
var _this;
|
|
4411
|
+
_classCallCheck(this, DayPeriodParser);
|
|
4412
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4413
|
+
args[_key] = arguments[_key];
|
|
4414
|
+
}
|
|
4415
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4416
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 80);
|
|
4417
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['a', 'b', 't', 'T']);
|
|
4418
|
+
return _this;
|
|
4419
|
+
}
|
|
4420
|
+
_createClass(DayPeriodParser, [{
|
|
4421
|
+
key: "parse",
|
|
4422
|
+
value: function parse(dateString, token, match) {
|
|
4423
|
+
switch (token) {
|
|
4424
|
+
case 'B':
|
|
4425
|
+
case 'BB':
|
|
4426
|
+
case 'BBB':
|
|
4427
|
+
return match.dayPeriod(dateString, {
|
|
4428
|
+
width: 'abbreviated',
|
|
4429
|
+
context: 'formatting'
|
|
4430
|
+
}) || match.dayPeriod(dateString, {
|
|
4431
|
+
width: 'narrow',
|
|
4432
|
+
context: 'formatting'
|
|
4433
|
+
});
|
|
4434
|
+
case 'BBBBB':
|
|
4435
|
+
return match.dayPeriod(dateString, {
|
|
4436
|
+
width: 'narrow',
|
|
4437
|
+
context: 'formatting'
|
|
4438
|
+
});
|
|
4439
|
+
case 'BBBB':
|
|
4440
|
+
default:
|
|
4441
|
+
return match.dayPeriod(dateString, {
|
|
4442
|
+
width: 'wide',
|
|
4443
|
+
context: 'formatting'
|
|
4444
|
+
}) || match.dayPeriod(dateString, {
|
|
4445
|
+
width: 'abbreviated',
|
|
4446
|
+
context: 'formatting'
|
|
4447
|
+
}) || match.dayPeriod(dateString, {
|
|
4448
|
+
width: 'narrow',
|
|
4449
|
+
context: 'formatting'
|
|
4450
|
+
});
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
}, {
|
|
4454
|
+
key: "set",
|
|
4455
|
+
value: function set(date, _flags, value) {
|
|
4456
|
+
date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0);
|
|
4457
|
+
return date;
|
|
4458
|
+
}
|
|
4459
|
+
}]);
|
|
4460
|
+
return DayPeriodParser;
|
|
4461
|
+
}(Parser);
|
|
4462
|
+
|
|
4463
|
+
var Hour1to12Parser = /*#__PURE__*/function (_Parser) {
|
|
4464
|
+
_inherits(Hour1to12Parser, _Parser);
|
|
4465
|
+
var _super = _createSuper(Hour1to12Parser);
|
|
4466
|
+
function Hour1to12Parser() {
|
|
4467
|
+
var _this;
|
|
4468
|
+
_classCallCheck(this, Hour1to12Parser);
|
|
4469
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4470
|
+
args[_key] = arguments[_key];
|
|
4471
|
+
}
|
|
4472
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4473
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 70);
|
|
4474
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['H', 'K', 'k', 't', 'T']);
|
|
4475
|
+
return _this;
|
|
4476
|
+
}
|
|
4477
|
+
_createClass(Hour1to12Parser, [{
|
|
4478
|
+
key: "parse",
|
|
4479
|
+
value: function parse(dateString, token, match) {
|
|
4480
|
+
switch (token) {
|
|
4481
|
+
case 'h':
|
|
4482
|
+
return parseNumericPattern(numericPatterns.hour12h, dateString);
|
|
4483
|
+
case 'ho':
|
|
4484
|
+
return match.ordinalNumber(dateString, {
|
|
4485
|
+
unit: 'hour'
|
|
4486
|
+
});
|
|
4487
|
+
default:
|
|
4488
|
+
return parseNDigits(token.length, dateString);
|
|
4489
|
+
}
|
|
4490
|
+
}
|
|
4491
|
+
}, {
|
|
4492
|
+
key: "validate",
|
|
4493
|
+
value: function validate(_date, value) {
|
|
4494
|
+
return value >= 1 && value <= 12;
|
|
4495
|
+
}
|
|
4496
|
+
}, {
|
|
4497
|
+
key: "set",
|
|
4498
|
+
value: function set(date, _flags, value) {
|
|
4499
|
+
var isPM = date.getUTCHours() >= 12;
|
|
4500
|
+
if (isPM && value < 12) {
|
|
4501
|
+
date.setUTCHours(value + 12, 0, 0, 0);
|
|
4502
|
+
} else if (!isPM && value === 12) {
|
|
4503
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
4504
|
+
} else {
|
|
4505
|
+
date.setUTCHours(value, 0, 0, 0);
|
|
4506
|
+
}
|
|
4507
|
+
return date;
|
|
4508
|
+
}
|
|
4509
|
+
}]);
|
|
4510
|
+
return Hour1to12Parser;
|
|
4511
|
+
}(Parser);
|
|
4512
|
+
|
|
4513
|
+
var Hour0to23Parser = /*#__PURE__*/function (_Parser) {
|
|
4514
|
+
_inherits(Hour0to23Parser, _Parser);
|
|
4515
|
+
var _super = _createSuper(Hour0to23Parser);
|
|
4516
|
+
function Hour0to23Parser() {
|
|
4517
|
+
var _this;
|
|
4518
|
+
_classCallCheck(this, Hour0to23Parser);
|
|
4519
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4520
|
+
args[_key] = arguments[_key];
|
|
4521
|
+
}
|
|
4522
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4523
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 70);
|
|
4524
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['a', 'b', 'h', 'K', 'k', 't', 'T']);
|
|
4525
|
+
return _this;
|
|
4526
|
+
}
|
|
4527
|
+
_createClass(Hour0to23Parser, [{
|
|
4528
|
+
key: "parse",
|
|
4529
|
+
value: function parse(dateString, token, match) {
|
|
4530
|
+
switch (token) {
|
|
4531
|
+
case 'H':
|
|
4532
|
+
return parseNumericPattern(numericPatterns.hour23h, dateString);
|
|
4533
|
+
case 'Ho':
|
|
4534
|
+
return match.ordinalNumber(dateString, {
|
|
4535
|
+
unit: 'hour'
|
|
4536
|
+
});
|
|
4537
|
+
default:
|
|
4538
|
+
return parseNDigits(token.length, dateString);
|
|
4539
|
+
}
|
|
4540
|
+
}
|
|
4541
|
+
}, {
|
|
4542
|
+
key: "validate",
|
|
4543
|
+
value: function validate(_date, value) {
|
|
4544
|
+
return value >= 0 && value <= 23;
|
|
4545
|
+
}
|
|
4546
|
+
}, {
|
|
4547
|
+
key: "set",
|
|
4548
|
+
value: function set(date, _flags, value) {
|
|
4549
|
+
date.setUTCHours(value, 0, 0, 0);
|
|
4550
|
+
return date;
|
|
4551
|
+
}
|
|
4552
|
+
}]);
|
|
4553
|
+
return Hour0to23Parser;
|
|
4554
|
+
}(Parser);
|
|
4555
|
+
|
|
4556
|
+
var Hour0To11Parser = /*#__PURE__*/function (_Parser) {
|
|
4557
|
+
_inherits(Hour0To11Parser, _Parser);
|
|
4558
|
+
var _super = _createSuper(Hour0To11Parser);
|
|
4559
|
+
function Hour0To11Parser() {
|
|
4560
|
+
var _this;
|
|
4561
|
+
_classCallCheck(this, Hour0To11Parser);
|
|
4562
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4563
|
+
args[_key] = arguments[_key];
|
|
4564
|
+
}
|
|
4565
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4566
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 70);
|
|
4567
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['h', 'H', 'k', 't', 'T']);
|
|
4568
|
+
return _this;
|
|
4569
|
+
}
|
|
4570
|
+
_createClass(Hour0To11Parser, [{
|
|
4571
|
+
key: "parse",
|
|
4572
|
+
value: function parse(dateString, token, match) {
|
|
4573
|
+
switch (token) {
|
|
4574
|
+
case 'K':
|
|
4575
|
+
return parseNumericPattern(numericPatterns.hour11h, dateString);
|
|
4576
|
+
case 'Ko':
|
|
4577
|
+
return match.ordinalNumber(dateString, {
|
|
4578
|
+
unit: 'hour'
|
|
4579
|
+
});
|
|
4580
|
+
default:
|
|
4581
|
+
return parseNDigits(token.length, dateString);
|
|
4582
|
+
}
|
|
4583
|
+
}
|
|
4584
|
+
}, {
|
|
4585
|
+
key: "validate",
|
|
4586
|
+
value: function validate(_date, value) {
|
|
4587
|
+
return value >= 0 && value <= 11;
|
|
4588
|
+
}
|
|
4589
|
+
}, {
|
|
4590
|
+
key: "set",
|
|
4591
|
+
value: function set(date, _flags, value) {
|
|
4592
|
+
var isPM = date.getUTCHours() >= 12;
|
|
4593
|
+
if (isPM && value < 12) {
|
|
4594
|
+
date.setUTCHours(value + 12, 0, 0, 0);
|
|
4595
|
+
} else {
|
|
4596
|
+
date.setUTCHours(value, 0, 0, 0);
|
|
4597
|
+
}
|
|
4598
|
+
return date;
|
|
4599
|
+
}
|
|
4600
|
+
}]);
|
|
4601
|
+
return Hour0To11Parser;
|
|
4602
|
+
}(Parser);
|
|
4603
|
+
|
|
4604
|
+
var Hour1To24Parser = /*#__PURE__*/function (_Parser) {
|
|
4605
|
+
_inherits(Hour1To24Parser, _Parser);
|
|
4606
|
+
var _super = _createSuper(Hour1To24Parser);
|
|
4607
|
+
function Hour1To24Parser() {
|
|
4608
|
+
var _this;
|
|
4609
|
+
_classCallCheck(this, Hour1To24Parser);
|
|
4610
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4611
|
+
args[_key] = arguments[_key];
|
|
4612
|
+
}
|
|
4613
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4614
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 70);
|
|
4615
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['a', 'b', 'h', 'H', 'K', 't', 'T']);
|
|
4616
|
+
return _this;
|
|
4617
|
+
}
|
|
4618
|
+
_createClass(Hour1To24Parser, [{
|
|
4619
|
+
key: "parse",
|
|
4620
|
+
value: function parse(dateString, token, match) {
|
|
4621
|
+
switch (token) {
|
|
4622
|
+
case 'k':
|
|
4623
|
+
return parseNumericPattern(numericPatterns.hour24h, dateString);
|
|
4624
|
+
case 'ko':
|
|
4625
|
+
return match.ordinalNumber(dateString, {
|
|
4626
|
+
unit: 'hour'
|
|
4627
|
+
});
|
|
4628
|
+
default:
|
|
4629
|
+
return parseNDigits(token.length, dateString);
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4632
|
+
}, {
|
|
4633
|
+
key: "validate",
|
|
4634
|
+
value: function validate(_date, value) {
|
|
4635
|
+
return value >= 1 && value <= 24;
|
|
4636
|
+
}
|
|
4637
|
+
}, {
|
|
4638
|
+
key: "set",
|
|
4639
|
+
value: function set(date, _flags, value) {
|
|
4640
|
+
var hours = value <= 24 ? value % 24 : value;
|
|
4641
|
+
date.setUTCHours(hours, 0, 0, 0);
|
|
4642
|
+
return date;
|
|
4643
|
+
}
|
|
4644
|
+
}]);
|
|
4645
|
+
return Hour1To24Parser;
|
|
4646
|
+
}(Parser);
|
|
4647
|
+
|
|
4648
|
+
var MinuteParser = /*#__PURE__*/function (_Parser) {
|
|
4649
|
+
_inherits(MinuteParser, _Parser);
|
|
4650
|
+
var _super = _createSuper(MinuteParser);
|
|
4651
|
+
function MinuteParser() {
|
|
4652
|
+
var _this;
|
|
4653
|
+
_classCallCheck(this, MinuteParser);
|
|
4654
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4655
|
+
args[_key] = arguments[_key];
|
|
4656
|
+
}
|
|
4657
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4658
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 60);
|
|
4659
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['t', 'T']);
|
|
4660
|
+
return _this;
|
|
4661
|
+
}
|
|
4662
|
+
_createClass(MinuteParser, [{
|
|
4663
|
+
key: "parse",
|
|
4664
|
+
value: function parse(dateString, token, match) {
|
|
4665
|
+
switch (token) {
|
|
4666
|
+
case 'm':
|
|
4667
|
+
return parseNumericPattern(numericPatterns.minute, dateString);
|
|
4668
|
+
case 'mo':
|
|
4669
|
+
return match.ordinalNumber(dateString, {
|
|
4670
|
+
unit: 'minute'
|
|
4671
|
+
});
|
|
4672
|
+
default:
|
|
4673
|
+
return parseNDigits(token.length, dateString);
|
|
4674
|
+
}
|
|
4675
|
+
}
|
|
4676
|
+
}, {
|
|
4677
|
+
key: "validate",
|
|
4678
|
+
value: function validate(_date, value) {
|
|
4679
|
+
return value >= 0 && value <= 59;
|
|
4680
|
+
}
|
|
4681
|
+
}, {
|
|
4682
|
+
key: "set",
|
|
4683
|
+
value: function set(date, _flags, value) {
|
|
4684
|
+
date.setUTCMinutes(value, 0, 0);
|
|
4685
|
+
return date;
|
|
4686
|
+
}
|
|
4687
|
+
}]);
|
|
4688
|
+
return MinuteParser;
|
|
4689
|
+
}(Parser);
|
|
4690
|
+
|
|
4691
|
+
var SecondParser = /*#__PURE__*/function (_Parser) {
|
|
4692
|
+
_inherits(SecondParser, _Parser);
|
|
4693
|
+
var _super = _createSuper(SecondParser);
|
|
4694
|
+
function SecondParser() {
|
|
4695
|
+
var _this;
|
|
4696
|
+
_classCallCheck(this, SecondParser);
|
|
4697
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4698
|
+
args[_key] = arguments[_key];
|
|
4699
|
+
}
|
|
4700
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4701
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 50);
|
|
4702
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['t', 'T']);
|
|
4703
|
+
return _this;
|
|
4704
|
+
}
|
|
4705
|
+
_createClass(SecondParser, [{
|
|
4706
|
+
key: "parse",
|
|
4707
|
+
value: function parse(dateString, token, match) {
|
|
4708
|
+
switch (token) {
|
|
4709
|
+
case 's':
|
|
4710
|
+
return parseNumericPattern(numericPatterns.second, dateString);
|
|
4711
|
+
case 'so':
|
|
4712
|
+
return match.ordinalNumber(dateString, {
|
|
4713
|
+
unit: 'second'
|
|
4714
|
+
});
|
|
4715
|
+
default:
|
|
4716
|
+
return parseNDigits(token.length, dateString);
|
|
4717
|
+
}
|
|
4718
|
+
}
|
|
4719
|
+
}, {
|
|
4720
|
+
key: "validate",
|
|
4721
|
+
value: function validate(_date, value) {
|
|
4722
|
+
return value >= 0 && value <= 59;
|
|
4723
|
+
}
|
|
4724
|
+
}, {
|
|
4725
|
+
key: "set",
|
|
4726
|
+
value: function set(date, _flags, value) {
|
|
4727
|
+
date.setUTCSeconds(value, 0);
|
|
4728
|
+
return date;
|
|
4729
|
+
}
|
|
4730
|
+
}]);
|
|
4731
|
+
return SecondParser;
|
|
4732
|
+
}(Parser);
|
|
4733
|
+
|
|
4734
|
+
var FractionOfSecondParser = /*#__PURE__*/function (_Parser) {
|
|
4735
|
+
_inherits(FractionOfSecondParser, _Parser);
|
|
4736
|
+
var _super = _createSuper(FractionOfSecondParser);
|
|
4737
|
+
function FractionOfSecondParser() {
|
|
4738
|
+
var _this;
|
|
4739
|
+
_classCallCheck(this, FractionOfSecondParser);
|
|
4740
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4741
|
+
args[_key] = arguments[_key];
|
|
4742
|
+
}
|
|
4743
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4744
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 30);
|
|
4745
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['t', 'T']);
|
|
4746
|
+
return _this;
|
|
4747
|
+
}
|
|
4748
|
+
_createClass(FractionOfSecondParser, [{
|
|
4749
|
+
key: "parse",
|
|
4750
|
+
value: function parse(dateString, token) {
|
|
4751
|
+
var valueCallback = function valueCallback(value) {
|
|
4752
|
+
return Math.floor(value * Math.pow(10, -token.length + 3));
|
|
4753
|
+
};
|
|
4754
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
4755
|
+
}
|
|
4756
|
+
}, {
|
|
4757
|
+
key: "set",
|
|
4758
|
+
value: function set(date, _flags, value) {
|
|
4759
|
+
date.setUTCMilliseconds(value);
|
|
4760
|
+
return date;
|
|
4761
|
+
}
|
|
4762
|
+
}]);
|
|
4763
|
+
return FractionOfSecondParser;
|
|
4764
|
+
}(Parser);
|
|
4765
|
+
|
|
4766
|
+
var ISOTimezoneWithZParser = /*#__PURE__*/function (_Parser) {
|
|
4767
|
+
_inherits(ISOTimezoneWithZParser, _Parser);
|
|
4768
|
+
var _super = _createSuper(ISOTimezoneWithZParser);
|
|
4769
|
+
function ISOTimezoneWithZParser() {
|
|
4770
|
+
var _this;
|
|
4771
|
+
_classCallCheck(this, ISOTimezoneWithZParser);
|
|
4772
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4773
|
+
args[_key] = arguments[_key];
|
|
4774
|
+
}
|
|
4775
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4776
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 10);
|
|
4777
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['t', 'T', 'x']);
|
|
4778
|
+
return _this;
|
|
4779
|
+
}
|
|
4780
|
+
_createClass(ISOTimezoneWithZParser, [{
|
|
4781
|
+
key: "parse",
|
|
4782
|
+
value: function parse(dateString, token) {
|
|
4783
|
+
switch (token) {
|
|
4784
|
+
case 'X':
|
|
4785
|
+
return parseTimezonePattern(timezonePatterns.basicOptionalMinutes, dateString);
|
|
4786
|
+
case 'XX':
|
|
4787
|
+
return parseTimezonePattern(timezonePatterns.basic, dateString);
|
|
4788
|
+
case 'XXXX':
|
|
4789
|
+
return parseTimezonePattern(timezonePatterns.basicOptionalSeconds, dateString);
|
|
4790
|
+
case 'XXXXX':
|
|
4791
|
+
return parseTimezonePattern(timezonePatterns.extendedOptionalSeconds, dateString);
|
|
4792
|
+
case 'XXX':
|
|
4793
|
+
default:
|
|
4794
|
+
return parseTimezonePattern(timezonePatterns.extended, dateString);
|
|
4795
|
+
}
|
|
4796
|
+
}
|
|
4797
|
+
}, {
|
|
4798
|
+
key: "set",
|
|
4799
|
+
value: function set(date, flags, value) {
|
|
4800
|
+
if (flags.timestampIsSet) {
|
|
4801
|
+
return date;
|
|
4802
|
+
}
|
|
4803
|
+
return new Date(date.getTime() - value);
|
|
4804
|
+
}
|
|
4805
|
+
}]);
|
|
4806
|
+
return ISOTimezoneWithZParser;
|
|
4807
|
+
}(Parser);
|
|
4808
|
+
|
|
4809
|
+
var ISOTimezoneParser = /*#__PURE__*/function (_Parser) {
|
|
4810
|
+
_inherits(ISOTimezoneParser, _Parser);
|
|
4811
|
+
var _super = _createSuper(ISOTimezoneParser);
|
|
4812
|
+
function ISOTimezoneParser() {
|
|
4813
|
+
var _this;
|
|
4814
|
+
_classCallCheck(this, ISOTimezoneParser);
|
|
4815
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4816
|
+
args[_key] = arguments[_key];
|
|
4817
|
+
}
|
|
4818
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4819
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 10);
|
|
4820
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['t', 'T', 'X']);
|
|
4821
|
+
return _this;
|
|
4822
|
+
}
|
|
4823
|
+
_createClass(ISOTimezoneParser, [{
|
|
4824
|
+
key: "parse",
|
|
4825
|
+
value: function parse(dateString, token) {
|
|
4826
|
+
switch (token) {
|
|
4827
|
+
case 'x':
|
|
4828
|
+
return parseTimezonePattern(timezonePatterns.basicOptionalMinutes, dateString);
|
|
4829
|
+
case 'xx':
|
|
4830
|
+
return parseTimezonePattern(timezonePatterns.basic, dateString);
|
|
4831
|
+
case 'xxxx':
|
|
4832
|
+
return parseTimezonePattern(timezonePatterns.basicOptionalSeconds, dateString);
|
|
4833
|
+
case 'xxxxx':
|
|
4834
|
+
return parseTimezonePattern(timezonePatterns.extendedOptionalSeconds, dateString);
|
|
4835
|
+
case 'xxx':
|
|
4836
|
+
default:
|
|
4837
|
+
return parseTimezonePattern(timezonePatterns.extended, dateString);
|
|
4838
|
+
}
|
|
4839
|
+
}
|
|
4840
|
+
}, {
|
|
4841
|
+
key: "set",
|
|
4842
|
+
value: function set(date, flags, value) {
|
|
4843
|
+
if (flags.timestampIsSet) {
|
|
4844
|
+
return date;
|
|
4845
|
+
}
|
|
4846
|
+
return new Date(date.getTime() - value);
|
|
4847
|
+
}
|
|
4848
|
+
}]);
|
|
4849
|
+
return ISOTimezoneParser;
|
|
4850
|
+
}(Parser);
|
|
4851
|
+
|
|
4852
|
+
var TimestampSecondsParser = /*#__PURE__*/function (_Parser) {
|
|
4853
|
+
_inherits(TimestampSecondsParser, _Parser);
|
|
4854
|
+
var _super = _createSuper(TimestampSecondsParser);
|
|
4855
|
+
function TimestampSecondsParser() {
|
|
4856
|
+
var _this;
|
|
4857
|
+
_classCallCheck(this, TimestampSecondsParser);
|
|
4858
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4859
|
+
args[_key] = arguments[_key];
|
|
4860
|
+
}
|
|
4861
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4862
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 40);
|
|
4863
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", '*');
|
|
4864
|
+
return _this;
|
|
4865
|
+
}
|
|
4866
|
+
_createClass(TimestampSecondsParser, [{
|
|
4867
|
+
key: "parse",
|
|
4868
|
+
value: function parse(dateString) {
|
|
4869
|
+
return parseAnyDigitsSigned(dateString);
|
|
4870
|
+
}
|
|
4871
|
+
}, {
|
|
4872
|
+
key: "set",
|
|
4873
|
+
value: function set(_date, _flags, value) {
|
|
4874
|
+
return [new Date(value * 1000), {
|
|
4875
|
+
timestampIsSet: true
|
|
4876
|
+
}];
|
|
4877
|
+
}
|
|
4878
|
+
}]);
|
|
4879
|
+
return TimestampSecondsParser;
|
|
4880
|
+
}(Parser);
|
|
4881
|
+
|
|
4882
|
+
var TimestampMillisecondsParser = /*#__PURE__*/function (_Parser) {
|
|
4883
|
+
_inherits(TimestampMillisecondsParser, _Parser);
|
|
4884
|
+
var _super = _createSuper(TimestampMillisecondsParser);
|
|
4885
|
+
function TimestampMillisecondsParser() {
|
|
4886
|
+
var _this;
|
|
4887
|
+
_classCallCheck(this, TimestampMillisecondsParser);
|
|
4888
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4889
|
+
args[_key] = arguments[_key];
|
|
4890
|
+
}
|
|
4891
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
4892
|
+
_defineProperty(_assertThisInitialized(_this), "priority", 20);
|
|
4893
|
+
_defineProperty(_assertThisInitialized(_this), "incompatibleTokens", '*');
|
|
4894
|
+
return _this;
|
|
4895
|
+
}
|
|
4896
|
+
_createClass(TimestampMillisecondsParser, [{
|
|
4897
|
+
key: "parse",
|
|
4898
|
+
value: function parse(dateString) {
|
|
4899
|
+
return parseAnyDigitsSigned(dateString);
|
|
4900
|
+
}
|
|
4901
|
+
}, {
|
|
4902
|
+
key: "set",
|
|
4903
|
+
value: function set(_date, _flags, value) {
|
|
4904
|
+
return [new Date(value), {
|
|
4905
|
+
timestampIsSet: true
|
|
4906
|
+
}];
|
|
4907
|
+
}
|
|
4908
|
+
}]);
|
|
4909
|
+
return TimestampMillisecondsParser;
|
|
4910
|
+
}(Parser);
|
|
4911
|
+
|
|
4912
|
+
/*
|
|
4913
|
+
* | | Unit | | Unit |
|
|
4914
|
+
* |-----|--------------------------------|-----|--------------------------------|
|
|
4915
|
+
* | a | AM, PM | A* | Milliseconds in day |
|
|
4916
|
+
* | b | AM, PM, noon, midnight | B | Flexible day period |
|
|
4917
|
+
* | c | Stand-alone local day of week | C* | Localized hour w/ day period |
|
|
4918
|
+
* | d | Day of month | D | Day of year |
|
|
4919
|
+
* | e | Local day of week | E | Day of week |
|
|
4920
|
+
* | f | | F* | Day of week in month |
|
|
4921
|
+
* | g* | Modified Julian day | G | Era |
|
|
4922
|
+
* | h | Hour [1-12] | H | Hour [0-23] |
|
|
4923
|
+
* | i! | ISO day of week | I! | ISO week of year |
|
|
4924
|
+
* | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
|
|
4925
|
+
* | k | Hour [1-24] | K | Hour [0-11] |
|
|
4926
|
+
* | l* | (deprecated) | L | Stand-alone month |
|
|
4927
|
+
* | m | Minute | M | Month |
|
|
4928
|
+
* | n | | N | |
|
|
4929
|
+
* | o! | Ordinal number modifier | O* | Timezone (GMT) |
|
|
4930
|
+
* | p | | P | |
|
|
4931
|
+
* | q | Stand-alone quarter | Q | Quarter |
|
|
4932
|
+
* | r* | Related Gregorian year | R! | ISO week-numbering year |
|
|
4933
|
+
* | s | Second | S | Fraction of second |
|
|
4934
|
+
* | t! | Seconds timestamp | T! | Milliseconds timestamp |
|
|
4935
|
+
* | u | Extended year | U* | Cyclic year |
|
|
4936
|
+
* | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
|
|
4937
|
+
* | w | Local week of year | W* | Week of month |
|
|
4938
|
+
* | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
|
|
4939
|
+
* | y | Year (abs) | Y | Local week-numbering year |
|
|
4940
|
+
* | z* | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
|
|
4941
|
+
*
|
|
4942
|
+
* Letters marked by * are not implemented but reserved by Unicode standard.
|
|
4943
|
+
*
|
|
4944
|
+
* Letters marked by ! are non-standard, but implemented by date-fns:
|
|
4945
|
+
* - `o` modifies the previous token to turn it into an ordinal (see `parse` docs)
|
|
4946
|
+
* - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
|
|
4947
|
+
* i.e. 7 for Sunday, 1 for Monday, etc.
|
|
4948
|
+
* - `I` is ISO week of year, as opposed to `w` which is local week of year.
|
|
4949
|
+
* - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
|
|
4950
|
+
* `R` is supposed to be used in conjunction with `I` and `i`
|
|
4951
|
+
* for universal ISO week-numbering date, whereas
|
|
4952
|
+
* `Y` is supposed to be used in conjunction with `w` and `e`
|
|
4953
|
+
* for week-numbering date specific to the locale.
|
|
4954
|
+
*/
|
|
4955
|
+
var parsers = {
|
|
4956
|
+
G: new EraParser(),
|
|
4957
|
+
y: new YearParser(),
|
|
4958
|
+
Y: new LocalWeekYearParser(),
|
|
4959
|
+
R: new ISOWeekYearParser(),
|
|
4960
|
+
u: new ExtendedYearParser(),
|
|
4961
|
+
Q: new QuarterParser(),
|
|
4962
|
+
q: new StandAloneQuarterParser(),
|
|
4963
|
+
M: new MonthParser(),
|
|
4964
|
+
L: new StandAloneMonthParser(),
|
|
4965
|
+
w: new LocalWeekParser(),
|
|
4966
|
+
I: new ISOWeekParser(),
|
|
4967
|
+
d: new DateParser(),
|
|
4968
|
+
D: new DayOfYearParser(),
|
|
4969
|
+
E: new DayParser(),
|
|
4970
|
+
e: new LocalDayParser(),
|
|
4971
|
+
c: new StandAloneLocalDayParser(),
|
|
4972
|
+
i: new ISODayParser(),
|
|
4973
|
+
a: new AMPMParser(),
|
|
4974
|
+
b: new AMPMMidnightParser(),
|
|
4975
|
+
B: new DayPeriodParser(),
|
|
4976
|
+
h: new Hour1to12Parser(),
|
|
4977
|
+
H: new Hour0to23Parser(),
|
|
4978
|
+
K: new Hour0To11Parser(),
|
|
4979
|
+
k: new Hour1To24Parser(),
|
|
4980
|
+
m: new MinuteParser(),
|
|
4981
|
+
s: new SecondParser(),
|
|
4982
|
+
S: new FractionOfSecondParser(),
|
|
4983
|
+
X: new ISOTimezoneWithZParser(),
|
|
4984
|
+
x: new ISOTimezoneParser(),
|
|
4985
|
+
t: new TimestampSecondsParser(),
|
|
4986
|
+
T: new TimestampMillisecondsParser()
|
|
4987
|
+
};
|
|
4988
|
+
|
|
4989
|
+
// - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
|
|
4990
|
+
// (one of the certain letters followed by `o`)
|
|
4991
|
+
// - (\w)\1* matches any sequences of the same letter
|
|
4992
|
+
// - '' matches two quote characters in a row
|
|
4993
|
+
// - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
|
|
4994
|
+
// except a single quote symbol, which ends the sequence.
|
|
4995
|
+
// Two quote characters do not end the sequence.
|
|
4996
|
+
// If there is no matching single quote
|
|
4997
|
+
// then the sequence will continue until the end of the string.
|
|
4998
|
+
// - . matches any single character unmatched by previous parts of the RegExps
|
|
4999
|
+
var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
|
|
5000
|
+
|
|
5001
|
+
// This RegExp catches symbols escaped by quotes, and also
|
|
5002
|
+
// sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
|
|
5003
|
+
var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
5004
|
+
var escapedStringRegExp = /^'([^]*?)'?$/;
|
|
5005
|
+
var doubleQuoteRegExp = /''/g;
|
|
5006
|
+
var notWhitespaceRegExp = /\S/;
|
|
5007
|
+
var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
|
|
5008
|
+
|
|
5009
|
+
/**
|
|
5010
|
+
* @name parse
|
|
5011
|
+
* @category Common Helpers
|
|
5012
|
+
* @summary Parse the date.
|
|
5013
|
+
*
|
|
5014
|
+
* @description
|
|
5015
|
+
* Return the date parsed from string using the given format string.
|
|
5016
|
+
*
|
|
5017
|
+
* > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
|
|
5018
|
+
* > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5019
|
+
*
|
|
5020
|
+
* The characters in the format string wrapped between two single quotes characters (') are escaped.
|
|
5021
|
+
* Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
|
|
5022
|
+
*
|
|
5023
|
+
* Format of the format string is based on Unicode Technical Standard #35:
|
|
5024
|
+
* https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
5025
|
+
* with a few additions (see note 5 below the table).
|
|
5026
|
+
*
|
|
5027
|
+
* Not all tokens are compatible. Combinations that don't make sense or could lead to bugs are prohibited
|
|
5028
|
+
* and will throw `RangeError`. For example usage of 24-hour format token with AM/PM token will throw an exception:
|
|
5029
|
+
*
|
|
5030
|
+
* ```javascript
|
|
5031
|
+
* parse('23 AM', 'HH a', new Date())
|
|
5032
|
+
* //=> RangeError: The format string mustn't contain `HH` and `a` at the same time
|
|
5033
|
+
* ```
|
|
5034
|
+
*
|
|
5035
|
+
* See the compatibility table: https://docs.google.com/spreadsheets/d/e/2PACX-1vQOPU3xUhplll6dyoMmVUXHKl_8CRDs6_ueLmex3SoqwhuolkuN3O05l4rqx5h1dKX8eb46Ul-CCSrq/pubhtml?gid=0&single=true
|
|
5036
|
+
*
|
|
5037
|
+
* Accepted format string patterns:
|
|
5038
|
+
* | Unit |Prior| Pattern | Result examples | Notes |
|
|
5039
|
+
* |---------------------------------|-----|---------|-----------------------------------|-------|
|
|
5040
|
+
* | Era | 140 | G..GGG | AD, BC | |
|
|
5041
|
+
* | | | GGGG | Anno Domini, Before Christ | 2 |
|
|
5042
|
+
* | | | GGGGG | A, B | |
|
|
5043
|
+
* | Calendar year | 130 | y | 44, 1, 1900, 2017, 9999 | 4 |
|
|
5044
|
+
* | | | yo | 44th, 1st, 1900th, 9999999th | 4,5 |
|
|
5045
|
+
* | | | yy | 44, 01, 00, 17 | 4 |
|
|
5046
|
+
* | | | yyy | 044, 001, 123, 999 | 4 |
|
|
5047
|
+
* | | | yyyy | 0044, 0001, 1900, 2017 | 4 |
|
|
5048
|
+
* | | | yyyyy | ... | 2,4 |
|
|
5049
|
+
* | Local week-numbering year | 130 | Y | 44, 1, 1900, 2017, 9000 | 4 |
|
|
5050
|
+
* | | | Yo | 44th, 1st, 1900th, 9999999th | 4,5 |
|
|
5051
|
+
* | | | YY | 44, 01, 00, 17 | 4,6 |
|
|
5052
|
+
* | | | YYY | 044, 001, 123, 999 | 4 |
|
|
5053
|
+
* | | | YYYY | 0044, 0001, 1900, 2017 | 4,6 |
|
|
5054
|
+
* | | | YYYYY | ... | 2,4 |
|
|
5055
|
+
* | ISO week-numbering year | 130 | R | -43, 1, 1900, 2017, 9999, -9999 | 4,5 |
|
|
5056
|
+
* | | | RR | -43, 01, 00, 17 | 4,5 |
|
|
5057
|
+
* | | | RRR | -043, 001, 123, 999, -999 | 4,5 |
|
|
5058
|
+
* | | | RRRR | -0043, 0001, 2017, 9999, -9999 | 4,5 |
|
|
5059
|
+
* | | | RRRRR | ... | 2,4,5 |
|
|
5060
|
+
* | Extended year | 130 | u | -43, 1, 1900, 2017, 9999, -999 | 4 |
|
|
5061
|
+
* | | | uu | -43, 01, 99, -99 | 4 |
|
|
5062
|
+
* | | | uuu | -043, 001, 123, 999, -999 | 4 |
|
|
5063
|
+
* | | | uuuu | -0043, 0001, 2017, 9999, -9999 | 4 |
|
|
5064
|
+
* | | | uuuuu | ... | 2,4 |
|
|
5065
|
+
* | Quarter (formatting) | 120 | Q | 1, 2, 3, 4 | |
|
|
5066
|
+
* | | | Qo | 1st, 2nd, 3rd, 4th | 5 |
|
|
5067
|
+
* | | | QQ | 01, 02, 03, 04 | |
|
|
5068
|
+
* | | | QQQ | Q1, Q2, Q3, Q4 | |
|
|
5069
|
+
* | | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
|
|
5070
|
+
* | | | QQQQQ | 1, 2, 3, 4 | 4 |
|
|
5071
|
+
* | Quarter (stand-alone) | 120 | q | 1, 2, 3, 4 | |
|
|
5072
|
+
* | | | qo | 1st, 2nd, 3rd, 4th | 5 |
|
|
5073
|
+
* | | | qq | 01, 02, 03, 04 | |
|
|
5074
|
+
* | | | qqq | Q1, Q2, Q3, Q4 | |
|
|
5075
|
+
* | | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
|
|
5076
|
+
* | | | qqqqq | 1, 2, 3, 4 | 3 |
|
|
5077
|
+
* | Month (formatting) | 110 | M | 1, 2, ..., 12 | |
|
|
5078
|
+
* | | | Mo | 1st, 2nd, ..., 12th | 5 |
|
|
5079
|
+
* | | | MM | 01, 02, ..., 12 | |
|
|
5080
|
+
* | | | MMM | Jan, Feb, ..., Dec | |
|
|
5081
|
+
* | | | MMMM | January, February, ..., December | 2 |
|
|
5082
|
+
* | | | MMMMM | J, F, ..., D | |
|
|
5083
|
+
* | Month (stand-alone) | 110 | L | 1, 2, ..., 12 | |
|
|
5084
|
+
* | | | Lo | 1st, 2nd, ..., 12th | 5 |
|
|
5085
|
+
* | | | LL | 01, 02, ..., 12 | |
|
|
5086
|
+
* | | | LLL | Jan, Feb, ..., Dec | |
|
|
5087
|
+
* | | | LLLL | January, February, ..., December | 2 |
|
|
5088
|
+
* | | | LLLLL | J, F, ..., D | |
|
|
5089
|
+
* | Local week of year | 100 | w | 1, 2, ..., 53 | |
|
|
5090
|
+
* | | | wo | 1st, 2nd, ..., 53th | 5 |
|
|
5091
|
+
* | | | ww | 01, 02, ..., 53 | |
|
|
5092
|
+
* | ISO week of year | 100 | I | 1, 2, ..., 53 | 5 |
|
|
5093
|
+
* | | | Io | 1st, 2nd, ..., 53th | 5 |
|
|
5094
|
+
* | | | II | 01, 02, ..., 53 | 5 |
|
|
5095
|
+
* | Day of month | 90 | d | 1, 2, ..., 31 | |
|
|
5096
|
+
* | | | do | 1st, 2nd, ..., 31st | 5 |
|
|
5097
|
+
* | | | dd | 01, 02, ..., 31 | |
|
|
5098
|
+
* | Day of year | 90 | D | 1, 2, ..., 365, 366 | 7 |
|
|
5099
|
+
* | | | Do | 1st, 2nd, ..., 365th, 366th | 5 |
|
|
5100
|
+
* | | | DD | 01, 02, ..., 365, 366 | 7 |
|
|
5101
|
+
* | | | DDD | 001, 002, ..., 365, 366 | |
|
|
5102
|
+
* | | | DDDD | ... | 2 |
|
|
5103
|
+
* | Day of week (formatting) | 90 | E..EEE | Mon, Tue, Wed, ..., Sun | |
|
|
5104
|
+
* | | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
|
|
5105
|
+
* | | | EEEEE | M, T, W, T, F, S, S | |
|
|
5106
|
+
* | | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
5107
|
+
* | ISO day of week (formatting) | 90 | i | 1, 2, 3, ..., 7 | 5 |
|
|
5108
|
+
* | | | io | 1st, 2nd, ..., 7th | 5 |
|
|
5109
|
+
* | | | ii | 01, 02, ..., 07 | 5 |
|
|
5110
|
+
* | | | iii | Mon, Tue, Wed, ..., Sun | 5 |
|
|
5111
|
+
* | | | iiii | Monday, Tuesday, ..., Sunday | 2,5 |
|
|
5112
|
+
* | | | iiiii | M, T, W, T, F, S, S | 5 |
|
|
5113
|
+
* | | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 5 |
|
|
5114
|
+
* | Local day of week (formatting) | 90 | e | 2, 3, 4, ..., 1 | |
|
|
5115
|
+
* | | | eo | 2nd, 3rd, ..., 1st | 5 |
|
|
5116
|
+
* | | | ee | 02, 03, ..., 01 | |
|
|
5117
|
+
* | | | eee | Mon, Tue, Wed, ..., Sun | |
|
|
5118
|
+
* | | | eeee | Monday, Tuesday, ..., Sunday | 2 |
|
|
5119
|
+
* | | | eeeee | M, T, W, T, F, S, S | |
|
|
5120
|
+
* | | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
5121
|
+
* | Local day of week (stand-alone) | 90 | c | 2, 3, 4, ..., 1 | |
|
|
5122
|
+
* | | | co | 2nd, 3rd, ..., 1st | 5 |
|
|
5123
|
+
* | | | cc | 02, 03, ..., 01 | |
|
|
5124
|
+
* | | | ccc | Mon, Tue, Wed, ..., Sun | |
|
|
5125
|
+
* | | | cccc | Monday, Tuesday, ..., Sunday | 2 |
|
|
5126
|
+
* | | | ccccc | M, T, W, T, F, S, S | |
|
|
5127
|
+
* | | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
5128
|
+
* | AM, PM | 80 | a..aaa | AM, PM | |
|
|
5129
|
+
* | | | aaaa | a.m., p.m. | 2 |
|
|
5130
|
+
* | | | aaaaa | a, p | |
|
|
5131
|
+
* | AM, PM, noon, midnight | 80 | b..bbb | AM, PM, noon, midnight | |
|
|
5132
|
+
* | | | bbbb | a.m., p.m., noon, midnight | 2 |
|
|
5133
|
+
* | | | bbbbb | a, p, n, mi | |
|
|
5134
|
+
* | Flexible day period | 80 | B..BBB | at night, in the morning, ... | |
|
|
5135
|
+
* | | | BBBB | at night, in the morning, ... | 2 |
|
|
5136
|
+
* | | | BBBBB | at night, in the morning, ... | |
|
|
5137
|
+
* | Hour [1-12] | 70 | h | 1, 2, ..., 11, 12 | |
|
|
5138
|
+
* | | | ho | 1st, 2nd, ..., 11th, 12th | 5 |
|
|
5139
|
+
* | | | hh | 01, 02, ..., 11, 12 | |
|
|
5140
|
+
* | Hour [0-23] | 70 | H | 0, 1, 2, ..., 23 | |
|
|
5141
|
+
* | | | Ho | 0th, 1st, 2nd, ..., 23rd | 5 |
|
|
5142
|
+
* | | | HH | 00, 01, 02, ..., 23 | |
|
|
5143
|
+
* | Hour [0-11] | 70 | K | 1, 2, ..., 11, 0 | |
|
|
5144
|
+
* | | | Ko | 1st, 2nd, ..., 11th, 0th | 5 |
|
|
5145
|
+
* | | | KK | 01, 02, ..., 11, 00 | |
|
|
5146
|
+
* | Hour [1-24] | 70 | k | 24, 1, 2, ..., 23 | |
|
|
5147
|
+
* | | | ko | 24th, 1st, 2nd, ..., 23rd | 5 |
|
|
5148
|
+
* | | | kk | 24, 01, 02, ..., 23 | |
|
|
5149
|
+
* | Minute | 60 | m | 0, 1, ..., 59 | |
|
|
5150
|
+
* | | | mo | 0th, 1st, ..., 59th | 5 |
|
|
5151
|
+
* | | | mm | 00, 01, ..., 59 | |
|
|
5152
|
+
* | Second | 50 | s | 0, 1, ..., 59 | |
|
|
5153
|
+
* | | | so | 0th, 1st, ..., 59th | 5 |
|
|
5154
|
+
* | | | ss | 00, 01, ..., 59 | |
|
|
5155
|
+
* | Seconds timestamp | 40 | t | 512969520 | |
|
|
5156
|
+
* | | | tt | ... | 2 |
|
|
5157
|
+
* | Fraction of second | 30 | S | 0, 1, ..., 9 | |
|
|
5158
|
+
* | | | SS | 00, 01, ..., 99 | |
|
|
5159
|
+
* | | | SSS | 000, 001, ..., 999 | |
|
|
5160
|
+
* | | | SSSS | ... | 2 |
|
|
5161
|
+
* | Milliseconds timestamp | 20 | T | 512969520900 | |
|
|
5162
|
+
* | | | TT | ... | 2 |
|
|
5163
|
+
* | Timezone (ISO-8601 w/ Z) | 10 | X | -08, +0530, Z | |
|
|
5164
|
+
* | | | XX | -0800, +0530, Z | |
|
|
5165
|
+
* | | | XXX | -08:00, +05:30, Z | |
|
|
5166
|
+
* | | | XXXX | -0800, +0530, Z, +123456 | 2 |
|
|
5167
|
+
* | | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
|
|
5168
|
+
* | Timezone (ISO-8601 w/o Z) | 10 | x | -08, +0530, +00 | |
|
|
5169
|
+
* | | | xx | -0800, +0530, +0000 | |
|
|
5170
|
+
* | | | xxx | -08:00, +05:30, +00:00 | 2 |
|
|
5171
|
+
* | | | xxxx | -0800, +0530, +0000, +123456 | |
|
|
5172
|
+
* | | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
|
|
5173
|
+
* | Long localized date | NA | P | 05/29/1453 | 5,8 |
|
|
5174
|
+
* | | | PP | May 29, 1453 | |
|
|
5175
|
+
* | | | PPP | May 29th, 1453 | |
|
|
5176
|
+
* | | | PPPP | Sunday, May 29th, 1453 | 2,5,8 |
|
|
5177
|
+
* | Long localized time | NA | p | 12:00 AM | 5,8 |
|
|
5178
|
+
* | | | pp | 12:00:00 AM | |
|
|
5179
|
+
* | Combination of date and time | NA | Pp | 05/29/1453, 12:00 AM | |
|
|
5180
|
+
* | | | PPpp | May 29, 1453, 12:00:00 AM | |
|
|
5181
|
+
* | | | PPPpp | May 29th, 1453 at ... | |
|
|
5182
|
+
* | | | PPPPpp | Sunday, May 29th, 1453 at ... | 2,5,8 |
|
|
5183
|
+
* Notes:
|
|
5184
|
+
* 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
|
|
5185
|
+
* are the same as "stand-alone" units, but are different in some languages.
|
|
5186
|
+
* "Formatting" units are declined according to the rules of the language
|
|
5187
|
+
* in the context of a date. "Stand-alone" units are always nominative singular.
|
|
5188
|
+
* In `format` function, they will produce different result:
|
|
5189
|
+
*
|
|
5190
|
+
* `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
|
|
5191
|
+
*
|
|
5192
|
+
* `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
|
|
5193
|
+
*
|
|
5194
|
+
* `parse` will try to match both formatting and stand-alone units interchangably.
|
|
5195
|
+
*
|
|
5196
|
+
* 2. Any sequence of the identical letters is a pattern, unless it is escaped by
|
|
5197
|
+
* the single quote characters (see below).
|
|
5198
|
+
* If the sequence is longer than listed in table:
|
|
5199
|
+
* - for numerical units (`yyyyyyyy`) `parse` will try to match a number
|
|
5200
|
+
* as wide as the sequence
|
|
5201
|
+
* - for text units (`MMMMMMMM`) `parse` will try to match the widest variation of the unit.
|
|
5202
|
+
* These variations are marked with "2" in the last column of the table.
|
|
5203
|
+
*
|
|
5204
|
+
* 3. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
|
|
5205
|
+
* These tokens represent the shortest form of the quarter.
|
|
5206
|
+
*
|
|
5207
|
+
* 4. The main difference between `y` and `u` patterns are B.C. years:
|
|
5208
|
+
*
|
|
5209
|
+
* | Year | `y` | `u` |
|
|
5210
|
+
* |------|-----|-----|
|
|
5211
|
+
* | AC 1 | 1 | 1 |
|
|
5212
|
+
* | BC 1 | 1 | 0 |
|
|
5213
|
+
* | BC 2 | 2 | -1 |
|
|
5214
|
+
*
|
|
5215
|
+
* Also `yy` will try to guess the century of two digit year by proximity with `referenceDate`:
|
|
5216
|
+
*
|
|
5217
|
+
* `parse('50', 'yy', new Date(2018, 0, 1)) //=> Sat Jan 01 2050 00:00:00`
|
|
5218
|
+
*
|
|
5219
|
+
* `parse('75', 'yy', new Date(2018, 0, 1)) //=> Wed Jan 01 1975 00:00:00`
|
|
5220
|
+
*
|
|
5221
|
+
* while `uu` will just assign the year as is:
|
|
5222
|
+
*
|
|
5223
|
+
* `parse('50', 'uu', new Date(2018, 0, 1)) //=> Sat Jan 01 0050 00:00:00`
|
|
5224
|
+
*
|
|
5225
|
+
* `parse('75', 'uu', new Date(2018, 0, 1)) //=> Tue Jan 01 0075 00:00:00`
|
|
5226
|
+
*
|
|
5227
|
+
* The same difference is true for local and ISO week-numbering years (`Y` and `R`),
|
|
5228
|
+
* except local week-numbering years are dependent on `options.weekStartsOn`
|
|
5229
|
+
* and `options.firstWeekContainsDate` (compare [setISOWeekYear]{@link https://date-fns.org/docs/setISOWeekYear}
|
|
5230
|
+
* and [setWeekYear]{@link https://date-fns.org/docs/setWeekYear}).
|
|
5231
|
+
*
|
|
5232
|
+
* 5. These patterns are not in the Unicode Technical Standard #35:
|
|
5233
|
+
* - `i`: ISO day of week
|
|
5234
|
+
* - `I`: ISO week of year
|
|
5235
|
+
* - `R`: ISO week-numbering year
|
|
5236
|
+
* - `o`: ordinal number modifier
|
|
5237
|
+
* - `P`: long localized date
|
|
5238
|
+
* - `p`: long localized time
|
|
5239
|
+
*
|
|
5240
|
+
* 6. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
|
|
5241
|
+
* You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5242
|
+
*
|
|
5243
|
+
* 7. `D` and `DD` tokens represent days of the year but they are ofthen confused with days of the month.
|
|
5244
|
+
* You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5245
|
+
*
|
|
5246
|
+
* 8. `P+` tokens do not have a defined priority since they are merely aliases to other tokens based
|
|
5247
|
+
* on the given locale.
|
|
5248
|
+
*
|
|
5249
|
+
* using `en-US` locale: `P` => `MM/dd/yyyy`
|
|
5250
|
+
* using `en-US` locale: `p` => `hh:mm a`
|
|
5251
|
+
* using `pt-BR` locale: `P` => `dd/MM/yyyy`
|
|
5252
|
+
* using `pt-BR` locale: `p` => `HH:mm`
|
|
5253
|
+
*
|
|
5254
|
+
* Values will be assigned to the date in the descending order of its unit's priority.
|
|
5255
|
+
* Units of an equal priority overwrite each other in the order of appearance.
|
|
5256
|
+
*
|
|
5257
|
+
* If no values of higher priority are parsed (e.g. when parsing string 'January 1st' without a year),
|
|
5258
|
+
* the values will be taken from 3rd argument `referenceDate` which works as a context of parsing.
|
|
5259
|
+
*
|
|
5260
|
+
* `referenceDate` must be passed for correct work of the function.
|
|
5261
|
+
* If you're not sure which `referenceDate` to supply, create a new instance of Date:
|
|
5262
|
+
* `parse('02/11/2014', 'MM/dd/yyyy', new Date())`
|
|
5263
|
+
* In this case parsing will be done in the context of the current date.
|
|
5264
|
+
* If `referenceDate` is `Invalid Date` or a value not convertible to valid `Date`,
|
|
5265
|
+
* then `Invalid Date` will be returned.
|
|
5266
|
+
*
|
|
5267
|
+
* The result may vary by locale.
|
|
5268
|
+
*
|
|
5269
|
+
* If `formatString` matches with `dateString` but does not provides tokens, `referenceDate` will be returned.
|
|
5270
|
+
*
|
|
5271
|
+
* If parsing failed, `Invalid Date` will be returned.
|
|
5272
|
+
* Invalid Date is a Date, whose time value is NaN.
|
|
5273
|
+
* Time value of Date: http://es5.github.io/#x15.9.1.1
|
|
5274
|
+
*
|
|
5275
|
+
* @param {String} dateString - the string to parse
|
|
5276
|
+
* @param {String} formatString - the string of tokens
|
|
5277
|
+
* @param {Date|Number} referenceDate - defines values missing from the parsed dateString
|
|
5278
|
+
* @param {Object} [options] - an object with options.
|
|
5279
|
+
* @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
|
|
5280
|
+
* @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
|
|
5281
|
+
* @param {1|2|3|4|5|6|7} [options.firstWeekContainsDate=1] - the day of January, which is always in the first week of the year
|
|
5282
|
+
* @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`;
|
|
5283
|
+
* see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5284
|
+
* @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`;
|
|
5285
|
+
* see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5286
|
+
* @returns {Date} the parsed date
|
|
5287
|
+
* @throws {TypeError} 3 arguments required
|
|
5288
|
+
* @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
|
|
5289
|
+
* @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7
|
|
5290
|
+
* @throws {RangeError} `options.locale` must contain `match` property
|
|
5291
|
+
* @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5292
|
+
* @throws {RangeError} use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5293
|
+
* @throws {RangeError} use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5294
|
+
* @throws {RangeError} use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
5295
|
+
* @throws {RangeError} format string contains an unescaped latin alphabet character
|
|
5296
|
+
*
|
|
5297
|
+
* @example
|
|
5298
|
+
* // Parse 11 February 2014 from middle-endian format:
|
|
5299
|
+
* var result = parse('02/11/2014', 'MM/dd/yyyy', new Date())
|
|
5300
|
+
* //=> Tue Feb 11 2014 00:00:00
|
|
5301
|
+
*
|
|
5302
|
+
* @example
|
|
5303
|
+
* // Parse 28th of February in Esperanto locale in the context of 2010 year:
|
|
5304
|
+
* import eo from 'date-fns/locale/eo'
|
|
5305
|
+
* var result = parse('28-a de februaro', "do 'de' MMMM", new Date(2010, 0, 1), {
|
|
5306
|
+
* locale: eo
|
|
5307
|
+
* })
|
|
5308
|
+
* //=> Sun Feb 28 2010 00:00:00
|
|
5309
|
+
*/
|
|
5310
|
+
function parse(dirtyDateString, dirtyFormatString, dirtyReferenceDate, options) {
|
|
5311
|
+
var _ref, _options$locale, _ref2, _ref3, _ref4, _options$firstWeekCon, _options$locale2, _options$locale2$opti, _defaultOptions$local, _defaultOptions$local2, _ref5, _ref6, _ref7, _options$weekStartsOn, _options$locale3, _options$locale3$opti, _defaultOptions$local3, _defaultOptions$local4;
|
|
5312
|
+
requiredArgs(3, arguments);
|
|
5313
|
+
var dateString = String(dirtyDateString);
|
|
5314
|
+
var formatString = String(dirtyFormatString);
|
|
5315
|
+
var defaultOptions = getDefaultOptions();
|
|
5316
|
+
var locale = (_ref = (_options$locale = options === null || options === void 0 ? void 0 : options.locale) !== null && _options$locale !== void 0 ? _options$locale : defaultOptions.locale) !== null && _ref !== void 0 ? _ref : defaultLocale;
|
|
5317
|
+
if (!locale.match) {
|
|
5318
|
+
throw new RangeError('locale must contain match property');
|
|
5319
|
+
}
|
|
5320
|
+
var firstWeekContainsDate = toInteger((_ref2 = (_ref3 = (_ref4 = (_options$firstWeekCon = options === null || options === void 0 ? void 0 : options.firstWeekContainsDate) !== null && _options$firstWeekCon !== void 0 ? _options$firstWeekCon : options === null || options === void 0 ? void 0 : (_options$locale2 = options.locale) === null || _options$locale2 === void 0 ? void 0 : (_options$locale2$opti = _options$locale2.options) === null || _options$locale2$opti === void 0 ? void 0 : _options$locale2$opti.firstWeekContainsDate) !== null && _ref4 !== void 0 ? _ref4 : defaultOptions.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.firstWeekContainsDate) !== null && _ref2 !== void 0 ? _ref2 : 1);
|
|
5321
|
+
|
|
5322
|
+
// Test if weekStartsOn is between 1 and 7 _and_ is not NaN
|
|
5323
|
+
if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
|
|
5324
|
+
throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
|
|
5325
|
+
}
|
|
5326
|
+
var weekStartsOn = toInteger((_ref5 = (_ref6 = (_ref7 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale3 = options.locale) === null || _options$locale3 === void 0 ? void 0 : (_options$locale3$opti = _options$locale3.options) === null || _options$locale3$opti === void 0 ? void 0 : _options$locale3$opti.weekStartsOn) !== null && _ref7 !== void 0 ? _ref7 : defaultOptions.weekStartsOn) !== null && _ref6 !== void 0 ? _ref6 : (_defaultOptions$local3 = defaultOptions.locale) === null || _defaultOptions$local3 === void 0 ? void 0 : (_defaultOptions$local4 = _defaultOptions$local3.options) === null || _defaultOptions$local4 === void 0 ? void 0 : _defaultOptions$local4.weekStartsOn) !== null && _ref5 !== void 0 ? _ref5 : 0);
|
|
5327
|
+
|
|
5328
|
+
// Test if weekStartsOn is between 0 and 6 _and_ is not NaN
|
|
5329
|
+
if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
|
|
5330
|
+
throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
|
|
5331
|
+
}
|
|
5332
|
+
if (formatString === '') {
|
|
5333
|
+
if (dateString === '') {
|
|
5334
|
+
return toDate(dirtyReferenceDate);
|
|
5335
|
+
} else {
|
|
5336
|
+
return new Date(NaN);
|
|
5337
|
+
}
|
|
5338
|
+
}
|
|
5339
|
+
var subFnOptions = {
|
|
5340
|
+
firstWeekContainsDate: firstWeekContainsDate,
|
|
5341
|
+
weekStartsOn: weekStartsOn,
|
|
5342
|
+
locale: locale
|
|
5343
|
+
};
|
|
5344
|
+
|
|
5345
|
+
// If timezone isn't specified, it will be set to the system timezone
|
|
5346
|
+
var setters = [new DateToSystemTimezoneSetter()];
|
|
5347
|
+
var tokens = formatString.match(longFormattingTokensRegExp).map(function (substring) {
|
|
5348
|
+
var firstCharacter = substring[0];
|
|
5349
|
+
if (firstCharacter in longFormatters$1) {
|
|
5350
|
+
var longFormatter = longFormatters$1[firstCharacter];
|
|
5351
|
+
return longFormatter(substring, locale.formatLong);
|
|
5352
|
+
}
|
|
5353
|
+
return substring;
|
|
5354
|
+
}).join('').match(formattingTokensRegExp);
|
|
5355
|
+
var usedTokens = [];
|
|
5356
|
+
var _iterator = _createForOfIteratorHelper(tokens),
|
|
5357
|
+
_step;
|
|
5358
|
+
try {
|
|
5359
|
+
var _loop = function _loop() {
|
|
5360
|
+
var token = _step.value;
|
|
5361
|
+
if (!(options !== null && options !== void 0 && options.useAdditionalWeekYearTokens) && isProtectedWeekYearToken(token)) {
|
|
5362
|
+
throwProtectedError(token, formatString, dirtyDateString);
|
|
5363
|
+
}
|
|
5364
|
+
if (!(options !== null && options !== void 0 && options.useAdditionalDayOfYearTokens) && isProtectedDayOfYearToken(token)) {
|
|
5365
|
+
throwProtectedError(token, formatString, dirtyDateString);
|
|
5366
|
+
}
|
|
5367
|
+
var firstCharacter = token[0];
|
|
5368
|
+
var parser = parsers[firstCharacter];
|
|
5369
|
+
if (parser) {
|
|
5370
|
+
var incompatibleTokens = parser.incompatibleTokens;
|
|
5371
|
+
if (Array.isArray(incompatibleTokens)) {
|
|
5372
|
+
var incompatibleToken = usedTokens.find(function (usedToken) {
|
|
5373
|
+
return incompatibleTokens.includes(usedToken.token) || usedToken.token === firstCharacter;
|
|
5374
|
+
});
|
|
5375
|
+
if (incompatibleToken) {
|
|
5376
|
+
throw new RangeError("The format string mustn't contain `".concat(incompatibleToken.fullToken, "` and `").concat(token, "` at the same time"));
|
|
5377
|
+
}
|
|
5378
|
+
} else if (parser.incompatibleTokens === '*' && usedTokens.length > 0) {
|
|
5379
|
+
throw new RangeError("The format string mustn't contain `".concat(token, "` and any other token at the same time"));
|
|
5380
|
+
}
|
|
5381
|
+
usedTokens.push({
|
|
5382
|
+
token: firstCharacter,
|
|
5383
|
+
fullToken: token
|
|
5384
|
+
});
|
|
5385
|
+
var parseResult = parser.run(dateString, token, locale.match, subFnOptions);
|
|
5386
|
+
if (!parseResult) {
|
|
5387
|
+
return {
|
|
5388
|
+
v: new Date(NaN)
|
|
5389
|
+
};
|
|
5390
|
+
}
|
|
5391
|
+
setters.push(parseResult.setter);
|
|
5392
|
+
dateString = parseResult.rest;
|
|
5393
|
+
} else {
|
|
5394
|
+
if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
|
|
5395
|
+
throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`');
|
|
5396
|
+
}
|
|
5397
|
+
|
|
5398
|
+
// Replace two single quote characters with one single quote character
|
|
5399
|
+
if (token === "''") {
|
|
5400
|
+
token = "'";
|
|
5401
|
+
} else if (firstCharacter === "'") {
|
|
5402
|
+
token = cleanEscapedString(token);
|
|
5403
|
+
}
|
|
5404
|
+
|
|
5405
|
+
// Cut token from string, or, if string doesn't match the token, return Invalid Date
|
|
5406
|
+
if (dateString.indexOf(token) === 0) {
|
|
5407
|
+
dateString = dateString.slice(token.length);
|
|
5408
|
+
} else {
|
|
5409
|
+
return {
|
|
5410
|
+
v: new Date(NaN)
|
|
5411
|
+
};
|
|
5412
|
+
}
|
|
5413
|
+
}
|
|
5414
|
+
};
|
|
5415
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
5416
|
+
var _ret = _loop();
|
|
5417
|
+
if (_typeof(_ret) === "object") return _ret.v;
|
|
5418
|
+
}
|
|
5419
|
+
|
|
5420
|
+
// Check if the remaining input contains something other than whitespace
|
|
5421
|
+
} catch (err) {
|
|
5422
|
+
_iterator.e(err);
|
|
5423
|
+
} finally {
|
|
5424
|
+
_iterator.f();
|
|
5425
|
+
}
|
|
5426
|
+
if (dateString.length > 0 && notWhitespaceRegExp.test(dateString)) {
|
|
5427
|
+
return new Date(NaN);
|
|
5428
|
+
}
|
|
5429
|
+
var uniquePrioritySetters = setters.map(function (setter) {
|
|
5430
|
+
return setter.priority;
|
|
5431
|
+
}).sort(function (a, b) {
|
|
5432
|
+
return b - a;
|
|
5433
|
+
}).filter(function (priority, index, array) {
|
|
5434
|
+
return array.indexOf(priority) === index;
|
|
5435
|
+
}).map(function (priority) {
|
|
5436
|
+
return setters.filter(function (setter) {
|
|
5437
|
+
return setter.priority === priority;
|
|
5438
|
+
}).sort(function (a, b) {
|
|
5439
|
+
return b.subPriority - a.subPriority;
|
|
5440
|
+
});
|
|
5441
|
+
}).map(function (setterArray) {
|
|
5442
|
+
return setterArray[0];
|
|
5443
|
+
});
|
|
5444
|
+
var date = toDate(dirtyReferenceDate);
|
|
5445
|
+
if (isNaN(date.getTime())) {
|
|
5446
|
+
return new Date(NaN);
|
|
5447
|
+
}
|
|
5448
|
+
|
|
5449
|
+
// Convert the date in system timezone to the same date in UTC+00:00 timezone.
|
|
5450
|
+
var utcDate = subMilliseconds(date, getTimezoneOffsetInMilliseconds(date));
|
|
5451
|
+
var flags = {};
|
|
5452
|
+
var _iterator2 = _createForOfIteratorHelper(uniquePrioritySetters),
|
|
5453
|
+
_step2;
|
|
5454
|
+
try {
|
|
5455
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
5456
|
+
var setter = _step2.value;
|
|
5457
|
+
if (!setter.validate(utcDate, subFnOptions)) {
|
|
5458
|
+
return new Date(NaN);
|
|
5459
|
+
}
|
|
5460
|
+
var result = setter.set(utcDate, flags, subFnOptions);
|
|
5461
|
+
// Result is tuple (date, flags)
|
|
5462
|
+
if (Array.isArray(result)) {
|
|
5463
|
+
utcDate = result[0];
|
|
5464
|
+
assign(flags, result[1]);
|
|
5465
|
+
// Result is date
|
|
5466
|
+
} else {
|
|
5467
|
+
utcDate = result;
|
|
5468
|
+
}
|
|
5469
|
+
}
|
|
5470
|
+
} catch (err) {
|
|
5471
|
+
_iterator2.e(err);
|
|
5472
|
+
} finally {
|
|
5473
|
+
_iterator2.f();
|
|
5474
|
+
}
|
|
5475
|
+
return utcDate;
|
|
5476
|
+
}
|
|
5477
|
+
function cleanEscapedString(input) {
|
|
5478
|
+
return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
|
|
5479
|
+
}
|
|
5480
|
+
|
|
5481
|
+
/**
|
|
5482
|
+
* @name isToday
|
|
5483
|
+
* @category Day Helpers
|
|
5484
|
+
* @summary Is the given date today?
|
|
5485
|
+
* @pure false
|
|
5486
|
+
*
|
|
5487
|
+
* @description
|
|
5488
|
+
* Is the given date today?
|
|
5489
|
+
*
|
|
5490
|
+
* > ⚠️ Please note that this function is not present in the FP submodule as
|
|
5491
|
+
* > it uses `Date.now()` internally hence impure and can't be safely curried.
|
|
5492
|
+
*
|
|
5493
|
+
* @param {Date|Number} date - the date to check
|
|
5494
|
+
* @returns {Boolean} the date is today
|
|
5495
|
+
* @throws {TypeError} 1 argument required
|
|
5496
|
+
*
|
|
5497
|
+
* @example
|
|
5498
|
+
* // If today is 6 October 2014, is 6 October 14:00:00 today?
|
|
5499
|
+
* const result = isToday(new Date(2014, 9, 6, 14, 0))
|
|
5500
|
+
* //=> true
|
|
5501
|
+
*/
|
|
5502
|
+
function isToday(dirtyDate) {
|
|
5503
|
+
requiredArgs(1, arguments);
|
|
5504
|
+
return isSameDay(dirtyDate, Date.now());
|
|
5505
|
+
}
|
|
5506
|
+
|
|
5507
|
+
/**
|
|
5508
|
+
* @name subDays
|
|
5509
|
+
* @category Day Helpers
|
|
5510
|
+
* @summary Subtract the specified number of days from the given date.
|
|
5511
|
+
*
|
|
5512
|
+
* @description
|
|
5513
|
+
* Subtract the specified number of days from the given date.
|
|
5514
|
+
*
|
|
5515
|
+
* @param {Date|Number} date - the date to be changed
|
|
5516
|
+
* @param {Number} amount - the amount of days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
5517
|
+
* @returns {Date} the new date with the days subtracted
|
|
5518
|
+
* @throws {TypeError} 2 arguments required
|
|
5519
|
+
*
|
|
5520
|
+
* @example
|
|
5521
|
+
* // Subtract 10 days from 1 September 2014:
|
|
5522
|
+
* const result = subDays(new Date(2014, 8, 1), 10)
|
|
5523
|
+
* //=> Fri Aug 22 2014 00:00:00
|
|
5524
|
+
*/
|
|
5525
|
+
function subDays(dirtyDate, dirtyAmount) {
|
|
5526
|
+
requiredArgs(2, arguments);
|
|
5527
|
+
var amount = toInteger(dirtyAmount);
|
|
5528
|
+
return addDays(dirtyDate, -amount);
|
|
5529
|
+
}
|
|
5530
|
+
|
|
5531
|
+
/**
|
|
5532
|
+
* @name parseISO
|
|
5533
|
+
* @category Common Helpers
|
|
5534
|
+
* @summary Parse ISO string
|
|
5535
|
+
*
|
|
5536
|
+
* @description
|
|
5537
|
+
* Parse the given string in ISO 8601 format and return an instance of Date.
|
|
5538
|
+
*
|
|
5539
|
+
* Function accepts complete ISO 8601 formats as well as partial implementations.
|
|
5540
|
+
* ISO 8601: http://en.wikipedia.org/wiki/ISO_8601
|
|
5541
|
+
*
|
|
5542
|
+
* If the argument isn't a string, the function cannot parse the string or
|
|
5543
|
+
* the values are invalid, it returns Invalid Date.
|
|
5544
|
+
*
|
|
5545
|
+
* @param {String} argument - the value to convert
|
|
5546
|
+
* @param {Object} [options] - an object with options.
|
|
5547
|
+
* @param {0|1|2} [options.additionalDigits=2] - the additional number of digits in the extended year format
|
|
5548
|
+
* @returns {Date} the parsed date in the local time zone
|
|
5549
|
+
* @throws {TypeError} 1 argument required
|
|
5550
|
+
* @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
|
|
5551
|
+
*
|
|
5552
|
+
* @example
|
|
5553
|
+
* // Convert string '2014-02-11T11:30:30' to date:
|
|
5554
|
+
* const result = parseISO('2014-02-11T11:30:30')
|
|
5555
|
+
* //=> Tue Feb 11 2014 11:30:30
|
|
5556
|
+
*
|
|
5557
|
+
* @example
|
|
5558
|
+
* // Convert string '+02014101' to date,
|
|
5559
|
+
* // if the additional number of digits in the extended year format is 1:
|
|
5560
|
+
* const result = parseISO('+02014101', { additionalDigits: 1 })
|
|
5561
|
+
* //=> Fri Apr 11 2014 00:00:00
|
|
5562
|
+
*/
|
|
5563
|
+
function parseISO(argument, options) {
|
|
5564
|
+
var _options$additionalDi;
|
|
5565
|
+
requiredArgs(1, arguments);
|
|
5566
|
+
var additionalDigits = toInteger((_options$additionalDi = options === null || options === void 0 ? void 0 : options.additionalDigits) !== null && _options$additionalDi !== void 0 ? _options$additionalDi : 2);
|
|
5567
|
+
if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) {
|
|
5568
|
+
throw new RangeError('additionalDigits must be 0, 1 or 2');
|
|
5569
|
+
}
|
|
5570
|
+
if (!(typeof argument === 'string' || Object.prototype.toString.call(argument) === '[object String]')) {
|
|
5571
|
+
return new Date(NaN);
|
|
5572
|
+
}
|
|
5573
|
+
var dateStrings = splitDateString(argument);
|
|
5574
|
+
var date;
|
|
5575
|
+
if (dateStrings.date) {
|
|
5576
|
+
var parseYearResult = parseYear(dateStrings.date, additionalDigits);
|
|
5577
|
+
date = parseDate(parseYearResult.restDateString, parseYearResult.year);
|
|
5578
|
+
}
|
|
5579
|
+
if (!date || isNaN(date.getTime())) {
|
|
5580
|
+
return new Date(NaN);
|
|
5581
|
+
}
|
|
5582
|
+
var timestamp = date.getTime();
|
|
5583
|
+
var time = 0;
|
|
5584
|
+
var offset;
|
|
5585
|
+
if (dateStrings.time) {
|
|
5586
|
+
time = parseTime(dateStrings.time);
|
|
5587
|
+
if (isNaN(time)) {
|
|
5588
|
+
return new Date(NaN);
|
|
5589
|
+
}
|
|
5590
|
+
}
|
|
5591
|
+
if (dateStrings.timezone) {
|
|
5592
|
+
offset = parseTimezone(dateStrings.timezone);
|
|
5593
|
+
if (isNaN(offset)) {
|
|
5594
|
+
return new Date(NaN);
|
|
5595
|
+
}
|
|
5596
|
+
} else {
|
|
5597
|
+
var dirtyDate = new Date(timestamp + time);
|
|
5598
|
+
// js parsed string assuming it's in UTC timezone
|
|
5599
|
+
// but we need it to be parsed in our timezone
|
|
5600
|
+
// so we use utc values to build date in our timezone.
|
|
5601
|
+
// Year values from 0 to 99 map to the years 1900 to 1999
|
|
5602
|
+
// so set year explicitly with setFullYear.
|
|
5603
|
+
var result = new Date(0);
|
|
5604
|
+
result.setFullYear(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate());
|
|
5605
|
+
result.setHours(dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds());
|
|
5606
|
+
return result;
|
|
5607
|
+
}
|
|
5608
|
+
return new Date(timestamp + time + offset);
|
|
5609
|
+
}
|
|
5610
|
+
var patterns = {
|
|
5611
|
+
dateTimeDelimiter: /[T ]/,
|
|
5612
|
+
timeZoneDelimiter: /[Z ]/i,
|
|
5613
|
+
timezone: /([Z+-].*)$/
|
|
5614
|
+
};
|
|
5615
|
+
var dateRegex = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/;
|
|
5616
|
+
var timeRegex = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/;
|
|
5617
|
+
var timezoneRegex = /^([+-])(\d{2})(?::?(\d{2}))?$/;
|
|
5618
|
+
function splitDateString(dateString) {
|
|
5619
|
+
var dateStrings = {};
|
|
5620
|
+
var array = dateString.split(patterns.dateTimeDelimiter);
|
|
5621
|
+
var timeString;
|
|
5622
|
+
|
|
5623
|
+
// The regex match should only return at maximum two array elements.
|
|
5624
|
+
// [date], [time], or [date, time].
|
|
5625
|
+
if (array.length > 2) {
|
|
5626
|
+
return dateStrings;
|
|
5627
|
+
}
|
|
5628
|
+
if (/:/.test(array[0])) {
|
|
5629
|
+
timeString = array[0];
|
|
5630
|
+
} else {
|
|
5631
|
+
dateStrings.date = array[0];
|
|
5632
|
+
timeString = array[1];
|
|
5633
|
+
if (patterns.timeZoneDelimiter.test(dateStrings.date)) {
|
|
5634
|
+
dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0];
|
|
5635
|
+
timeString = dateString.substr(dateStrings.date.length, dateString.length);
|
|
5636
|
+
}
|
|
5637
|
+
}
|
|
5638
|
+
if (timeString) {
|
|
5639
|
+
var token = patterns.timezone.exec(timeString);
|
|
5640
|
+
if (token) {
|
|
5641
|
+
dateStrings.time = timeString.replace(token[1], '');
|
|
5642
|
+
dateStrings.timezone = token[1];
|
|
5643
|
+
} else {
|
|
5644
|
+
dateStrings.time = timeString;
|
|
5645
|
+
}
|
|
5646
|
+
}
|
|
5647
|
+
return dateStrings;
|
|
5648
|
+
}
|
|
5649
|
+
function parseYear(dateString, additionalDigits) {
|
|
5650
|
+
var regex = new RegExp('^(?:(\\d{4}|[+-]\\d{' + (4 + additionalDigits) + '})|(\\d{2}|[+-]\\d{' + (2 + additionalDigits) + '})$)');
|
|
5651
|
+
var captures = dateString.match(regex);
|
|
5652
|
+
// Invalid ISO-formatted year
|
|
5653
|
+
if (!captures) return {
|
|
5654
|
+
year: NaN,
|
|
5655
|
+
restDateString: ''
|
|
5656
|
+
};
|
|
5657
|
+
var year = captures[1] ? parseInt(captures[1]) : null;
|
|
5658
|
+
var century = captures[2] ? parseInt(captures[2]) : null;
|
|
5659
|
+
|
|
5660
|
+
// either year or century is null, not both
|
|
5661
|
+
return {
|
|
5662
|
+
year: century === null ? year : century * 100,
|
|
5663
|
+
restDateString: dateString.slice((captures[1] || captures[2]).length)
|
|
5664
|
+
};
|
|
5665
|
+
}
|
|
5666
|
+
function parseDate(dateString, year) {
|
|
5667
|
+
// Invalid ISO-formatted year
|
|
5668
|
+
if (year === null) return new Date(NaN);
|
|
5669
|
+
var captures = dateString.match(dateRegex);
|
|
5670
|
+
// Invalid ISO-formatted string
|
|
5671
|
+
if (!captures) return new Date(NaN);
|
|
5672
|
+
var isWeekDate = !!captures[4];
|
|
5673
|
+
var dayOfYear = parseDateUnit(captures[1]);
|
|
5674
|
+
var month = parseDateUnit(captures[2]) - 1;
|
|
5675
|
+
var day = parseDateUnit(captures[3]);
|
|
5676
|
+
var week = parseDateUnit(captures[4]);
|
|
5677
|
+
var dayOfWeek = parseDateUnit(captures[5]) - 1;
|
|
5678
|
+
if (isWeekDate) {
|
|
5679
|
+
if (!validateWeekDate(year, week, dayOfWeek)) {
|
|
2886
5680
|
return new Date(NaN);
|
|
2887
5681
|
}
|
|
2888
5682
|
return dayOfISOWeekYear(year, week, dayOfWeek);
|
|
@@ -3447,7 +6241,7 @@ var locale = {
|
|
|
3447
6241
|
};
|
|
3448
6242
|
const ptBR = locale;
|
|
3449
6243
|
|
|
3450
|
-
const curaCalendarCss = ":host{display:block;width:var(--width);min-width:var(--min-width);max-width:var(--max-width);margin:0 auto}:host .calendar{display:flex;flex-direction:column;gap:5px;width:var(--width);min-width:var(--min-width);max-width:var(--max-width);border-radius:4px;overflow:hidden;background:#fff;font-family:var(--font-family)}:host .calendar.embedded{border:2px solid var(--neutral-light);padding:0px 12px 12px 12px}:host .calendar.floating{box-shadow:0 4px 8px var(--neutral-light)}:host .header{position:relative;padding:12px 0}:host .header::after{content:\"\";position:absolute;bottom:0;left:2px;right:2px;border-bottom:2px dotted var(--neutral-light)}:host .month-year{display:flex;padding:12px 8px;justify-content:space-between;align-self:stretch}:host .month-year.dropdown{padding:0%}:host .select{display:flex;padding:7px 10px 0px;justify-content:center;align-items:center;gap:6px;flex:1 0 0}:host .drop-month{display:flex;max-width:118px;padding:0px;align-items:flex-start;gap:0px;flex:1 0 0}:host .drop-year{display:flex;min-width:80px;max-width:85px;padding:0px;align-items:flex-start;gap:0px;flex:1 0 0}:host .days-of-week{display:flex;height:30px;padding:4px;justify-content:center;align-items:center;gap:4px;flex-shrink:0}:host .day{flex:1;text-align:center}:host .dates{display:flex;flex-wrap:wrap;align-items:center;align-self:stretch;gap:0}:host .icon{cursor:pointer;position:relative;overflow:hidden;border-radius:50%}:host .icon.dropdown{margin-top:10px}:host .icon::before{content:\"\";position:absolute;border-radius:50%;top:50%;left:50%;width:20px;height:20px;background:var(--primary-base);transform:translate(-50%, -50%) scale(0);transition:transform 0.2s ease}:host .icon:active::before{transform:translate(-50%, -50%) scale(1)}:host .icon:active{transform:scale(1)}:host .collapsed-container{text-align:center;position:relative;display:flex;align-items:center;justify-content:center;padding-top:10px}:host .collapsed-container::before{content:\"\";position:absolute;bottom:0;top:0;left:2px;right:2px;border-top:2px dotted var(--neutral-light)}:host .date{display:flex;justify-content:center;align-items:center;height:auto;width:14.2857142857%;aspect-ratio:1;font-size:14px;cursor:pointer;position:relative;box-sizing:border-box;text-align:center;flex-shrink:0}:host .date.today{border:2px solid var(--primary-darker);border-radius:50%;color:var(--primary-darker)}:host .date.selected{color:var(--select-label) !important;background:var(--primary-base);border-radius:50%}:host .date.default-dates{color:var(--select-label) !important;background:var(--primary-base);border-radius:50%;border:none}:host .date.invalid{color:var(--neutral-dark) !important;cursor:not-allowed}:host .date.invalid:hover{background:none;box-shadow:none}:host .date.valid{color:var(--primary-darker);font-weight:var(--font-weight-bold)}:host .date.range.start{border-radius:50% 0 0 50%;color:var(--select-label) !important;background:var(--primary-base)}:host .date.range.interval{border-radius:0;background:var(--primary-lighter);color:var(--neutral-black) !important}:host .date.range.interval.today{border:none}:host .date.range.end{border-radius:0 50% 50% 0;color:var(--select-label) !important;background:var(--primary-base)}:host .date:hover{background:var(--primary-lighter);border-radius:50%;color:var(--neutral-white)}:host select,:host input{width:60px;font-size:16px;box-shadow:0 2px 2px var(--neutral-black);padding:5px;border-radius:4px;border:1px solid #ccc;background:#f7f7f7}";
|
|
6244
|
+
const curaCalendarCss = ":host{display:block;width:var(--width);min-width:var(--min-width);max-width:var(--max-width);margin:0 auto}:host .calendar{display:flex;flex-direction:column;gap:5px;width:var(--width);min-width:var(--min-width);max-width:var(--max-width);border-radius:4px;overflow:hidden;background:#fff;font-family:var(--font-family)}:host .calendar.embedded{border:2px solid var(--neutral-light);padding:0px 12px 12px 12px}:host .calendar.floating{box-shadow:0 4px 8px var(--neutral-light)}:host .header{position:relative;padding:12px 0}:host .header::after{content:\"\";position:absolute;bottom:0;left:2px;right:2px;border-bottom:2px dotted var(--neutral-light)}:host .month-year{display:flex;padding:12px 8px;justify-content:space-between;align-self:stretch}:host .month-year.dropdown{padding:0%}:host .select{display:flex;padding:7px 10px 0px;justify-content:center;align-items:center;gap:6px;flex:1 0 0}:host .drop-month{display:flex;max-width:118px;padding:0px;align-items:flex-start;gap:0px;flex:1 0 0}:host .drop-year{display:flex;min-width:80px;max-width:85px;padding:0px;align-items:flex-start;gap:0px;flex:1 0 0}:host .days-of-week{display:flex;height:30px;padding:4px;justify-content:center;align-items:center;gap:4px;flex-shrink:0}:host .day{flex:1;text-align:center}:host .dates{display:flex;flex-wrap:wrap;align-items:center;align-self:stretch;gap:0}:host .icon{cursor:pointer;position:relative;overflow:hidden;border-radius:50%}:host .icon.dropdown{margin-top:10px}:host .icon::before{content:\"\";position:absolute;border-radius:50%;top:50%;left:50%;width:20px;height:20px;background:var(--primary-base);transform:translate(-50%, -50%) scale(0);transition:transform 0.2s ease}:host .icon:active::before{transform:translate(-50%, -50%) scale(1)}:host .icon:active{transform:scale(1)}:host .collapsed-container{text-align:center;position:relative;display:flex;align-items:center;justify-content:center;padding-top:10px}:host .collapsed-container::before{content:\"\";position:absolute;bottom:0;top:0;left:2px;right:2px;border-top:2px dotted var(--neutral-light)}:host .date{display:flex;justify-content:center;align-items:center;height:auto;width:14.2857142857%;aspect-ratio:1;font-size:14px;cursor:pointer;position:relative;box-sizing:border-box;text-align:center;flex-shrink:0}:host .date.today{border:2px solid var(--primary-darker);border-radius:50%;color:var(--primary-darker)}:host .date.selected{color:var(--select-label) !important;background:var(--primary-base);border-radius:50%}:host .date.default-dates{color:var(--select-label) !important;background:var(--primary-base);border-radius:50%;border:none}:host .date.invalid{color:var(--neutral-dark) !important;cursor:not-allowed}:host .date.invalid:hover{background:none;box-shadow:none}:host .date.valid{color:var(--primary-darker);font-weight:var(--font-weight-bold)}:host .date.range.start{border-radius:50% 0 0 50%;color:var(--select-label) !important;background:var(--primary-base)}:host .date.range.interval{border-radius:0;background:var(--primary-lighter);color:var(--neutral-black) !important}:host .date.range.interval.today{border:none}:host .date.range.end{border-radius:0 50% 50% 0;color:var(--select-label) !important;background:var(--primary-base)}@media (min-width: 992px){:host .date:hover{background:var(--primary-lighter);border-radius:50%;color:var(--neutral-white)}}:host select,:host input{width:60px;font-size:16px;box-shadow:0 2px 2px var(--neutral-black);padding:5px;border-radius:4px;border:1px solid #ccc;background:#f7f7f7}";
|
|
3451
6245
|
const CuraCalendarStyle0 = curaCalendarCss;
|
|
3452
6246
|
|
|
3453
6247
|
const CuraCalendar = class {
|
|
@@ -3522,7 +6316,9 @@ const CuraCalendar = class {
|
|
|
3522
6316
|
}
|
|
3523
6317
|
}
|
|
3524
6318
|
this.defaultDates = this.expandDateRanges(this.defaultDate);
|
|
3525
|
-
|
|
6319
|
+
if (this.defaultDate[0]) {
|
|
6320
|
+
this.currentDate = parse(this.defaultDate[0], this.dateFormat, new Date());
|
|
6321
|
+
}
|
|
3526
6322
|
}
|
|
3527
6323
|
/**
|
|
3528
6324
|
* Get the locale for the calendar.
|
|
@@ -3669,7 +6465,7 @@ const CuraCalendar = class {
|
|
|
3669
6465
|
* @param {Date} date - The date to select.
|
|
3670
6466
|
*/
|
|
3671
6467
|
selectSingleDate(date) {
|
|
3672
|
-
this.
|
|
6468
|
+
this.defaultDate = [];
|
|
3673
6469
|
this.selectedDates = [date];
|
|
3674
6470
|
}
|
|
3675
6471
|
/**
|
|
@@ -3769,10 +6565,12 @@ const CuraCalendar = class {
|
|
|
3769
6565
|
const daysIncurrentDate = eachDayOfInterval({ start, end });
|
|
3770
6566
|
const prevMonthStart = startOfMonth(addMonths(start, -1));
|
|
3771
6567
|
const prevMonthEnd = endOfMonth(prevMonthStart);
|
|
3772
|
-
const daysInPrevMonth =
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
6568
|
+
const daysInPrevMonth = getDay(start) > 0
|
|
6569
|
+
? eachDayOfInterval({
|
|
6570
|
+
start: subDays(prevMonthEnd, getDay(start) - 1),
|
|
6571
|
+
end: prevMonthEnd,
|
|
6572
|
+
})
|
|
6573
|
+
: [];
|
|
3776
6574
|
const nextMonthStart = startOfMonth(addMonths(end, 1));
|
|
3777
6575
|
const nextMonthEnd = endOfMonth(nextMonthStart);
|
|
3778
6576
|
const remainingDays = WEEKS_IN_CALENDAR_VIEW - getDay(end);
|
|
@@ -3780,7 +6578,7 @@ const CuraCalendar = class {
|
|
|
3780
6578
|
start: nextMonthStart,
|
|
3781
6579
|
end: addDays(nextMonthEnd, remainingDays),
|
|
3782
6580
|
});
|
|
3783
|
-
const totalDays = [...daysInPrevMonth
|
|
6581
|
+
const totalDays = [...daysInPrevMonth, ...daysIncurrentDate, ...daysInNextMonth];
|
|
3784
6582
|
return totalDays.slice(0, DAYS_IN_CALENDAR_VIEW);
|
|
3785
6583
|
}
|
|
3786
6584
|
/**
|
|
@@ -3894,6 +6692,7 @@ const CuraCalendar = class {
|
|
|
3894
6692
|
this.selectedDates = this.customDates;
|
|
3895
6693
|
}
|
|
3896
6694
|
handleDefaultDateChange(newValue) {
|
|
6695
|
+
this.selectedDates = [];
|
|
3897
6696
|
if (typeof newValue === 'string') {
|
|
3898
6697
|
const parsedDefaultDate = JSON.parse(newValue || '[]');
|
|
3899
6698
|
if (typeof parsedDefaultDate === 'string') {
|
|
@@ -3907,13 +6706,13 @@ const CuraCalendar = class {
|
|
|
3907
6706
|
}
|
|
3908
6707
|
render() {
|
|
3909
6708
|
const { months } = this.fetchMonthNames();
|
|
3910
|
-
return (h(Host, { key: '
|
|
6709
|
+
return (h(Host, { key: '622035565961e1a2a1917f402e853e29ed01b1fe', style: this.getHostCSSProperties() }, h("div", { key: '7d41f8769f65218c130751e25e0a9ee7126b930c', class: `calendar ${this.floating ? 'floating' : ''} ${this.embedded ? 'embedded' : ''}`, style: this.styles }, h("header", { key: '796f3f0d0fa3972151803f8b37707d7f33349c41', class: "header" }, h("div", { key: 'aa1d4dc49765ccbef9181f58696eeac4eb2336b3', class: `month-year ${this.type === 'dropdown' && 'dropdown'}` }, h("cura-icon", { key: '9003a5aa57d9bf0217eef70452ffac20c434e1b2', class: `icon ${this.type === 'dropdown' && 'dropdown'}`, name: "left", color: this.determinePrevButtonColor(), onClick: !this.collapsed ? () => this.updateCurrentMonth('prev') : () => this.updateCurrentWeek('prev') }), this.type === 'dropdown' ? (h("div", { class: "select" }, h("cura-select", { size: "small", class: "drop-month", mode: "transparent", value: months[getMonth(this.currentDate)], onSelected: e => this.onMonthDropdownChange(e) }, months.map((month, index) => (h("cura-select-option", { size: "xsmall", key: index, value: month }, month)))), h("cura-select", { size: "small", class: "drop-year", mode: "transparent", value: getYear(this.currentDate).toString(), onSelected: e => this.onYearDropdownChange(e) }, this.fetchYearList().map((year, index) => (h("cura-select-option", { key: index, value: year.toString() }, year.toString())))))) : (h("cura-label", { color: "neutral-black", size: "large" }, months[getMonth(this.currentDate)].slice(0, 3), ", ", getYear(this.currentDate))), h("cura-icon", { key: '331511ce7960285c1245fcc23179cc7d4837869d', class: `icon ${this.type === 'dropdown' && 'dropdown'}`, name: "right", color: "primary-base", onClick: !this.collapsed ? () => this.updateCurrentMonth('next') : () => this.updateCurrentWeek('next') }))), h("span", { key: '4fc77ed5e8a40b95a88a6879299e78b8dfcf3ce6', class: "days-of-week" }, this.fetchWeekDays().map((day, index) => (h("cura-label", { class: "day", size: "xsmall", color: "neutral-black", weight: "bold", key: index }, day === 'sab' ? 'SÁB' : day.toLocaleUpperCase())))), h("div", { key: '311a707add171474195d075a7694eb10197c6263', class: "dates" }, !this.collapsed
|
|
3911
6710
|
? this.fetchDaysOfMonth().map((day, index) => (h("div", { key: index, class: this.getClasses(day), onClick: () => this.onDateClick(day) }, day ? format(day, 'd') : '')))
|
|
3912
6711
|
: this.fetchDaysOfWeek().map((day, index) => (h("div", { key: index, class: this.getClasses(day), onClick: () => this.onDateClick(day) }, day ? format(day, 'd') : '')))), this.collapsed !== null ? (this.collapsed ? (h("div", { class: "collapsed-container" }, h("cura-button-transparent", { onClick: () => this.showNotColapsedCalendar(), size: "small", color: "primary", fontColor: "dark", iconName: "plusCircle" }, "Veja mais datas"))) : (h("div", { class: "collapsed-container" }, h("cura-button-transparent", { onClick: () => this.showColapsedCalendar(), size: "small", color: "primary", fontColor: "dark", iconName: "minusCircle" }, "Veja menos datas")))) : null)));
|
|
3913
6712
|
}
|
|
3914
6713
|
static get watchers() { return {
|
|
3915
|
-
"
|
|
3916
|
-
"
|
|
6714
|
+
"defaultDate": ["initializeDefaultDates", "handleDefaultDateChange"],
|
|
6715
|
+
"customDates": ["watchDefaultDatesArray"]
|
|
3917
6716
|
}; }
|
|
3918
6717
|
};
|
|
3919
6718
|
CuraCalendar.style = CuraCalendarStyle0;
|