q2-tecton-elements 1.21.2 → 1.22.0

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