@utrecht/calendar-react 1.0.4 → 1.0.5

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/index.mjs CHANGED
@@ -1,427 +1,3642 @@
1
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
1
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { startOfWeek, endOfWeek, eachDayOfInterval, isSameDay, endOfDay, parseISO, setYear, getYear, addYears, setMonth, addMonths, format, isSameMonth, formatISO, isBefore, startOfDay, isAfter, startOfMonth, addWeeks } from 'date-fns';
4
- import { enUS } from 'date-fns/locale';
5
- import chunk from 'lodash.chunk';
6
- import { useState } from 'react';
7
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
8
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
9
- import { Button } from '@utrecht/button-react';
10
- import clsx$1, { clsx } from 'clsx';
11
-
12
- var _excluded$c = ["children"];
13
- function ownKeys$c(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
- function _objectSpread$c(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$c(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
- var CalendarNavigation = function CalendarNavigation(_ref) {
16
- var children = _ref.children,
17
- props = _objectWithoutProperties(_ref, _excluded$c);
18
- return jsx("div", _objectSpread$c(_objectSpread$c({
19
- className: "utrecht-calendar__navigation"
20
- }, props), {}, {
21
- children: children
22
- }));
23
- };
24
-
25
- var _excluded$b = ["children", "className"];
26
- function ownKeys$b(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
- function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$b(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
28
- var CalendarButton = function CalendarButton(_ref) {
29
- var children = _ref.children,
30
- className = _ref.className,
31
- props = _objectWithoutProperties(_ref, _excluded$b);
32
- return jsx(Button, _objectSpread$b(_objectSpread$b({
33
- appearance: "subtle-button"
34
- }, props), {}, {
35
- className: clsx('utrecht-calendar__button', className),
36
- children: children
37
- }));
38
- };
39
-
40
- var _excluded$a = ["children"];
41
- function ownKeys$a(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
42
- function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
43
- var CalendarIcon = function CalendarIcon(_ref) {
44
- var children = _ref.children,
45
- props = _objectWithoutProperties(_ref, _excluded$a);
46
- return jsx("div", _objectSpread$a(_objectSpread$a({
47
- className: clsx('utrecht-calendar__icon')
48
- }, props), {}, {
49
- children: children
50
- }));
51
- };
52
-
53
- var _excluded$9 = ["onPreviousClick", "onNextClick", "previousIcon", "nextIcon", "children"];
54
- function ownKeys$9(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
55
- function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
56
- var CalendarNavigationButtons = function CalendarNavigationButtons(_ref) {
57
- var onPreviousClick = _ref.onPreviousClick,
58
- onNextClick = _ref.onNextClick,
59
- previousIcon = _ref.previousIcon,
60
- nextIcon = _ref.nextIcon,
61
- children = _ref.children,
62
- props = _objectWithoutProperties(_ref, _excluded$9);
63
- return jsxs("div", {
64
- className: "utrecht-calendar__navigation-buttons",
65
- children: [jsx(CalendarButton, _objectSpread$9(_objectSpread$9({
66
- onClick: onPreviousClick
67
- }, props), {}, {
68
- children: jsx(CalendarIcon, {
69
- children: previousIcon
70
- })
71
- })), children, jsx(CalendarButton, _objectSpread$9(_objectSpread$9({
72
- onClick: onNextClick
73
- }, props), {}, {
74
- children: jsx(CalendarIcon, {
75
- children: nextIcon
76
- })
77
- }))]
78
- });
79
- };
80
-
81
- var _excluded$8 = ["children"];
82
- function ownKeys$8(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
83
- function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
84
- var CalendarNavigationLabel = function CalendarNavigationLabel(_ref) {
85
- var children = _ref.children,
86
- props = _objectWithoutProperties(_ref, _excluded$8);
87
- return jsx("time", _objectSpread$8(_objectSpread$8({
88
- className: "utrecht-calendar__navigation-label"
89
- }, props), {}, {
90
- children: children
91
- }));
92
- };
93
-
94
- var _excluded$7 = ["children"];
95
- function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
96
- function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
97
- var CalendarTableDaysContainer = function CalendarTableDaysContainer(_ref) {
98
- var children = _ref.children,
99
- props = _objectWithoutProperties(_ref, _excluded$7);
100
- return jsx("tbody", _objectSpread$7(_objectSpread$7({}, props), {}, {
101
- className: "utrecht-calendar__table-days-container",
102
- children: children
103
- }));
104
- };
105
-
106
- var _excluded$6 = ["children"];
107
- function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
108
- function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
109
- var CalendarTableDaysItem = function CalendarTableDaysItem(_ref) {
110
- var children = _ref.children,
111
- props = _objectWithoutProperties(_ref, _excluded$6);
112
- return jsx("tr", _objectSpread$6(_objectSpread$6({}, props), {}, {
113
- children: children
114
- }));
115
- };
116
-
117
- var _excluded$5 = ["day", "dayOutOfTheMonth", "isToday", "emphasis", "selected", "disabled"];
118
- function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
119
- function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
120
- var CalendarTableDaysItemDay = function CalendarTableDaysItemDay(_ref) {
121
- var day = _ref.day,
122
- dayOutOfTheMonth = _ref.dayOutOfTheMonth,
123
- isToday = _ref.isToday,
124
- emphasis = _ref.emphasis,
125
- selected = _ref.selected,
126
- disabled = _ref.disabled,
127
- props = _objectWithoutProperties(_ref, _excluded$5);
128
- return jsx("td", {
129
- children: jsx(CalendarButton, _objectSpread$5(_objectSpread$5({
130
- className: clsx$1('utrecht-calendar__table-days-item-day', {
131
- 'utrecht-calendar__table-days-item-day--out-of-the-month': dayOutOfTheMonth
132
- }, {
133
- 'utrecht-calendar__table-days-item-day--is-today': isToday
134
- }, {
135
- 'utrecht-calendar__table-days-item-day--emphasis': emphasis
136
- }, {
137
- 'utrecht-calendar__table-days-item-day--selected': selected
138
- }),
139
- disabled: disabled
140
- }, props), {}, {
141
- children: day
142
- }))
143
- });
144
- };
145
-
146
- var CalendarTableWeeksContainer = function CalendarTableWeeksContainer(_ref) {
147
- var children = _ref.children;
148
- return jsx("thead", {
149
- className: "utrecht-calendar__table-weeks-container",
150
- children: jsx("tr", {
151
- className: "utrecht-calendar__table-weeks-container-content",
152
- children: children
153
- })
154
- });
155
- };
156
-
157
- var _excluded$4 = ["children"];
158
- function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
159
- function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
160
- var CalendarTableWeeksItem = function CalendarTableWeeksItem(_ref) {
161
- var children = _ref.children,
162
- props = _objectWithoutProperties(_ref, _excluded$4);
163
- return jsx("th", _objectSpread$4(_objectSpread$4({}, props), {}, {
164
- className: "utrecht-calendar__table-weeks-item",
165
- children: children
166
- }));
167
- };
168
-
169
- var _excluded$3 = ["title", "titleId"];
170
- function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
171
- function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
172
- var IconArrowLeft = function IconArrowLeft(_ref) {
173
- var title = _ref.title,
174
- titleId = _ref.titleId,
175
- props = _objectWithoutProperties(_ref, _excluded$3);
176
- return jsxs("svg", _objectSpread$3(_objectSpread$3({
177
- width: "100%",
178
- height: "100%",
179
- fill: "none",
180
- xmlns: "http://www.w3.org/2000/svg",
181
- "aria-labelledby": titleId
182
- }, props), {}, {
183
- children: [title ? jsx("title", {
184
- id: titleId,
185
- children: title
186
- }) : null, jsx("path", {
187
- d: "M15.41 16.59 10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41Z",
188
- fill: "currentColor"
189
- })]
190
- }));
191
- };
192
-
193
- var _excluded$2 = ["title", "titleId"];
194
- function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
195
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
196
- var IconArrowLeftDouble = function IconArrowLeftDouble(_ref) {
197
- var title = _ref.title,
198
- titleId = _ref.titleId,
199
- props = _objectWithoutProperties(_ref, _excluded$2);
200
- return jsxs("svg", _objectSpread$2(_objectSpread$2({
201
- width: "100%",
202
- height: "100%",
203
- fill: "none",
204
- xmlns: "http://www.w3.org/2000/svg",
205
- "aria-labelledby": titleId
206
- }, props), {}, {
207
- children: [title ? jsx("title", {
208
- id: titleId,
209
- children: title
210
- }) : null, jsx("path", {
211
- d: "M17.59 18 19 16.59 14.42 12 19 7.41 17.59 6l-6 6 6 6Z",
212
- fill: "currentColor"
213
- }), jsx("path", {
214
- d: "m11 18 1.41-1.41L7.83 12l4.58-4.59L11 6l-6 6 6 6Z",
215
- fill: "currentColor"
216
- })]
217
- }));
218
- };
219
-
220
- var _excluded$1 = ["title", "titleId"];
221
- function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
222
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
223
- var IconArrowRight = function IconArrowRight(_ref) {
224
- var title = _ref.title,
225
- titleId = _ref.titleId,
226
- props = _objectWithoutProperties(_ref, _excluded$1);
227
- return jsxs("svg", _objectSpread$1(_objectSpread$1({
228
- width: "100%",
229
- height: "100%",
230
- fill: "none",
231
- xmlns: "http://www.w3.org/2000/svg",
232
- "aria-labelledby": titleId
233
- }, props), {}, {
234
- children: [title ? jsx("title", {
235
- id: titleId,
236
- children: title
237
- }) : null, jsx("path", {
238
- d: "M8.59 16.59 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41Z",
239
- fill: "currentColor"
240
- })]
241
- }));
242
- };
243
-
244
- var _excluded = ["title", "titleId"];
245
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
246
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
247
- var IconArrowRightDouble = function IconArrowRightDouble(_ref) {
248
- var title = _ref.title,
249
- titleId = _ref.titleId,
250
- props = _objectWithoutProperties(_ref, _excluded);
251
- return jsxs("svg", _objectSpread(_objectSpread({
252
- fill: "none",
253
- width: "100%",
254
- height: "100%",
255
- xmlns: "http://www.w3.org/2000/svg",
256
- "aria-labelledby": titleId
257
- }, props), {}, {
258
- children: [title ? jsx("title", {
259
- id: titleId,
260
- children: title
261
- }) : null, jsx("path", {
262
- d: "M6.41 6 5 7.41 9.58 12 5 16.59 6.41 18l6-6-6-6Z",
263
- fill: "currentColor"
264
- }), jsx("path", {
265
- d: "m13 6-1.41 1.41L16.17 12l-4.58 4.59L13 18l6-6-6-6Z",
266
- fill: "currentColor"
267
- })]
268
- }));
2
+ import { forwardRef, useState } from 'react';
3
+ import _typeof from '@babel/runtime/helpers/esm/typeof';
4
+
5
+ function toInteger$1(dirtyNumber) {
6
+ if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
7
+ return NaN;
8
+ }
9
+ var number = Number(dirtyNumber);
10
+ if (isNaN(number)) {
11
+ return number;
12
+ }
13
+ return number < 0 ? Math.ceil(number) : Math.floor(number);
14
+ }
15
+
16
+ function requiredArgs(required, args) {
17
+ if (args.length < required) {
18
+ throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
19
+ }
20
+ }
21
+
22
+ /**
23
+ * @name toDate
24
+ * @category Common Helpers
25
+ * @summary Convert the given argument to an instance of Date.
26
+ *
27
+ * @description
28
+ * Convert the given argument to an instance of Date.
29
+ *
30
+ * If the argument is an instance of Date, the function returns its clone.
31
+ *
32
+ * If the argument is a number, it is treated as a timestamp.
33
+ *
34
+ * If the argument is none of the above, the function returns Invalid Date.
35
+ *
36
+ * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
37
+ *
38
+ * @param {Date|Number} argument - the value to convert
39
+ * @returns {Date} the parsed date in the local time zone
40
+ * @throws {TypeError} 1 argument required
41
+ *
42
+ * @example
43
+ * // Clone the date:
44
+ * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
45
+ * //=> Tue Feb 11 2014 11:30:30
46
+ *
47
+ * @example
48
+ * // Convert the timestamp to date:
49
+ * const result = toDate(1392098430000)
50
+ * //=> Tue Feb 11 2014 11:30:30
51
+ */
52
+ function toDate(argument) {
53
+ requiredArgs(1, arguments);
54
+ var argStr = Object.prototype.toString.call(argument);
55
+
56
+ // Clone the date
57
+ if (argument instanceof Date || _typeof(argument) === 'object' && argStr === '[object Date]') {
58
+ // Prevent the date to lose the milliseconds when passed to new Date() in IE10
59
+ return new Date(argument.getTime());
60
+ } else if (typeof argument === 'number' || argStr === '[object Number]') {
61
+ return new Date(argument);
62
+ } else {
63
+ if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {
64
+ // eslint-disable-next-line no-console
65
+ console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments");
66
+ // eslint-disable-next-line no-console
67
+ console.warn(new Error().stack);
68
+ }
69
+ return new Date(NaN);
70
+ }
71
+ }
72
+
73
+ /**
74
+ * @name addDays
75
+ * @category Day Helpers
76
+ * @summary Add the specified number of days to the given date.
77
+ *
78
+ * @description
79
+ * Add the specified number of days to the given date.
80
+ *
81
+ * @param {Date|Number} date - the date to be changed
82
+ * @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
83
+ * @returns {Date} - the new date with the days added
84
+ * @throws {TypeError} - 2 arguments required
85
+ *
86
+ * @example
87
+ * // Add 10 days to 1 September 2014:
88
+ * const result = addDays(new Date(2014, 8, 1), 10)
89
+ * //=> Thu Sep 11 2014 00:00:00
90
+ */
91
+ function addDays(dirtyDate, dirtyAmount) {
92
+ requiredArgs(2, arguments);
93
+ var date = toDate(dirtyDate);
94
+ var amount = toInteger$1(dirtyAmount);
95
+ if (isNaN(amount)) {
96
+ return new Date(NaN);
97
+ }
98
+ if (!amount) {
99
+ // If 0 days, no-op to avoid changing times in the hour before end of DST
100
+ return date;
101
+ }
102
+ date.setDate(date.getDate() + amount);
103
+ return date;
104
+ }
105
+
106
+ /**
107
+ * @name addMonths
108
+ * @category Month Helpers
109
+ * @summary Add the specified number of months to the given date.
110
+ *
111
+ * @description
112
+ * Add the specified number of months to the given date.
113
+ *
114
+ * @param {Date|Number} date - the date to be changed
115
+ * @param {Number} amount - the amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
116
+ * @returns {Date} the new date with the months added
117
+ * @throws {TypeError} 2 arguments required
118
+ *
119
+ * @example
120
+ * // Add 5 months to 1 September 2014:
121
+ * const result = addMonths(new Date(2014, 8, 1), 5)
122
+ * //=> Sun Feb 01 2015 00:00:00
123
+ */
124
+ function addMonths(dirtyDate, dirtyAmount) {
125
+ requiredArgs(2, arguments);
126
+ var date = toDate(dirtyDate);
127
+ var amount = toInteger$1(dirtyAmount);
128
+ if (isNaN(amount)) {
129
+ return new Date(NaN);
130
+ }
131
+ if (!amount) {
132
+ // If 0 months, no-op to avoid changing times in the hour before end of DST
133
+ return date;
134
+ }
135
+ var dayOfMonth = date.getDate();
136
+
137
+ // The JS Date object supports date math by accepting out-of-bounds values for
138
+ // month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and
139
+ // new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we
140
+ // want except that dates will wrap around the end of a month, meaning that
141
+ // new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So
142
+ // we'll default to the end of the desired month by adding 1 to the desired
143
+ // month and using a date of 0 to back up one day to the end of the desired
144
+ // month.
145
+ var endOfDesiredMonth = new Date(date.getTime());
146
+ endOfDesiredMonth.setMonth(date.getMonth() + amount + 1, 0);
147
+ var daysInMonth = endOfDesiredMonth.getDate();
148
+ if (dayOfMonth >= daysInMonth) {
149
+ // If we're already at the end of the month, then this is the correct date
150
+ // and we're done.
151
+ return endOfDesiredMonth;
152
+ } else {
153
+ // Otherwise, we now know that setting the original day-of-month value won't
154
+ // cause an overflow, so set the desired day-of-month. Note that we can't
155
+ // just set the date of `endOfDesiredMonth` because that object may have had
156
+ // its time changed in the unusual case where where a DST transition was on
157
+ // the last day of the month and its local time was in the hour skipped or
158
+ // repeated next to a DST transition. So we use `date` instead which is
159
+ // guaranteed to still have the original time.
160
+ date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth);
161
+ return date;
162
+ }
163
+ }
164
+
165
+ /**
166
+ * @name addMilliseconds
167
+ * @category Millisecond Helpers
168
+ * @summary Add the specified number of milliseconds to the given date.
169
+ *
170
+ * @description
171
+ * Add the specified number of milliseconds to the given date.
172
+ *
173
+ * @param {Date|Number} date - the date to be changed
174
+ * @param {Number} amount - the amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
175
+ * @returns {Date} the new date with the milliseconds added
176
+ * @throws {TypeError} 2 arguments required
177
+ *
178
+ * @example
179
+ * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
180
+ * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
181
+ * //=> Thu Jul 10 2014 12:45:30.750
182
+ */
183
+ function addMilliseconds(dirtyDate, dirtyAmount) {
184
+ requiredArgs(2, arguments);
185
+ var timestamp = toDate(dirtyDate).getTime();
186
+ var amount = toInteger$1(dirtyAmount);
187
+ return new Date(timestamp + amount);
188
+ }
189
+
190
+ var defaultOptions = {};
191
+ function getDefaultOptions() {
192
+ return defaultOptions;
193
+ }
194
+
195
+ /**
196
+ * @name startOfWeek
197
+ * @category Week Helpers
198
+ * @summary Return the start of a week for the given date.
199
+ *
200
+ * @description
201
+ * Return the start of a week for the given date.
202
+ * The result will be in the local timezone.
203
+ *
204
+ * @param {Date|Number} date - the original date
205
+ * @param {Object} [options] - an object with options.
206
+ * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
207
+ * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
208
+ * @returns {Date} the start of a week
209
+ * @throws {TypeError} 1 argument required
210
+ * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
211
+ *
212
+ * @example
213
+ * // The start of a week for 2 September 2014 11:55:00:
214
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
215
+ * //=> Sun Aug 31 2014 00:00:00
216
+ *
217
+ * @example
218
+ * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
219
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
220
+ * //=> Mon Sep 01 2014 00:00:00
221
+ */
222
+ function startOfWeek(dirtyDate, options) {
223
+ var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
224
+ requiredArgs(1, arguments);
225
+ var defaultOptions = getDefaultOptions();
226
+ var weekStartsOn = toInteger$1((_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);
227
+
228
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
229
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
230
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
231
+ }
232
+ var date = toDate(dirtyDate);
233
+ var day = date.getDay();
234
+ var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
235
+ date.setDate(date.getDate() - diff);
236
+ date.setHours(0, 0, 0, 0);
237
+ return date;
238
+ }
239
+
240
+ /**
241
+ * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
242
+ * They usually appear for dates that denote time before the timezones were introduced
243
+ * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
244
+ * and GMT+01:00:00 after that date)
245
+ *
246
+ * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
247
+ * which would lead to incorrect calculations.
248
+ *
249
+ * This function returns the timezone offset in milliseconds that takes seconds in account.
250
+ */
251
+ function getTimezoneOffsetInMilliseconds(date) {
252
+ var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
253
+ utcDate.setUTCFullYear(date.getFullYear());
254
+ return date.getTime() - utcDate.getTime();
255
+ }
256
+
257
+ /**
258
+ * @name startOfDay
259
+ * @category Day Helpers
260
+ * @summary Return the start of a day for the given date.
261
+ *
262
+ * @description
263
+ * Return the start of a day for the given date.
264
+ * The result will be in the local timezone.
265
+ *
266
+ * @param {Date|Number} date - the original date
267
+ * @returns {Date} the start of a day
268
+ * @throws {TypeError} 1 argument required
269
+ *
270
+ * @example
271
+ * // The start of a day for 2 September 2014 11:55:00:
272
+ * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
273
+ * //=> Tue Sep 02 2014 00:00:00
274
+ */
275
+ function startOfDay(dirtyDate) {
276
+ requiredArgs(1, arguments);
277
+ var date = toDate(dirtyDate);
278
+ date.setHours(0, 0, 0, 0);
279
+ return date;
280
+ }
281
+
282
+ /**
283
+ * @name addWeeks
284
+ * @category Week Helpers
285
+ * @summary Add the specified number of weeks to the given date.
286
+ *
287
+ * @description
288
+ * Add the specified number of week to the given date.
289
+ *
290
+ * @param {Date|Number} date - the date to be changed
291
+ * @param {Number} amount - the amount of weeks to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
292
+ * @returns {Date} the new date with the weeks added
293
+ * @throws {TypeError} 2 arguments required
294
+ *
295
+ * @example
296
+ * // Add 4 weeks to 1 September 2014:
297
+ * const result = addWeeks(new Date(2014, 8, 1), 4)
298
+ * //=> Mon Sep 29 2014 00:00:00
299
+ */
300
+ function addWeeks(dirtyDate, dirtyAmount) {
301
+ requiredArgs(2, arguments);
302
+ var amount = toInteger$1(dirtyAmount);
303
+ var days = amount * 7;
304
+ return addDays(dirtyDate, days);
305
+ }
306
+
307
+ /**
308
+ * @name addYears
309
+ * @category Year Helpers
310
+ * @summary Add the specified number of years to the given date.
311
+ *
312
+ * @description
313
+ * Add the specified number of years to the given date.
314
+ *
315
+ * @param {Date|Number} date - the date to be changed
316
+ * @param {Number} amount - the amount of years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
317
+ * @returns {Date} the new date with the years added
318
+ * @throws {TypeError} 2 arguments required
319
+ *
320
+ * @example
321
+ * // Add 5 years to 1 September 2014:
322
+ * const result = addYears(new Date(2014, 8, 1), 5)
323
+ * //=> Sun Sep 01 2019 00:00:00
324
+ */
325
+ function addYears(dirtyDate, dirtyAmount) {
326
+ requiredArgs(2, arguments);
327
+ var amount = toInteger$1(dirtyAmount);
328
+ return addMonths(dirtyDate, amount * 12);
329
+ }
330
+
331
+ /**
332
+ * Days in 1 week.
333
+ *
334
+ * @name daysInWeek
335
+ * @constant
336
+ * @type {number}
337
+ * @default
338
+ */
339
+
340
+ /**
341
+ * Milliseconds in 1 minute
342
+ *
343
+ * @name millisecondsInMinute
344
+ * @constant
345
+ * @type {number}
346
+ * @default
347
+ */
348
+ var millisecondsInMinute = 60000;
349
+
350
+ /**
351
+ * Milliseconds in 1 hour
352
+ *
353
+ * @name millisecondsInHour
354
+ * @constant
355
+ * @type {number}
356
+ * @default
357
+ */
358
+ var millisecondsInHour = 3600000;
359
+
360
+ /**
361
+ * @name isSameDay
362
+ * @category Day Helpers
363
+ * @summary Are the given dates in the same day (and year and month)?
364
+ *
365
+ * @description
366
+ * Are the given dates in the same day (and year and month)?
367
+ *
368
+ * @param {Date|Number} dateLeft - the first date to check
369
+ * @param {Date|Number} dateRight - the second date to check
370
+ * @returns {Boolean} the dates are in the same day (and year and month)
371
+ * @throws {TypeError} 2 arguments required
372
+ *
373
+ * @example
374
+ * // Are 4 September 06:00:00 and 4 September 18:00:00 in the same day?
375
+ * const result = isSameDay(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 18, 0))
376
+ * //=> true
377
+ *
378
+ * @example
379
+ * // Are 4 September and 4 October in the same day?
380
+ * const result = isSameDay(new Date(2014, 8, 4), new Date(2014, 9, 4))
381
+ * //=> false
382
+ *
383
+ * @example
384
+ * // Are 4 September, 2014 and 4 September, 2015 in the same day?
385
+ * const result = isSameDay(new Date(2014, 8, 4), new Date(2015, 8, 4))
386
+ * //=> false
387
+ */
388
+ function isSameDay(dirtyDateLeft, dirtyDateRight) {
389
+ requiredArgs(2, arguments);
390
+ var dateLeftStartOfDay = startOfDay(dirtyDateLeft);
391
+ var dateRightStartOfDay = startOfDay(dirtyDateRight);
392
+ return dateLeftStartOfDay.getTime() === dateRightStartOfDay.getTime();
393
+ }
394
+
395
+ /**
396
+ * @name isDate
397
+ * @category Common Helpers
398
+ * @summary Is the given value a date?
399
+ *
400
+ * @description
401
+ * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
402
+ *
403
+ * @param {*} value - the value to check
404
+ * @returns {boolean} true if the given value is a date
405
+ * @throws {TypeError} 1 arguments required
406
+ *
407
+ * @example
408
+ * // For a valid date:
409
+ * const result = isDate(new Date())
410
+ * //=> true
411
+ *
412
+ * @example
413
+ * // For an invalid date:
414
+ * const result = isDate(new Date(NaN))
415
+ * //=> true
416
+ *
417
+ * @example
418
+ * // For some value:
419
+ * const result = isDate('2014-02-31')
420
+ * //=> false
421
+ *
422
+ * @example
423
+ * // For an object:
424
+ * const result = isDate({})
425
+ * //=> false
426
+ */
427
+ function isDate(value) {
428
+ requiredArgs(1, arguments);
429
+ return value instanceof Date || _typeof(value) === 'object' && Object.prototype.toString.call(value) === '[object Date]';
430
+ }
431
+
432
+ /**
433
+ * @name isValid
434
+ * @category Common Helpers
435
+ * @summary Is the given date valid?
436
+ *
437
+ * @description
438
+ * Returns false if argument is Invalid Date and true otherwise.
439
+ * Argument is converted to Date using `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
440
+ * Invalid Date is a Date, whose time value is NaN.
441
+ *
442
+ * Time value of Date: http://es5.github.io/#x15.9.1.1
443
+ *
444
+ * @param {*} date - the date to check
445
+ * @returns {Boolean} the date is valid
446
+ * @throws {TypeError} 1 argument required
447
+ *
448
+ * @example
449
+ * // For the valid date:
450
+ * const result = isValid(new Date(2014, 1, 31))
451
+ * //=> true
452
+ *
453
+ * @example
454
+ * // For the value, convertable into a date:
455
+ * const result = isValid(1393804800000)
456
+ * //=> true
457
+ *
458
+ * @example
459
+ * // For the invalid date:
460
+ * const result = isValid(new Date(''))
461
+ * //=> false
462
+ */
463
+ function isValid(dirtyDate) {
464
+ requiredArgs(1, arguments);
465
+ if (!isDate(dirtyDate) && typeof dirtyDate !== 'number') {
466
+ return false;
467
+ }
468
+ var date = toDate(dirtyDate);
469
+ return !isNaN(Number(date));
470
+ }
471
+
472
+ /**
473
+ * @name endOfDay
474
+ * @category Day Helpers
475
+ * @summary Return the end of a day for the given date.
476
+ *
477
+ * @description
478
+ * Return the end of a day for the given date.
479
+ * The result will be in the local timezone.
480
+ *
481
+ * @param {Date|Number} date - the original date
482
+ * @returns {Date} the end of a day
483
+ * @throws {TypeError} 1 argument required
484
+ *
485
+ * @example
486
+ * // The end of a day for 2 September 2014 11:55:00:
487
+ * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0))
488
+ * //=> Tue Sep 02 2014 23:59:59.999
489
+ */
490
+ function endOfDay(dirtyDate) {
491
+ requiredArgs(1, arguments);
492
+ var date = toDate(dirtyDate);
493
+ date.setHours(23, 59, 59, 999);
494
+ return date;
495
+ }
496
+
497
+ /**
498
+ * @name eachDayOfInterval
499
+ * @category Interval Helpers
500
+ * @summary Return the array of dates within the specified time interval.
501
+ *
502
+ * @description
503
+ * Return the array of dates within the specified time interval.
504
+ *
505
+ * @param {Interval} interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval}
506
+ * @param {Object} [options] - an object with options.
507
+ * @param {Number} [options.step=1] - the step to increment by. The value should be more than 1.
508
+ * @returns {Date[]} the array with starts of days from the day of the interval start to the day of the interval end
509
+ * @throws {TypeError} 1 argument required
510
+ * @throws {RangeError} `options.step` must be a number greater than 1
511
+ * @throws {RangeError} The start of an interval cannot be after its end
512
+ * @throws {RangeError} Date in interval cannot be `Invalid Date`
513
+ *
514
+ * @example
515
+ * // Each day between 6 October 2014 and 10 October 2014:
516
+ * const result = eachDayOfInterval({
517
+ * start: new Date(2014, 9, 6),
518
+ * end: new Date(2014, 9, 10)
519
+ * })
520
+ * //=> [
521
+ * // Mon Oct 06 2014 00:00:00,
522
+ * // Tue Oct 07 2014 00:00:00,
523
+ * // Wed Oct 08 2014 00:00:00,
524
+ * // Thu Oct 09 2014 00:00:00,
525
+ * // Fri Oct 10 2014 00:00:00
526
+ * // ]
527
+ */
528
+ function eachDayOfInterval(dirtyInterval, options) {
529
+ var _options$step;
530
+ requiredArgs(1, arguments);
531
+ var interval = dirtyInterval || {};
532
+ var startDate = toDate(interval.start);
533
+ var endDate = toDate(interval.end);
534
+ var endTime = endDate.getTime();
535
+
536
+ // Throw an exception if start date is after end date or if any date is `Invalid Date`
537
+ if (!(startDate.getTime() <= endTime)) {
538
+ throw new RangeError('Invalid interval');
539
+ }
540
+ var dates = [];
541
+ var currentDate = startDate;
542
+ currentDate.setHours(0, 0, 0, 0);
543
+ var step = Number((_options$step = void 0 ) !== null && _options$step !== void 0 ? _options$step : 1);
544
+ if (step < 1 || isNaN(step)) throw new RangeError('`options.step` must be a number greater than 1');
545
+ while (currentDate.getTime() <= endTime) {
546
+ dates.push(toDate(currentDate));
547
+ currentDate.setDate(currentDate.getDate() + step);
548
+ currentDate.setHours(0, 0, 0, 0);
549
+ }
550
+ return dates;
551
+ }
552
+
553
+ /**
554
+ * @name startOfMonth
555
+ * @category Month Helpers
556
+ * @summary Return the start of a month for the given date.
557
+ *
558
+ * @description
559
+ * Return the start of a month for the given date.
560
+ * The result will be in the local timezone.
561
+ *
562
+ * @param {Date|Number} date - the original date
563
+ * @returns {Date} the start of a month
564
+ * @throws {TypeError} 1 argument required
565
+ *
566
+ * @example
567
+ * // The start of a month for 2 September 2014 11:55:00:
568
+ * const result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0))
569
+ * //=> Mon Sep 01 2014 00:00:00
570
+ */
571
+ function startOfMonth(dirtyDate) {
572
+ requiredArgs(1, arguments);
573
+ var date = toDate(dirtyDate);
574
+ date.setDate(1);
575
+ date.setHours(0, 0, 0, 0);
576
+ return date;
577
+ }
578
+
579
+ /**
580
+ * @name endOfWeek
581
+ * @category Week Helpers
582
+ * @summary Return the end of a week for the given date.
583
+ *
584
+ * @description
585
+ * Return the end of a week for the given date.
586
+ * The result will be in the local timezone.
587
+ *
588
+ * @param {Date|Number} date - the original date
589
+ * @param {Object} [options] - an object with options.
590
+ * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
591
+ * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
592
+ * @returns {Date} the end of a week
593
+ * @throws {TypeError} 1 argument required
594
+ * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
595
+ *
596
+ * @example
597
+ * // The end of a week for 2 September 2014 11:55:00:
598
+ * const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0))
599
+ * //=> Sat Sep 06 2014 23:59:59.999
600
+ *
601
+ * @example
602
+ * // If the week starts on Monday, the end of the week for 2 September 2014 11:55:00:
603
+ * const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
604
+ * //=> Sun Sep 07 2014 23:59:59.999
605
+ */
606
+ function endOfWeek(dirtyDate, options) {
607
+ var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
608
+ requiredArgs(1, arguments);
609
+ var defaultOptions = getDefaultOptions();
610
+ var weekStartsOn = toInteger$1((_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);
611
+
612
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
613
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
614
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
615
+ }
616
+ var date = toDate(dirtyDate);
617
+ var day = date.getDay();
618
+ var diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn);
619
+ date.setDate(date.getDate() + diff);
620
+ date.setHours(23, 59, 59, 999);
621
+ return date;
622
+ }
623
+
624
+ /**
625
+ * @name subMilliseconds
626
+ * @category Millisecond Helpers
627
+ * @summary Subtract the specified number of milliseconds from the given date.
628
+ *
629
+ * @description
630
+ * Subtract the specified number of milliseconds from the given date.
631
+ *
632
+ * @param {Date|Number} date - the date to be changed
633
+ * @param {Number} amount - the amount of milliseconds to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
634
+ * @returns {Date} the new date with the milliseconds subtracted
635
+ * @throws {TypeError} 2 arguments required
636
+ *
637
+ * @example
638
+ * // Subtract 750 milliseconds from 10 July 2014 12:45:30.000:
639
+ * const result = subMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
640
+ * //=> Thu Jul 10 2014 12:45:29.250
641
+ */
642
+ function subMilliseconds(dirtyDate, dirtyAmount) {
643
+ requiredArgs(2, arguments);
644
+ var amount = toInteger$1(dirtyAmount);
645
+ return addMilliseconds(dirtyDate, -amount);
646
+ }
647
+
648
+ var MILLISECONDS_IN_DAY = 86400000;
649
+ function getUTCDayOfYear(dirtyDate) {
650
+ requiredArgs(1, arguments);
651
+ var date = toDate(dirtyDate);
652
+ var timestamp = date.getTime();
653
+ date.setUTCMonth(0, 1);
654
+ date.setUTCHours(0, 0, 0, 0);
655
+ var startOfYearTimestamp = date.getTime();
656
+ var difference = timestamp - startOfYearTimestamp;
657
+ return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
658
+ }
659
+
660
+ function startOfUTCISOWeek(dirtyDate) {
661
+ requiredArgs(1, arguments);
662
+ var weekStartsOn = 1;
663
+ var date = toDate(dirtyDate);
664
+ var day = date.getUTCDay();
665
+ var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
666
+ date.setUTCDate(date.getUTCDate() - diff);
667
+ date.setUTCHours(0, 0, 0, 0);
668
+ return date;
669
+ }
670
+
671
+ function getUTCISOWeekYear(dirtyDate) {
672
+ requiredArgs(1, arguments);
673
+ var date = toDate(dirtyDate);
674
+ var year = date.getUTCFullYear();
675
+ var fourthOfJanuaryOfNextYear = new Date(0);
676
+ fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
677
+ fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
678
+ var startOfNextYear = startOfUTCISOWeek(fourthOfJanuaryOfNextYear);
679
+ var fourthOfJanuaryOfThisYear = new Date(0);
680
+ fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
681
+ fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
682
+ var startOfThisYear = startOfUTCISOWeek(fourthOfJanuaryOfThisYear);
683
+ if (date.getTime() >= startOfNextYear.getTime()) {
684
+ return year + 1;
685
+ } else if (date.getTime() >= startOfThisYear.getTime()) {
686
+ return year;
687
+ } else {
688
+ return year - 1;
689
+ }
690
+ }
691
+
692
+ function startOfUTCISOWeekYear(dirtyDate) {
693
+ requiredArgs(1, arguments);
694
+ var year = getUTCISOWeekYear(dirtyDate);
695
+ var fourthOfJanuary = new Date(0);
696
+ fourthOfJanuary.setUTCFullYear(year, 0, 4);
697
+ fourthOfJanuary.setUTCHours(0, 0, 0, 0);
698
+ var date = startOfUTCISOWeek(fourthOfJanuary);
699
+ return date;
700
+ }
701
+
702
+ var MILLISECONDS_IN_WEEK$1 = 604800000;
703
+ function getUTCISOWeek(dirtyDate) {
704
+ requiredArgs(1, arguments);
705
+ var date = toDate(dirtyDate);
706
+ var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime();
707
+
708
+ // Round the number of days to the nearest integer
709
+ // because the number of milliseconds in a week is not constant
710
+ // (e.g. it's different in the week of the daylight saving time clock shift)
711
+ return Math.round(diff / MILLISECONDS_IN_WEEK$1) + 1;
712
+ }
713
+
714
+ function startOfUTCWeek(dirtyDate, options) {
715
+ var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
716
+ requiredArgs(1, arguments);
717
+ var defaultOptions = getDefaultOptions();
718
+ var weekStartsOn = toInteger$1((_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);
719
+
720
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
721
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
722
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
723
+ }
724
+ var date = toDate(dirtyDate);
725
+ var day = date.getUTCDay();
726
+ var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
727
+ date.setUTCDate(date.getUTCDate() - diff);
728
+ date.setUTCHours(0, 0, 0, 0);
729
+ return date;
730
+ }
731
+
732
+ function getUTCWeekYear(dirtyDate, options) {
733
+ var _ref, _ref2, _ref3, _options$firstWeekCon, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
734
+ requiredArgs(1, arguments);
735
+ var date = toDate(dirtyDate);
736
+ var year = date.getUTCFullYear();
737
+ var defaultOptions = getDefaultOptions();
738
+ var firstWeekContainsDate = toInteger$1((_ref = (_ref2 = (_ref3 = (_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$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.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.firstWeekContainsDate) !== 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.firstWeekContainsDate) !== null && _ref !== void 0 ? _ref : 1);
739
+
740
+ // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
741
+ if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
742
+ throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
743
+ }
744
+ var firstWeekOfNextYear = new Date(0);
745
+ firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate);
746
+ firstWeekOfNextYear.setUTCHours(0, 0, 0, 0);
747
+ var startOfNextYear = startOfUTCWeek(firstWeekOfNextYear, options);
748
+ var firstWeekOfThisYear = new Date(0);
749
+ firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
750
+ firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
751
+ var startOfThisYear = startOfUTCWeek(firstWeekOfThisYear, options);
752
+ if (date.getTime() >= startOfNextYear.getTime()) {
753
+ return year + 1;
754
+ } else if (date.getTime() >= startOfThisYear.getTime()) {
755
+ return year;
756
+ } else {
757
+ return year - 1;
758
+ }
759
+ }
760
+
761
+ function startOfUTCWeekYear(dirtyDate, options) {
762
+ var _ref, _ref2, _ref3, _options$firstWeekCon, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
763
+ requiredArgs(1, arguments);
764
+ var defaultOptions = getDefaultOptions();
765
+ var firstWeekContainsDate = toInteger$1((_ref = (_ref2 = (_ref3 = (_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$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.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.firstWeekContainsDate) !== 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.firstWeekContainsDate) !== null && _ref !== void 0 ? _ref : 1);
766
+ var year = getUTCWeekYear(dirtyDate, options);
767
+ var firstWeek = new Date(0);
768
+ firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
769
+ firstWeek.setUTCHours(0, 0, 0, 0);
770
+ var date = startOfUTCWeek(firstWeek, options);
771
+ return date;
772
+ }
773
+
774
+ var MILLISECONDS_IN_WEEK = 604800000;
775
+ function getUTCWeek(dirtyDate, options) {
776
+ requiredArgs(1, arguments);
777
+ var date = toDate(dirtyDate);
778
+ var diff = startOfUTCWeek(date, options).getTime() - startOfUTCWeekYear(date, options).getTime();
779
+
780
+ // Round the number of days to the nearest integer
781
+ // because the number of milliseconds in a week is not constant
782
+ // (e.g. it's different in the week of the daylight saving time clock shift)
783
+ return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
784
+ }
785
+
786
+ function addLeadingZeros(number, targetLength) {
787
+ var sign = number < 0 ? '-' : '';
788
+ var output = Math.abs(number).toString();
789
+ while (output.length < targetLength) {
790
+ output = '0' + output;
791
+ }
792
+ return sign + output;
793
+ }
794
+
795
+ /*
796
+ * | | Unit | | Unit |
797
+ * |-----|--------------------------------|-----|--------------------------------|
798
+ * | a | AM, PM | A* | |
799
+ * | d | Day of month | D | |
800
+ * | h | Hour [1-12] | H | Hour [0-23] |
801
+ * | m | Minute | M | Month |
802
+ * | s | Second | S | Fraction of second |
803
+ * | y | Year (abs) | Y | |
804
+ *
805
+ * Letters marked by * are not implemented but reserved by Unicode standard.
806
+ */
807
+ var formatters$1 = {
808
+ // Year
809
+ y: function y(date, token) {
810
+ // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
811
+ // | Year | y | yy | yyy | yyyy | yyyyy |
812
+ // |----------|-------|----|-------|-------|-------|
813
+ // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
814
+ // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
815
+ // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
816
+ // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
817
+ // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
818
+
819
+ var signedYear = date.getUTCFullYear();
820
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
821
+ var year = signedYear > 0 ? signedYear : 1 - signedYear;
822
+ return addLeadingZeros(token === 'yy' ? year % 100 : year, token.length);
823
+ },
824
+ // Month
825
+ M: function M(date, token) {
826
+ var month = date.getUTCMonth();
827
+ return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2);
828
+ },
829
+ // Day of the month
830
+ d: function d(date, token) {
831
+ return addLeadingZeros(date.getUTCDate(), token.length);
832
+ },
833
+ // AM or PM
834
+ a: function a(date, token) {
835
+ var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
836
+ switch (token) {
837
+ case 'a':
838
+ case 'aa':
839
+ return dayPeriodEnumValue.toUpperCase();
840
+ case 'aaa':
841
+ return dayPeriodEnumValue;
842
+ case 'aaaaa':
843
+ return dayPeriodEnumValue[0];
844
+ case 'aaaa':
845
+ default:
846
+ return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
847
+ }
848
+ },
849
+ // Hour [1-12]
850
+ h: function h(date, token) {
851
+ return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length);
852
+ },
853
+ // Hour [0-23]
854
+ H: function H(date, token) {
855
+ return addLeadingZeros(date.getUTCHours(), token.length);
856
+ },
857
+ // Minute
858
+ m: function m(date, token) {
859
+ return addLeadingZeros(date.getUTCMinutes(), token.length);
860
+ },
861
+ // Second
862
+ s: function s(date, token) {
863
+ return addLeadingZeros(date.getUTCSeconds(), token.length);
864
+ },
865
+ // Fraction of second
866
+ S: function S(date, token) {
867
+ var numberOfDigits = token.length;
868
+ var milliseconds = date.getUTCMilliseconds();
869
+ var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
870
+ return addLeadingZeros(fractionalSeconds, token.length);
871
+ }
872
+ };
873
+
874
+ var dayPeriodEnum = {
875
+ am: 'am',
876
+ pm: 'pm',
877
+ midnight: 'midnight',
878
+ noon: 'noon',
879
+ morning: 'morning',
880
+ afternoon: 'afternoon',
881
+ evening: 'evening',
882
+ night: 'night'
883
+ };
884
+ /*
885
+ * | | Unit | | Unit |
886
+ * |-----|--------------------------------|-----|--------------------------------|
887
+ * | a | AM, PM | A* | Milliseconds in day |
888
+ * | b | AM, PM, noon, midnight | B | Flexible day period |
889
+ * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
890
+ * | d | Day of month | D | Day of year |
891
+ * | e | Local day of week | E | Day of week |
892
+ * | f | | F* | Day of week in month |
893
+ * | g* | Modified Julian day | G | Era |
894
+ * | h | Hour [1-12] | H | Hour [0-23] |
895
+ * | i! | ISO day of week | I! | ISO week of year |
896
+ * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
897
+ * | k | Hour [1-24] | K | Hour [0-11] |
898
+ * | l* | (deprecated) | L | Stand-alone month |
899
+ * | m | Minute | M | Month |
900
+ * | n | | N | |
901
+ * | o! | Ordinal number modifier | O | Timezone (GMT) |
902
+ * | p! | Long localized time | P! | Long localized date |
903
+ * | q | Stand-alone quarter | Q | Quarter |
904
+ * | r* | Related Gregorian year | R! | ISO week-numbering year |
905
+ * | s | Second | S | Fraction of second |
906
+ * | t! | Seconds timestamp | T! | Milliseconds timestamp |
907
+ * | u | Extended year | U* | Cyclic year |
908
+ * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
909
+ * | w | Local week of year | W* | Week of month |
910
+ * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
911
+ * | y | Year (abs) | Y | Local week-numbering year |
912
+ * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
913
+ *
914
+ * Letters marked by * are not implemented but reserved by Unicode standard.
915
+ *
916
+ * Letters marked by ! are non-standard, but implemented by date-fns:
917
+ * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
918
+ * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
919
+ * i.e. 7 for Sunday, 1 for Monday, etc.
920
+ * - `I` is ISO week of year, as opposed to `w` which is local week of year.
921
+ * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
922
+ * `R` is supposed to be used in conjunction with `I` and `i`
923
+ * for universal ISO week-numbering date, whereas
924
+ * `Y` is supposed to be used in conjunction with `w` and `e`
925
+ * for week-numbering date specific to the locale.
926
+ * - `P` is long localized date format
927
+ * - `p` is long localized time format
928
+ */
929
+
930
+ var formatters = {
931
+ // Era
932
+ G: function G(date, token, localize) {
933
+ var era = date.getUTCFullYear() > 0 ? 1 : 0;
934
+ switch (token) {
935
+ // AD, BC
936
+ case 'G':
937
+ case 'GG':
938
+ case 'GGG':
939
+ return localize.era(era, {
940
+ width: 'abbreviated'
941
+ });
942
+ // A, B
943
+ case 'GGGGG':
944
+ return localize.era(era, {
945
+ width: 'narrow'
946
+ });
947
+ // Anno Domini, Before Christ
948
+ case 'GGGG':
949
+ default:
950
+ return localize.era(era, {
951
+ width: 'wide'
952
+ });
953
+ }
954
+ },
955
+ // Year
956
+ y: function y(date, token, localize) {
957
+ // Ordinal number
958
+ if (token === 'yo') {
959
+ var signedYear = date.getUTCFullYear();
960
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
961
+ var year = signedYear > 0 ? signedYear : 1 - signedYear;
962
+ return localize.ordinalNumber(year, {
963
+ unit: 'year'
964
+ });
965
+ }
966
+ return formatters$1.y(date, token);
967
+ },
968
+ // Local week-numbering year
969
+ Y: function Y(date, token, localize, options) {
970
+ var signedWeekYear = getUTCWeekYear(date, options);
971
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
972
+ var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
973
+
974
+ // Two digit year
975
+ if (token === 'YY') {
976
+ var twoDigitYear = weekYear % 100;
977
+ return addLeadingZeros(twoDigitYear, 2);
978
+ }
979
+
980
+ // Ordinal number
981
+ if (token === 'Yo') {
982
+ return localize.ordinalNumber(weekYear, {
983
+ unit: 'year'
984
+ });
985
+ }
986
+
987
+ // Padding
988
+ return addLeadingZeros(weekYear, token.length);
989
+ },
990
+ // ISO week-numbering year
991
+ R: function R(date, token) {
992
+ var isoWeekYear = getUTCISOWeekYear(date);
993
+
994
+ // Padding
995
+ return addLeadingZeros(isoWeekYear, token.length);
996
+ },
997
+ // Extended year. This is a single number designating the year of this calendar system.
998
+ // The main difference between `y` and `u` localizers are B.C. years:
999
+ // | Year | `y` | `u` |
1000
+ // |------|-----|-----|
1001
+ // | AC 1 | 1 | 1 |
1002
+ // | BC 1 | 1 | 0 |
1003
+ // | BC 2 | 2 | -1 |
1004
+ // Also `yy` always returns the last two digits of a year,
1005
+ // while `uu` pads single digit years to 2 characters and returns other years unchanged.
1006
+ u: function u(date, token) {
1007
+ var year = date.getUTCFullYear();
1008
+ return addLeadingZeros(year, token.length);
1009
+ },
1010
+ // Quarter
1011
+ Q: function Q(date, token, localize) {
1012
+ var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
1013
+ switch (token) {
1014
+ // 1, 2, 3, 4
1015
+ case 'Q':
1016
+ return String(quarter);
1017
+ // 01, 02, 03, 04
1018
+ case 'QQ':
1019
+ return addLeadingZeros(quarter, 2);
1020
+ // 1st, 2nd, 3rd, 4th
1021
+ case 'Qo':
1022
+ return localize.ordinalNumber(quarter, {
1023
+ unit: 'quarter'
1024
+ });
1025
+ // Q1, Q2, Q3, Q4
1026
+ case 'QQQ':
1027
+ return localize.quarter(quarter, {
1028
+ width: 'abbreviated',
1029
+ context: 'formatting'
1030
+ });
1031
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
1032
+ case 'QQQQQ':
1033
+ return localize.quarter(quarter, {
1034
+ width: 'narrow',
1035
+ context: 'formatting'
1036
+ });
1037
+ // 1st quarter, 2nd quarter, ...
1038
+ case 'QQQQ':
1039
+ default:
1040
+ return localize.quarter(quarter, {
1041
+ width: 'wide',
1042
+ context: 'formatting'
1043
+ });
1044
+ }
1045
+ },
1046
+ // Stand-alone quarter
1047
+ q: function q(date, token, localize) {
1048
+ var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
1049
+ switch (token) {
1050
+ // 1, 2, 3, 4
1051
+ case 'q':
1052
+ return String(quarter);
1053
+ // 01, 02, 03, 04
1054
+ case 'qq':
1055
+ return addLeadingZeros(quarter, 2);
1056
+ // 1st, 2nd, 3rd, 4th
1057
+ case 'qo':
1058
+ return localize.ordinalNumber(quarter, {
1059
+ unit: 'quarter'
1060
+ });
1061
+ // Q1, Q2, Q3, Q4
1062
+ case 'qqq':
1063
+ return localize.quarter(quarter, {
1064
+ width: 'abbreviated',
1065
+ context: 'standalone'
1066
+ });
1067
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
1068
+ case 'qqqqq':
1069
+ return localize.quarter(quarter, {
1070
+ width: 'narrow',
1071
+ context: 'standalone'
1072
+ });
1073
+ // 1st quarter, 2nd quarter, ...
1074
+ case 'qqqq':
1075
+ default:
1076
+ return localize.quarter(quarter, {
1077
+ width: 'wide',
1078
+ context: 'standalone'
1079
+ });
1080
+ }
1081
+ },
1082
+ // Month
1083
+ M: function M(date, token, localize) {
1084
+ var month = date.getUTCMonth();
1085
+ switch (token) {
1086
+ case 'M':
1087
+ case 'MM':
1088
+ return formatters$1.M(date, token);
1089
+ // 1st, 2nd, ..., 12th
1090
+ case 'Mo':
1091
+ return localize.ordinalNumber(month + 1, {
1092
+ unit: 'month'
1093
+ });
1094
+ // Jan, Feb, ..., Dec
1095
+ case 'MMM':
1096
+ return localize.month(month, {
1097
+ width: 'abbreviated',
1098
+ context: 'formatting'
1099
+ });
1100
+ // J, F, ..., D
1101
+ case 'MMMMM':
1102
+ return localize.month(month, {
1103
+ width: 'narrow',
1104
+ context: 'formatting'
1105
+ });
1106
+ // January, February, ..., December
1107
+ case 'MMMM':
1108
+ default:
1109
+ return localize.month(month, {
1110
+ width: 'wide',
1111
+ context: 'formatting'
1112
+ });
1113
+ }
1114
+ },
1115
+ // Stand-alone month
1116
+ L: function L(date, token, localize) {
1117
+ var month = date.getUTCMonth();
1118
+ switch (token) {
1119
+ // 1, 2, ..., 12
1120
+ case 'L':
1121
+ return String(month + 1);
1122
+ // 01, 02, ..., 12
1123
+ case 'LL':
1124
+ return addLeadingZeros(month + 1, 2);
1125
+ // 1st, 2nd, ..., 12th
1126
+ case 'Lo':
1127
+ return localize.ordinalNumber(month + 1, {
1128
+ unit: 'month'
1129
+ });
1130
+ // Jan, Feb, ..., Dec
1131
+ case 'LLL':
1132
+ return localize.month(month, {
1133
+ width: 'abbreviated',
1134
+ context: 'standalone'
1135
+ });
1136
+ // J, F, ..., D
1137
+ case 'LLLLL':
1138
+ return localize.month(month, {
1139
+ width: 'narrow',
1140
+ context: 'standalone'
1141
+ });
1142
+ // January, February, ..., December
1143
+ case 'LLLL':
1144
+ default:
1145
+ return localize.month(month, {
1146
+ width: 'wide',
1147
+ context: 'standalone'
1148
+ });
1149
+ }
1150
+ },
1151
+ // Local week of year
1152
+ w: function w(date, token, localize, options) {
1153
+ var week = getUTCWeek(date, options);
1154
+ if (token === 'wo') {
1155
+ return localize.ordinalNumber(week, {
1156
+ unit: 'week'
1157
+ });
1158
+ }
1159
+ return addLeadingZeros(week, token.length);
1160
+ },
1161
+ // ISO week of year
1162
+ I: function I(date, token, localize) {
1163
+ var isoWeek = getUTCISOWeek(date);
1164
+ if (token === 'Io') {
1165
+ return localize.ordinalNumber(isoWeek, {
1166
+ unit: 'week'
1167
+ });
1168
+ }
1169
+ return addLeadingZeros(isoWeek, token.length);
1170
+ },
1171
+ // Day of the month
1172
+ d: function d(date, token, localize) {
1173
+ if (token === 'do') {
1174
+ return localize.ordinalNumber(date.getUTCDate(), {
1175
+ unit: 'date'
1176
+ });
1177
+ }
1178
+ return formatters$1.d(date, token);
1179
+ },
1180
+ // Day of year
1181
+ D: function D(date, token, localize) {
1182
+ var dayOfYear = getUTCDayOfYear(date);
1183
+ if (token === 'Do') {
1184
+ return localize.ordinalNumber(dayOfYear, {
1185
+ unit: 'dayOfYear'
1186
+ });
1187
+ }
1188
+ return addLeadingZeros(dayOfYear, token.length);
1189
+ },
1190
+ // Day of week
1191
+ E: function E(date, token, localize) {
1192
+ var dayOfWeek = date.getUTCDay();
1193
+ switch (token) {
1194
+ // Tue
1195
+ case 'E':
1196
+ case 'EE':
1197
+ case 'EEE':
1198
+ return localize.day(dayOfWeek, {
1199
+ width: 'abbreviated',
1200
+ context: 'formatting'
1201
+ });
1202
+ // T
1203
+ case 'EEEEE':
1204
+ return localize.day(dayOfWeek, {
1205
+ width: 'narrow',
1206
+ context: 'formatting'
1207
+ });
1208
+ // Tu
1209
+ case 'EEEEEE':
1210
+ return localize.day(dayOfWeek, {
1211
+ width: 'short',
1212
+ context: 'formatting'
1213
+ });
1214
+ // Tuesday
1215
+ case 'EEEE':
1216
+ default:
1217
+ return localize.day(dayOfWeek, {
1218
+ width: 'wide',
1219
+ context: 'formatting'
1220
+ });
1221
+ }
1222
+ },
1223
+ // Local day of week
1224
+ e: function e(date, token, localize, options) {
1225
+ var dayOfWeek = date.getUTCDay();
1226
+ var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1227
+ switch (token) {
1228
+ // Numerical value (Nth day of week with current locale or weekStartsOn)
1229
+ case 'e':
1230
+ return String(localDayOfWeek);
1231
+ // Padded numerical value
1232
+ case 'ee':
1233
+ return addLeadingZeros(localDayOfWeek, 2);
1234
+ // 1st, 2nd, ..., 7th
1235
+ case 'eo':
1236
+ return localize.ordinalNumber(localDayOfWeek, {
1237
+ unit: 'day'
1238
+ });
1239
+ case 'eee':
1240
+ return localize.day(dayOfWeek, {
1241
+ width: 'abbreviated',
1242
+ context: 'formatting'
1243
+ });
1244
+ // T
1245
+ case 'eeeee':
1246
+ return localize.day(dayOfWeek, {
1247
+ width: 'narrow',
1248
+ context: 'formatting'
1249
+ });
1250
+ // Tu
1251
+ case 'eeeeee':
1252
+ return localize.day(dayOfWeek, {
1253
+ width: 'short',
1254
+ context: 'formatting'
1255
+ });
1256
+ // Tuesday
1257
+ case 'eeee':
1258
+ default:
1259
+ return localize.day(dayOfWeek, {
1260
+ width: 'wide',
1261
+ context: 'formatting'
1262
+ });
1263
+ }
1264
+ },
1265
+ // Stand-alone local day of week
1266
+ c: function c(date, token, localize, options) {
1267
+ var dayOfWeek = date.getUTCDay();
1268
+ var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1269
+ switch (token) {
1270
+ // Numerical value (same as in `e`)
1271
+ case 'c':
1272
+ return String(localDayOfWeek);
1273
+ // Padded numerical value
1274
+ case 'cc':
1275
+ return addLeadingZeros(localDayOfWeek, token.length);
1276
+ // 1st, 2nd, ..., 7th
1277
+ case 'co':
1278
+ return localize.ordinalNumber(localDayOfWeek, {
1279
+ unit: 'day'
1280
+ });
1281
+ case 'ccc':
1282
+ return localize.day(dayOfWeek, {
1283
+ width: 'abbreviated',
1284
+ context: 'standalone'
1285
+ });
1286
+ // T
1287
+ case 'ccccc':
1288
+ return localize.day(dayOfWeek, {
1289
+ width: 'narrow',
1290
+ context: 'standalone'
1291
+ });
1292
+ // Tu
1293
+ case 'cccccc':
1294
+ return localize.day(dayOfWeek, {
1295
+ width: 'short',
1296
+ context: 'standalone'
1297
+ });
1298
+ // Tuesday
1299
+ case 'cccc':
1300
+ default:
1301
+ return localize.day(dayOfWeek, {
1302
+ width: 'wide',
1303
+ context: 'standalone'
1304
+ });
1305
+ }
1306
+ },
1307
+ // ISO day of week
1308
+ i: function i(date, token, localize) {
1309
+ var dayOfWeek = date.getUTCDay();
1310
+ var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
1311
+ switch (token) {
1312
+ // 2
1313
+ case 'i':
1314
+ return String(isoDayOfWeek);
1315
+ // 02
1316
+ case 'ii':
1317
+ return addLeadingZeros(isoDayOfWeek, token.length);
1318
+ // 2nd
1319
+ case 'io':
1320
+ return localize.ordinalNumber(isoDayOfWeek, {
1321
+ unit: 'day'
1322
+ });
1323
+ // Tue
1324
+ case 'iii':
1325
+ return localize.day(dayOfWeek, {
1326
+ width: 'abbreviated',
1327
+ context: 'formatting'
1328
+ });
1329
+ // T
1330
+ case 'iiiii':
1331
+ return localize.day(dayOfWeek, {
1332
+ width: 'narrow',
1333
+ context: 'formatting'
1334
+ });
1335
+ // Tu
1336
+ case 'iiiiii':
1337
+ return localize.day(dayOfWeek, {
1338
+ width: 'short',
1339
+ context: 'formatting'
1340
+ });
1341
+ // Tuesday
1342
+ case 'iiii':
1343
+ default:
1344
+ return localize.day(dayOfWeek, {
1345
+ width: 'wide',
1346
+ context: 'formatting'
1347
+ });
1348
+ }
1349
+ },
1350
+ // AM or PM
1351
+ a: function a(date, token, localize) {
1352
+ var hours = date.getUTCHours();
1353
+ var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1354
+ switch (token) {
1355
+ case 'a':
1356
+ case 'aa':
1357
+ return localize.dayPeriod(dayPeriodEnumValue, {
1358
+ width: 'abbreviated',
1359
+ context: 'formatting'
1360
+ });
1361
+ case 'aaa':
1362
+ return localize.dayPeriod(dayPeriodEnumValue, {
1363
+ width: 'abbreviated',
1364
+ context: 'formatting'
1365
+ }).toLowerCase();
1366
+ case 'aaaaa':
1367
+ return localize.dayPeriod(dayPeriodEnumValue, {
1368
+ width: 'narrow',
1369
+ context: 'formatting'
1370
+ });
1371
+ case 'aaaa':
1372
+ default:
1373
+ return localize.dayPeriod(dayPeriodEnumValue, {
1374
+ width: 'wide',
1375
+ context: 'formatting'
1376
+ });
1377
+ }
1378
+ },
1379
+ // AM, PM, midnight, noon
1380
+ b: function b(date, token, localize) {
1381
+ var hours = date.getUTCHours();
1382
+ var dayPeriodEnumValue;
1383
+ if (hours === 12) {
1384
+ dayPeriodEnumValue = dayPeriodEnum.noon;
1385
+ } else if (hours === 0) {
1386
+ dayPeriodEnumValue = dayPeriodEnum.midnight;
1387
+ } else {
1388
+ dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1389
+ }
1390
+ switch (token) {
1391
+ case 'b':
1392
+ case 'bb':
1393
+ return localize.dayPeriod(dayPeriodEnumValue, {
1394
+ width: 'abbreviated',
1395
+ context: 'formatting'
1396
+ });
1397
+ case 'bbb':
1398
+ return localize.dayPeriod(dayPeriodEnumValue, {
1399
+ width: 'abbreviated',
1400
+ context: 'formatting'
1401
+ }).toLowerCase();
1402
+ case 'bbbbb':
1403
+ return localize.dayPeriod(dayPeriodEnumValue, {
1404
+ width: 'narrow',
1405
+ context: 'formatting'
1406
+ });
1407
+ case 'bbbb':
1408
+ default:
1409
+ return localize.dayPeriod(dayPeriodEnumValue, {
1410
+ width: 'wide',
1411
+ context: 'formatting'
1412
+ });
1413
+ }
1414
+ },
1415
+ // in the morning, in the afternoon, in the evening, at night
1416
+ B: function B(date, token, localize) {
1417
+ var hours = date.getUTCHours();
1418
+ var dayPeriodEnumValue;
1419
+ if (hours >= 17) {
1420
+ dayPeriodEnumValue = dayPeriodEnum.evening;
1421
+ } else if (hours >= 12) {
1422
+ dayPeriodEnumValue = dayPeriodEnum.afternoon;
1423
+ } else if (hours >= 4) {
1424
+ dayPeriodEnumValue = dayPeriodEnum.morning;
1425
+ } else {
1426
+ dayPeriodEnumValue = dayPeriodEnum.night;
1427
+ }
1428
+ switch (token) {
1429
+ case 'B':
1430
+ case 'BB':
1431
+ case 'BBB':
1432
+ return localize.dayPeriod(dayPeriodEnumValue, {
1433
+ width: 'abbreviated',
1434
+ context: 'formatting'
1435
+ });
1436
+ case 'BBBBB':
1437
+ return localize.dayPeriod(dayPeriodEnumValue, {
1438
+ width: 'narrow',
1439
+ context: 'formatting'
1440
+ });
1441
+ case 'BBBB':
1442
+ default:
1443
+ return localize.dayPeriod(dayPeriodEnumValue, {
1444
+ width: 'wide',
1445
+ context: 'formatting'
1446
+ });
1447
+ }
1448
+ },
1449
+ // Hour [1-12]
1450
+ h: function h(date, token, localize) {
1451
+ if (token === 'ho') {
1452
+ var hours = date.getUTCHours() % 12;
1453
+ if (hours === 0) hours = 12;
1454
+ return localize.ordinalNumber(hours, {
1455
+ unit: 'hour'
1456
+ });
1457
+ }
1458
+ return formatters$1.h(date, token);
1459
+ },
1460
+ // Hour [0-23]
1461
+ H: function H(date, token, localize) {
1462
+ if (token === 'Ho') {
1463
+ return localize.ordinalNumber(date.getUTCHours(), {
1464
+ unit: 'hour'
1465
+ });
1466
+ }
1467
+ return formatters$1.H(date, token);
1468
+ },
1469
+ // Hour [0-11]
1470
+ K: function K(date, token, localize) {
1471
+ var hours = date.getUTCHours() % 12;
1472
+ if (token === 'Ko') {
1473
+ return localize.ordinalNumber(hours, {
1474
+ unit: 'hour'
1475
+ });
1476
+ }
1477
+ return addLeadingZeros(hours, token.length);
1478
+ },
1479
+ // Hour [1-24]
1480
+ k: function k(date, token, localize) {
1481
+ var hours = date.getUTCHours();
1482
+ if (hours === 0) hours = 24;
1483
+ if (token === 'ko') {
1484
+ return localize.ordinalNumber(hours, {
1485
+ unit: 'hour'
1486
+ });
1487
+ }
1488
+ return addLeadingZeros(hours, token.length);
1489
+ },
1490
+ // Minute
1491
+ m: function m(date, token, localize) {
1492
+ if (token === 'mo') {
1493
+ return localize.ordinalNumber(date.getUTCMinutes(), {
1494
+ unit: 'minute'
1495
+ });
1496
+ }
1497
+ return formatters$1.m(date, token);
1498
+ },
1499
+ // Second
1500
+ s: function s(date, token, localize) {
1501
+ if (token === 'so') {
1502
+ return localize.ordinalNumber(date.getUTCSeconds(), {
1503
+ unit: 'second'
1504
+ });
1505
+ }
1506
+ return formatters$1.s(date, token);
1507
+ },
1508
+ // Fraction of second
1509
+ S: function S(date, token) {
1510
+ return formatters$1.S(date, token);
1511
+ },
1512
+ // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
1513
+ X: function X(date, token, _localize, options) {
1514
+ var originalDate = options._originalDate || date;
1515
+ var timezoneOffset = originalDate.getTimezoneOffset();
1516
+ if (timezoneOffset === 0) {
1517
+ return 'Z';
1518
+ }
1519
+ switch (token) {
1520
+ // Hours and optional minutes
1521
+ case 'X':
1522
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
1523
+
1524
+ // Hours, minutes and optional seconds without `:` delimiter
1525
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1526
+ // so this token always has the same output as `XX`
1527
+ case 'XXXX':
1528
+ case 'XX':
1529
+ // Hours and minutes without `:` delimiter
1530
+ return formatTimezone(timezoneOffset);
1531
+
1532
+ // Hours, minutes and optional seconds with `:` delimiter
1533
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1534
+ // so this token always has the same output as `XXX`
1535
+ case 'XXXXX':
1536
+ case 'XXX': // Hours and minutes with `:` delimiter
1537
+ default:
1538
+ return formatTimezone(timezoneOffset, ':');
1539
+ }
1540
+ },
1541
+ // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
1542
+ x: function x(date, token, _localize, options) {
1543
+ var originalDate = options._originalDate || date;
1544
+ var timezoneOffset = originalDate.getTimezoneOffset();
1545
+ switch (token) {
1546
+ // Hours and optional minutes
1547
+ case 'x':
1548
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
1549
+
1550
+ // Hours, minutes and optional seconds without `:` delimiter
1551
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1552
+ // so this token always has the same output as `xx`
1553
+ case 'xxxx':
1554
+ case 'xx':
1555
+ // Hours and minutes without `:` delimiter
1556
+ return formatTimezone(timezoneOffset);
1557
+
1558
+ // Hours, minutes and optional seconds with `:` delimiter
1559
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1560
+ // so this token always has the same output as `xxx`
1561
+ case 'xxxxx':
1562
+ case 'xxx': // Hours and minutes with `:` delimiter
1563
+ default:
1564
+ return formatTimezone(timezoneOffset, ':');
1565
+ }
1566
+ },
1567
+ // Timezone (GMT)
1568
+ O: function O(date, token, _localize, options) {
1569
+ var originalDate = options._originalDate || date;
1570
+ var timezoneOffset = originalDate.getTimezoneOffset();
1571
+ switch (token) {
1572
+ // Short
1573
+ case 'O':
1574
+ case 'OO':
1575
+ case 'OOO':
1576
+ return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1577
+ // Long
1578
+ case 'OOOO':
1579
+ default:
1580
+ return 'GMT' + formatTimezone(timezoneOffset, ':');
1581
+ }
1582
+ },
1583
+ // Timezone (specific non-location)
1584
+ z: function z(date, token, _localize, options) {
1585
+ var originalDate = options._originalDate || date;
1586
+ var timezoneOffset = originalDate.getTimezoneOffset();
1587
+ switch (token) {
1588
+ // Short
1589
+ case 'z':
1590
+ case 'zz':
1591
+ case 'zzz':
1592
+ return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1593
+ // Long
1594
+ case 'zzzz':
1595
+ default:
1596
+ return 'GMT' + formatTimezone(timezoneOffset, ':');
1597
+ }
1598
+ },
1599
+ // Seconds timestamp
1600
+ t: function t(date, token, _localize, options) {
1601
+ var originalDate = options._originalDate || date;
1602
+ var timestamp = Math.floor(originalDate.getTime() / 1000);
1603
+ return addLeadingZeros(timestamp, token.length);
1604
+ },
1605
+ // Milliseconds timestamp
1606
+ T: function T(date, token, _localize, options) {
1607
+ var originalDate = options._originalDate || date;
1608
+ var timestamp = originalDate.getTime();
1609
+ return addLeadingZeros(timestamp, token.length);
1610
+ }
269
1611
  };
1612
+ function formatTimezoneShort(offset, dirtyDelimiter) {
1613
+ var sign = offset > 0 ? '-' : '+';
1614
+ var absOffset = Math.abs(offset);
1615
+ var hours = Math.floor(absOffset / 60);
1616
+ var minutes = absOffset % 60;
1617
+ if (minutes === 0) {
1618
+ return sign + String(hours);
1619
+ }
1620
+ var delimiter = dirtyDelimiter;
1621
+ return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
1622
+ }
1623
+ function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
1624
+ if (offset % 60 === 0) {
1625
+ var sign = offset > 0 ? '-' : '+';
1626
+ return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
1627
+ }
1628
+ return formatTimezone(offset, dirtyDelimiter);
1629
+ }
1630
+ function formatTimezone(offset, dirtyDelimiter) {
1631
+ var delimiter = dirtyDelimiter || '';
1632
+ var sign = offset > 0 ? '-' : '+';
1633
+ var absOffset = Math.abs(offset);
1634
+ var hours = addLeadingZeros(Math.floor(absOffset / 60), 2);
1635
+ var minutes = addLeadingZeros(absOffset % 60, 2);
1636
+ return sign + hours + delimiter + minutes;
1637
+ }
1638
+
1639
+ var dateLongFormatter = function dateLongFormatter(pattern, formatLong) {
1640
+ switch (pattern) {
1641
+ case 'P':
1642
+ return formatLong.date({
1643
+ width: 'short'
1644
+ });
1645
+ case 'PP':
1646
+ return formatLong.date({
1647
+ width: 'medium'
1648
+ });
1649
+ case 'PPP':
1650
+ return formatLong.date({
1651
+ width: 'long'
1652
+ });
1653
+ case 'PPPP':
1654
+ default:
1655
+ return formatLong.date({
1656
+ width: 'full'
1657
+ });
1658
+ }
1659
+ };
1660
+ var timeLongFormatter = function timeLongFormatter(pattern, formatLong) {
1661
+ switch (pattern) {
1662
+ case 'p':
1663
+ return formatLong.time({
1664
+ width: 'short'
1665
+ });
1666
+ case 'pp':
1667
+ return formatLong.time({
1668
+ width: 'medium'
1669
+ });
1670
+ case 'ppp':
1671
+ return formatLong.time({
1672
+ width: 'long'
1673
+ });
1674
+ case 'pppp':
1675
+ default:
1676
+ return formatLong.time({
1677
+ width: 'full'
1678
+ });
1679
+ }
1680
+ };
1681
+ var dateTimeLongFormatter = function dateTimeLongFormatter(pattern, formatLong) {
1682
+ var matchResult = pattern.match(/(P+)(p+)?/) || [];
1683
+ var datePattern = matchResult[1];
1684
+ var timePattern = matchResult[2];
1685
+ if (!timePattern) {
1686
+ return dateLongFormatter(pattern, formatLong);
1687
+ }
1688
+ var dateTimeFormat;
1689
+ switch (datePattern) {
1690
+ case 'P':
1691
+ dateTimeFormat = formatLong.dateTime({
1692
+ width: 'short'
1693
+ });
1694
+ break;
1695
+ case 'PP':
1696
+ dateTimeFormat = formatLong.dateTime({
1697
+ width: 'medium'
1698
+ });
1699
+ break;
1700
+ case 'PPP':
1701
+ dateTimeFormat = formatLong.dateTime({
1702
+ width: 'long'
1703
+ });
1704
+ break;
1705
+ case 'PPPP':
1706
+ default:
1707
+ dateTimeFormat = formatLong.dateTime({
1708
+ width: 'full'
1709
+ });
1710
+ break;
1711
+ }
1712
+ return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
1713
+ };
1714
+ var longFormatters = {
1715
+ p: timeLongFormatter,
1716
+ P: dateTimeLongFormatter
1717
+ };
1718
+
1719
+ var protectedDayOfYearTokens = ['D', 'DD'];
1720
+ var protectedWeekYearTokens = ['YY', 'YYYY'];
1721
+ function isProtectedDayOfYearToken(token) {
1722
+ return protectedDayOfYearTokens.indexOf(token) !== -1;
1723
+ }
1724
+ function isProtectedWeekYearToken(token) {
1725
+ return protectedWeekYearTokens.indexOf(token) !== -1;
1726
+ }
1727
+ function throwProtectedError(token, format, input) {
1728
+ if (token === 'YYYY') {
1729
+ throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
1730
+ } else if (token === 'YY') {
1731
+ throw new RangeError("Use `yy` instead of `YY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
1732
+ } else if (token === 'D') {
1733
+ throw new RangeError("Use `d` instead of `D` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
1734
+ } else if (token === 'DD') {
1735
+ throw new RangeError("Use `dd` instead of `DD` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
1736
+ }
1737
+ }
1738
+
1739
+ var formatDistanceLocale = {
1740
+ lessThanXSeconds: {
1741
+ one: 'less than a second',
1742
+ other: 'less than {{count}} seconds'
1743
+ },
1744
+ xSeconds: {
1745
+ one: '1 second',
1746
+ other: '{{count}} seconds'
1747
+ },
1748
+ halfAMinute: 'half a minute',
1749
+ lessThanXMinutes: {
1750
+ one: 'less than a minute',
1751
+ other: 'less than {{count}} minutes'
1752
+ },
1753
+ xMinutes: {
1754
+ one: '1 minute',
1755
+ other: '{{count}} minutes'
1756
+ },
1757
+ aboutXHours: {
1758
+ one: 'about 1 hour',
1759
+ other: 'about {{count}} hours'
1760
+ },
1761
+ xHours: {
1762
+ one: '1 hour',
1763
+ other: '{{count}} hours'
1764
+ },
1765
+ xDays: {
1766
+ one: '1 day',
1767
+ other: '{{count}} days'
1768
+ },
1769
+ aboutXWeeks: {
1770
+ one: 'about 1 week',
1771
+ other: 'about {{count}} weeks'
1772
+ },
1773
+ xWeeks: {
1774
+ one: '1 week',
1775
+ other: '{{count}} weeks'
1776
+ },
1777
+ aboutXMonths: {
1778
+ one: 'about 1 month',
1779
+ other: 'about {{count}} months'
1780
+ },
1781
+ xMonths: {
1782
+ one: '1 month',
1783
+ other: '{{count}} months'
1784
+ },
1785
+ aboutXYears: {
1786
+ one: 'about 1 year',
1787
+ other: 'about {{count}} years'
1788
+ },
1789
+ xYears: {
1790
+ one: '1 year',
1791
+ other: '{{count}} years'
1792
+ },
1793
+ overXYears: {
1794
+ one: 'over 1 year',
1795
+ other: 'over {{count}} years'
1796
+ },
1797
+ almostXYears: {
1798
+ one: 'almost 1 year',
1799
+ other: 'almost {{count}} years'
1800
+ }
1801
+ };
1802
+ var formatDistance = function formatDistance(token, count, options) {
1803
+ var result;
1804
+ var tokenValue = formatDistanceLocale[token];
1805
+ if (typeof tokenValue === 'string') {
1806
+ result = tokenValue;
1807
+ } else if (count === 1) {
1808
+ result = tokenValue.one;
1809
+ } else {
1810
+ result = tokenValue.other.replace('{{count}}', count.toString());
1811
+ }
1812
+ if (options !== null && options !== void 0 && options.addSuffix) {
1813
+ if (options.comparison && options.comparison > 0) {
1814
+ return 'in ' + result;
1815
+ } else {
1816
+ return result + ' ago';
1817
+ }
1818
+ }
1819
+ return result;
1820
+ };
1821
+
1822
+ function buildFormatLongFn(args) {
1823
+ return function () {
1824
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1825
+ // TODO: Remove String()
1826
+ var width = options.width ? String(options.width) : args.defaultWidth;
1827
+ var format = args.formats[width] || args.formats[args.defaultWidth];
1828
+ return format;
1829
+ };
1830
+ }
1831
+
1832
+ var dateFormats = {
1833
+ full: 'EEEE, MMMM do, y',
1834
+ long: 'MMMM do, y',
1835
+ medium: 'MMM d, y',
1836
+ short: 'MM/dd/yyyy'
1837
+ };
1838
+ var timeFormats = {
1839
+ full: 'h:mm:ss a zzzz',
1840
+ long: 'h:mm:ss a z',
1841
+ medium: 'h:mm:ss a',
1842
+ short: 'h:mm a'
1843
+ };
1844
+ var dateTimeFormats = {
1845
+ full: "{{date}} 'at' {{time}}",
1846
+ long: "{{date}} 'at' {{time}}",
1847
+ medium: '{{date}}, {{time}}',
1848
+ short: '{{date}}, {{time}}'
1849
+ };
1850
+ var formatLong = {
1851
+ date: buildFormatLongFn({
1852
+ formats: dateFormats,
1853
+ defaultWidth: 'full'
1854
+ }),
1855
+ time: buildFormatLongFn({
1856
+ formats: timeFormats,
1857
+ defaultWidth: 'full'
1858
+ }),
1859
+ dateTime: buildFormatLongFn({
1860
+ formats: dateTimeFormats,
1861
+ defaultWidth: 'full'
1862
+ })
1863
+ };
1864
+
1865
+ var formatRelativeLocale = {
1866
+ lastWeek: "'last' eeee 'at' p",
1867
+ yesterday: "'yesterday at' p",
1868
+ today: "'today at' p",
1869
+ tomorrow: "'tomorrow at' p",
1870
+ nextWeek: "eeee 'at' p",
1871
+ other: 'P'
1872
+ };
1873
+ var formatRelative = function formatRelative(token, _date, _baseDate, _options) {
1874
+ return formatRelativeLocale[token];
1875
+ };
1876
+
1877
+ function buildLocalizeFn(args) {
1878
+ return function (dirtyIndex, options) {
1879
+ var context = options !== null && options !== void 0 && options.context ? String(options.context) : 'standalone';
1880
+ var valuesArray;
1881
+ if (context === 'formatting' && args.formattingValues) {
1882
+ var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
1883
+ var width = options !== null && options !== void 0 && options.width ? String(options.width) : defaultWidth;
1884
+ valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
1885
+ } else {
1886
+ var _defaultWidth = args.defaultWidth;
1887
+ var _width = options !== null && options !== void 0 && options.width ? String(options.width) : args.defaultWidth;
1888
+ valuesArray = args.values[_width] || args.values[_defaultWidth];
1889
+ }
1890
+ var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex;
1891
+ // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
1892
+ return valuesArray[index];
1893
+ };
1894
+ }
1895
+
1896
+ var eraValues = {
1897
+ narrow: ['B', 'A'],
1898
+ abbreviated: ['BC', 'AD'],
1899
+ wide: ['Before Christ', 'Anno Domini']
1900
+ };
1901
+ var quarterValues = {
1902
+ narrow: ['1', '2', '3', '4'],
1903
+ abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
1904
+ wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter']
1905
+ };
1906
+
1907
+ // Note: in English, the names of days of the week and months are capitalized.
1908
+ // If you are making a new locale based on this one, check if the same is true for the language you're working on.
1909
+ // Generally, formatted dates should look like they are in the middle of a sentence,
1910
+ // e.g. in Spanish language the weekdays and months should be in the lowercase.
1911
+ var monthValues = {
1912
+ narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
1913
+ abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
1914
+ wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
1915
+ };
1916
+ var dayValues = {
1917
+ narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
1918
+ short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
1919
+ abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
1920
+ wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
1921
+ };
1922
+ var dayPeriodValues = {
1923
+ narrow: {
1924
+ am: 'a',
1925
+ pm: 'p',
1926
+ midnight: 'mi',
1927
+ noon: 'n',
1928
+ morning: 'morning',
1929
+ afternoon: 'afternoon',
1930
+ evening: 'evening',
1931
+ night: 'night'
1932
+ },
1933
+ abbreviated: {
1934
+ am: 'AM',
1935
+ pm: 'PM',
1936
+ midnight: 'midnight',
1937
+ noon: 'noon',
1938
+ morning: 'morning',
1939
+ afternoon: 'afternoon',
1940
+ evening: 'evening',
1941
+ night: 'night'
1942
+ },
1943
+ wide: {
1944
+ am: 'a.m.',
1945
+ pm: 'p.m.',
1946
+ midnight: 'midnight',
1947
+ noon: 'noon',
1948
+ morning: 'morning',
1949
+ afternoon: 'afternoon',
1950
+ evening: 'evening',
1951
+ night: 'night'
1952
+ }
1953
+ };
1954
+ var formattingDayPeriodValues = {
1955
+ narrow: {
1956
+ am: 'a',
1957
+ pm: 'p',
1958
+ midnight: 'mi',
1959
+ noon: 'n',
1960
+ morning: 'in the morning',
1961
+ afternoon: 'in the afternoon',
1962
+ evening: 'in the evening',
1963
+ night: 'at night'
1964
+ },
1965
+ abbreviated: {
1966
+ am: 'AM',
1967
+ pm: 'PM',
1968
+ midnight: 'midnight',
1969
+ noon: 'noon',
1970
+ morning: 'in the morning',
1971
+ afternoon: 'in the afternoon',
1972
+ evening: 'in the evening',
1973
+ night: 'at night'
1974
+ },
1975
+ wide: {
1976
+ am: 'a.m.',
1977
+ pm: 'p.m.',
1978
+ midnight: 'midnight',
1979
+ noon: 'noon',
1980
+ morning: 'in the morning',
1981
+ afternoon: 'in the afternoon',
1982
+ evening: 'in the evening',
1983
+ night: 'at night'
1984
+ }
1985
+ };
1986
+ var ordinalNumber = function ordinalNumber(dirtyNumber, _options) {
1987
+ var number = Number(dirtyNumber);
1988
+
1989
+ // If ordinal numbers depend on context, for example,
1990
+ // if they are different for different grammatical genders,
1991
+ // use `options.unit`.
1992
+ //
1993
+ // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
1994
+ // 'day', 'hour', 'minute', 'second'.
1995
+
1996
+ var rem100 = number % 100;
1997
+ if (rem100 > 20 || rem100 < 10) {
1998
+ switch (rem100 % 10) {
1999
+ case 1:
2000
+ return number + 'st';
2001
+ case 2:
2002
+ return number + 'nd';
2003
+ case 3:
2004
+ return number + 'rd';
2005
+ }
2006
+ }
2007
+ return number + 'th';
2008
+ };
2009
+ var localize = {
2010
+ ordinalNumber: ordinalNumber,
2011
+ era: buildLocalizeFn({
2012
+ values: eraValues,
2013
+ defaultWidth: 'wide'
2014
+ }),
2015
+ quarter: buildLocalizeFn({
2016
+ values: quarterValues,
2017
+ defaultWidth: 'wide',
2018
+ argumentCallback: function argumentCallback(quarter) {
2019
+ return quarter - 1;
2020
+ }
2021
+ }),
2022
+ month: buildLocalizeFn({
2023
+ values: monthValues,
2024
+ defaultWidth: 'wide'
2025
+ }),
2026
+ day: buildLocalizeFn({
2027
+ values: dayValues,
2028
+ defaultWidth: 'wide'
2029
+ }),
2030
+ dayPeriod: buildLocalizeFn({
2031
+ values: dayPeriodValues,
2032
+ defaultWidth: 'wide',
2033
+ formattingValues: formattingDayPeriodValues,
2034
+ defaultFormattingWidth: 'wide'
2035
+ })
2036
+ };
2037
+
2038
+ function buildMatchFn(args) {
2039
+ return function (string) {
2040
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2041
+ var width = options.width;
2042
+ var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
2043
+ var matchResult = string.match(matchPattern);
2044
+ if (!matchResult) {
2045
+ return null;
2046
+ }
2047
+ var matchedString = matchResult[0];
2048
+ var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
2049
+ var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) {
2050
+ return pattern.test(matchedString);
2051
+ }) : findKey(parsePatterns, function (pattern) {
2052
+ return pattern.test(matchedString);
2053
+ });
2054
+ var value;
2055
+ value = args.valueCallback ? args.valueCallback(key) : key;
2056
+ value = options.valueCallback ? options.valueCallback(value) : value;
2057
+ var rest = string.slice(matchedString.length);
2058
+ return {
2059
+ value: value,
2060
+ rest: rest
2061
+ };
2062
+ };
2063
+ }
2064
+ function findKey(object, predicate) {
2065
+ for (var key in object) {
2066
+ if (object.hasOwnProperty(key) && predicate(object[key])) {
2067
+ return key;
2068
+ }
2069
+ }
2070
+ return undefined;
2071
+ }
2072
+ function findIndex(array, predicate) {
2073
+ for (var key = 0; key < array.length; key++) {
2074
+ if (predicate(array[key])) {
2075
+ return key;
2076
+ }
2077
+ }
2078
+ return undefined;
2079
+ }
2080
+
2081
+ function buildMatchPatternFn(args) {
2082
+ return function (string) {
2083
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2084
+ var matchResult = string.match(args.matchPattern);
2085
+ if (!matchResult) return null;
2086
+ var matchedString = matchResult[0];
2087
+ var parseResult = string.match(args.parsePattern);
2088
+ if (!parseResult) return null;
2089
+ var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
2090
+ value = options.valueCallback ? options.valueCallback(value) : value;
2091
+ var rest = string.slice(matchedString.length);
2092
+ return {
2093
+ value: value,
2094
+ rest: rest
2095
+ };
2096
+ };
2097
+ }
2098
+
2099
+ var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
2100
+ var parseOrdinalNumberPattern = /\d+/i;
2101
+ var matchEraPatterns = {
2102
+ narrow: /^(b|a)/i,
2103
+ abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
2104
+ wide: /^(before christ|before common era|anno domini|common era)/i
2105
+ };
2106
+ var parseEraPatterns = {
2107
+ any: [/^b/i, /^(a|c)/i]
2108
+ };
2109
+ var matchQuarterPatterns = {
2110
+ narrow: /^[1234]/i,
2111
+ abbreviated: /^q[1234]/i,
2112
+ wide: /^[1234](th|st|nd|rd)? quarter/i
2113
+ };
2114
+ var parseQuarterPatterns = {
2115
+ any: [/1/i, /2/i, /3/i, /4/i]
2116
+ };
2117
+ var matchMonthPatterns = {
2118
+ narrow: /^[jfmasond]/i,
2119
+ abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
2120
+ wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
2121
+ };
2122
+ var parseMonthPatterns = {
2123
+ narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i],
2124
+ any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i]
2125
+ };
2126
+ var matchDayPatterns = {
2127
+ narrow: /^[smtwf]/i,
2128
+ short: /^(su|mo|tu|we|th|fr|sa)/i,
2129
+ abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
2130
+ wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
2131
+ };
2132
+ var parseDayPatterns = {
2133
+ narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
2134
+ any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
2135
+ };
2136
+ var matchDayPeriodPatterns = {
2137
+ narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
2138
+ any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
2139
+ };
2140
+ var parseDayPeriodPatterns = {
2141
+ any: {
2142
+ am: /^a/i,
2143
+ pm: /^p/i,
2144
+ midnight: /^mi/i,
2145
+ noon: /^no/i,
2146
+ morning: /morning/i,
2147
+ afternoon: /afternoon/i,
2148
+ evening: /evening/i,
2149
+ night: /night/i
2150
+ }
2151
+ };
2152
+ var match = {
2153
+ ordinalNumber: buildMatchPatternFn({
2154
+ matchPattern: matchOrdinalNumberPattern,
2155
+ parsePattern: parseOrdinalNumberPattern,
2156
+ valueCallback: function valueCallback(value) {
2157
+ return parseInt(value, 10);
2158
+ }
2159
+ }),
2160
+ era: buildMatchFn({
2161
+ matchPatterns: matchEraPatterns,
2162
+ defaultMatchWidth: 'wide',
2163
+ parsePatterns: parseEraPatterns,
2164
+ defaultParseWidth: 'any'
2165
+ }),
2166
+ quarter: buildMatchFn({
2167
+ matchPatterns: matchQuarterPatterns,
2168
+ defaultMatchWidth: 'wide',
2169
+ parsePatterns: parseQuarterPatterns,
2170
+ defaultParseWidth: 'any',
2171
+ valueCallback: function valueCallback(index) {
2172
+ return index + 1;
2173
+ }
2174
+ }),
2175
+ month: buildMatchFn({
2176
+ matchPatterns: matchMonthPatterns,
2177
+ defaultMatchWidth: 'wide',
2178
+ parsePatterns: parseMonthPatterns,
2179
+ defaultParseWidth: 'any'
2180
+ }),
2181
+ day: buildMatchFn({
2182
+ matchPatterns: matchDayPatterns,
2183
+ defaultMatchWidth: 'wide',
2184
+ parsePatterns: parseDayPatterns,
2185
+ defaultParseWidth: 'any'
2186
+ }),
2187
+ dayPeriod: buildMatchFn({
2188
+ matchPatterns: matchDayPeriodPatterns,
2189
+ defaultMatchWidth: 'any',
2190
+ parsePatterns: parseDayPeriodPatterns,
2191
+ defaultParseWidth: 'any'
2192
+ })
2193
+ };
2194
+
2195
+ /**
2196
+ * @type {Locale}
2197
+ * @category Locales
2198
+ * @summary English locale (United States).
2199
+ * @language English
2200
+ * @iso-639-2 eng
2201
+ * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}
2202
+ * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}
2203
+ */
2204
+ var locale = {
2205
+ code: 'en-US',
2206
+ formatDistance: formatDistance,
2207
+ formatLong: formatLong,
2208
+ formatRelative: formatRelative,
2209
+ localize: localize,
2210
+ match: match,
2211
+ options: {
2212
+ weekStartsOn: 0 /* Sunday */,
2213
+ firstWeekContainsDate: 1
2214
+ }
2215
+ };
2216
+
2217
+ // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
2218
+ // (one of the certain letters followed by `o`)
2219
+ // - (\w)\1* matches any sequences of the same letter
2220
+ // - '' matches two quote characters in a row
2221
+ // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
2222
+ // except a single quote symbol, which ends the sequence.
2223
+ // Two quote characters do not end the sequence.
2224
+ // If there is no matching single quote
2225
+ // then the sequence will continue until the end of the string.
2226
+ // - . matches any single character unmatched by previous parts of the RegExps
2227
+ var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
2228
+
2229
+ // This RegExp catches symbols escaped by quotes, and also
2230
+ // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
2231
+ var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
2232
+ var escapedStringRegExp = /^'([^]*?)'?$/;
2233
+ var doubleQuoteRegExp = /''/g;
2234
+ var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
2235
+
2236
+ /**
2237
+ * @name format
2238
+ * @category Common Helpers
2239
+ * @summary Format the date.
2240
+ *
2241
+ * @description
2242
+ * Return the formatted date string in the given format. The result may vary by locale.
2243
+ *
2244
+ * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
2245
+ * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2246
+ *
2247
+ * The characters wrapped between two single quotes characters (') are escaped.
2248
+ * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
2249
+ * (see the last example)
2250
+ *
2251
+ * Format of the string is based on Unicode Technical Standard #35:
2252
+ * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
2253
+ * with a few additions (see note 7 below the table).
2254
+ *
2255
+ * Accepted patterns:
2256
+ * | Unit | Pattern | Result examples | Notes |
2257
+ * |---------------------------------|---------|-----------------------------------|-------|
2258
+ * | Era | G..GGG | AD, BC | |
2259
+ * | | GGGG | Anno Domini, Before Christ | 2 |
2260
+ * | | GGGGG | A, B | |
2261
+ * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
2262
+ * | | yo | 44th, 1st, 0th, 17th | 5,7 |
2263
+ * | | yy | 44, 01, 00, 17 | 5 |
2264
+ * | | yyy | 044, 001, 1900, 2017 | 5 |
2265
+ * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
2266
+ * | | yyyyy | ... | 3,5 |
2267
+ * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
2268
+ * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
2269
+ * | | YY | 44, 01, 00, 17 | 5,8 |
2270
+ * | | YYY | 044, 001, 1900, 2017 | 5 |
2271
+ * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
2272
+ * | | YYYYY | ... | 3,5 |
2273
+ * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
2274
+ * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
2275
+ * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
2276
+ * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
2277
+ * | | RRRRR | ... | 3,5,7 |
2278
+ * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
2279
+ * | | uu | -43, 01, 1900, 2017 | 5 |
2280
+ * | | uuu | -043, 001, 1900, 2017 | 5 |
2281
+ * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
2282
+ * | | uuuuu | ... | 3,5 |
2283
+ * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
2284
+ * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
2285
+ * | | QQ | 01, 02, 03, 04 | |
2286
+ * | | QQQ | Q1, Q2, Q3, Q4 | |
2287
+ * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
2288
+ * | | QQQQQ | 1, 2, 3, 4 | 4 |
2289
+ * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
2290
+ * | | qo | 1st, 2nd, 3rd, 4th | 7 |
2291
+ * | | qq | 01, 02, 03, 04 | |
2292
+ * | | qqq | Q1, Q2, Q3, Q4 | |
2293
+ * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
2294
+ * | | qqqqq | 1, 2, 3, 4 | 4 |
2295
+ * | Month (formatting) | M | 1, 2, ..., 12 | |
2296
+ * | | Mo | 1st, 2nd, ..., 12th | 7 |
2297
+ * | | MM | 01, 02, ..., 12 | |
2298
+ * | | MMM | Jan, Feb, ..., Dec | |
2299
+ * | | MMMM | January, February, ..., December | 2 |
2300
+ * | | MMMMM | J, F, ..., D | |
2301
+ * | Month (stand-alone) | L | 1, 2, ..., 12 | |
2302
+ * | | Lo | 1st, 2nd, ..., 12th | 7 |
2303
+ * | | LL | 01, 02, ..., 12 | |
2304
+ * | | LLL | Jan, Feb, ..., Dec | |
2305
+ * | | LLLL | January, February, ..., December | 2 |
2306
+ * | | LLLLL | J, F, ..., D | |
2307
+ * | Local week of year | w | 1, 2, ..., 53 | |
2308
+ * | | wo | 1st, 2nd, ..., 53th | 7 |
2309
+ * | | ww | 01, 02, ..., 53 | |
2310
+ * | ISO week of year | I | 1, 2, ..., 53 | 7 |
2311
+ * | | Io | 1st, 2nd, ..., 53th | 7 |
2312
+ * | | II | 01, 02, ..., 53 | 7 |
2313
+ * | Day of month | d | 1, 2, ..., 31 | |
2314
+ * | | do | 1st, 2nd, ..., 31st | 7 |
2315
+ * | | dd | 01, 02, ..., 31 | |
2316
+ * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
2317
+ * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
2318
+ * | | DD | 01, 02, ..., 365, 366 | 9 |
2319
+ * | | DDD | 001, 002, ..., 365, 366 | |
2320
+ * | | DDDD | ... | 3 |
2321
+ * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
2322
+ * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
2323
+ * | | EEEEE | M, T, W, T, F, S, S | |
2324
+ * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
2325
+ * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
2326
+ * | | io | 1st, 2nd, ..., 7th | 7 |
2327
+ * | | ii | 01, 02, ..., 07 | 7 |
2328
+ * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
2329
+ * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
2330
+ * | | iiiii | M, T, W, T, F, S, S | 7 |
2331
+ * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
2332
+ * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
2333
+ * | | eo | 2nd, 3rd, ..., 1st | 7 |
2334
+ * | | ee | 02, 03, ..., 01 | |
2335
+ * | | eee | Mon, Tue, Wed, ..., Sun | |
2336
+ * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
2337
+ * | | eeeee | M, T, W, T, F, S, S | |
2338
+ * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
2339
+ * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
2340
+ * | | co | 2nd, 3rd, ..., 1st | 7 |
2341
+ * | | cc | 02, 03, ..., 01 | |
2342
+ * | | ccc | Mon, Tue, Wed, ..., Sun | |
2343
+ * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
2344
+ * | | ccccc | M, T, W, T, F, S, S | |
2345
+ * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
2346
+ * | AM, PM | a..aa | AM, PM | |
2347
+ * | | aaa | am, pm | |
2348
+ * | | aaaa | a.m., p.m. | 2 |
2349
+ * | | aaaaa | a, p | |
2350
+ * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
2351
+ * | | bbb | am, pm, noon, midnight | |
2352
+ * | | bbbb | a.m., p.m., noon, midnight | 2 |
2353
+ * | | bbbbb | a, p, n, mi | |
2354
+ * | Flexible day period | B..BBB | at night, in the morning, ... | |
2355
+ * | | BBBB | at night, in the morning, ... | 2 |
2356
+ * | | BBBBB | at night, in the morning, ... | |
2357
+ * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
2358
+ * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
2359
+ * | | hh | 01, 02, ..., 11, 12 | |
2360
+ * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
2361
+ * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
2362
+ * | | HH | 00, 01, 02, ..., 23 | |
2363
+ * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
2364
+ * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
2365
+ * | | KK | 01, 02, ..., 11, 00 | |
2366
+ * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
2367
+ * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
2368
+ * | | kk | 24, 01, 02, ..., 23 | |
2369
+ * | Minute | m | 0, 1, ..., 59 | |
2370
+ * | | mo | 0th, 1st, ..., 59th | 7 |
2371
+ * | | mm | 00, 01, ..., 59 | |
2372
+ * | Second | s | 0, 1, ..., 59 | |
2373
+ * | | so | 0th, 1st, ..., 59th | 7 |
2374
+ * | | ss | 00, 01, ..., 59 | |
2375
+ * | Fraction of second | S | 0, 1, ..., 9 | |
2376
+ * | | SS | 00, 01, ..., 99 | |
2377
+ * | | SSS | 000, 001, ..., 999 | |
2378
+ * | | SSSS | ... | 3 |
2379
+ * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
2380
+ * | | XX | -0800, +0530, Z | |
2381
+ * | | XXX | -08:00, +05:30, Z | |
2382
+ * | | XXXX | -0800, +0530, Z, +123456 | 2 |
2383
+ * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
2384
+ * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
2385
+ * | | xx | -0800, +0530, +0000 | |
2386
+ * | | xxx | -08:00, +05:30, +00:00 | 2 |
2387
+ * | | xxxx | -0800, +0530, +0000, +123456 | |
2388
+ * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
2389
+ * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
2390
+ * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
2391
+ * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
2392
+ * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
2393
+ * | Seconds timestamp | t | 512969520 | 7 |
2394
+ * | | tt | ... | 3,7 |
2395
+ * | Milliseconds timestamp | T | 512969520900 | 7 |
2396
+ * | | TT | ... | 3,7 |
2397
+ * | Long localized date | P | 04/29/1453 | 7 |
2398
+ * | | PP | Apr 29, 1453 | 7 |
2399
+ * | | PPP | April 29th, 1453 | 7 |
2400
+ * | | PPPP | Friday, April 29th, 1453 | 2,7 |
2401
+ * | Long localized time | p | 12:00 AM | 7 |
2402
+ * | | pp | 12:00:00 AM | 7 |
2403
+ * | | ppp | 12:00:00 AM GMT+2 | 7 |
2404
+ * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
2405
+ * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
2406
+ * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
2407
+ * | | PPPppp | April 29th, 1453 at ... | 7 |
2408
+ * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
2409
+ * Notes:
2410
+ * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
2411
+ * are the same as "stand-alone" units, but are different in some languages.
2412
+ * "Formatting" units are declined according to the rules of the language
2413
+ * in the context of a date. "Stand-alone" units are always nominative singular:
2414
+ *
2415
+ * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
2416
+ *
2417
+ * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
2418
+ *
2419
+ * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
2420
+ * the single quote characters (see below).
2421
+ * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
2422
+ * the output will be the same as default pattern for this unit, usually
2423
+ * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
2424
+ * are marked with "2" in the last column of the table.
2425
+ *
2426
+ * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
2427
+ *
2428
+ * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
2429
+ *
2430
+ * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
2431
+ *
2432
+ * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
2433
+ *
2434
+ * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
2435
+ *
2436
+ * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
2437
+ * The output will be padded with zeros to match the length of the pattern.
2438
+ *
2439
+ * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
2440
+ *
2441
+ * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
2442
+ * These tokens represent the shortest form of the quarter.
2443
+ *
2444
+ * 5. The main difference between `y` and `u` patterns are B.C. years:
2445
+ *
2446
+ * | Year | `y` | `u` |
2447
+ * |------|-----|-----|
2448
+ * | AC 1 | 1 | 1 |
2449
+ * | BC 1 | 1 | 0 |
2450
+ * | BC 2 | 2 | -1 |
2451
+ *
2452
+ * Also `yy` always returns the last two digits of a year,
2453
+ * while `uu` pads single digit years to 2 characters and returns other years unchanged:
2454
+ *
2455
+ * | Year | `yy` | `uu` |
2456
+ * |------|------|------|
2457
+ * | 1 | 01 | 01 |
2458
+ * | 14 | 14 | 14 |
2459
+ * | 376 | 76 | 376 |
2460
+ * | 1453 | 53 | 1453 |
2461
+ *
2462
+ * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
2463
+ * except local week-numbering years are dependent on `options.weekStartsOn`
2464
+ * and `options.firstWeekContainsDate` (compare [getISOWeekYear]{@link https://date-fns.org/docs/getISOWeekYear}
2465
+ * and [getWeekYear]{@link https://date-fns.org/docs/getWeekYear}).
2466
+ *
2467
+ * 6. Specific non-location timezones are currently unavailable in `date-fns`,
2468
+ * so right now these tokens fall back to GMT timezones.
2469
+ *
2470
+ * 7. These patterns are not in the Unicode Technical Standard #35:
2471
+ * - `i`: ISO day of week
2472
+ * - `I`: ISO week of year
2473
+ * - `R`: ISO week-numbering year
2474
+ * - `t`: seconds timestamp
2475
+ * - `T`: milliseconds timestamp
2476
+ * - `o`: ordinal number modifier
2477
+ * - `P`: long localized date
2478
+ * - `p`: long localized time
2479
+ *
2480
+ * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
2481
+ * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2482
+ *
2483
+ * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
2484
+ * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2485
+ *
2486
+ * @param {Date|Number} date - the original date
2487
+ * @param {String} format - the string of tokens
2488
+ * @param {Object} [options] - an object with options.
2489
+ * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
2490
+ * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
2491
+ * @param {Number} [options.firstWeekContainsDate=1] - the day of January, which is
2492
+ * @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`;
2493
+ * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2494
+ * @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`;
2495
+ * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2496
+ * @returns {String} the formatted date string
2497
+ * @throws {TypeError} 2 arguments required
2498
+ * @throws {RangeError} `date` must not be Invalid Date
2499
+ * @throws {RangeError} `options.locale` must contain `localize` property
2500
+ * @throws {RangeError} `options.locale` must contain `formatLong` property
2501
+ * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
2502
+ * @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7
2503
+ * @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
2504
+ * @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
2505
+ * @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
2506
+ * @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
2507
+ * @throws {RangeError} format string contains an unescaped latin alphabet character
2508
+ *
2509
+ * @example
2510
+ * // Represent 11 February 2014 in middle-endian format:
2511
+ * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
2512
+ * //=> '02/11/2014'
2513
+ *
2514
+ * @example
2515
+ * // Represent 2 July 2014 in Esperanto:
2516
+ * import { eoLocale } from 'date-fns/locale/eo'
2517
+ * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
2518
+ * locale: eoLocale
2519
+ * })
2520
+ * //=> '2-a de julio 2014'
2521
+ *
2522
+ * @example
2523
+ * // Escape string by single quote characters:
2524
+ * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
2525
+ * //=> "3 o'clock"
2526
+ */
2527
+
2528
+ function format(dirtyDate, dirtyFormatStr, options) {
2529
+ 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;
2530
+ requiredArgs(2, arguments);
2531
+ var formatStr = String(dirtyFormatStr);
2532
+ var defaultOptions = getDefaultOptions();
2533
+ var locale$1 = (_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 : locale;
2534
+ var firstWeekContainsDate = toInteger$1((_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);
2535
+
2536
+ // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
2537
+ if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
2538
+ throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
2539
+ }
2540
+ var weekStartsOn = toInteger$1((_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);
2541
+
2542
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
2543
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
2544
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
2545
+ }
2546
+ if (!locale$1.localize) {
2547
+ throw new RangeError('locale must contain localize property');
2548
+ }
2549
+ if (!locale$1.formatLong) {
2550
+ throw new RangeError('locale must contain formatLong property');
2551
+ }
2552
+ var originalDate = toDate(dirtyDate);
2553
+ if (!isValid(originalDate)) {
2554
+ throw new RangeError('Invalid time value');
2555
+ }
2556
+
2557
+ // Convert the date in system timezone to the same date in UTC+00:00 timezone.
2558
+ // This ensures that when UTC functions will be implemented, locales will be compatible with them.
2559
+ // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376
2560
+ var timezoneOffset = getTimezoneOffsetInMilliseconds(originalDate);
2561
+ var utcDate = subMilliseconds(originalDate, timezoneOffset);
2562
+ var formatterOptions = {
2563
+ firstWeekContainsDate: firstWeekContainsDate,
2564
+ weekStartsOn: weekStartsOn,
2565
+ locale: locale$1,
2566
+ _originalDate: originalDate
2567
+ };
2568
+ var result = formatStr.match(longFormattingTokensRegExp).map(function (substring) {
2569
+ var firstCharacter = substring[0];
2570
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
2571
+ var longFormatter = longFormatters[firstCharacter];
2572
+ return longFormatter(substring, locale$1.formatLong);
2573
+ }
2574
+ return substring;
2575
+ }).join('').match(formattingTokensRegExp).map(function (substring) {
2576
+ // Replace two single quote characters with one single quote character
2577
+ if (substring === "''") {
2578
+ return "'";
2579
+ }
2580
+ var firstCharacter = substring[0];
2581
+ if (firstCharacter === "'") {
2582
+ return cleanEscapedString(substring);
2583
+ }
2584
+ var formatter = formatters[firstCharacter];
2585
+ if (formatter) {
2586
+ if (!(options !== null && options !== void 0 && options.useAdditionalWeekYearTokens) && isProtectedWeekYearToken(substring)) {
2587
+ throwProtectedError(substring, dirtyFormatStr, String(dirtyDate));
2588
+ }
2589
+ if (!(options !== null && options !== void 0 && options.useAdditionalDayOfYearTokens) && isProtectedDayOfYearToken(substring)) {
2590
+ throwProtectedError(substring, dirtyFormatStr, String(dirtyDate));
2591
+ }
2592
+ return formatter(utcDate, substring, locale$1.localize, formatterOptions);
2593
+ }
2594
+ if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
2595
+ throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`');
2596
+ }
2597
+ return substring;
2598
+ }).join('');
2599
+ return result;
2600
+ }
2601
+ function cleanEscapedString(input) {
2602
+ var matched = input.match(escapedStringRegExp);
2603
+ if (!matched) {
2604
+ return input;
2605
+ }
2606
+ return matched[1].replace(doubleQuoteRegExp, "'");
2607
+ }
2608
+
2609
+ /**
2610
+ * @name formatISO
2611
+ * @category Common Helpers
2612
+ * @summary Format the date according to the ISO 8601 standard (https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003169814.htm).
2613
+ *
2614
+ * @description
2615
+ * Return the formatted date string in ISO 8601 format. Options may be passed to control the parts and notations of the date.
2616
+ *
2617
+ * @param {Date|Number} date - the original date
2618
+ * @param {Object} [options] - an object with options.
2619
+ * @param {'extended'|'basic'} [options.format='extended'] - if 'basic', hide delimiters between date and time values.
2620
+ * @param {'complete'|'date'|'time'} [options.representation='complete'] - format date, time with local time zone, or both.
2621
+ * @returns {String} the formatted date string (in local time zone)
2622
+ * @throws {TypeError} 1 argument required
2623
+ * @throws {RangeError} `date` must not be Invalid Date
2624
+ * @throws {RangeError} `options.format` must be 'extended' or 'basic'
2625
+ * @throws {RangeError} `options.representation` must be 'date', 'time' or 'complete'
2626
+ *
2627
+ * @example
2628
+ * // Represent 18 September 2019 in ISO 8601 format (local time zone is UTC):
2629
+ * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52))
2630
+ * //=> '2019-09-18T19:00:52Z'
2631
+ *
2632
+ * @example
2633
+ * // Represent 18 September 2019 in ISO 8601, short format (local time zone is UTC):
2634
+ * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { format: 'basic' })
2635
+ * //=> '20190918T190052'
2636
+ *
2637
+ * @example
2638
+ * // Represent 18 September 2019 in ISO 8601 format, date only:
2639
+ * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { representation: 'date' })
2640
+ * //=> '2019-09-18'
2641
+ *
2642
+ * @example
2643
+ * // Represent 18 September 2019 in ISO 8601 format, time only (local time zone is UTC):
2644
+ * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { representation: 'time' })
2645
+ * //=> '19:00:52Z'
2646
+ */
2647
+ function formatISO(date, options) {
2648
+ var _options$format, _options$representati;
2649
+ requiredArgs(1, arguments);
2650
+ var originalDate = toDate(date);
2651
+ if (isNaN(originalDate.getTime())) {
2652
+ throw new RangeError('Invalid time value');
2653
+ }
2654
+ var format = String((_options$format = void 0 ) !== null && _options$format !== void 0 ? _options$format : 'extended');
2655
+ var representation = String((_options$representati = void 0 ) !== null && _options$representati !== void 0 ? _options$representati : 'complete');
2656
+ if (format !== 'extended' && format !== 'basic') {
2657
+ throw new RangeError("format must be 'extended' or 'basic'");
2658
+ }
2659
+ if (representation !== 'date' && representation !== 'time' && representation !== 'complete') {
2660
+ throw new RangeError("representation must be 'date', 'time', or 'complete'");
2661
+ }
2662
+ var result = '';
2663
+ var tzOffset = '';
2664
+ var dateDelimiter = format === 'extended' ? '-' : '';
2665
+ var timeDelimiter = format === 'extended' ? ':' : '';
2666
+
2667
+ // Representation is either 'date' or 'complete'
2668
+ if (representation !== 'time') {
2669
+ var day = addLeadingZeros(originalDate.getDate(), 2);
2670
+ var month = addLeadingZeros(originalDate.getMonth() + 1, 2);
2671
+ var year = addLeadingZeros(originalDate.getFullYear(), 4);
2672
+
2673
+ // yyyyMMdd or yyyy-MM-dd.
2674
+ result = "".concat(year).concat(dateDelimiter).concat(month).concat(dateDelimiter).concat(day);
2675
+ }
2676
+
2677
+ // Representation is either 'time' or 'complete'
2678
+ if (representation !== 'date') {
2679
+ // Add the timezone.
2680
+ var offset = originalDate.getTimezoneOffset();
2681
+ if (offset !== 0) {
2682
+ var absoluteOffset = Math.abs(offset);
2683
+ var hourOffset = addLeadingZeros(Math.floor(absoluteOffset / 60), 2);
2684
+ var minuteOffset = addLeadingZeros(absoluteOffset % 60, 2);
2685
+ // If less than 0, the sign is +, because it is ahead of time.
2686
+ var sign = offset < 0 ? '+' : '-';
2687
+ tzOffset = "".concat(sign).concat(hourOffset, ":").concat(minuteOffset);
2688
+ } else {
2689
+ tzOffset = 'Z';
2690
+ }
2691
+ var hour = addLeadingZeros(originalDate.getHours(), 2);
2692
+ var minute = addLeadingZeros(originalDate.getMinutes(), 2);
2693
+ var second = addLeadingZeros(originalDate.getSeconds(), 2);
2694
+
2695
+ // If there's also date, separate it with time with 'T'
2696
+ var separator = result === '' ? '' : 'T';
2697
+
2698
+ // Creates a time string consisting of hour, minute, and second, separated by delimiters, if defined.
2699
+ var time = [hour, minute, second].join(timeDelimiter);
2700
+
2701
+ // HHmmss or HH:mm:ss.
2702
+ result = "".concat(result).concat(separator).concat(time).concat(tzOffset);
2703
+ }
2704
+ return result;
2705
+ }
2706
+
2707
+ /**
2708
+ * @name getDaysInMonth
2709
+ * @category Month Helpers
2710
+ * @summary Get the number of days in a month of the given date.
2711
+ *
2712
+ * @description
2713
+ * Get the number of days in a month of the given date.
2714
+ *
2715
+ * @param {Date|Number} date - the given date
2716
+ * @returns {Number} the number of days in a month
2717
+ * @throws {TypeError} 1 argument required
2718
+ *
2719
+ * @example
2720
+ * // How many days are in February 2000?
2721
+ * const result = getDaysInMonth(new Date(2000, 1))
2722
+ * //=> 29
2723
+ */
2724
+ function getDaysInMonth(dirtyDate) {
2725
+ requiredArgs(1, arguments);
2726
+ var date = toDate(dirtyDate);
2727
+ var year = date.getFullYear();
2728
+ var monthIndex = date.getMonth();
2729
+ var lastDayOfMonth = new Date(0);
2730
+ lastDayOfMonth.setFullYear(year, monthIndex + 1, 0);
2731
+ lastDayOfMonth.setHours(0, 0, 0, 0);
2732
+ return lastDayOfMonth.getDate();
2733
+ }
2734
+
2735
+ /**
2736
+ * @name getYear
2737
+ * @category Year Helpers
2738
+ * @summary Get the year of the given date.
2739
+ *
2740
+ * @description
2741
+ * Get the year of the given date.
2742
+ *
2743
+ * @param {Date|Number} date - the given date
2744
+ * @returns {Number} the year
2745
+ * @throws {TypeError} 1 argument required
2746
+ *
2747
+ * @example
2748
+ * // Which year is 2 July 2014?
2749
+ * const result = getYear(new Date(2014, 6, 2))
2750
+ * //=> 2014
2751
+ */
2752
+ function getYear(dirtyDate) {
2753
+ requiredArgs(1, arguments);
2754
+ return toDate(dirtyDate).getFullYear();
2755
+ }
2756
+
2757
+ /**
2758
+ * @name isAfter
2759
+ * @category Common Helpers
2760
+ * @summary Is the first date after the second one?
2761
+ *
2762
+ * @description
2763
+ * Is the first date after the second one?
2764
+ *
2765
+ * @param {Date|Number} date - the date that should be after the other one to return true
2766
+ * @param {Date|Number} dateToCompare - the date to compare with
2767
+ * @returns {Boolean} the first date is after the second date
2768
+ * @throws {TypeError} 2 arguments required
2769
+ *
2770
+ * @example
2771
+ * // Is 10 July 1989 after 11 February 1987?
2772
+ * const result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
2773
+ * //=> true
2774
+ */
2775
+ function isAfter(dirtyDate, dirtyDateToCompare) {
2776
+ requiredArgs(2, arguments);
2777
+ var date = toDate(dirtyDate);
2778
+ var dateToCompare = toDate(dirtyDateToCompare);
2779
+ return date.getTime() > dateToCompare.getTime();
2780
+ }
2781
+
2782
+ /**
2783
+ * @name isBefore
2784
+ * @category Common Helpers
2785
+ * @summary Is the first date before the second one?
2786
+ *
2787
+ * @description
2788
+ * Is the first date before the second one?
2789
+ *
2790
+ * @param {Date|Number} date - the date that should be before the other one to return true
2791
+ * @param {Date|Number} dateToCompare - the date to compare with
2792
+ * @returns {Boolean} the first date is before the second date
2793
+ * @throws {TypeError} 2 arguments required
2794
+ *
2795
+ * @example
2796
+ * // Is 10 July 1989 before 11 February 1987?
2797
+ * const result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))
2798
+ * //=> false
2799
+ */
2800
+ function isBefore(dirtyDate, dirtyDateToCompare) {
2801
+ requiredArgs(2, arguments);
2802
+ var date = toDate(dirtyDate);
2803
+ var dateToCompare = toDate(dirtyDateToCompare);
2804
+ return date.getTime() < dateToCompare.getTime();
2805
+ }
2806
+
2807
+ /**
2808
+ * @name isSameMonth
2809
+ * @category Month Helpers
2810
+ * @summary Are the given dates in the same month (and year)?
2811
+ *
2812
+ * @description
2813
+ * Are the given dates in the same month (and year)?
2814
+ *
2815
+ * @param {Date|Number} dateLeft - the first date to check
2816
+ * @param {Date|Number} dateRight - the second date to check
2817
+ * @returns {Boolean} the dates are in the same month (and year)
2818
+ * @throws {TypeError} 2 arguments required
2819
+ *
2820
+ * @example
2821
+ * // Are 2 September 2014 and 25 September 2014 in the same month?
2822
+ * const result = isSameMonth(new Date(2014, 8, 2), new Date(2014, 8, 25))
2823
+ * //=> true
2824
+ *
2825
+ * @example
2826
+ * // Are 2 September 2014 and 25 September 2015 in the same month?
2827
+ * const result = isSameMonth(new Date(2014, 8, 2), new Date(2015, 8, 25))
2828
+ * //=> false
2829
+ */
2830
+ function isSameMonth(dirtyDateLeft, dirtyDateRight) {
2831
+ requiredArgs(2, arguments);
2832
+ var dateLeft = toDate(dirtyDateLeft);
2833
+ var dateRight = toDate(dirtyDateRight);
2834
+ return dateLeft.getFullYear() === dateRight.getFullYear() && dateLeft.getMonth() === dateRight.getMonth();
2835
+ }
2836
+
2837
+ /**
2838
+ * @name parseISO
2839
+ * @category Common Helpers
2840
+ * @summary Parse ISO string
2841
+ *
2842
+ * @description
2843
+ * Parse the given string in ISO 8601 format and return an instance of Date.
2844
+ *
2845
+ * Function accepts complete ISO 8601 formats as well as partial implementations.
2846
+ * ISO 8601: http://en.wikipedia.org/wiki/ISO_8601
2847
+ *
2848
+ * If the argument isn't a string, the function cannot parse the string or
2849
+ * the values are invalid, it returns Invalid Date.
2850
+ *
2851
+ * @param {String} argument - the value to convert
2852
+ * @param {Object} [options] - an object with options.
2853
+ * @param {0|1|2} [options.additionalDigits=2] - the additional number of digits in the extended year format
2854
+ * @returns {Date} the parsed date in the local time zone
2855
+ * @throws {TypeError} 1 argument required
2856
+ * @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
2857
+ *
2858
+ * @example
2859
+ * // Convert string '2014-02-11T11:30:30' to date:
2860
+ * const result = parseISO('2014-02-11T11:30:30')
2861
+ * //=> Tue Feb 11 2014 11:30:30
2862
+ *
2863
+ * @example
2864
+ * // Convert string '+02014101' to date,
2865
+ * // if the additional number of digits in the extended year format is 1:
2866
+ * const result = parseISO('+02014101', { additionalDigits: 1 })
2867
+ * //=> Fri Apr 11 2014 00:00:00
2868
+ */
2869
+ function parseISO(argument, options) {
2870
+ var _options$additionalDi;
2871
+ requiredArgs(1, arguments);
2872
+ var additionalDigits = toInteger$1((_options$additionalDi = void 0 ) !== null && _options$additionalDi !== void 0 ? _options$additionalDi : 2);
2873
+ if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) {
2874
+ throw new RangeError('additionalDigits must be 0, 1 or 2');
2875
+ }
2876
+ if (!(typeof argument === 'string' || Object.prototype.toString.call(argument) === '[object String]')) {
2877
+ return new Date(NaN);
2878
+ }
2879
+ var dateStrings = splitDateString(argument);
2880
+ var date;
2881
+ if (dateStrings.date) {
2882
+ var parseYearResult = parseYear(dateStrings.date, additionalDigits);
2883
+ date = parseDate(parseYearResult.restDateString, parseYearResult.year);
2884
+ }
2885
+ if (!date || isNaN(date.getTime())) {
2886
+ return new Date(NaN);
2887
+ }
2888
+ var timestamp = date.getTime();
2889
+ var time = 0;
2890
+ var offset;
2891
+ if (dateStrings.time) {
2892
+ time = parseTime(dateStrings.time);
2893
+ if (isNaN(time)) {
2894
+ return new Date(NaN);
2895
+ }
2896
+ }
2897
+ if (dateStrings.timezone) {
2898
+ offset = parseTimezone(dateStrings.timezone);
2899
+ if (isNaN(offset)) {
2900
+ return new Date(NaN);
2901
+ }
2902
+ } else {
2903
+ var dirtyDate = new Date(timestamp + time);
2904
+ // js parsed string assuming it's in UTC timezone
2905
+ // but we need it to be parsed in our timezone
2906
+ // so we use utc values to build date in our timezone.
2907
+ // Year values from 0 to 99 map to the years 1900 to 1999
2908
+ // so set year explicitly with setFullYear.
2909
+ var result = new Date(0);
2910
+ result.setFullYear(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate());
2911
+ result.setHours(dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds());
2912
+ return result;
2913
+ }
2914
+ return new Date(timestamp + time + offset);
2915
+ }
2916
+ var patterns = {
2917
+ dateTimeDelimiter: /[T ]/,
2918
+ timeZoneDelimiter: /[Z ]/i,
2919
+ timezone: /([Z+-].*)$/
2920
+ };
2921
+ var dateRegex = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/;
2922
+ var timeRegex = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/;
2923
+ var timezoneRegex = /^([+-])(\d{2})(?::?(\d{2}))?$/;
2924
+ function splitDateString(dateString) {
2925
+ var dateStrings = {};
2926
+ var array = dateString.split(patterns.dateTimeDelimiter);
2927
+ var timeString;
2928
+
2929
+ // The regex match should only return at maximum two array elements.
2930
+ // [date], [time], or [date, time].
2931
+ if (array.length > 2) {
2932
+ return dateStrings;
2933
+ }
2934
+ if (/:/.test(array[0])) {
2935
+ timeString = array[0];
2936
+ } else {
2937
+ dateStrings.date = array[0];
2938
+ timeString = array[1];
2939
+ if (patterns.timeZoneDelimiter.test(dateStrings.date)) {
2940
+ dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0];
2941
+ timeString = dateString.substr(dateStrings.date.length, dateString.length);
2942
+ }
2943
+ }
2944
+ if (timeString) {
2945
+ var token = patterns.timezone.exec(timeString);
2946
+ if (token) {
2947
+ dateStrings.time = timeString.replace(token[1], '');
2948
+ dateStrings.timezone = token[1];
2949
+ } else {
2950
+ dateStrings.time = timeString;
2951
+ }
2952
+ }
2953
+ return dateStrings;
2954
+ }
2955
+ function parseYear(dateString, additionalDigits) {
2956
+ var regex = new RegExp('^(?:(\\d{4}|[+-]\\d{' + (4 + additionalDigits) + '})|(\\d{2}|[+-]\\d{' + (2 + additionalDigits) + '})$)');
2957
+ var captures = dateString.match(regex);
2958
+ // Invalid ISO-formatted year
2959
+ if (!captures) return {
2960
+ year: NaN,
2961
+ restDateString: ''
2962
+ };
2963
+ var year = captures[1] ? parseInt(captures[1]) : null;
2964
+ var century = captures[2] ? parseInt(captures[2]) : null;
2965
+
2966
+ // either year or century is null, not both
2967
+ return {
2968
+ year: century === null ? year : century * 100,
2969
+ restDateString: dateString.slice((captures[1] || captures[2]).length)
2970
+ };
2971
+ }
2972
+ function parseDate(dateString, year) {
2973
+ // Invalid ISO-formatted year
2974
+ if (year === null) return new Date(NaN);
2975
+ var captures = dateString.match(dateRegex);
2976
+ // Invalid ISO-formatted string
2977
+ if (!captures) return new Date(NaN);
2978
+ var isWeekDate = !!captures[4];
2979
+ var dayOfYear = parseDateUnit(captures[1]);
2980
+ var month = parseDateUnit(captures[2]) - 1;
2981
+ var day = parseDateUnit(captures[3]);
2982
+ var week = parseDateUnit(captures[4]);
2983
+ var dayOfWeek = parseDateUnit(captures[5]) - 1;
2984
+ if (isWeekDate) {
2985
+ if (!validateWeekDate(year, week, dayOfWeek)) {
2986
+ return new Date(NaN);
2987
+ }
2988
+ return dayOfISOWeekYear(year, week, dayOfWeek);
2989
+ } else {
2990
+ var date = new Date(0);
2991
+ if (!validateDate(year, month, day) || !validateDayOfYearDate(year, dayOfYear)) {
2992
+ return new Date(NaN);
2993
+ }
2994
+ date.setUTCFullYear(year, month, Math.max(dayOfYear, day));
2995
+ return date;
2996
+ }
2997
+ }
2998
+ function parseDateUnit(value) {
2999
+ return value ? parseInt(value) : 1;
3000
+ }
3001
+ function parseTime(timeString) {
3002
+ var captures = timeString.match(timeRegex);
3003
+ if (!captures) return NaN; // Invalid ISO-formatted time
3004
+
3005
+ var hours = parseTimeUnit(captures[1]);
3006
+ var minutes = parseTimeUnit(captures[2]);
3007
+ var seconds = parseTimeUnit(captures[3]);
3008
+ if (!validateTime(hours, minutes, seconds)) {
3009
+ return NaN;
3010
+ }
3011
+ return hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * 1000;
3012
+ }
3013
+ function parseTimeUnit(value) {
3014
+ return value && parseFloat(value.replace(',', '.')) || 0;
3015
+ }
3016
+ function parseTimezone(timezoneString) {
3017
+ if (timezoneString === 'Z') return 0;
3018
+ var captures = timezoneString.match(timezoneRegex);
3019
+ if (!captures) return 0;
3020
+ var sign = captures[1] === '+' ? -1 : 1;
3021
+ var hours = parseInt(captures[2]);
3022
+ var minutes = captures[3] && parseInt(captures[3]) || 0;
3023
+ if (!validateTimezone(hours, minutes)) {
3024
+ return NaN;
3025
+ }
3026
+ return sign * (hours * millisecondsInHour + minutes * millisecondsInMinute);
3027
+ }
3028
+ function dayOfISOWeekYear(isoWeekYear, week, day) {
3029
+ var date = new Date(0);
3030
+ date.setUTCFullYear(isoWeekYear, 0, 4);
3031
+ var fourthOfJanuaryDay = date.getUTCDay() || 7;
3032
+ var diff = (week - 1) * 7 + day + 1 - fourthOfJanuaryDay;
3033
+ date.setUTCDate(date.getUTCDate() + diff);
3034
+ return date;
3035
+ }
3036
+
3037
+ // Validation functions
3038
+
3039
+ // February is null to handle the leap year (using ||)
3040
+ var daysInMonths = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
3041
+ function isLeapYearIndex(year) {
3042
+ return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
3043
+ }
3044
+ function validateDate(year, month, date) {
3045
+ return month >= 0 && month <= 11 && date >= 1 && date <= (daysInMonths[month] || (isLeapYearIndex(year) ? 29 : 28));
3046
+ }
3047
+ function validateDayOfYearDate(year, dayOfYear) {
3048
+ return dayOfYear >= 1 && dayOfYear <= (isLeapYearIndex(year) ? 366 : 365);
3049
+ }
3050
+ function validateWeekDate(_year, week, day) {
3051
+ return week >= 1 && week <= 53 && day >= 0 && day <= 6;
3052
+ }
3053
+ function validateTime(hours, minutes, seconds) {
3054
+ if (hours === 24) {
3055
+ return minutes === 0 && seconds === 0;
3056
+ }
3057
+ return seconds >= 0 && seconds < 60 && minutes >= 0 && minutes < 60 && hours >= 0 && hours < 25;
3058
+ }
3059
+ function validateTimezone(_hours, minutes) {
3060
+ return minutes >= 0 && minutes <= 59;
3061
+ }
3062
+
3063
+ /**
3064
+ * @name setMonth
3065
+ * @category Month Helpers
3066
+ * @summary Set the month to the given date.
3067
+ *
3068
+ * @description
3069
+ * Set the month to the given date.
3070
+ *
3071
+ * @param {Date|Number} date - the date to be changed
3072
+ * @param {Number} month - the month of the new date
3073
+ * @returns {Date} the new date with the month set
3074
+ * @throws {TypeError} 2 arguments required
3075
+ *
3076
+ * @example
3077
+ * // Set February to 1 September 2014:
3078
+ * const result = setMonth(new Date(2014, 8, 1), 1)
3079
+ * //=> Sat Feb 01 2014 00:00:00
3080
+ */
3081
+ function setMonth(dirtyDate, dirtyMonth) {
3082
+ requiredArgs(2, arguments);
3083
+ var date = toDate(dirtyDate);
3084
+ var month = toInteger$1(dirtyMonth);
3085
+ var year = date.getFullYear();
3086
+ var day = date.getDate();
3087
+ var dateWithDesiredMonth = new Date(0);
3088
+ dateWithDesiredMonth.setFullYear(year, month, 15);
3089
+ dateWithDesiredMonth.setHours(0, 0, 0, 0);
3090
+ var daysInMonth = getDaysInMonth(dateWithDesiredMonth);
3091
+ // Set the last day of the new month
3092
+ // if the original date was the last day of the longer month
3093
+ date.setMonth(month, Math.min(day, daysInMonth));
3094
+ return date;
3095
+ }
3096
+
3097
+ /**
3098
+ * @name setYear
3099
+ * @category Year Helpers
3100
+ * @summary Set the year to the given date.
3101
+ *
3102
+ * @description
3103
+ * Set the year to the given date.
3104
+ *
3105
+ * @param {Date|Number} date - the date to be changed
3106
+ * @param {Number} year - the year of the new date
3107
+ * @returns {Date} the new date with the year set
3108
+ * @throws {TypeError} 2 arguments required
3109
+ *
3110
+ * @example
3111
+ * // Set year 2013 to 1 September 2014:
3112
+ * const result = setYear(new Date(2014, 8, 1), 2013)
3113
+ * //=> Sun Sep 01 2013 00:00:00
3114
+ */
3115
+ function setYear(dirtyDate, dirtyYear) {
3116
+ requiredArgs(2, arguments);
3117
+ var date = toDate(dirtyDate);
3118
+ var year = toInteger$1(dirtyYear);
3119
+
3120
+ // Check if date is Invalid Date because Date.prototype.setFullYear ignores the value of Invalid Date
3121
+ if (isNaN(date.getTime())) {
3122
+ return new Date(NaN);
3123
+ }
3124
+ date.setFullYear(year);
3125
+ return date;
3126
+ }
3127
+
3128
+ /**
3129
+ * The base implementation of `_.slice` without an iteratee call guard.
3130
+ *
3131
+ * @private
3132
+ * @param {Array} array The array to slice.
3133
+ * @param {number} [start=0] The start position.
3134
+ * @param {number} [end=array.length] The end position.
3135
+ * @returns {Array} Returns the slice of `array`.
3136
+ */
3137
+ function baseSlice(array, start, end) {
3138
+ var index = -1,
3139
+ length = array.length;
3140
+
3141
+ if (start < 0) {
3142
+ start = -start > length ? 0 : (length + start);
3143
+ }
3144
+ end = end > length ? length : end;
3145
+ if (end < 0) {
3146
+ end += length;
3147
+ }
3148
+ length = start > end ? 0 : ((end - start) >>> 0);
3149
+ start >>>= 0;
3150
+
3151
+ var result = Array(length);
3152
+ while (++index < length) {
3153
+ result[index] = array[index + start];
3154
+ }
3155
+ return result;
3156
+ }
3157
+
3158
+ /** Detect free variable `global` from Node.js. */
3159
+ var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
3160
+
3161
+ /** Detect free variable `self`. */
3162
+ var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
3163
+
3164
+ /** Used as a reference to the global object. */
3165
+ var root = freeGlobal || freeSelf || Function('return this')();
3166
+
3167
+ /** Built-in value references. */
3168
+ var Symbol = root.Symbol;
3169
+
3170
+ /** Used for built-in method references. */
3171
+ var objectProto$1 = Object.prototype;
3172
+
3173
+ /** Used to check objects for own properties. */
3174
+ var hasOwnProperty = objectProto$1.hasOwnProperty;
3175
+
3176
+ /**
3177
+ * Used to resolve the
3178
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
3179
+ * of values.
3180
+ */
3181
+ var nativeObjectToString$1 = objectProto$1.toString;
3182
+
3183
+ /** Built-in value references. */
3184
+ var symToStringTag$1 = Symbol ? Symbol.toStringTag : undefined;
3185
+
3186
+ /**
3187
+ * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
3188
+ *
3189
+ * @private
3190
+ * @param {*} value The value to query.
3191
+ * @returns {string} Returns the raw `toStringTag`.
3192
+ */
3193
+ function getRawTag(value) {
3194
+ var isOwn = hasOwnProperty.call(value, symToStringTag$1),
3195
+ tag = value[symToStringTag$1];
3196
+
3197
+ try {
3198
+ value[symToStringTag$1] = undefined;
3199
+ var unmasked = true;
3200
+ } catch (e) {}
3201
+
3202
+ var result = nativeObjectToString$1.call(value);
3203
+ if (unmasked) {
3204
+ if (isOwn) {
3205
+ value[symToStringTag$1] = tag;
3206
+ } else {
3207
+ delete value[symToStringTag$1];
3208
+ }
3209
+ }
3210
+ return result;
3211
+ }
3212
+
3213
+ /** Used for built-in method references. */
3214
+ var objectProto = Object.prototype;
3215
+
3216
+ /**
3217
+ * Used to resolve the
3218
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
3219
+ * of values.
3220
+ */
3221
+ var nativeObjectToString = objectProto.toString;
3222
+
3223
+ /**
3224
+ * Converts `value` to a string using `Object.prototype.toString`.
3225
+ *
3226
+ * @private
3227
+ * @param {*} value The value to convert.
3228
+ * @returns {string} Returns the converted string.
3229
+ */
3230
+ function objectToString(value) {
3231
+ return nativeObjectToString.call(value);
3232
+ }
3233
+
3234
+ /** `Object#toString` result references. */
3235
+ var nullTag = '[object Null]',
3236
+ undefinedTag = '[object Undefined]';
3237
+
3238
+ /** Built-in value references. */
3239
+ var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
3240
+
3241
+ /**
3242
+ * The base implementation of `getTag` without fallbacks for buggy environments.
3243
+ *
3244
+ * @private
3245
+ * @param {*} value The value to query.
3246
+ * @returns {string} Returns the `toStringTag`.
3247
+ */
3248
+ function baseGetTag(value) {
3249
+ if (value == null) {
3250
+ return value === undefined ? undefinedTag : nullTag;
3251
+ }
3252
+ return (symToStringTag && symToStringTag in Object(value))
3253
+ ? getRawTag(value)
3254
+ : objectToString(value);
3255
+ }
3256
+
3257
+ /**
3258
+ * Checks if `value` is the
3259
+ * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
3260
+ * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
3261
+ *
3262
+ * @static
3263
+ * @memberOf _
3264
+ * @since 0.1.0
3265
+ * @category Lang
3266
+ * @param {*} value The value to check.
3267
+ * @returns {boolean} Returns `true` if `value` is an object, else `false`.
3268
+ * @example
3269
+ *
3270
+ * _.isObject({});
3271
+ * // => true
3272
+ *
3273
+ * _.isObject([1, 2, 3]);
3274
+ * // => true
3275
+ *
3276
+ * _.isObject(_.noop);
3277
+ * // => true
3278
+ *
3279
+ * _.isObject(null);
3280
+ * // => false
3281
+ */
3282
+ function isObject(value) {
3283
+ var type = typeof value;
3284
+ return value != null && (type == 'object' || type == 'function');
3285
+ }
3286
+
3287
+ /** Used to match a single whitespace character. */
3288
+ var reWhitespace = /\s/;
3289
+
3290
+ /**
3291
+ * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
3292
+ * character of `string`.
3293
+ *
3294
+ * @private
3295
+ * @param {string} string The string to inspect.
3296
+ * @returns {number} Returns the index of the last non-whitespace character.
3297
+ */
3298
+ function trimmedEndIndex(string) {
3299
+ var index = string.length;
3300
+
3301
+ while (index-- && reWhitespace.test(string.charAt(index))) {}
3302
+ return index;
3303
+ }
3304
+
3305
+ /** Used to match leading whitespace. */
3306
+ var reTrimStart = /^\s+/;
3307
+
3308
+ /**
3309
+ * The base implementation of `_.trim`.
3310
+ *
3311
+ * @private
3312
+ * @param {string} string The string to trim.
3313
+ * @returns {string} Returns the trimmed string.
3314
+ */
3315
+ function baseTrim(string) {
3316
+ return string
3317
+ ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
3318
+ : string;
3319
+ }
3320
+
3321
+ /**
3322
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
3323
+ * and has a `typeof` result of "object".
3324
+ *
3325
+ * @static
3326
+ * @memberOf _
3327
+ * @since 4.0.0
3328
+ * @category Lang
3329
+ * @param {*} value The value to check.
3330
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
3331
+ * @example
3332
+ *
3333
+ * _.isObjectLike({});
3334
+ * // => true
3335
+ *
3336
+ * _.isObjectLike([1, 2, 3]);
3337
+ * // => true
3338
+ *
3339
+ * _.isObjectLike(_.noop);
3340
+ * // => false
3341
+ *
3342
+ * _.isObjectLike(null);
3343
+ * // => false
3344
+ */
3345
+ function isObjectLike(value) {
3346
+ return value != null && typeof value == 'object';
3347
+ }
3348
+
3349
+ /** `Object#toString` result references. */
3350
+ var symbolTag = '[object Symbol]';
3351
+
3352
+ /**
3353
+ * Checks if `value` is classified as a `Symbol` primitive or object.
3354
+ *
3355
+ * @static
3356
+ * @memberOf _
3357
+ * @since 4.0.0
3358
+ * @category Lang
3359
+ * @param {*} value The value to check.
3360
+ * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
3361
+ * @example
3362
+ *
3363
+ * _.isSymbol(Symbol.iterator);
3364
+ * // => true
3365
+ *
3366
+ * _.isSymbol('abc');
3367
+ * // => false
3368
+ */
3369
+ function isSymbol(value) {
3370
+ return typeof value == 'symbol' ||
3371
+ (isObjectLike(value) && baseGetTag(value) == symbolTag);
3372
+ }
3373
+
3374
+ /** Used as references for various `Number` constants. */
3375
+ var NAN = 0 / 0;
3376
+
3377
+ /** Used to detect bad signed hexadecimal string values. */
3378
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
3379
+
3380
+ /** Used to detect binary string values. */
3381
+ var reIsBinary = /^0b[01]+$/i;
3382
+
3383
+ /** Used to detect octal string values. */
3384
+ var reIsOctal = /^0o[0-7]+$/i;
3385
+
3386
+ /** Built-in method references without a dependency on `root`. */
3387
+ var freeParseInt = parseInt;
3388
+
3389
+ /**
3390
+ * Converts `value` to a number.
3391
+ *
3392
+ * @static
3393
+ * @memberOf _
3394
+ * @since 4.0.0
3395
+ * @category Lang
3396
+ * @param {*} value The value to process.
3397
+ * @returns {number} Returns the number.
3398
+ * @example
3399
+ *
3400
+ * _.toNumber(3.2);
3401
+ * // => 3.2
3402
+ *
3403
+ * _.toNumber(Number.MIN_VALUE);
3404
+ * // => 5e-324
3405
+ *
3406
+ * _.toNumber(Infinity);
3407
+ * // => Infinity
3408
+ *
3409
+ * _.toNumber('3.2');
3410
+ * // => 3.2
3411
+ */
3412
+ function toNumber(value) {
3413
+ if (typeof value == 'number') {
3414
+ return value;
3415
+ }
3416
+ if (isSymbol(value)) {
3417
+ return NAN;
3418
+ }
3419
+ if (isObject(value)) {
3420
+ var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
3421
+ value = isObject(other) ? (other + '') : other;
3422
+ }
3423
+ if (typeof value != 'string') {
3424
+ return value === 0 ? value : +value;
3425
+ }
3426
+ value = baseTrim(value);
3427
+ var isBinary = reIsBinary.test(value);
3428
+ return (isBinary || reIsOctal.test(value))
3429
+ ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
3430
+ : (reIsBadHex.test(value) ? NAN : +value);
3431
+ }
3432
+
3433
+ /** Used as references for various `Number` constants. */
3434
+ var INFINITY = 1 / 0,
3435
+ MAX_INTEGER = 1.7976931348623157e+308;
3436
+
3437
+ /**
3438
+ * Converts `value` to a finite number.
3439
+ *
3440
+ * @static
3441
+ * @memberOf _
3442
+ * @since 4.12.0
3443
+ * @category Lang
3444
+ * @param {*} value The value to convert.
3445
+ * @returns {number} Returns the converted number.
3446
+ * @example
3447
+ *
3448
+ * _.toFinite(3.2);
3449
+ * // => 3.2
3450
+ *
3451
+ * _.toFinite(Number.MIN_VALUE);
3452
+ * // => 5e-324
3453
+ *
3454
+ * _.toFinite(Infinity);
3455
+ * // => 1.7976931348623157e+308
3456
+ *
3457
+ * _.toFinite('3.2');
3458
+ * // => 3.2
3459
+ */
3460
+ function toFinite(value) {
3461
+ if (!value) {
3462
+ return value === 0 ? value : 0;
3463
+ }
3464
+ value = toNumber(value);
3465
+ if (value === INFINITY || value === -INFINITY) {
3466
+ var sign = (value < 0 ? -1 : 1);
3467
+ return sign * MAX_INTEGER;
3468
+ }
3469
+ return value === value ? value : 0;
3470
+ }
3471
+
3472
+ /**
3473
+ * Converts `value` to an integer.
3474
+ *
3475
+ * **Note:** This method is loosely based on
3476
+ * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
3477
+ *
3478
+ * @static
3479
+ * @memberOf _
3480
+ * @since 4.0.0
3481
+ * @category Lang
3482
+ * @param {*} value The value to convert.
3483
+ * @returns {number} Returns the converted integer.
3484
+ * @example
3485
+ *
3486
+ * _.toInteger(3.2);
3487
+ * // => 3
3488
+ *
3489
+ * _.toInteger(Number.MIN_VALUE);
3490
+ * // => 0
3491
+ *
3492
+ * _.toInteger(Infinity);
3493
+ * // => 1.7976931348623157e+308
3494
+ *
3495
+ * _.toInteger('3.2');
3496
+ * // => 3
3497
+ */
3498
+ function toInteger(value) {
3499
+ var result = toFinite(value),
3500
+ remainder = result % 1;
3501
+
3502
+ return result === result ? (remainder ? result - remainder : result) : 0;
3503
+ }
3504
+
3505
+ /* Built-in method references for those with the same name as other `lodash` methods. */
3506
+ var nativeCeil = Math.ceil,
3507
+ nativeMax = Math.max;
3508
+
3509
+ /**
3510
+ * Creates an array of elements split into groups the length of `size`.
3511
+ * If `array` can't be split evenly, the final chunk will be the remaining
3512
+ * elements.
3513
+ *
3514
+ * @static
3515
+ * @memberOf _
3516
+ * @since 3.0.0
3517
+ * @category Array
3518
+ * @param {Array} array The array to process.
3519
+ * @param {number} [size=1] The length of each chunk
3520
+ * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
3521
+ * @returns {Array} Returns the new array of chunks.
3522
+ * @example
3523
+ *
3524
+ * _.chunk(['a', 'b', 'c', 'd'], 2);
3525
+ * // => [['a', 'b'], ['c', 'd']]
3526
+ *
3527
+ * _.chunk(['a', 'b', 'c', 'd'], 3);
3528
+ * // => [['a', 'b', 'c'], ['d']]
3529
+ */
3530
+ function chunk(array, size, guard) {
3531
+ if ((size === undefined)) {
3532
+ size = 1;
3533
+ } else {
3534
+ size = nativeMax(toInteger(size), 0);
3535
+ }
3536
+ var length = array == null ? 0 : array.length;
3537
+ if (!length || size < 1) {
3538
+ return [];
3539
+ }
3540
+ var index = 0,
3541
+ resIndex = 0,
3542
+ result = Array(nativeCeil(length / size));
3543
+
3544
+ while (index < length) {
3545
+ result[resIndex++] = baseSlice(array, index, (index += size));
3546
+ }
3547
+ return result;
3548
+ }
3549
+
3550
+ const CalendarNavigation = ({ children, ...props }) => (jsx("div", { className: "utrecht-calendar__navigation", ...props, children: children }));
3551
+
3552
+ function r$1(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r$1(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx$1(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r$1(e))&&(n&&(n+=" "),n+=t);return n}
3553
+
3554
+ const Button = forwardRef(({ appearance, busy, disabled, children, className, hint, icon, label, pressed, type, ...restProps }, ref) => {
3555
+ return (jsxs("button", { ref: ref, className: clsx$1('utrecht-button', busy && 'utrecht-button--busy', disabled && 'utrecht-button--disabled', type === 'submit' && 'utrecht-button--submit', appearance === 'primary-action-button' && 'utrecht-button--primary-action', appearance === 'secondary-action-button' && 'utrecht-button--secondary-action', appearance === 'subtle-button' && 'utrecht-button--subtle', hint === 'danger' && 'utrecht-button--danger', hint === 'warning' && 'utrecht-button--warning', hint === 'ready' && 'utrecht-button--ready', pressed === true && 'utrecht-button--pressed', className), "aria-busy": busy || undefined, "aria-pressed": typeof pressed === 'boolean' ? pressed : undefined, disabled: disabled, type: type || 'button', ...restProps, children: [icon, label && jsx("span", { className: "utrecht-button__label", children: label }), children] }));
3556
+ });
3557
+ Button.displayName = 'Button';
3558
+
3559
+ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
3560
+
3561
+ const CalendarButton = ({ children, className, ...props }) => (jsx(Button, { appearance: "subtle-button", ...props, className: clsx('utrecht-calendar__button', className), children: children }));
3562
+
3563
+ const CalendarIcon = ({ children, ...props }) => (jsx("div", { className: clsx('utrecht-calendar__icon'), ...props, children: children }));
3564
+
3565
+ const CalendarNavigationButtons = ({ onPreviousClick, onNextClick, previousIcon, nextIcon, children, ...props }) => (jsxs("div", { className: "utrecht-calendar__navigation-buttons", children: [jsx(CalendarButton, { onClick: onPreviousClick, ...props, children: jsx(CalendarIcon, { children: previousIcon }) }), children, jsx(CalendarButton, { onClick: onNextClick, ...props, children: jsx(CalendarIcon, { children: nextIcon }) })] }));
3566
+
3567
+ const CalendarNavigationLabel = ({ children, ...props }) => (jsx("time", { className: "utrecht-calendar__navigation-label", ...props, children: children }));
3568
+
3569
+ const CalendarTableDaysContainer = ({ children, ...props }) => (jsx("tbody", { ...props, className: "utrecht-calendar__table-days-container", children: children }));
3570
+
3571
+ const CalendarTableDaysItem = ({ children, ...props }) => (jsx("tr", { ...props, children: children }));
3572
+
3573
+ const CalendarTableDaysItemDay = ({ day, dayOutOfTheMonth, isToday, emphasis, selected, disabled, ...props }) => (jsx("td", { children: jsx(CalendarButton, { className: clsx('utrecht-calendar__table-days-item-day', { 'utrecht-calendar__table-days-item-day--out-of-the-month': dayOutOfTheMonth }, { 'utrecht-calendar__table-days-item-day--is-today': isToday }, { 'utrecht-calendar__table-days-item-day--emphasis': emphasis }, { 'utrecht-calendar__table-days-item-day--selected': selected }), disabled: disabled, ...props, children: day }) }));
3574
+
3575
+ const CalendarTableWeeksContainer = ({ children }) => (jsx("thead", { className: "utrecht-calendar__table-weeks-container", children: jsx("tr", { className: "utrecht-calendar__table-weeks-container-content", children: children }) }));
3576
+
3577
+ const CalendarTableWeeksItem = ({ children, ...props }) => (jsx("th", { ...props, className: "utrecht-calendar__table-weeks-item", children: children }));
3578
+
3579
+ const IconArrowLeft = ({ title, titleId, ...props }) => (jsxs("svg", { width: "100%", height: "100%", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-labelledby": titleId, ...props, children: [title ? jsx("title", { id: titleId, children: title }) : null, jsx("path", { d: "M15.41 16.59 10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41Z", fill: "currentColor" })] }));
3580
+
3581
+ const IconArrowLeftDouble = ({ title, titleId, ...props }) => (jsxs("svg", { width: "100%", height: "100%", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-labelledby": titleId, ...props, children: [title ? jsx("title", { id: titleId, children: title }) : null, jsx("path", { d: "M17.59 18 19 16.59 14.42 12 19 7.41 17.59 6l-6 6 6 6Z", fill: "currentColor" }), jsx("path", { d: "m11 18 1.41-1.41L7.83 12l4.58-4.59L11 6l-6 6 6 6Z", fill: "currentColor" })] }));
3582
+
3583
+ const IconArrowRight = ({ title, titleId, ...props }) => (jsxs("svg", { width: "100%", height: "100%", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-labelledby": titleId, ...props, children: [title ? jsx("title", { id: titleId, children: title }) : null, jsx("path", { d: "M8.59 16.59 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41Z", fill: "currentColor" })] }));
3584
+
3585
+ const IconArrowRightDouble = ({ title, titleId, ...props }) => (jsxs("svg", { fill: "none", width: "100%", height: "100%", xmlns: "http://www.w3.org/2000/svg", "aria-labelledby": titleId, ...props, children: [title ? jsx("title", { id: titleId, children: title }) : null, jsx("path", { d: "M6.41 6 5 7.41 9.58 12 5 16.59 6.41 18l6-6-6-6Z", fill: "currentColor" }), jsx("path", { d: "m13 6-1.41 1.41L16.17 12l-4.58 4.59L13 18l6-6-6-6Z", fill: "currentColor" })] }));
270
3586
 
271
3587
  function createCalendar(today) {
272
- var start = startOfWeek(startOfMonth(today), {
273
- weekStartsOn: 1 /* Monday */
274
- });
275
- var end = endOfWeek(addWeeks(start, 5), {
276
- weekStartsOn: 1 /* Monday */
277
- });
278
- return eachDayOfInterval({
279
- start: start,
280
- end: end
281
- });
3588
+ const start = startOfWeek(startOfMonth(today), {
3589
+ weekStartsOn: 1 /* Monday */,
3590
+ });
3591
+ const end = endOfWeek(addWeeks(start, 5), {
3592
+ weekStartsOn: 1 /* Monday */,
3593
+ });
3594
+ return eachDayOfInterval({ start, end });
282
3595
  }
283
3596
  /**
284
3597
  * Calendar Component
285
3598
  * powered by date-fns, so that make it easy to use the `date-fns` date functions & locale
286
3599
  * */
287
- var Calendar = function Calendar(_ref) {
288
- var onCalendarClick = _ref.onCalendarClick,
289
- events = _ref.events,
290
- currentDate = _ref.currentDate,
291
- _ref$locale = _ref.locale,
292
- locale = _ref$locale === void 0 ? enUS : _ref$locale,
293
- _ref$previousYearButt = _ref.previousYearButtonTitle,
294
- previousYearButtonTitle = _ref$previousYearButt === void 0 ? 'Previous year' : _ref$previousYearButt,
295
- _ref$nextYearButtonTi = _ref.nextYearButtonTitle,
296
- nextYearButtonTitle = _ref$nextYearButtonTi === void 0 ? 'Next year' : _ref$nextYearButtonTi,
297
- _ref$previousMonthBut = _ref.previousMonthButtonTitle,
298
- previousMonthButtonTitle = _ref$previousMonthBut === void 0 ? 'Previous month' : _ref$previousMonthBut,
299
- _ref$nextMonthButtonT = _ref.nextMonthButtonTitle,
300
- nextMonthButtonTitle = _ref$nextMonthButtonT === void 0 ? 'Next month' : _ref$nextMonthButtonT,
301
- minDate = _ref.minDate,
302
- maxDate = _ref.maxDate;
303
- var _useState = useState(currentDate || new Date()),
304
- _useState2 = _slicedToArray(_useState, 2),
305
- visibleMonth = _useState2[0],
306
- setVisibleMonth = _useState2[1];
307
- var _useState3 = useState(currentDate),
308
- _useState4 = _slicedToArray(_useState3, 2),
309
- selectedDate = _useState4[0],
310
- setSelectedDate = _useState4[1];
311
- var calendar = createCalendar(visibleMonth);
312
- var start = startOfWeek(visibleMonth, {
313
- weekStartsOn: 1
314
- });
315
- var end = endOfWeek(visibleMonth, {
316
- weekStartsOn: 1
317
- });
318
- var currentWeek = eachDayOfInterval({
319
- start: start,
320
- end: end
321
- }).map(function (day) {
322
- return day;
323
- });
324
- var chunksWeeks = chunk(calendar, calendar.length / 6);
325
- var weeks = chunksWeeks.map(function (week) {
326
- return week.map(function (date) {
327
- var currentEvent = events && events.length > 0 && events.find(function (e) {
328
- return isSameDay(endOfDay(parseISO(e.date)), date);
329
- });
330
- if (currentEvent) {
331
- return {
332
- date: date,
333
- emphasis: currentEvent.emphasis,
334
- selected: currentEvent.selected,
335
- disabled: currentEvent.disabled
336
- };
337
- } else {
338
- return {
339
- date: date,
340
- emphasis: false,
341
- selected: false,
342
- disabled: false
343
- };
344
- }
345
- });
346
- });
347
- return jsxs("div", {
348
- className: "utrecht-calendar",
349
- children: [jsx(CalendarNavigation, {
350
- children: jsx(CalendarNavigationButtons, {
351
- previousIcon: jsx(IconArrowLeftDouble, {
352
- title: previousYearButtonTitle
353
- }),
354
- nextIcon: jsx(IconArrowRightDouble, {
355
- title: nextYearButtonTitle
356
- }),
357
- onPreviousClick: function onPreviousClick() {
358
- return setVisibleMonth(setYear(visibleMonth, getYear(visibleMonth) - 1));
359
- },
360
- onNextClick: function onNextClick() {
361
- return setVisibleMonth(addYears(visibleMonth, 1));
362
- },
363
- children: jsx(CalendarNavigationButtons, {
364
- previousIcon: jsx(IconArrowLeft, {
365
- title: previousMonthButtonTitle
366
- }),
367
- nextIcon: jsx(IconArrowRight, {
368
- title: nextMonthButtonTitle
369
- }),
370
- onPreviousClick: function onPreviousClick() {
371
- return setVisibleMonth(setMonth(visibleMonth, visibleMonth.getMonth() - 1));
372
- },
373
- onNextClick: function onNextClick() {
374
- return setVisibleMonth(addMonths(visibleMonth, 1));
375
- },
376
- children: jsx(CalendarNavigationLabel, {
377
- dateTime: format(visibleMonth, 'yyyy-mm'),
378
- children: format(visibleMonth, 'LLLL Y', {
379
- locale: locale
380
- })
381
- })
382
- })
383
- })
384
- }), jsxs("table", {
385
- className: "utrecht-calendar__table",
386
- role: "grid",
387
- children: [jsx(CalendarTableWeeksContainer, {
388
- children: currentWeek && currentWeek.length > 0 && currentWeek.map(function (day, index) {
389
- return jsx(CalendarTableWeeksItem, {
390
- scope: "col",
391
- abbr: format(day, 'EEEE', {
392
- locale: locale
393
- }),
394
- children: format(day, 'EEEEEE', {
395
- locale: locale
396
- })
397
- }, index);
398
- })
399
- }), jsx(CalendarTableDaysContainer, {
400
- children: weeks && weeks.length > 0 && weeks.map(function (week, index) {
401
- return jsx(CalendarTableDaysItem, {
402
- children: week.map(function (day, index) {
403
- return jsx(CalendarTableDaysItemDay, {
404
- isToday: isSameDay(day.date, Date.now()),
405
- dayOutOfTheMonth: !isSameMonth(day.date, visibleMonth),
406
- onClick: function onClick() {
407
- setVisibleMonth(day.date);
408
- setSelectedDate(day.date);
409
- onCalendarClick(formatISO(day.date));
410
- },
411
- "aria-label": format(day.date, 'eeee dd LLLL Y', {
412
- locale: locale
413
- }),
414
- day: day.date.getDate().toString(),
415
- emphasis: day.emphasis,
416
- selected: day.selected || selectedDate && isSameDay(day.date, selectedDate),
417
- disabled: day.disabled || minDate && isBefore(day.date, startOfDay(minDate)) || maxDate && isAfter(day.date, endOfDay(maxDate))
418
- }, index);
419
- })
420
- }, index);
421
- })
422
- })]
423
- })]
424
- });
3600
+ const Calendar = ({ onCalendarClick, events, currentDate, locale: locale$1 = locale, previousYearButtonTitle = 'Previous year', nextYearButtonTitle = 'Next year', previousMonthButtonTitle = 'Previous month', nextMonthButtonTitle = 'Next month', minDate, maxDate, }) => {
3601
+ const [visibleMonth, setVisibleMonth] = useState(currentDate || new Date());
3602
+ const [selectedDate, setSelectedDate] = useState(currentDate);
3603
+ const calendar = createCalendar(visibleMonth);
3604
+ const start = startOfWeek(visibleMonth, { weekStartsOn: 1 });
3605
+ const end = endOfWeek(visibleMonth, { weekStartsOn: 1 });
3606
+ const currentWeek = eachDayOfInterval({ start, end }).map((day) => day);
3607
+ const chunksWeeks = chunk(calendar, calendar.length / 6);
3608
+ const weeks = chunksWeeks.map((week) => week.map((date) => {
3609
+ const currentEvent = events && events.length > 0 && events.find((e) => isSameDay(endOfDay(parseISO(e.date)), date));
3610
+ if (currentEvent) {
3611
+ return {
3612
+ date,
3613
+ emphasis: currentEvent.emphasis,
3614
+ selected: currentEvent.selected,
3615
+ disabled: currentEvent.disabled,
3616
+ };
3617
+ }
3618
+ else {
3619
+ return {
3620
+ date,
3621
+ emphasis: false,
3622
+ selected: false,
3623
+ disabled: false,
3624
+ };
3625
+ }
3626
+ }));
3627
+ return (jsxs("div", { className: "utrecht-calendar", children: [jsx(CalendarNavigation, { children: jsx(CalendarNavigationButtons, { previousIcon: jsx(IconArrowLeftDouble, { title: previousYearButtonTitle }), nextIcon: jsx(IconArrowRightDouble, { title: nextYearButtonTitle }), onPreviousClick: () => setVisibleMonth(setYear(visibleMonth, getYear(visibleMonth) - 1)), onNextClick: () => setVisibleMonth(addYears(visibleMonth, 1)), children: jsx(CalendarNavigationButtons, { previousIcon: jsx(IconArrowLeft, { title: previousMonthButtonTitle }), nextIcon: jsx(IconArrowRight, { title: nextMonthButtonTitle }), onPreviousClick: () => setVisibleMonth(setMonth(visibleMonth, visibleMonth.getMonth() - 1)), onNextClick: () => setVisibleMonth(addMonths(visibleMonth, 1)), children: jsx(CalendarNavigationLabel, { dateTime: format(visibleMonth, 'yyyy-mm'), children: format(visibleMonth, 'LLLL Y', { locale: locale$1 }) }) }) }) }), jsxs("table", { className: "utrecht-calendar__table", role: "grid", children: [jsx(CalendarTableWeeksContainer, { children: currentWeek &&
3628
+ currentWeek.length > 0 &&
3629
+ currentWeek.map((day, index) => (jsx(CalendarTableWeeksItem, { scope: "col", abbr: format(day, 'EEEE', { locale: locale$1 }), children: format(day, 'EEEEEE', { locale: locale$1 }) }, index))) }), jsx(CalendarTableDaysContainer, { children: weeks &&
3630
+ weeks.length > 0 &&
3631
+ weeks.map((week, index) => (jsx(CalendarTableDaysItem, { children: week.map((day, index) => {
3632
+ return (jsx(CalendarTableDaysItemDay, { isToday: isSameDay(day.date, Date.now()), dayOutOfTheMonth: !isSameMonth(day.date, visibleMonth), onClick: () => {
3633
+ setVisibleMonth(day.date);
3634
+ setSelectedDate(day.date);
3635
+ onCalendarClick(formatISO(day.date));
3636
+ }, "aria-label": format(day.date, 'eeee dd LLLL Y', { locale: locale$1 }), day: day.date.getDate().toString(), emphasis: day.emphasis, selected: day.selected || (selectedDate && isSameDay(day.date, selectedDate)), disabled: day.disabled ||
3637
+ (minDate && isBefore(day.date, startOfDay(minDate))) ||
3638
+ (maxDate && isAfter(day.date, endOfDay(maxDate))) }, index));
3639
+ }) }, index))) })] })] }));
425
3640
  };
426
3641
 
427
3642
  export { Calendar };