@everymatrix/lottery-oddsbom-ticket-history 0.7.27 → 0.7.28

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.
@@ -1,3034 +0,0 @@
1
- import { r as registerInstance, h } from './index-e66667d7.js';
2
-
3
- const StyleCacheKey = '__WIDGET_GLOBAL_STYLE_CACHE__';
4
-
5
- /**
6
- * @name setClientStyling
7
- * @description Method used to create and append to the passed element of the widget a style element with the content received
8
- * @param {HTMLElement} stylingContainer The reference element of the widget
9
- * @param {string} clientStyling The style content
10
- */
11
- function setClientStyling(stylingContainer, clientStyling) {
12
- if (stylingContainer) {
13
- const sheet = document.createElement('style');
14
- sheet.innerHTML = clientStyling;
15
- stylingContainer.appendChild(sheet);
16
- }
17
- }
18
-
19
- /**
20
- * @name setClientStylingURL
21
- * @description Method used to create and append to the passed element of the widget a style element with the content fetched from a given URL
22
- * @param {HTMLElement} stylingContainer The reference element of the widget
23
- * @param {string} clientStylingUrl The URL of the style content
24
- */
25
- function setClientStylingURL(stylingContainer, clientStylingUrl) {
26
- if (!stylingContainer || !clientStylingUrl) return;
27
-
28
- const url = new URL(clientStylingUrl);
29
-
30
- fetch(url.href)
31
- .then((res) => res.text())
32
- .then((data) => {
33
- const cssFile = document.createElement('style');
34
- cssFile.innerHTML = data;
35
- if (stylingContainer) {
36
- stylingContainer.appendChild(cssFile);
37
- }
38
- })
39
- .catch((err) => {
40
- console.error('There was an error while trying to load client styling from URL', err);
41
- });
42
- }
43
-
44
- /**
45
- * @name setStreamLibrary
46
- * @description Method used to create and append to the passed element of the widget a style element with content fetched from the MessageBus
47
- * @param {HTMLElement} stylingContainer The highest element of the widget
48
- * @param {string} domain The domain from where the content should be fetched (e.g. 'Casino.Style', 'App.Style', 'casino-footer.style', etc.)
49
- * @param {ref} subscription A reference to a variable where the subscription should be saved for unsubscribing when no longer needed
50
- * @param {boolean} useAdoptedStyleSheets A flag to gradually enable testing of adoptedStyleSheets
51
- */
52
- function setStreamStyling(stylingContainer, domain, subscription, useAdoptedStyleSheets = false) {
53
- if (!window.emMessageBus) return;
54
-
55
- const supportAdoptStyle = 'adoptedStyleSheets' in Document.prototype;
56
-
57
- if (!supportAdoptStyle || !useAdoptedStyleSheets) {
58
- subscription = getStyleTagSubscription(stylingContainer, domain);
59
-
60
- return subscription;
61
- }
62
-
63
- if (!window[StyleCacheKey]) {
64
- window[StyleCacheKey] = {};
65
- }
66
- subscription = getAdoptStyleSubscription(stylingContainer, domain);
67
-
68
- const originalUnsubscribe = subscription.unsubscribe.bind(subscription);
69
- const wrappedUnsubscribe = () => {
70
- if (window[StyleCacheKey][domain]) {
71
- const cachedObject = window[StyleCacheKey][domain];
72
- cachedObject.refCount > 1
73
- ? (cachedObject.refCount = cachedObject.refCount - 1)
74
- : delete window[StyleCacheKey][domain];
75
- }
76
-
77
- originalUnsubscribe();
78
- };
79
- subscription.unsubscribe = wrappedUnsubscribe;
80
-
81
- return subscription;
82
- }
83
-
84
- function getStyleTagSubscription(stylingContainer, domain) {
85
- const sheet = document.createElement('style');
86
-
87
- return window.emMessageBus.subscribe(domain, (data) => {
88
- if (stylingContainer) {
89
- sheet.innerHTML = data;
90
- stylingContainer.appendChild(sheet);
91
- }
92
- });
93
- }
94
-
95
- function getAdoptStyleSubscription(stylingContainer, domain) {
96
- return window.emMessageBus.subscribe(domain, (data) => {
97
- if (!stylingContainer) return;
98
-
99
- const shadowRoot = stylingContainer.getRootNode();
100
- const cacheStyleObject = window[StyleCacheKey];
101
- let cachedStyle = cacheStyleObject[domain]?.sheet;
102
-
103
- if (!cachedStyle) {
104
- cachedStyle = new CSSStyleSheet();
105
- cachedStyle.replaceSync(data);
106
- cacheStyleObject[domain] = {
107
- sheet: cachedStyle,
108
- refCount: 1
109
- };
110
- } else {
111
- cacheStyleObject[domain].refCount = cacheStyleObject[domain].refCount + 1;
112
- }
113
-
114
- const currentSheets = shadowRoot.adoptedStyleSheets || [];
115
- if (!currentSheets.includes(cachedStyle)) {
116
- shadowRoot.adoptedStyleSheets = [...currentSheets, cachedStyle];
117
- }
118
- });
119
- }
120
-
121
- var GameType;
122
- (function (GameType) {
123
- GameType["Lottery"] = "Lottery";
124
- GameType["PoolGame"] = "PoolGame";
125
- })(GameType || (GameType = {}));
126
- var GameBettingObject;
127
- (function (GameBettingObject) {
128
- GameBettingObject["Tipping"] = "HomeDrawAway";
129
- GameBettingObject["Oddsbomben"] = "CorrectScore";
130
- })(GameBettingObject || (GameBettingObject = {}));
131
- var TicketStatus;
132
- (function (TicketStatus) {
133
- TicketStatus["Settled"] = "Settled";
134
- TicketStatus["Purchased"] = "Purchased";
135
- TicketStatus["Canceled"] = "Canceled";
136
- })(TicketStatus || (TicketStatus = {}));
137
- var DrawResult;
138
- (function (DrawResult) {
139
- DrawResult["WON"] = "Won";
140
- DrawResult["LOST"] = "Lost";
141
- })(DrawResult || (DrawResult = {}));
142
-
143
- function _typeof(o) {
144
- "@babel/helpers - typeof";
145
-
146
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
147
- return typeof o;
148
- } : function (o) {
149
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
150
- }, _typeof(o);
151
- }
152
-
153
- function toInteger(dirtyNumber) {
154
- if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
155
- return NaN;
156
- }
157
- var number = Number(dirtyNumber);
158
- if (isNaN(number)) {
159
- return number;
160
- }
161
- return number < 0 ? Math.ceil(number) : Math.floor(number);
162
- }
163
-
164
- function requiredArgs(required, args) {
165
- if (args.length < required) {
166
- throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
167
- }
168
- }
169
-
170
- /**
171
- * @name toDate
172
- * @category Common Helpers
173
- * @summary Convert the given argument to an instance of Date.
174
- *
175
- * @description
176
- * Convert the given argument to an instance of Date.
177
- *
178
- * If the argument is an instance of Date, the function returns its clone.
179
- *
180
- * If the argument is a number, it is treated as a timestamp.
181
- *
182
- * If the argument is none of the above, the function returns Invalid Date.
183
- *
184
- * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
185
- *
186
- * @param {Date|Number} argument - the value to convert
187
- * @returns {Date} the parsed date in the local time zone
188
- * @throws {TypeError} 1 argument required
189
- *
190
- * @example
191
- * // Clone the date:
192
- * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
193
- * //=> Tue Feb 11 2014 11:30:30
194
- *
195
- * @example
196
- * // Convert the timestamp to date:
197
- * const result = toDate(1392098430000)
198
- * //=> Tue Feb 11 2014 11:30:30
199
- */
200
- function toDate(argument) {
201
- requiredArgs(1, arguments);
202
- var argStr = Object.prototype.toString.call(argument);
203
-
204
- // Clone the date
205
- if (argument instanceof Date || _typeof(argument) === 'object' && argStr === '[object Date]') {
206
- // Prevent the date to lose the milliseconds when passed to new Date() in IE10
207
- return new Date(argument.getTime());
208
- } else if (typeof argument === 'number' || argStr === '[object Number]') {
209
- return new Date(argument);
210
- } else {
211
- if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {
212
- // eslint-disable-next-line no-console
213
- 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");
214
- // eslint-disable-next-line no-console
215
- console.warn(new Error().stack);
216
- }
217
- return new Date(NaN);
218
- }
219
- }
220
-
221
- /**
222
- * @name addMilliseconds
223
- * @category Millisecond Helpers
224
- * @summary Add the specified number of milliseconds to the given date.
225
- *
226
- * @description
227
- * Add the specified number of milliseconds to the given date.
228
- *
229
- * @param {Date|Number} date - the date to be changed
230
- * @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`.
231
- * @returns {Date} the new date with the milliseconds added
232
- * @throws {TypeError} 2 arguments required
233
- *
234
- * @example
235
- * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
236
- * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
237
- * //=> Thu Jul 10 2014 12:45:30.750
238
- */
239
- function addMilliseconds(dirtyDate, dirtyAmount) {
240
- requiredArgs(2, arguments);
241
- var timestamp = toDate(dirtyDate).getTime();
242
- var amount = toInteger(dirtyAmount);
243
- return new Date(timestamp + amount);
244
- }
245
-
246
- var defaultOptions = {};
247
- function getDefaultOptions() {
248
- return defaultOptions;
249
- }
250
-
251
- /**
252
- * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
253
- * They usually appear for dates that denote time before the timezones were introduced
254
- * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
255
- * and GMT+01:00:00 after that date)
256
- *
257
- * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
258
- * which would lead to incorrect calculations.
259
- *
260
- * This function returns the timezone offset in milliseconds that takes seconds in account.
261
- */
262
- function getTimezoneOffsetInMilliseconds(date) {
263
- var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
264
- utcDate.setUTCFullYear(date.getFullYear());
265
- return date.getTime() - utcDate.getTime();
266
- }
267
-
268
- /**
269
- * Days in 1 week.
270
- *
271
- * @name daysInWeek
272
- * @constant
273
- * @type {number}
274
- * @default
275
- */
276
-
277
- /**
278
- * Milliseconds in 1 minute
279
- *
280
- * @name millisecondsInMinute
281
- * @constant
282
- * @type {number}
283
- * @default
284
- */
285
- var millisecondsInMinute = 60000;
286
-
287
- /**
288
- * Milliseconds in 1 hour
289
- *
290
- * @name millisecondsInHour
291
- * @constant
292
- * @type {number}
293
- * @default
294
- */
295
- var millisecondsInHour = 3600000;
296
-
297
- /**
298
- * @name isDate
299
- * @category Common Helpers
300
- * @summary Is the given value a date?
301
- *
302
- * @description
303
- * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
304
- *
305
- * @param {*} value - the value to check
306
- * @returns {boolean} true if the given value is a date
307
- * @throws {TypeError} 1 arguments required
308
- *
309
- * @example
310
- * // For a valid date:
311
- * const result = isDate(new Date())
312
- * //=> true
313
- *
314
- * @example
315
- * // For an invalid date:
316
- * const result = isDate(new Date(NaN))
317
- * //=> true
318
- *
319
- * @example
320
- * // For some value:
321
- * const result = isDate('2014-02-31')
322
- * //=> false
323
- *
324
- * @example
325
- * // For an object:
326
- * const result = isDate({})
327
- * //=> false
328
- */
329
- function isDate(value) {
330
- requiredArgs(1, arguments);
331
- return value instanceof Date || _typeof(value) === 'object' && Object.prototype.toString.call(value) === '[object Date]';
332
- }
333
-
334
- /**
335
- * @name isValid
336
- * @category Common Helpers
337
- * @summary Is the given date valid?
338
- *
339
- * @description
340
- * Returns false if argument is Invalid Date and true otherwise.
341
- * Argument is converted to Date using `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
342
- * Invalid Date is a Date, whose time value is NaN.
343
- *
344
- * Time value of Date: http://es5.github.io/#x15.9.1.1
345
- *
346
- * @param {*} date - the date to check
347
- * @returns {Boolean} the date is valid
348
- * @throws {TypeError} 1 argument required
349
- *
350
- * @example
351
- * // For the valid date:
352
- * const result = isValid(new Date(2014, 1, 31))
353
- * //=> true
354
- *
355
- * @example
356
- * // For the value, convertable into a date:
357
- * const result = isValid(1393804800000)
358
- * //=> true
359
- *
360
- * @example
361
- * // For the invalid date:
362
- * const result = isValid(new Date(''))
363
- * //=> false
364
- */
365
- function isValid(dirtyDate) {
366
- requiredArgs(1, arguments);
367
- if (!isDate(dirtyDate) && typeof dirtyDate !== 'number') {
368
- return false;
369
- }
370
- var date = toDate(dirtyDate);
371
- return !isNaN(Number(date));
372
- }
373
-
374
- /**
375
- * @name subMilliseconds
376
- * @category Millisecond Helpers
377
- * @summary Subtract the specified number of milliseconds from the given date.
378
- *
379
- * @description
380
- * Subtract the specified number of milliseconds from the given date.
381
- *
382
- * @param {Date|Number} date - the date to be changed
383
- * @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`.
384
- * @returns {Date} the new date with the milliseconds subtracted
385
- * @throws {TypeError} 2 arguments required
386
- *
387
- * @example
388
- * // Subtract 750 milliseconds from 10 July 2014 12:45:30.000:
389
- * const result = subMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
390
- * //=> Thu Jul 10 2014 12:45:29.250
391
- */
392
- function subMilliseconds(dirtyDate, dirtyAmount) {
393
- requiredArgs(2, arguments);
394
- var amount = toInteger(dirtyAmount);
395
- return addMilliseconds(dirtyDate, -amount);
396
- }
397
-
398
- var MILLISECONDS_IN_DAY = 86400000;
399
- function getUTCDayOfYear(dirtyDate) {
400
- requiredArgs(1, arguments);
401
- var date = toDate(dirtyDate);
402
- var timestamp = date.getTime();
403
- date.setUTCMonth(0, 1);
404
- date.setUTCHours(0, 0, 0, 0);
405
- var startOfYearTimestamp = date.getTime();
406
- var difference = timestamp - startOfYearTimestamp;
407
- return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
408
- }
409
-
410
- function startOfUTCISOWeek(dirtyDate) {
411
- requiredArgs(1, arguments);
412
- var weekStartsOn = 1;
413
- var date = toDate(dirtyDate);
414
- var day = date.getUTCDay();
415
- var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
416
- date.setUTCDate(date.getUTCDate() - diff);
417
- date.setUTCHours(0, 0, 0, 0);
418
- return date;
419
- }
420
-
421
- function getUTCISOWeekYear(dirtyDate) {
422
- requiredArgs(1, arguments);
423
- var date = toDate(dirtyDate);
424
- var year = date.getUTCFullYear();
425
- var fourthOfJanuaryOfNextYear = new Date(0);
426
- fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
427
- fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
428
- var startOfNextYear = startOfUTCISOWeek(fourthOfJanuaryOfNextYear);
429
- var fourthOfJanuaryOfThisYear = new Date(0);
430
- fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
431
- fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
432
- var startOfThisYear = startOfUTCISOWeek(fourthOfJanuaryOfThisYear);
433
- if (date.getTime() >= startOfNextYear.getTime()) {
434
- return year + 1;
435
- } else if (date.getTime() >= startOfThisYear.getTime()) {
436
- return year;
437
- } else {
438
- return year - 1;
439
- }
440
- }
441
-
442
- function startOfUTCISOWeekYear(dirtyDate) {
443
- requiredArgs(1, arguments);
444
- var year = getUTCISOWeekYear(dirtyDate);
445
- var fourthOfJanuary = new Date(0);
446
- fourthOfJanuary.setUTCFullYear(year, 0, 4);
447
- fourthOfJanuary.setUTCHours(0, 0, 0, 0);
448
- var date = startOfUTCISOWeek(fourthOfJanuary);
449
- return date;
450
- }
451
-
452
- var MILLISECONDS_IN_WEEK$1 = 604800000;
453
- function getUTCISOWeek(dirtyDate) {
454
- requiredArgs(1, arguments);
455
- var date = toDate(dirtyDate);
456
- var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime();
457
-
458
- // Round the number of days to the nearest integer
459
- // because the number of milliseconds in a week is not constant
460
- // (e.g. it's different in the week of the daylight saving time clock shift)
461
- return Math.round(diff / MILLISECONDS_IN_WEEK$1) + 1;
462
- }
463
-
464
- function startOfUTCWeek(dirtyDate, options) {
465
- var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
466
- requiredArgs(1, arguments);
467
- var defaultOptions = getDefaultOptions();
468
- 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);
469
-
470
- // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
471
- if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
472
- throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
473
- }
474
- var date = toDate(dirtyDate);
475
- var day = date.getUTCDay();
476
- var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
477
- date.setUTCDate(date.getUTCDate() - diff);
478
- date.setUTCHours(0, 0, 0, 0);
479
- return date;
480
- }
481
-
482
- function getUTCWeekYear(dirtyDate, options) {
483
- var _ref, _ref2, _ref3, _options$firstWeekCon, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
484
- requiredArgs(1, arguments);
485
- var date = toDate(dirtyDate);
486
- var year = date.getUTCFullYear();
487
- var defaultOptions = getDefaultOptions();
488
- 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);
489
-
490
- // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
491
- if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
492
- throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
493
- }
494
- var firstWeekOfNextYear = new Date(0);
495
- firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate);
496
- firstWeekOfNextYear.setUTCHours(0, 0, 0, 0);
497
- var startOfNextYear = startOfUTCWeek(firstWeekOfNextYear, options);
498
- var firstWeekOfThisYear = new Date(0);
499
- firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
500
- firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
501
- var startOfThisYear = startOfUTCWeek(firstWeekOfThisYear, options);
502
- if (date.getTime() >= startOfNextYear.getTime()) {
503
- return year + 1;
504
- } else if (date.getTime() >= startOfThisYear.getTime()) {
505
- return year;
506
- } else {
507
- return year - 1;
508
- }
509
- }
510
-
511
- function startOfUTCWeekYear(dirtyDate, options) {
512
- var _ref, _ref2, _ref3, _options$firstWeekCon, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
513
- requiredArgs(1, arguments);
514
- var defaultOptions = getDefaultOptions();
515
- 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);
516
- var year = getUTCWeekYear(dirtyDate, options);
517
- var firstWeek = new Date(0);
518
- firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
519
- firstWeek.setUTCHours(0, 0, 0, 0);
520
- var date = startOfUTCWeek(firstWeek, options);
521
- return date;
522
- }
523
-
524
- var MILLISECONDS_IN_WEEK = 604800000;
525
- function getUTCWeek(dirtyDate, options) {
526
- requiredArgs(1, arguments);
527
- var date = toDate(dirtyDate);
528
- var diff = startOfUTCWeek(date, options).getTime() - startOfUTCWeekYear(date, options).getTime();
529
-
530
- // Round the number of days to the nearest integer
531
- // because the number of milliseconds in a week is not constant
532
- // (e.g. it's different in the week of the daylight saving time clock shift)
533
- return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
534
- }
535
-
536
- function addLeadingZeros(number, targetLength) {
537
- var sign = number < 0 ? '-' : '';
538
- var output = Math.abs(number).toString();
539
- while (output.length < targetLength) {
540
- output = '0' + output;
541
- }
542
- return sign + output;
543
- }
544
-
545
- /*
546
- * | | Unit | | Unit |
547
- * |-----|--------------------------------|-----|--------------------------------|
548
- * | a | AM, PM | A* | |
549
- * | d | Day of month | D | |
550
- * | h | Hour [1-12] | H | Hour [0-23] |
551
- * | m | Minute | M | Month |
552
- * | s | Second | S | Fraction of second |
553
- * | y | Year (abs) | Y | |
554
- *
555
- * Letters marked by * are not implemented but reserved by Unicode standard.
556
- */
557
- var formatters$2 = {
558
- // Year
559
- y: function y(date, token) {
560
- // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
561
- // | Year | y | yy | yyy | yyyy | yyyyy |
562
- // |----------|-------|----|-------|-------|-------|
563
- // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
564
- // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
565
- // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
566
- // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
567
- // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
568
-
569
- var signedYear = date.getUTCFullYear();
570
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
571
- var year = signedYear > 0 ? signedYear : 1 - signedYear;
572
- return addLeadingZeros(token === 'yy' ? year % 100 : year, token.length);
573
- },
574
- // Month
575
- M: function M(date, token) {
576
- var month = date.getUTCMonth();
577
- return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2);
578
- },
579
- // Day of the month
580
- d: function d(date, token) {
581
- return addLeadingZeros(date.getUTCDate(), token.length);
582
- },
583
- // AM or PM
584
- a: function a(date, token) {
585
- var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
586
- switch (token) {
587
- case 'a':
588
- case 'aa':
589
- return dayPeriodEnumValue.toUpperCase();
590
- case 'aaa':
591
- return dayPeriodEnumValue;
592
- case 'aaaaa':
593
- return dayPeriodEnumValue[0];
594
- case 'aaaa':
595
- default:
596
- return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
597
- }
598
- },
599
- // Hour [1-12]
600
- h: function h(date, token) {
601
- return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length);
602
- },
603
- // Hour [0-23]
604
- H: function H(date, token) {
605
- return addLeadingZeros(date.getUTCHours(), token.length);
606
- },
607
- // Minute
608
- m: function m(date, token) {
609
- return addLeadingZeros(date.getUTCMinutes(), token.length);
610
- },
611
- // Second
612
- s: function s(date, token) {
613
- return addLeadingZeros(date.getUTCSeconds(), token.length);
614
- },
615
- // Fraction of second
616
- S: function S(date, token) {
617
- var numberOfDigits = token.length;
618
- var milliseconds = date.getUTCMilliseconds();
619
- var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
620
- return addLeadingZeros(fractionalSeconds, token.length);
621
- }
622
- };
623
- const formatters$3 = formatters$2;
624
-
625
- var dayPeriodEnum = {
626
- am: 'am',
627
- pm: 'pm',
628
- midnight: 'midnight',
629
- noon: 'noon',
630
- morning: 'morning',
631
- afternoon: 'afternoon',
632
- evening: 'evening',
633
- night: 'night'
634
- };
635
- /*
636
- * | | Unit | | Unit |
637
- * |-----|--------------------------------|-----|--------------------------------|
638
- * | a | AM, PM | A* | Milliseconds in day |
639
- * | b | AM, PM, noon, midnight | B | Flexible day period |
640
- * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
641
- * | d | Day of month | D | Day of year |
642
- * | e | Local day of week | E | Day of week |
643
- * | f | | F* | Day of week in month |
644
- * | g* | Modified Julian day | G | Era |
645
- * | h | Hour [1-12] | H | Hour [0-23] |
646
- * | i! | ISO day of week | I! | ISO week of year |
647
- * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
648
- * | k | Hour [1-24] | K | Hour [0-11] |
649
- * | l* | (deprecated) | L | Stand-alone month |
650
- * | m | Minute | M | Month |
651
- * | n | | N | |
652
- * | o! | Ordinal number modifier | O | Timezone (GMT) |
653
- * | p! | Long localized time | P! | Long localized date |
654
- * | q | Stand-alone quarter | Q | Quarter |
655
- * | r* | Related Gregorian year | R! | ISO week-numbering year |
656
- * | s | Second | S | Fraction of second |
657
- * | t! | Seconds timestamp | T! | Milliseconds timestamp |
658
- * | u | Extended year | U* | Cyclic year |
659
- * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
660
- * | w | Local week of year | W* | Week of month |
661
- * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
662
- * | y | Year (abs) | Y | Local week-numbering year |
663
- * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
664
- *
665
- * Letters marked by * are not implemented but reserved by Unicode standard.
666
- *
667
- * Letters marked by ! are non-standard, but implemented by date-fns:
668
- * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
669
- * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
670
- * i.e. 7 for Sunday, 1 for Monday, etc.
671
- * - `I` is ISO week of year, as opposed to `w` which is local week of year.
672
- * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
673
- * `R` is supposed to be used in conjunction with `I` and `i`
674
- * for universal ISO week-numbering date, whereas
675
- * `Y` is supposed to be used in conjunction with `w` and `e`
676
- * for week-numbering date specific to the locale.
677
- * - `P` is long localized date format
678
- * - `p` is long localized time format
679
- */
680
-
681
- var formatters = {
682
- // Era
683
- G: function G(date, token, localize) {
684
- var era = date.getUTCFullYear() > 0 ? 1 : 0;
685
- switch (token) {
686
- // AD, BC
687
- case 'G':
688
- case 'GG':
689
- case 'GGG':
690
- return localize.era(era, {
691
- width: 'abbreviated'
692
- });
693
- // A, B
694
- case 'GGGGG':
695
- return localize.era(era, {
696
- width: 'narrow'
697
- });
698
- // Anno Domini, Before Christ
699
- case 'GGGG':
700
- default:
701
- return localize.era(era, {
702
- width: 'wide'
703
- });
704
- }
705
- },
706
- // Year
707
- y: function y(date, token, localize) {
708
- // Ordinal number
709
- if (token === 'yo') {
710
- var signedYear = date.getUTCFullYear();
711
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
712
- var year = signedYear > 0 ? signedYear : 1 - signedYear;
713
- return localize.ordinalNumber(year, {
714
- unit: 'year'
715
- });
716
- }
717
- return formatters$3.y(date, token);
718
- },
719
- // Local week-numbering year
720
- Y: function Y(date, token, localize, options) {
721
- var signedWeekYear = getUTCWeekYear(date, options);
722
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
723
- var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
724
-
725
- // Two digit year
726
- if (token === 'YY') {
727
- var twoDigitYear = weekYear % 100;
728
- return addLeadingZeros(twoDigitYear, 2);
729
- }
730
-
731
- // Ordinal number
732
- if (token === 'Yo') {
733
- return localize.ordinalNumber(weekYear, {
734
- unit: 'year'
735
- });
736
- }
737
-
738
- // Padding
739
- return addLeadingZeros(weekYear, token.length);
740
- },
741
- // ISO week-numbering year
742
- R: function R(date, token) {
743
- var isoWeekYear = getUTCISOWeekYear(date);
744
-
745
- // Padding
746
- return addLeadingZeros(isoWeekYear, token.length);
747
- },
748
- // Extended year. This is a single number designating the year of this calendar system.
749
- // The main difference between `y` and `u` localizers are B.C. years:
750
- // | Year | `y` | `u` |
751
- // |------|-----|-----|
752
- // | AC 1 | 1 | 1 |
753
- // | BC 1 | 1 | 0 |
754
- // | BC 2 | 2 | -1 |
755
- // Also `yy` always returns the last two digits of a year,
756
- // while `uu` pads single digit years to 2 characters and returns other years unchanged.
757
- u: function u(date, token) {
758
- var year = date.getUTCFullYear();
759
- return addLeadingZeros(year, token.length);
760
- },
761
- // Quarter
762
- Q: function Q(date, token, localize) {
763
- var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
764
- switch (token) {
765
- // 1, 2, 3, 4
766
- case 'Q':
767
- return String(quarter);
768
- // 01, 02, 03, 04
769
- case 'QQ':
770
- return addLeadingZeros(quarter, 2);
771
- // 1st, 2nd, 3rd, 4th
772
- case 'Qo':
773
- return localize.ordinalNumber(quarter, {
774
- unit: 'quarter'
775
- });
776
- // Q1, Q2, Q3, Q4
777
- case 'QQQ':
778
- return localize.quarter(quarter, {
779
- width: 'abbreviated',
780
- context: 'formatting'
781
- });
782
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
783
- case 'QQQQQ':
784
- return localize.quarter(quarter, {
785
- width: 'narrow',
786
- context: 'formatting'
787
- });
788
- // 1st quarter, 2nd quarter, ...
789
- case 'QQQQ':
790
- default:
791
- return localize.quarter(quarter, {
792
- width: 'wide',
793
- context: 'formatting'
794
- });
795
- }
796
- },
797
- // Stand-alone quarter
798
- q: function q(date, token, localize) {
799
- var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
800
- switch (token) {
801
- // 1, 2, 3, 4
802
- case 'q':
803
- return String(quarter);
804
- // 01, 02, 03, 04
805
- case 'qq':
806
- return addLeadingZeros(quarter, 2);
807
- // 1st, 2nd, 3rd, 4th
808
- case 'qo':
809
- return localize.ordinalNumber(quarter, {
810
- unit: 'quarter'
811
- });
812
- // Q1, Q2, Q3, Q4
813
- case 'qqq':
814
- return localize.quarter(quarter, {
815
- width: 'abbreviated',
816
- context: 'standalone'
817
- });
818
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
819
- case 'qqqqq':
820
- return localize.quarter(quarter, {
821
- width: 'narrow',
822
- context: 'standalone'
823
- });
824
- // 1st quarter, 2nd quarter, ...
825
- case 'qqqq':
826
- default:
827
- return localize.quarter(quarter, {
828
- width: 'wide',
829
- context: 'standalone'
830
- });
831
- }
832
- },
833
- // Month
834
- M: function M(date, token, localize) {
835
- var month = date.getUTCMonth();
836
- switch (token) {
837
- case 'M':
838
- case 'MM':
839
- return formatters$3.M(date, token);
840
- // 1st, 2nd, ..., 12th
841
- case 'Mo':
842
- return localize.ordinalNumber(month + 1, {
843
- unit: 'month'
844
- });
845
- // Jan, Feb, ..., Dec
846
- case 'MMM':
847
- return localize.month(month, {
848
- width: 'abbreviated',
849
- context: 'formatting'
850
- });
851
- // J, F, ..., D
852
- case 'MMMMM':
853
- return localize.month(month, {
854
- width: 'narrow',
855
- context: 'formatting'
856
- });
857
- // January, February, ..., December
858
- case 'MMMM':
859
- default:
860
- return localize.month(month, {
861
- width: 'wide',
862
- context: 'formatting'
863
- });
864
- }
865
- },
866
- // Stand-alone month
867
- L: function L(date, token, localize) {
868
- var month = date.getUTCMonth();
869
- switch (token) {
870
- // 1, 2, ..., 12
871
- case 'L':
872
- return String(month + 1);
873
- // 01, 02, ..., 12
874
- case 'LL':
875
- return addLeadingZeros(month + 1, 2);
876
- // 1st, 2nd, ..., 12th
877
- case 'Lo':
878
- return localize.ordinalNumber(month + 1, {
879
- unit: 'month'
880
- });
881
- // Jan, Feb, ..., Dec
882
- case 'LLL':
883
- return localize.month(month, {
884
- width: 'abbreviated',
885
- context: 'standalone'
886
- });
887
- // J, F, ..., D
888
- case 'LLLLL':
889
- return localize.month(month, {
890
- width: 'narrow',
891
- context: 'standalone'
892
- });
893
- // January, February, ..., December
894
- case 'LLLL':
895
- default:
896
- return localize.month(month, {
897
- width: 'wide',
898
- context: 'standalone'
899
- });
900
- }
901
- },
902
- // Local week of year
903
- w: function w(date, token, localize, options) {
904
- var week = getUTCWeek(date, options);
905
- if (token === 'wo') {
906
- return localize.ordinalNumber(week, {
907
- unit: 'week'
908
- });
909
- }
910
- return addLeadingZeros(week, token.length);
911
- },
912
- // ISO week of year
913
- I: function I(date, token, localize) {
914
- var isoWeek = getUTCISOWeek(date);
915
- if (token === 'Io') {
916
- return localize.ordinalNumber(isoWeek, {
917
- unit: 'week'
918
- });
919
- }
920
- return addLeadingZeros(isoWeek, token.length);
921
- },
922
- // Day of the month
923
- d: function d(date, token, localize) {
924
- if (token === 'do') {
925
- return localize.ordinalNumber(date.getUTCDate(), {
926
- unit: 'date'
927
- });
928
- }
929
- return formatters$3.d(date, token);
930
- },
931
- // Day of year
932
- D: function D(date, token, localize) {
933
- var dayOfYear = getUTCDayOfYear(date);
934
- if (token === 'Do') {
935
- return localize.ordinalNumber(dayOfYear, {
936
- unit: 'dayOfYear'
937
- });
938
- }
939
- return addLeadingZeros(dayOfYear, token.length);
940
- },
941
- // Day of week
942
- E: function E(date, token, localize) {
943
- var dayOfWeek = date.getUTCDay();
944
- switch (token) {
945
- // Tue
946
- case 'E':
947
- case 'EE':
948
- case 'EEE':
949
- return localize.day(dayOfWeek, {
950
- width: 'abbreviated',
951
- context: 'formatting'
952
- });
953
- // T
954
- case 'EEEEE':
955
- return localize.day(dayOfWeek, {
956
- width: 'narrow',
957
- context: 'formatting'
958
- });
959
- // Tu
960
- case 'EEEEEE':
961
- return localize.day(dayOfWeek, {
962
- width: 'short',
963
- context: 'formatting'
964
- });
965
- // Tuesday
966
- case 'EEEE':
967
- default:
968
- return localize.day(dayOfWeek, {
969
- width: 'wide',
970
- context: 'formatting'
971
- });
972
- }
973
- },
974
- // Local day of week
975
- e: function e(date, token, localize, options) {
976
- var dayOfWeek = date.getUTCDay();
977
- var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
978
- switch (token) {
979
- // Numerical value (Nth day of week with current locale or weekStartsOn)
980
- case 'e':
981
- return String(localDayOfWeek);
982
- // Padded numerical value
983
- case 'ee':
984
- return addLeadingZeros(localDayOfWeek, 2);
985
- // 1st, 2nd, ..., 7th
986
- case 'eo':
987
- return localize.ordinalNumber(localDayOfWeek, {
988
- unit: 'day'
989
- });
990
- case 'eee':
991
- return localize.day(dayOfWeek, {
992
- width: 'abbreviated',
993
- context: 'formatting'
994
- });
995
- // T
996
- case 'eeeee':
997
- return localize.day(dayOfWeek, {
998
- width: 'narrow',
999
- context: 'formatting'
1000
- });
1001
- // Tu
1002
- case 'eeeeee':
1003
- return localize.day(dayOfWeek, {
1004
- width: 'short',
1005
- context: 'formatting'
1006
- });
1007
- // Tuesday
1008
- case 'eeee':
1009
- default:
1010
- return localize.day(dayOfWeek, {
1011
- width: 'wide',
1012
- context: 'formatting'
1013
- });
1014
- }
1015
- },
1016
- // Stand-alone local day of week
1017
- c: function c(date, token, localize, options) {
1018
- var dayOfWeek = date.getUTCDay();
1019
- var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1020
- switch (token) {
1021
- // Numerical value (same as in `e`)
1022
- case 'c':
1023
- return String(localDayOfWeek);
1024
- // Padded numerical value
1025
- case 'cc':
1026
- return addLeadingZeros(localDayOfWeek, token.length);
1027
- // 1st, 2nd, ..., 7th
1028
- case 'co':
1029
- return localize.ordinalNumber(localDayOfWeek, {
1030
- unit: 'day'
1031
- });
1032
- case 'ccc':
1033
- return localize.day(dayOfWeek, {
1034
- width: 'abbreviated',
1035
- context: 'standalone'
1036
- });
1037
- // T
1038
- case 'ccccc':
1039
- return localize.day(dayOfWeek, {
1040
- width: 'narrow',
1041
- context: 'standalone'
1042
- });
1043
- // Tu
1044
- case 'cccccc':
1045
- return localize.day(dayOfWeek, {
1046
- width: 'short',
1047
- context: 'standalone'
1048
- });
1049
- // Tuesday
1050
- case 'cccc':
1051
- default:
1052
- return localize.day(dayOfWeek, {
1053
- width: 'wide',
1054
- context: 'standalone'
1055
- });
1056
- }
1057
- },
1058
- // ISO day of week
1059
- i: function i(date, token, localize) {
1060
- var dayOfWeek = date.getUTCDay();
1061
- var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
1062
- switch (token) {
1063
- // 2
1064
- case 'i':
1065
- return String(isoDayOfWeek);
1066
- // 02
1067
- case 'ii':
1068
- return addLeadingZeros(isoDayOfWeek, token.length);
1069
- // 2nd
1070
- case 'io':
1071
- return localize.ordinalNumber(isoDayOfWeek, {
1072
- unit: 'day'
1073
- });
1074
- // Tue
1075
- case 'iii':
1076
- return localize.day(dayOfWeek, {
1077
- width: 'abbreviated',
1078
- context: 'formatting'
1079
- });
1080
- // T
1081
- case 'iiiii':
1082
- return localize.day(dayOfWeek, {
1083
- width: 'narrow',
1084
- context: 'formatting'
1085
- });
1086
- // Tu
1087
- case 'iiiiii':
1088
- return localize.day(dayOfWeek, {
1089
- width: 'short',
1090
- context: 'formatting'
1091
- });
1092
- // Tuesday
1093
- case 'iiii':
1094
- default:
1095
- return localize.day(dayOfWeek, {
1096
- width: 'wide',
1097
- context: 'formatting'
1098
- });
1099
- }
1100
- },
1101
- // AM or PM
1102
- a: function a(date, token, localize) {
1103
- var hours = date.getUTCHours();
1104
- var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1105
- switch (token) {
1106
- case 'a':
1107
- case 'aa':
1108
- return localize.dayPeriod(dayPeriodEnumValue, {
1109
- width: 'abbreviated',
1110
- context: 'formatting'
1111
- });
1112
- case 'aaa':
1113
- return localize.dayPeriod(dayPeriodEnumValue, {
1114
- width: 'abbreviated',
1115
- context: 'formatting'
1116
- }).toLowerCase();
1117
- case 'aaaaa':
1118
- return localize.dayPeriod(dayPeriodEnumValue, {
1119
- width: 'narrow',
1120
- context: 'formatting'
1121
- });
1122
- case 'aaaa':
1123
- default:
1124
- return localize.dayPeriod(dayPeriodEnumValue, {
1125
- width: 'wide',
1126
- context: 'formatting'
1127
- });
1128
- }
1129
- },
1130
- // AM, PM, midnight, noon
1131
- b: function b(date, token, localize) {
1132
- var hours = date.getUTCHours();
1133
- var dayPeriodEnumValue;
1134
- if (hours === 12) {
1135
- dayPeriodEnumValue = dayPeriodEnum.noon;
1136
- } else if (hours === 0) {
1137
- dayPeriodEnumValue = dayPeriodEnum.midnight;
1138
- } else {
1139
- dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1140
- }
1141
- switch (token) {
1142
- case 'b':
1143
- case 'bb':
1144
- return localize.dayPeriod(dayPeriodEnumValue, {
1145
- width: 'abbreviated',
1146
- context: 'formatting'
1147
- });
1148
- case 'bbb':
1149
- return localize.dayPeriod(dayPeriodEnumValue, {
1150
- width: 'abbreviated',
1151
- context: 'formatting'
1152
- }).toLowerCase();
1153
- case 'bbbbb':
1154
- return localize.dayPeriod(dayPeriodEnumValue, {
1155
- width: 'narrow',
1156
- context: 'formatting'
1157
- });
1158
- case 'bbbb':
1159
- default:
1160
- return localize.dayPeriod(dayPeriodEnumValue, {
1161
- width: 'wide',
1162
- context: 'formatting'
1163
- });
1164
- }
1165
- },
1166
- // in the morning, in the afternoon, in the evening, at night
1167
- B: function B(date, token, localize) {
1168
- var hours = date.getUTCHours();
1169
- var dayPeriodEnumValue;
1170
- if (hours >= 17) {
1171
- dayPeriodEnumValue = dayPeriodEnum.evening;
1172
- } else if (hours >= 12) {
1173
- dayPeriodEnumValue = dayPeriodEnum.afternoon;
1174
- } else if (hours >= 4) {
1175
- dayPeriodEnumValue = dayPeriodEnum.morning;
1176
- } else {
1177
- dayPeriodEnumValue = dayPeriodEnum.night;
1178
- }
1179
- switch (token) {
1180
- case 'B':
1181
- case 'BB':
1182
- case 'BBB':
1183
- return localize.dayPeriod(dayPeriodEnumValue, {
1184
- width: 'abbreviated',
1185
- context: 'formatting'
1186
- });
1187
- case 'BBBBB':
1188
- return localize.dayPeriod(dayPeriodEnumValue, {
1189
- width: 'narrow',
1190
- context: 'formatting'
1191
- });
1192
- case 'BBBB':
1193
- default:
1194
- return localize.dayPeriod(dayPeriodEnumValue, {
1195
- width: 'wide',
1196
- context: 'formatting'
1197
- });
1198
- }
1199
- },
1200
- // Hour [1-12]
1201
- h: function h(date, token, localize) {
1202
- if (token === 'ho') {
1203
- var hours = date.getUTCHours() % 12;
1204
- if (hours === 0) hours = 12;
1205
- return localize.ordinalNumber(hours, {
1206
- unit: 'hour'
1207
- });
1208
- }
1209
- return formatters$3.h(date, token);
1210
- },
1211
- // Hour [0-23]
1212
- H: function H(date, token, localize) {
1213
- if (token === 'Ho') {
1214
- return localize.ordinalNumber(date.getUTCHours(), {
1215
- unit: 'hour'
1216
- });
1217
- }
1218
- return formatters$3.H(date, token);
1219
- },
1220
- // Hour [0-11]
1221
- K: function K(date, token, localize) {
1222
- var hours = date.getUTCHours() % 12;
1223
- if (token === 'Ko') {
1224
- return localize.ordinalNumber(hours, {
1225
- unit: 'hour'
1226
- });
1227
- }
1228
- return addLeadingZeros(hours, token.length);
1229
- },
1230
- // Hour [1-24]
1231
- k: function k(date, token, localize) {
1232
- var hours = date.getUTCHours();
1233
- if (hours === 0) hours = 24;
1234
- if (token === 'ko') {
1235
- return localize.ordinalNumber(hours, {
1236
- unit: 'hour'
1237
- });
1238
- }
1239
- return addLeadingZeros(hours, token.length);
1240
- },
1241
- // Minute
1242
- m: function m(date, token, localize) {
1243
- if (token === 'mo') {
1244
- return localize.ordinalNumber(date.getUTCMinutes(), {
1245
- unit: 'minute'
1246
- });
1247
- }
1248
- return formatters$3.m(date, token);
1249
- },
1250
- // Second
1251
- s: function s(date, token, localize) {
1252
- if (token === 'so') {
1253
- return localize.ordinalNumber(date.getUTCSeconds(), {
1254
- unit: 'second'
1255
- });
1256
- }
1257
- return formatters$3.s(date, token);
1258
- },
1259
- // Fraction of second
1260
- S: function S(date, token) {
1261
- return formatters$3.S(date, token);
1262
- },
1263
- // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
1264
- X: function X(date, token, _localize, options) {
1265
- var originalDate = options._originalDate || date;
1266
- var timezoneOffset = originalDate.getTimezoneOffset();
1267
- if (timezoneOffset === 0) {
1268
- return 'Z';
1269
- }
1270
- switch (token) {
1271
- // Hours and optional minutes
1272
- case 'X':
1273
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
1274
-
1275
- // Hours, minutes and optional seconds without `:` delimiter
1276
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1277
- // so this token always has the same output as `XX`
1278
- case 'XXXX':
1279
- case 'XX':
1280
- // Hours and minutes without `:` delimiter
1281
- return formatTimezone(timezoneOffset);
1282
-
1283
- // Hours, minutes and optional seconds with `:` delimiter
1284
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1285
- // so this token always has the same output as `XXX`
1286
- case 'XXXXX':
1287
- case 'XXX': // Hours and minutes with `:` delimiter
1288
- default:
1289
- return formatTimezone(timezoneOffset, ':');
1290
- }
1291
- },
1292
- // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
1293
- x: function x(date, token, _localize, options) {
1294
- var originalDate = options._originalDate || date;
1295
- var timezoneOffset = originalDate.getTimezoneOffset();
1296
- switch (token) {
1297
- // Hours and optional minutes
1298
- case 'x':
1299
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
1300
-
1301
- // Hours, minutes and optional seconds without `:` delimiter
1302
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1303
- // so this token always has the same output as `xx`
1304
- case 'xxxx':
1305
- case 'xx':
1306
- // Hours and minutes without `:` delimiter
1307
- return formatTimezone(timezoneOffset);
1308
-
1309
- // Hours, minutes and optional seconds with `:` delimiter
1310
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1311
- // so this token always has the same output as `xxx`
1312
- case 'xxxxx':
1313
- case 'xxx': // Hours and minutes with `:` delimiter
1314
- default:
1315
- return formatTimezone(timezoneOffset, ':');
1316
- }
1317
- },
1318
- // Timezone (GMT)
1319
- O: function O(date, token, _localize, options) {
1320
- var originalDate = options._originalDate || date;
1321
- var timezoneOffset = originalDate.getTimezoneOffset();
1322
- switch (token) {
1323
- // Short
1324
- case 'O':
1325
- case 'OO':
1326
- case 'OOO':
1327
- return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1328
- // Long
1329
- case 'OOOO':
1330
- default:
1331
- return 'GMT' + formatTimezone(timezoneOffset, ':');
1332
- }
1333
- },
1334
- // Timezone (specific non-location)
1335
- z: function z(date, token, _localize, options) {
1336
- var originalDate = options._originalDate || date;
1337
- var timezoneOffset = originalDate.getTimezoneOffset();
1338
- switch (token) {
1339
- // Short
1340
- case 'z':
1341
- case 'zz':
1342
- case 'zzz':
1343
- return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1344
- // Long
1345
- case 'zzzz':
1346
- default:
1347
- return 'GMT' + formatTimezone(timezoneOffset, ':');
1348
- }
1349
- },
1350
- // Seconds timestamp
1351
- t: function t(date, token, _localize, options) {
1352
- var originalDate = options._originalDate || date;
1353
- var timestamp = Math.floor(originalDate.getTime() / 1000);
1354
- return addLeadingZeros(timestamp, token.length);
1355
- },
1356
- // Milliseconds timestamp
1357
- T: function T(date, token, _localize, options) {
1358
- var originalDate = options._originalDate || date;
1359
- var timestamp = originalDate.getTime();
1360
- return addLeadingZeros(timestamp, token.length);
1361
- }
1362
- };
1363
- function formatTimezoneShort(offset, dirtyDelimiter) {
1364
- var sign = offset > 0 ? '-' : '+';
1365
- var absOffset = Math.abs(offset);
1366
- var hours = Math.floor(absOffset / 60);
1367
- var minutes = absOffset % 60;
1368
- if (minutes === 0) {
1369
- return sign + String(hours);
1370
- }
1371
- var delimiter = dirtyDelimiter || '';
1372
- return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
1373
- }
1374
- function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
1375
- if (offset % 60 === 0) {
1376
- var sign = offset > 0 ? '-' : '+';
1377
- return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
1378
- }
1379
- return formatTimezone(offset, dirtyDelimiter);
1380
- }
1381
- function formatTimezone(offset, dirtyDelimiter) {
1382
- var delimiter = dirtyDelimiter || '';
1383
- var sign = offset > 0 ? '-' : '+';
1384
- var absOffset = Math.abs(offset);
1385
- var hours = addLeadingZeros(Math.floor(absOffset / 60), 2);
1386
- var minutes = addLeadingZeros(absOffset % 60, 2);
1387
- return sign + hours + delimiter + minutes;
1388
- }
1389
- const formatters$1 = formatters;
1390
-
1391
- var dateLongFormatter = function dateLongFormatter(pattern, formatLong) {
1392
- switch (pattern) {
1393
- case 'P':
1394
- return formatLong.date({
1395
- width: 'short'
1396
- });
1397
- case 'PP':
1398
- return formatLong.date({
1399
- width: 'medium'
1400
- });
1401
- case 'PPP':
1402
- return formatLong.date({
1403
- width: 'long'
1404
- });
1405
- case 'PPPP':
1406
- default:
1407
- return formatLong.date({
1408
- width: 'full'
1409
- });
1410
- }
1411
- };
1412
- var timeLongFormatter = function timeLongFormatter(pattern, formatLong) {
1413
- switch (pattern) {
1414
- case 'p':
1415
- return formatLong.time({
1416
- width: 'short'
1417
- });
1418
- case 'pp':
1419
- return formatLong.time({
1420
- width: 'medium'
1421
- });
1422
- case 'ppp':
1423
- return formatLong.time({
1424
- width: 'long'
1425
- });
1426
- case 'pppp':
1427
- default:
1428
- return formatLong.time({
1429
- width: 'full'
1430
- });
1431
- }
1432
- };
1433
- var dateTimeLongFormatter = function dateTimeLongFormatter(pattern, formatLong) {
1434
- var matchResult = pattern.match(/(P+)(p+)?/) || [];
1435
- var datePattern = matchResult[1];
1436
- var timePattern = matchResult[2];
1437
- if (!timePattern) {
1438
- return dateLongFormatter(pattern, formatLong);
1439
- }
1440
- var dateTimeFormat;
1441
- switch (datePattern) {
1442
- case 'P':
1443
- dateTimeFormat = formatLong.dateTime({
1444
- width: 'short'
1445
- });
1446
- break;
1447
- case 'PP':
1448
- dateTimeFormat = formatLong.dateTime({
1449
- width: 'medium'
1450
- });
1451
- break;
1452
- case 'PPP':
1453
- dateTimeFormat = formatLong.dateTime({
1454
- width: 'long'
1455
- });
1456
- break;
1457
- case 'PPPP':
1458
- default:
1459
- dateTimeFormat = formatLong.dateTime({
1460
- width: 'full'
1461
- });
1462
- break;
1463
- }
1464
- return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
1465
- };
1466
- var longFormatters = {
1467
- p: timeLongFormatter,
1468
- P: dateTimeLongFormatter
1469
- };
1470
- const longFormatters$1 = longFormatters;
1471
-
1472
- var protectedDayOfYearTokens = ['D', 'DD'];
1473
- var protectedWeekYearTokens = ['YY', 'YYYY'];
1474
- function isProtectedDayOfYearToken(token) {
1475
- return protectedDayOfYearTokens.indexOf(token) !== -1;
1476
- }
1477
- function isProtectedWeekYearToken(token) {
1478
- return protectedWeekYearTokens.indexOf(token) !== -1;
1479
- }
1480
- function throwProtectedError(token, format, input) {
1481
- if (token === 'YYYY') {
1482
- 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"));
1483
- } else if (token === 'YY') {
1484
- 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"));
1485
- } else if (token === 'D') {
1486
- 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"));
1487
- } else if (token === 'DD') {
1488
- 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"));
1489
- }
1490
- }
1491
-
1492
- var formatDistanceLocale = {
1493
- lessThanXSeconds: {
1494
- one: 'less than a second',
1495
- other: 'less than {{count}} seconds'
1496
- },
1497
- xSeconds: {
1498
- one: '1 second',
1499
- other: '{{count}} seconds'
1500
- },
1501
- halfAMinute: 'half a minute',
1502
- lessThanXMinutes: {
1503
- one: 'less than a minute',
1504
- other: 'less than {{count}} minutes'
1505
- },
1506
- xMinutes: {
1507
- one: '1 minute',
1508
- other: '{{count}} minutes'
1509
- },
1510
- aboutXHours: {
1511
- one: 'about 1 hour',
1512
- other: 'about {{count}} hours'
1513
- },
1514
- xHours: {
1515
- one: '1 hour',
1516
- other: '{{count}} hours'
1517
- },
1518
- xDays: {
1519
- one: '1 day',
1520
- other: '{{count}} days'
1521
- },
1522
- aboutXWeeks: {
1523
- one: 'about 1 week',
1524
- other: 'about {{count}} weeks'
1525
- },
1526
- xWeeks: {
1527
- one: '1 week',
1528
- other: '{{count}} weeks'
1529
- },
1530
- aboutXMonths: {
1531
- one: 'about 1 month',
1532
- other: 'about {{count}} months'
1533
- },
1534
- xMonths: {
1535
- one: '1 month',
1536
- other: '{{count}} months'
1537
- },
1538
- aboutXYears: {
1539
- one: 'about 1 year',
1540
- other: 'about {{count}} years'
1541
- },
1542
- xYears: {
1543
- one: '1 year',
1544
- other: '{{count}} years'
1545
- },
1546
- overXYears: {
1547
- one: 'over 1 year',
1548
- other: 'over {{count}} years'
1549
- },
1550
- almostXYears: {
1551
- one: 'almost 1 year',
1552
- other: 'almost {{count}} years'
1553
- }
1554
- };
1555
- var formatDistance = function formatDistance(token, count, options) {
1556
- var result;
1557
- var tokenValue = formatDistanceLocale[token];
1558
- if (typeof tokenValue === 'string') {
1559
- result = tokenValue;
1560
- } else if (count === 1) {
1561
- result = tokenValue.one;
1562
- } else {
1563
- result = tokenValue.other.replace('{{count}}', count.toString());
1564
- }
1565
- if (options !== null && options !== void 0 && options.addSuffix) {
1566
- if (options.comparison && options.comparison > 0) {
1567
- return 'in ' + result;
1568
- } else {
1569
- return result + ' ago';
1570
- }
1571
- }
1572
- return result;
1573
- };
1574
- const formatDistance$1 = formatDistance;
1575
-
1576
- function buildFormatLongFn(args) {
1577
- return function () {
1578
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1579
- // TODO: Remove String()
1580
- var width = options.width ? String(options.width) : args.defaultWidth;
1581
- var format = args.formats[width] || args.formats[args.defaultWidth];
1582
- return format;
1583
- };
1584
- }
1585
-
1586
- var dateFormats = {
1587
- full: 'EEEE, MMMM do, y',
1588
- long: 'MMMM do, y',
1589
- medium: 'MMM d, y',
1590
- short: 'MM/dd/yyyy'
1591
- };
1592
- var timeFormats = {
1593
- full: 'h:mm:ss a zzzz',
1594
- long: 'h:mm:ss a z',
1595
- medium: 'h:mm:ss a',
1596
- short: 'h:mm a'
1597
- };
1598
- var dateTimeFormats = {
1599
- full: "{{date}} 'at' {{time}}",
1600
- long: "{{date}} 'at' {{time}}",
1601
- medium: '{{date}}, {{time}}',
1602
- short: '{{date}}, {{time}}'
1603
- };
1604
- var formatLong = {
1605
- date: buildFormatLongFn({
1606
- formats: dateFormats,
1607
- defaultWidth: 'full'
1608
- }),
1609
- time: buildFormatLongFn({
1610
- formats: timeFormats,
1611
- defaultWidth: 'full'
1612
- }),
1613
- dateTime: buildFormatLongFn({
1614
- formats: dateTimeFormats,
1615
- defaultWidth: 'full'
1616
- })
1617
- };
1618
- const formatLong$1 = formatLong;
1619
-
1620
- var formatRelativeLocale = {
1621
- lastWeek: "'last' eeee 'at' p",
1622
- yesterday: "'yesterday at' p",
1623
- today: "'today at' p",
1624
- tomorrow: "'tomorrow at' p",
1625
- nextWeek: "eeee 'at' p",
1626
- other: 'P'
1627
- };
1628
- var formatRelative = function formatRelative(token, _date, _baseDate, _options) {
1629
- return formatRelativeLocale[token];
1630
- };
1631
- const formatRelative$1 = formatRelative;
1632
-
1633
- function buildLocalizeFn(args) {
1634
- return function (dirtyIndex, options) {
1635
- var context = options !== null && options !== void 0 && options.context ? String(options.context) : 'standalone';
1636
- var valuesArray;
1637
- if (context === 'formatting' && args.formattingValues) {
1638
- var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
1639
- var width = options !== null && options !== void 0 && options.width ? String(options.width) : defaultWidth;
1640
- valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
1641
- } else {
1642
- var _defaultWidth = args.defaultWidth;
1643
- var _width = options !== null && options !== void 0 && options.width ? String(options.width) : args.defaultWidth;
1644
- valuesArray = args.values[_width] || args.values[_defaultWidth];
1645
- }
1646
- var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex;
1647
- // @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!
1648
- return valuesArray[index];
1649
- };
1650
- }
1651
-
1652
- var eraValues = {
1653
- narrow: ['B', 'A'],
1654
- abbreviated: ['BC', 'AD'],
1655
- wide: ['Before Christ', 'Anno Domini']
1656
- };
1657
- var quarterValues = {
1658
- narrow: ['1', '2', '3', '4'],
1659
- abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
1660
- wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter']
1661
- };
1662
-
1663
- // Note: in English, the names of days of the week and months are capitalized.
1664
- // If you are making a new locale based on this one, check if the same is true for the language you're working on.
1665
- // Generally, formatted dates should look like they are in the middle of a sentence,
1666
- // e.g. in Spanish language the weekdays and months should be in the lowercase.
1667
- var monthValues = {
1668
- narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
1669
- abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
1670
- wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
1671
- };
1672
- var dayValues = {
1673
- narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
1674
- short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
1675
- abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
1676
- wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
1677
- };
1678
- var dayPeriodValues = {
1679
- narrow: {
1680
- am: 'a',
1681
- pm: 'p',
1682
- midnight: 'mi',
1683
- noon: 'n',
1684
- morning: 'morning',
1685
- afternoon: 'afternoon',
1686
- evening: 'evening',
1687
- night: 'night'
1688
- },
1689
- abbreviated: {
1690
- am: 'AM',
1691
- pm: 'PM',
1692
- midnight: 'midnight',
1693
- noon: 'noon',
1694
- morning: 'morning',
1695
- afternoon: 'afternoon',
1696
- evening: 'evening',
1697
- night: 'night'
1698
- },
1699
- wide: {
1700
- am: 'a.m.',
1701
- pm: 'p.m.',
1702
- midnight: 'midnight',
1703
- noon: 'noon',
1704
- morning: 'morning',
1705
- afternoon: 'afternoon',
1706
- evening: 'evening',
1707
- night: 'night'
1708
- }
1709
- };
1710
- var formattingDayPeriodValues = {
1711
- narrow: {
1712
- am: 'a',
1713
- pm: 'p',
1714
- midnight: 'mi',
1715
- noon: 'n',
1716
- morning: 'in the morning',
1717
- afternoon: 'in the afternoon',
1718
- evening: 'in the evening',
1719
- night: 'at night'
1720
- },
1721
- abbreviated: {
1722
- am: 'AM',
1723
- pm: 'PM',
1724
- midnight: 'midnight',
1725
- noon: 'noon',
1726
- morning: 'in the morning',
1727
- afternoon: 'in the afternoon',
1728
- evening: 'in the evening',
1729
- night: 'at night'
1730
- },
1731
- wide: {
1732
- am: 'a.m.',
1733
- pm: 'p.m.',
1734
- midnight: 'midnight',
1735
- noon: 'noon',
1736
- morning: 'in the morning',
1737
- afternoon: 'in the afternoon',
1738
- evening: 'in the evening',
1739
- night: 'at night'
1740
- }
1741
- };
1742
- var ordinalNumber = function ordinalNumber(dirtyNumber, _options) {
1743
- var number = Number(dirtyNumber);
1744
-
1745
- // If ordinal numbers depend on context, for example,
1746
- // if they are different for different grammatical genders,
1747
- // use `options.unit`.
1748
- //
1749
- // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
1750
- // 'day', 'hour', 'minute', 'second'.
1751
-
1752
- var rem100 = number % 100;
1753
- if (rem100 > 20 || rem100 < 10) {
1754
- switch (rem100 % 10) {
1755
- case 1:
1756
- return number + 'st';
1757
- case 2:
1758
- return number + 'nd';
1759
- case 3:
1760
- return number + 'rd';
1761
- }
1762
- }
1763
- return number + 'th';
1764
- };
1765
- var localize = {
1766
- ordinalNumber: ordinalNumber,
1767
- era: buildLocalizeFn({
1768
- values: eraValues,
1769
- defaultWidth: 'wide'
1770
- }),
1771
- quarter: buildLocalizeFn({
1772
- values: quarterValues,
1773
- defaultWidth: 'wide',
1774
- argumentCallback: function argumentCallback(quarter) {
1775
- return quarter - 1;
1776
- }
1777
- }),
1778
- month: buildLocalizeFn({
1779
- values: monthValues,
1780
- defaultWidth: 'wide'
1781
- }),
1782
- day: buildLocalizeFn({
1783
- values: dayValues,
1784
- defaultWidth: 'wide'
1785
- }),
1786
- dayPeriod: buildLocalizeFn({
1787
- values: dayPeriodValues,
1788
- defaultWidth: 'wide',
1789
- formattingValues: formattingDayPeriodValues,
1790
- defaultFormattingWidth: 'wide'
1791
- })
1792
- };
1793
- const localize$1 = localize;
1794
-
1795
- function buildMatchFn(args) {
1796
- return function (string) {
1797
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1798
- var width = options.width;
1799
- var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
1800
- var matchResult = string.match(matchPattern);
1801
- if (!matchResult) {
1802
- return null;
1803
- }
1804
- var matchedString = matchResult[0];
1805
- var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
1806
- var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) {
1807
- return pattern.test(matchedString);
1808
- }) : findKey(parsePatterns, function (pattern) {
1809
- return pattern.test(matchedString);
1810
- });
1811
- var value;
1812
- value = args.valueCallback ? args.valueCallback(key) : key;
1813
- value = options.valueCallback ? options.valueCallback(value) : value;
1814
- var rest = string.slice(matchedString.length);
1815
- return {
1816
- value: value,
1817
- rest: rest
1818
- };
1819
- };
1820
- }
1821
- function findKey(object, predicate) {
1822
- for (var key in object) {
1823
- if (object.hasOwnProperty(key) && predicate(object[key])) {
1824
- return key;
1825
- }
1826
- }
1827
- return undefined;
1828
- }
1829
- function findIndex(array, predicate) {
1830
- for (var key = 0; key < array.length; key++) {
1831
- if (predicate(array[key])) {
1832
- return key;
1833
- }
1834
- }
1835
- return undefined;
1836
- }
1837
-
1838
- function buildMatchPatternFn(args) {
1839
- return function (string) {
1840
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1841
- var matchResult = string.match(args.matchPattern);
1842
- if (!matchResult) return null;
1843
- var matchedString = matchResult[0];
1844
- var parseResult = string.match(args.parsePattern);
1845
- if (!parseResult) return null;
1846
- var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
1847
- value = options.valueCallback ? options.valueCallback(value) : value;
1848
- var rest = string.slice(matchedString.length);
1849
- return {
1850
- value: value,
1851
- rest: rest
1852
- };
1853
- };
1854
- }
1855
-
1856
- var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
1857
- var parseOrdinalNumberPattern = /\d+/i;
1858
- var matchEraPatterns = {
1859
- narrow: /^(b|a)/i,
1860
- abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
1861
- wide: /^(before christ|before common era|anno domini|common era)/i
1862
- };
1863
- var parseEraPatterns = {
1864
- any: [/^b/i, /^(a|c)/i]
1865
- };
1866
- var matchQuarterPatterns = {
1867
- narrow: /^[1234]/i,
1868
- abbreviated: /^q[1234]/i,
1869
- wide: /^[1234](th|st|nd|rd)? quarter/i
1870
- };
1871
- var parseQuarterPatterns = {
1872
- any: [/1/i, /2/i, /3/i, /4/i]
1873
- };
1874
- var matchMonthPatterns = {
1875
- narrow: /^[jfmasond]/i,
1876
- abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
1877
- wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
1878
- };
1879
- var parseMonthPatterns = {
1880
- 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],
1881
- 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]
1882
- };
1883
- var matchDayPatterns = {
1884
- narrow: /^[smtwf]/i,
1885
- short: /^(su|mo|tu|we|th|fr|sa)/i,
1886
- abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
1887
- wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
1888
- };
1889
- var parseDayPatterns = {
1890
- narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
1891
- any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
1892
- };
1893
- var matchDayPeriodPatterns = {
1894
- narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
1895
- any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
1896
- };
1897
- var parseDayPeriodPatterns = {
1898
- any: {
1899
- am: /^a/i,
1900
- pm: /^p/i,
1901
- midnight: /^mi/i,
1902
- noon: /^no/i,
1903
- morning: /morning/i,
1904
- afternoon: /afternoon/i,
1905
- evening: /evening/i,
1906
- night: /night/i
1907
- }
1908
- };
1909
- var match = {
1910
- ordinalNumber: buildMatchPatternFn({
1911
- matchPattern: matchOrdinalNumberPattern,
1912
- parsePattern: parseOrdinalNumberPattern,
1913
- valueCallback: function valueCallback(value) {
1914
- return parseInt(value, 10);
1915
- }
1916
- }),
1917
- era: buildMatchFn({
1918
- matchPatterns: matchEraPatterns,
1919
- defaultMatchWidth: 'wide',
1920
- parsePatterns: parseEraPatterns,
1921
- defaultParseWidth: 'any'
1922
- }),
1923
- quarter: buildMatchFn({
1924
- matchPatterns: matchQuarterPatterns,
1925
- defaultMatchWidth: 'wide',
1926
- parsePatterns: parseQuarterPatterns,
1927
- defaultParseWidth: 'any',
1928
- valueCallback: function valueCallback(index) {
1929
- return index + 1;
1930
- }
1931
- }),
1932
- month: buildMatchFn({
1933
- matchPatterns: matchMonthPatterns,
1934
- defaultMatchWidth: 'wide',
1935
- parsePatterns: parseMonthPatterns,
1936
- defaultParseWidth: 'any'
1937
- }),
1938
- day: buildMatchFn({
1939
- matchPatterns: matchDayPatterns,
1940
- defaultMatchWidth: 'wide',
1941
- parsePatterns: parseDayPatterns,
1942
- defaultParseWidth: 'any'
1943
- }),
1944
- dayPeriod: buildMatchFn({
1945
- matchPatterns: matchDayPeriodPatterns,
1946
- defaultMatchWidth: 'any',
1947
- parsePatterns: parseDayPeriodPatterns,
1948
- defaultParseWidth: 'any'
1949
- })
1950
- };
1951
- const match$1 = match;
1952
-
1953
- /**
1954
- * @type {Locale}
1955
- * @category Locales
1956
- * @summary English locale (United States).
1957
- * @language English
1958
- * @iso-639-2 eng
1959
- * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}
1960
- * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}
1961
- */
1962
- var locale = {
1963
- code: 'en-US',
1964
- formatDistance: formatDistance$1,
1965
- formatLong: formatLong$1,
1966
- formatRelative: formatRelative$1,
1967
- localize: localize$1,
1968
- match: match$1,
1969
- options: {
1970
- weekStartsOn: 0 /* Sunday */,
1971
- firstWeekContainsDate: 1
1972
- }
1973
- };
1974
- const defaultLocale = locale;
1975
-
1976
- // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
1977
- // (one of the certain letters followed by `o`)
1978
- // - (\w)\1* matches any sequences of the same letter
1979
- // - '' matches two quote characters in a row
1980
- // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
1981
- // except a single quote symbol, which ends the sequence.
1982
- // Two quote characters do not end the sequence.
1983
- // If there is no matching single quote
1984
- // then the sequence will continue until the end of the string.
1985
- // - . matches any single character unmatched by previous parts of the RegExps
1986
- var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
1987
-
1988
- // This RegExp catches symbols escaped by quotes, and also
1989
- // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
1990
- var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
1991
- var escapedStringRegExp = /^'([^]*?)'?$/;
1992
- var doubleQuoteRegExp = /''/g;
1993
- var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
1994
-
1995
- /**
1996
- * @name format
1997
- * @category Common Helpers
1998
- * @summary Format the date.
1999
- *
2000
- * @description
2001
- * Return the formatted date string in the given format. The result may vary by locale.
2002
- *
2003
- * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
2004
- * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2005
- *
2006
- * The characters wrapped between two single quotes characters (') are escaped.
2007
- * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
2008
- * (see the last example)
2009
- *
2010
- * Format of the string is based on Unicode Technical Standard #35:
2011
- * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
2012
- * with a few additions (see note 7 below the table).
2013
- *
2014
- * Accepted patterns:
2015
- * | Unit | Pattern | Result examples | Notes |
2016
- * |---------------------------------|---------|-----------------------------------|-------|
2017
- * | Era | G..GGG | AD, BC | |
2018
- * | | GGGG | Anno Domini, Before Christ | 2 |
2019
- * | | GGGGG | A, B | |
2020
- * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
2021
- * | | yo | 44th, 1st, 0th, 17th | 5,7 |
2022
- * | | yy | 44, 01, 00, 17 | 5 |
2023
- * | | yyy | 044, 001, 1900, 2017 | 5 |
2024
- * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
2025
- * | | yyyyy | ... | 3,5 |
2026
- * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
2027
- * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
2028
- * | | YY | 44, 01, 00, 17 | 5,8 |
2029
- * | | YYY | 044, 001, 1900, 2017 | 5 |
2030
- * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
2031
- * | | YYYYY | ... | 3,5 |
2032
- * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
2033
- * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
2034
- * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
2035
- * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
2036
- * | | RRRRR | ... | 3,5,7 |
2037
- * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
2038
- * | | uu | -43, 01, 1900, 2017 | 5 |
2039
- * | | uuu | -043, 001, 1900, 2017 | 5 |
2040
- * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
2041
- * | | uuuuu | ... | 3,5 |
2042
- * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
2043
- * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
2044
- * | | QQ | 01, 02, 03, 04 | |
2045
- * | | QQQ | Q1, Q2, Q3, Q4 | |
2046
- * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
2047
- * | | QQQQQ | 1, 2, 3, 4 | 4 |
2048
- * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
2049
- * | | qo | 1st, 2nd, 3rd, 4th | 7 |
2050
- * | | qq | 01, 02, 03, 04 | |
2051
- * | | qqq | Q1, Q2, Q3, Q4 | |
2052
- * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
2053
- * | | qqqqq | 1, 2, 3, 4 | 4 |
2054
- * | Month (formatting) | M | 1, 2, ..., 12 | |
2055
- * | | Mo | 1st, 2nd, ..., 12th | 7 |
2056
- * | | MM | 01, 02, ..., 12 | |
2057
- * | | MMM | Jan, Feb, ..., Dec | |
2058
- * | | MMMM | January, February, ..., December | 2 |
2059
- * | | MMMMM | J, F, ..., D | |
2060
- * | Month (stand-alone) | L | 1, 2, ..., 12 | |
2061
- * | | Lo | 1st, 2nd, ..., 12th | 7 |
2062
- * | | LL | 01, 02, ..., 12 | |
2063
- * | | LLL | Jan, Feb, ..., Dec | |
2064
- * | | LLLL | January, February, ..., December | 2 |
2065
- * | | LLLLL | J, F, ..., D | |
2066
- * | Local week of year | w | 1, 2, ..., 53 | |
2067
- * | | wo | 1st, 2nd, ..., 53th | 7 |
2068
- * | | ww | 01, 02, ..., 53 | |
2069
- * | ISO week of year | I | 1, 2, ..., 53 | 7 |
2070
- * | | Io | 1st, 2nd, ..., 53th | 7 |
2071
- * | | II | 01, 02, ..., 53 | 7 |
2072
- * | Day of month | d | 1, 2, ..., 31 | |
2073
- * | | do | 1st, 2nd, ..., 31st | 7 |
2074
- * | | dd | 01, 02, ..., 31 | |
2075
- * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
2076
- * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
2077
- * | | DD | 01, 02, ..., 365, 366 | 9 |
2078
- * | | DDD | 001, 002, ..., 365, 366 | |
2079
- * | | DDDD | ... | 3 |
2080
- * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
2081
- * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
2082
- * | | EEEEE | M, T, W, T, F, S, S | |
2083
- * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
2084
- * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
2085
- * | | io | 1st, 2nd, ..., 7th | 7 |
2086
- * | | ii | 01, 02, ..., 07 | 7 |
2087
- * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
2088
- * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
2089
- * | | iiiii | M, T, W, T, F, S, S | 7 |
2090
- * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
2091
- * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
2092
- * | | eo | 2nd, 3rd, ..., 1st | 7 |
2093
- * | | ee | 02, 03, ..., 01 | |
2094
- * | | eee | Mon, Tue, Wed, ..., Sun | |
2095
- * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
2096
- * | | eeeee | M, T, W, T, F, S, S | |
2097
- * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
2098
- * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
2099
- * | | co | 2nd, 3rd, ..., 1st | 7 |
2100
- * | | cc | 02, 03, ..., 01 | |
2101
- * | | ccc | Mon, Tue, Wed, ..., Sun | |
2102
- * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
2103
- * | | ccccc | M, T, W, T, F, S, S | |
2104
- * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
2105
- * | AM, PM | a..aa | AM, PM | |
2106
- * | | aaa | am, pm | |
2107
- * | | aaaa | a.m., p.m. | 2 |
2108
- * | | aaaaa | a, p | |
2109
- * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
2110
- * | | bbb | am, pm, noon, midnight | |
2111
- * | | bbbb | a.m., p.m., noon, midnight | 2 |
2112
- * | | bbbbb | a, p, n, mi | |
2113
- * | Flexible day period | B..BBB | at night, in the morning, ... | |
2114
- * | | BBBB | at night, in the morning, ... | 2 |
2115
- * | | BBBBB | at night, in the morning, ... | |
2116
- * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
2117
- * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
2118
- * | | hh | 01, 02, ..., 11, 12 | |
2119
- * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
2120
- * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
2121
- * | | HH | 00, 01, 02, ..., 23 | |
2122
- * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
2123
- * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
2124
- * | | KK | 01, 02, ..., 11, 00 | |
2125
- * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
2126
- * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
2127
- * | | kk | 24, 01, 02, ..., 23 | |
2128
- * | Minute | m | 0, 1, ..., 59 | |
2129
- * | | mo | 0th, 1st, ..., 59th | 7 |
2130
- * | | mm | 00, 01, ..., 59 | |
2131
- * | Second | s | 0, 1, ..., 59 | |
2132
- * | | so | 0th, 1st, ..., 59th | 7 |
2133
- * | | ss | 00, 01, ..., 59 | |
2134
- * | Fraction of second | S | 0, 1, ..., 9 | |
2135
- * | | SS | 00, 01, ..., 99 | |
2136
- * | | SSS | 000, 001, ..., 999 | |
2137
- * | | SSSS | ... | 3 |
2138
- * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
2139
- * | | XX | -0800, +0530, Z | |
2140
- * | | XXX | -08:00, +05:30, Z | |
2141
- * | | XXXX | -0800, +0530, Z, +123456 | 2 |
2142
- * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
2143
- * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
2144
- * | | xx | -0800, +0530, +0000 | |
2145
- * | | xxx | -08:00, +05:30, +00:00 | 2 |
2146
- * | | xxxx | -0800, +0530, +0000, +123456 | |
2147
- * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
2148
- * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
2149
- * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
2150
- * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
2151
- * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
2152
- * | Seconds timestamp | t | 512969520 | 7 |
2153
- * | | tt | ... | 3,7 |
2154
- * | Milliseconds timestamp | T | 512969520900 | 7 |
2155
- * | | TT | ... | 3,7 |
2156
- * | Long localized date | P | 04/29/1453 | 7 |
2157
- * | | PP | Apr 29, 1453 | 7 |
2158
- * | | PPP | April 29th, 1453 | 7 |
2159
- * | | PPPP | Friday, April 29th, 1453 | 2,7 |
2160
- * | Long localized time | p | 12:00 AM | 7 |
2161
- * | | pp | 12:00:00 AM | 7 |
2162
- * | | ppp | 12:00:00 AM GMT+2 | 7 |
2163
- * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
2164
- * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
2165
- * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
2166
- * | | PPPppp | April 29th, 1453 at ... | 7 |
2167
- * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
2168
- * Notes:
2169
- * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
2170
- * are the same as "stand-alone" units, but are different in some languages.
2171
- * "Formatting" units are declined according to the rules of the language
2172
- * in the context of a date. "Stand-alone" units are always nominative singular:
2173
- *
2174
- * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
2175
- *
2176
- * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
2177
- *
2178
- * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
2179
- * the single quote characters (see below).
2180
- * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
2181
- * the output will be the same as default pattern for this unit, usually
2182
- * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
2183
- * are marked with "2" in the last column of the table.
2184
- *
2185
- * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
2186
- *
2187
- * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
2188
- *
2189
- * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
2190
- *
2191
- * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
2192
- *
2193
- * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
2194
- *
2195
- * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
2196
- * The output will be padded with zeros to match the length of the pattern.
2197
- *
2198
- * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
2199
- *
2200
- * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
2201
- * These tokens represent the shortest form of the quarter.
2202
- *
2203
- * 5. The main difference between `y` and `u` patterns are B.C. years:
2204
- *
2205
- * | Year | `y` | `u` |
2206
- * |------|-----|-----|
2207
- * | AC 1 | 1 | 1 |
2208
- * | BC 1 | 1 | 0 |
2209
- * | BC 2 | 2 | -1 |
2210
- *
2211
- * Also `yy` always returns the last two digits of a year,
2212
- * while `uu` pads single digit years to 2 characters and returns other years unchanged:
2213
- *
2214
- * | Year | `yy` | `uu` |
2215
- * |------|------|------|
2216
- * | 1 | 01 | 01 |
2217
- * | 14 | 14 | 14 |
2218
- * | 376 | 76 | 376 |
2219
- * | 1453 | 53 | 1453 |
2220
- *
2221
- * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
2222
- * except local week-numbering years are dependent on `options.weekStartsOn`
2223
- * and `options.firstWeekContainsDate` (compare [getISOWeekYear]{@link https://date-fns.org/docs/getISOWeekYear}
2224
- * and [getWeekYear]{@link https://date-fns.org/docs/getWeekYear}).
2225
- *
2226
- * 6. Specific non-location timezones are currently unavailable in `date-fns`,
2227
- * so right now these tokens fall back to GMT timezones.
2228
- *
2229
- * 7. These patterns are not in the Unicode Technical Standard #35:
2230
- * - `i`: ISO day of week
2231
- * - `I`: ISO week of year
2232
- * - `R`: ISO week-numbering year
2233
- * - `t`: seconds timestamp
2234
- * - `T`: milliseconds timestamp
2235
- * - `o`: ordinal number modifier
2236
- * - `P`: long localized date
2237
- * - `p`: long localized time
2238
- *
2239
- * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
2240
- * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2241
- *
2242
- * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
2243
- * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2244
- *
2245
- * @param {Date|Number} date - the original date
2246
- * @param {String} format - the string of tokens
2247
- * @param {Object} [options] - an object with options.
2248
- * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
2249
- * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
2250
- * @param {Number} [options.firstWeekContainsDate=1] - the day of January, which is
2251
- * @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`;
2252
- * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2253
- * @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`;
2254
- * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2255
- * @returns {String} the formatted date string
2256
- * @throws {TypeError} 2 arguments required
2257
- * @throws {RangeError} `date` must not be Invalid Date
2258
- * @throws {RangeError} `options.locale` must contain `localize` property
2259
- * @throws {RangeError} `options.locale` must contain `formatLong` property
2260
- * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
2261
- * @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7
2262
- * @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
2263
- * @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
2264
- * @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
2265
- * @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
2266
- * @throws {RangeError} format string contains an unescaped latin alphabet character
2267
- *
2268
- * @example
2269
- * // Represent 11 February 2014 in middle-endian format:
2270
- * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
2271
- * //=> '02/11/2014'
2272
- *
2273
- * @example
2274
- * // Represent 2 July 2014 in Esperanto:
2275
- * import { eoLocale } from 'date-fns/locale/eo'
2276
- * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
2277
- * locale: eoLocale
2278
- * })
2279
- * //=> '2-a de julio 2014'
2280
- *
2281
- * @example
2282
- * // Escape string by single quote characters:
2283
- * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
2284
- * //=> "3 o'clock"
2285
- */
2286
-
2287
- function format(dirtyDate, dirtyFormatStr, options) {
2288
- 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;
2289
- requiredArgs(2, arguments);
2290
- var formatStr = String(dirtyFormatStr);
2291
- var defaultOptions = getDefaultOptions();
2292
- var locale = (_ref = (_options$locale = options === null || options === void 0 ? void 0 : options.locale) !== null && _options$locale !== void 0 ? _options$locale : defaultOptions.locale) !== null && _ref !== void 0 ? _ref : defaultLocale;
2293
- 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);
2294
-
2295
- // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
2296
- if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
2297
- throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
2298
- }
2299
- 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);
2300
-
2301
- // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
2302
- if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
2303
- throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
2304
- }
2305
- if (!locale.localize) {
2306
- throw new RangeError('locale must contain localize property');
2307
- }
2308
- if (!locale.formatLong) {
2309
- throw new RangeError('locale must contain formatLong property');
2310
- }
2311
- var originalDate = toDate(dirtyDate);
2312
- if (!isValid(originalDate)) {
2313
- throw new RangeError('Invalid time value');
2314
- }
2315
-
2316
- // Convert the date in system timezone to the same date in UTC+00:00 timezone.
2317
- // This ensures that when UTC functions will be implemented, locales will be compatible with them.
2318
- // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376
2319
- var timezoneOffset = getTimezoneOffsetInMilliseconds(originalDate);
2320
- var utcDate = subMilliseconds(originalDate, timezoneOffset);
2321
- var formatterOptions = {
2322
- firstWeekContainsDate: firstWeekContainsDate,
2323
- weekStartsOn: weekStartsOn,
2324
- locale: locale,
2325
- _originalDate: originalDate
2326
- };
2327
- var result = formatStr.match(longFormattingTokensRegExp).map(function (substring) {
2328
- var firstCharacter = substring[0];
2329
- if (firstCharacter === 'p' || firstCharacter === 'P') {
2330
- var longFormatter = longFormatters$1[firstCharacter];
2331
- return longFormatter(substring, locale.formatLong);
2332
- }
2333
- return substring;
2334
- }).join('').match(formattingTokensRegExp).map(function (substring) {
2335
- // Replace two single quote characters with one single quote character
2336
- if (substring === "''") {
2337
- return "'";
2338
- }
2339
- var firstCharacter = substring[0];
2340
- if (firstCharacter === "'") {
2341
- return cleanEscapedString(substring);
2342
- }
2343
- var formatter = formatters$1[firstCharacter];
2344
- if (formatter) {
2345
- if (!(options !== null && options !== void 0 && options.useAdditionalWeekYearTokens) && isProtectedWeekYearToken(substring)) {
2346
- throwProtectedError(substring, dirtyFormatStr, String(dirtyDate));
2347
- }
2348
- if (!(options !== null && options !== void 0 && options.useAdditionalDayOfYearTokens) && isProtectedDayOfYearToken(substring)) {
2349
- throwProtectedError(substring, dirtyFormatStr, String(dirtyDate));
2350
- }
2351
- return formatter(utcDate, substring, locale.localize, formatterOptions);
2352
- }
2353
- if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
2354
- throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`');
2355
- }
2356
- return substring;
2357
- }).join('');
2358
- return result;
2359
- }
2360
- function cleanEscapedString(input) {
2361
- var matched = input.match(escapedStringRegExp);
2362
- if (!matched) {
2363
- return input;
2364
- }
2365
- return matched[1].replace(doubleQuoteRegExp, "'");
2366
- }
2367
-
2368
- /**
2369
- * @name parseISO
2370
- * @category Common Helpers
2371
- * @summary Parse ISO string
2372
- *
2373
- * @description
2374
- * Parse the given string in ISO 8601 format and return an instance of Date.
2375
- *
2376
- * Function accepts complete ISO 8601 formats as well as partial implementations.
2377
- * ISO 8601: http://en.wikipedia.org/wiki/ISO_8601
2378
- *
2379
- * If the argument isn't a string, the function cannot parse the string or
2380
- * the values are invalid, it returns Invalid Date.
2381
- *
2382
- * @param {String} argument - the value to convert
2383
- * @param {Object} [options] - an object with options.
2384
- * @param {0|1|2} [options.additionalDigits=2] - the additional number of digits in the extended year format
2385
- * @returns {Date} the parsed date in the local time zone
2386
- * @throws {TypeError} 1 argument required
2387
- * @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
2388
- *
2389
- * @example
2390
- * // Convert string '2014-02-11T11:30:30' to date:
2391
- * const result = parseISO('2014-02-11T11:30:30')
2392
- * //=> Tue Feb 11 2014 11:30:30
2393
- *
2394
- * @example
2395
- * // Convert string '+02014101' to date,
2396
- * // if the additional number of digits in the extended year format is 1:
2397
- * const result = parseISO('+02014101', { additionalDigits: 1 })
2398
- * //=> Fri Apr 11 2014 00:00:00
2399
- */
2400
- function parseISO(argument, options) {
2401
- var _options$additionalDi;
2402
- requiredArgs(1, arguments);
2403
- var additionalDigits = toInteger((_options$additionalDi = options === null || options === void 0 ? void 0 : options.additionalDigits) !== null && _options$additionalDi !== void 0 ? _options$additionalDi : 2);
2404
- if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) {
2405
- throw new RangeError('additionalDigits must be 0, 1 or 2');
2406
- }
2407
- if (!(typeof argument === 'string' || Object.prototype.toString.call(argument) === '[object String]')) {
2408
- return new Date(NaN);
2409
- }
2410
- var dateStrings = splitDateString(argument);
2411
- var date;
2412
- if (dateStrings.date) {
2413
- var parseYearResult = parseYear(dateStrings.date, additionalDigits);
2414
- date = parseDate(parseYearResult.restDateString, parseYearResult.year);
2415
- }
2416
- if (!date || isNaN(date.getTime())) {
2417
- return new Date(NaN);
2418
- }
2419
- var timestamp = date.getTime();
2420
- var time = 0;
2421
- var offset;
2422
- if (dateStrings.time) {
2423
- time = parseTime(dateStrings.time);
2424
- if (isNaN(time)) {
2425
- return new Date(NaN);
2426
- }
2427
- }
2428
- if (dateStrings.timezone) {
2429
- offset = parseTimezone(dateStrings.timezone);
2430
- if (isNaN(offset)) {
2431
- return new Date(NaN);
2432
- }
2433
- } else {
2434
- var dirtyDate = new Date(timestamp + time);
2435
- // js parsed string assuming it's in UTC timezone
2436
- // but we need it to be parsed in our timezone
2437
- // so we use utc values to build date in our timezone.
2438
- // Year values from 0 to 99 map to the years 1900 to 1999
2439
- // so set year explicitly with setFullYear.
2440
- var result = new Date(0);
2441
- result.setFullYear(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate());
2442
- result.setHours(dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds());
2443
- return result;
2444
- }
2445
- return new Date(timestamp + time + offset);
2446
- }
2447
- var patterns = {
2448
- dateTimeDelimiter: /[T ]/,
2449
- timeZoneDelimiter: /[Z ]/i,
2450
- timezone: /([Z+-].*)$/
2451
- };
2452
- var dateRegex = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/;
2453
- var timeRegex = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/;
2454
- var timezoneRegex = /^([+-])(\d{2})(?::?(\d{2}))?$/;
2455
- function splitDateString(dateString) {
2456
- var dateStrings = {};
2457
- var array = dateString.split(patterns.dateTimeDelimiter);
2458
- var timeString;
2459
-
2460
- // The regex match should only return at maximum two array elements.
2461
- // [date], [time], or [date, time].
2462
- if (array.length > 2) {
2463
- return dateStrings;
2464
- }
2465
- if (/:/.test(array[0])) {
2466
- timeString = array[0];
2467
- } else {
2468
- dateStrings.date = array[0];
2469
- timeString = array[1];
2470
- if (patterns.timeZoneDelimiter.test(dateStrings.date)) {
2471
- dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0];
2472
- timeString = dateString.substr(dateStrings.date.length, dateString.length);
2473
- }
2474
- }
2475
- if (timeString) {
2476
- var token = patterns.timezone.exec(timeString);
2477
- if (token) {
2478
- dateStrings.time = timeString.replace(token[1], '');
2479
- dateStrings.timezone = token[1];
2480
- } else {
2481
- dateStrings.time = timeString;
2482
- }
2483
- }
2484
- return dateStrings;
2485
- }
2486
- function parseYear(dateString, additionalDigits) {
2487
- var regex = new RegExp('^(?:(\\d{4}|[+-]\\d{' + (4 + additionalDigits) + '})|(\\d{2}|[+-]\\d{' + (2 + additionalDigits) + '})$)');
2488
- var captures = dateString.match(regex);
2489
- // Invalid ISO-formatted year
2490
- if (!captures) return {
2491
- year: NaN,
2492
- restDateString: ''
2493
- };
2494
- var year = captures[1] ? parseInt(captures[1]) : null;
2495
- var century = captures[2] ? parseInt(captures[2]) : null;
2496
-
2497
- // either year or century is null, not both
2498
- return {
2499
- year: century === null ? year : century * 100,
2500
- restDateString: dateString.slice((captures[1] || captures[2]).length)
2501
- };
2502
- }
2503
- function parseDate(dateString, year) {
2504
- // Invalid ISO-formatted year
2505
- if (year === null) return new Date(NaN);
2506
- var captures = dateString.match(dateRegex);
2507
- // Invalid ISO-formatted string
2508
- if (!captures) return new Date(NaN);
2509
- var isWeekDate = !!captures[4];
2510
- var dayOfYear = parseDateUnit(captures[1]);
2511
- var month = parseDateUnit(captures[2]) - 1;
2512
- var day = parseDateUnit(captures[3]);
2513
- var week = parseDateUnit(captures[4]);
2514
- var dayOfWeek = parseDateUnit(captures[5]) - 1;
2515
- if (isWeekDate) {
2516
- if (!validateWeekDate(year, week, dayOfWeek)) {
2517
- return new Date(NaN);
2518
- }
2519
- return dayOfISOWeekYear(year, week, dayOfWeek);
2520
- } else {
2521
- var date = new Date(0);
2522
- if (!validateDate(year, month, day) || !validateDayOfYearDate(year, dayOfYear)) {
2523
- return new Date(NaN);
2524
- }
2525
- date.setUTCFullYear(year, month, Math.max(dayOfYear, day));
2526
- return date;
2527
- }
2528
- }
2529
- function parseDateUnit(value) {
2530
- return value ? parseInt(value) : 1;
2531
- }
2532
- function parseTime(timeString) {
2533
- var captures = timeString.match(timeRegex);
2534
- if (!captures) return NaN; // Invalid ISO-formatted time
2535
-
2536
- var hours = parseTimeUnit(captures[1]);
2537
- var minutes = parseTimeUnit(captures[2]);
2538
- var seconds = parseTimeUnit(captures[3]);
2539
- if (!validateTime(hours, minutes, seconds)) {
2540
- return NaN;
2541
- }
2542
- return hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * 1000;
2543
- }
2544
- function parseTimeUnit(value) {
2545
- return value && parseFloat(value.replace(',', '.')) || 0;
2546
- }
2547
- function parseTimezone(timezoneString) {
2548
- if (timezoneString === 'Z') return 0;
2549
- var captures = timezoneString.match(timezoneRegex);
2550
- if (!captures) return 0;
2551
- var sign = captures[1] === '+' ? -1 : 1;
2552
- var hours = parseInt(captures[2]);
2553
- var minutes = captures[3] && parseInt(captures[3]) || 0;
2554
- if (!validateTimezone(hours, minutes)) {
2555
- return NaN;
2556
- }
2557
- return sign * (hours * millisecondsInHour + minutes * millisecondsInMinute);
2558
- }
2559
- function dayOfISOWeekYear(isoWeekYear, week, day) {
2560
- var date = new Date(0);
2561
- date.setUTCFullYear(isoWeekYear, 0, 4);
2562
- var fourthOfJanuaryDay = date.getUTCDay() || 7;
2563
- var diff = (week - 1) * 7 + day + 1 - fourthOfJanuaryDay;
2564
- date.setUTCDate(date.getUTCDate() + diff);
2565
- return date;
2566
- }
2567
-
2568
- // Validation functions
2569
-
2570
- // February is null to handle the leap year (using ||)
2571
- var daysInMonths = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
2572
- function isLeapYearIndex(year) {
2573
- return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
2574
- }
2575
- function validateDate(year, month, date) {
2576
- return month >= 0 && month <= 11 && date >= 1 && date <= (daysInMonths[month] || (isLeapYearIndex(year) ? 29 : 28));
2577
- }
2578
- function validateDayOfYearDate(year, dayOfYear) {
2579
- return dayOfYear >= 1 && dayOfYear <= (isLeapYearIndex(year) ? 366 : 365);
2580
- }
2581
- function validateWeekDate(_year, week, day) {
2582
- return week >= 1 && week <= 53 && day >= 0 && day <= 6;
2583
- }
2584
- function validateTime(hours, minutes, seconds) {
2585
- if (hours === 24) {
2586
- return minutes === 0 && seconds === 0;
2587
- }
2588
- return seconds >= 0 && seconds < 60 && minutes >= 0 && minutes < 60 && hours >= 0 && hours < 25;
2589
- }
2590
- function validateTimezone(_hours, minutes) {
2591
- return minutes >= 0 && minutes <= 59;
2592
- }
2593
-
2594
- function setDateFormate(dom) {
2595
- function formateDate(dateParts) {
2596
- const { year, month, day } = dateParts;
2597
- const date = new Date(year, month, day);
2598
- return format(date, 'dd/MM/yyyy');
2599
- }
2600
- function parseDate(inputValue) {
2601
- const [day, month, year] = inputValue.split('/');
2602
- return { year, month: parseInt(month) - 1, day };
2603
- }
2604
- dom.i18n = Object.assign(Object.assign({}, dom.i18n), { formatDate: formateDate, parseDate: parseDate });
2605
- }
2606
- const generateUUID = () => {
2607
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
2608
- var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
2609
- return v.toString(16);
2610
- });
2611
- };
2612
- function fetchRequest(url, method = 'GET', body = null, headers = {}) {
2613
- return new Promise((resolve, reject) => {
2614
- const uuid = generateUUID();
2615
- const headersOrigin = Object.assign({ 'Content-Type': 'application/json' }, headers);
2616
- if (method !== 'GET' && method !== 'HEAD') {
2617
- headersOrigin['X-Idempotency-Key'] = uuid;
2618
- }
2619
- const options = {
2620
- method,
2621
- headers: headersOrigin,
2622
- body: null
2623
- };
2624
- if (body && method !== 'GET' && method !== 'HEAD') {
2625
- options.body = JSON.stringify(body);
2626
- }
2627
- else {
2628
- delete options.body;
2629
- }
2630
- fetch(url, options)
2631
- .then((response) => {
2632
- if (!response.ok) {
2633
- return response.json().then((errorData) => {
2634
- const error = {
2635
- status: response.status,
2636
- statusText: response.statusText,
2637
- code: errorData.code || 'UNKNOWN_ERROR',
2638
- message: errorData.message || 'An unknown error occurred',
2639
- data: errorData.data || null
2640
- };
2641
- reject(error);
2642
- }, () => reject({
2643
- status: response.status,
2644
- statusText: response.statusText,
2645
- code: 'PARSE_ERROR',
2646
- message: 'Failed to parse error response'
2647
- }));
2648
- }
2649
- else {
2650
- return response.json();
2651
- }
2652
- })
2653
- .then((data) => resolve(data), (error) => reject(error));
2654
- });
2655
- }
2656
- function isEmptyValueOfArray(arr) {
2657
- if (arr.length === 0) {
2658
- return true;
2659
- }
2660
- const len = arr.length;
2661
- let count = 0;
2662
- for (let i = 0; i < len; i++) {
2663
- if (isEmptyValue(arr[i])) {
2664
- count++;
2665
- }
2666
- else {
2667
- return false;
2668
- }
2669
- }
2670
- if (count === len) {
2671
- return true;
2672
- }
2673
- return false;
2674
- }
2675
- function isEmptyValueOfObject(obj) {
2676
- if (Object.keys(obj).length === 0) {
2677
- return true;
2678
- }
2679
- const len = Object.keys(obj).length;
2680
- let count = 0;
2681
- for (const val of Object.values(obj)) {
2682
- if (isEmptyValue(val)) {
2683
- count++;
2684
- }
2685
- else {
2686
- return false;
2687
- }
2688
- }
2689
- if (count === len) {
2690
- return true;
2691
- }
2692
- return false;
2693
- }
2694
- function isEmptyValue(value, allowZero) {
2695
- if (value === null || value === undefined || value === '') {
2696
- return true;
2697
- }
2698
- else if (value === 0 && allowZero) {
2699
- return false;
2700
- }
2701
- else if (Array.isArray(value)) {
2702
- return isEmptyValueOfArray(value);
2703
- }
2704
- else if (Object.prototype.toString.call(value) === '[object Object]') {
2705
- return isEmptyValueOfObject(value);
2706
- }
2707
- else {
2708
- return !value;
2709
- }
2710
- }
2711
- function toQueryParams(params) {
2712
- const finalParams = {};
2713
- Object.entries(params).forEach(([key, value]) => {
2714
- if (!isEmptyValue(value, true)) {
2715
- finalParams[key] = value;
2716
- }
2717
- });
2718
- const queryString = Object.entries(finalParams)
2719
- .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
2720
- .join('&');
2721
- return queryString ? `?${queryString}` : '';
2722
- }
2723
- function thousandSeparator(value) {
2724
- var _a;
2725
- if (value === 0) {
2726
- return '0';
2727
- }
2728
- if (!value) {
2729
- return '';
2730
- }
2731
- value = value.toString();
2732
- const parts = value.split('.');
2733
- parts[0] = (_a = parts[0]) === null || _a === void 0 ? void 0 : _a.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
2734
- return parts.join('.');
2735
- }
2736
- const isMobile = (userAgent) => {
2737
- return !!(userAgent.toLowerCase().match(/android/i) ||
2738
- userAgent.toLowerCase().match(/blackberry|bb/i) ||
2739
- userAgent.toLowerCase().match(/iphone|ipad|ipod/i) ||
2740
- userAgent.toLowerCase().match(/windows phone|windows mobile|iemobile|wpdesktop/i));
2741
- };
2742
- function getDrawResults(item) {
2743
- var _a;
2744
- return transformResults((_a = item.winningNumbers[0]) === null || _a === void 0 ? void 0 : _a.poolGameOutcomes);
2745
- }
2746
- function getTicketResults(item) {
2747
- const res = item.selection.map((selection) => {
2748
- return selection.poolGameSelections;
2749
- });
2750
- return transformResults(res === null || res === void 0 ? void 0 : res[0]);
2751
- }
2752
- function transformResults(results) {
2753
- if (results && results.length > 0) {
2754
- return results.map((i) => i === null || i === void 0 ? void 0 : i[0]);
2755
- }
2756
- return [[]];
2757
- }
2758
- function getOrdinalSuffix(day) {
2759
- const j = day % 10;
2760
- const k = day % 100;
2761
- if (k >= 11 && k <= 13) {
2762
- return 'th';
2763
- }
2764
- switch (j) {
2765
- case 1:
2766
- return 'st';
2767
- case 2:
2768
- return 'nd';
2769
- case 3:
2770
- return 'rd';
2771
- default:
2772
- return 'th';
2773
- }
2774
- }
2775
- function formatDateToCustomFormat(isoString) {
2776
- const date = parseISO(isoString);
2777
- const day = date.getDate();
2778
- const dayName = format(date, 'EEEE');
2779
- const monthName = format(date, 'MMMM');
2780
- const suffix = getOrdinalSuffix(day);
2781
- return `${dayName} ${day}${suffix} ${monthName}`;
2782
- }
2783
-
2784
- async function fetchTicketList({ endpoint, filterData, sessionId }) {
2785
- try {
2786
- const { items = [], total } = await fetchRequest(`${endpoint}/tickets${toQueryParams(filterData)}`, 'GET', null, {
2787
- Authorization: `Bearer ${sessionId}`
2788
- });
2789
- return {
2790
- dataSource: items,
2791
- total: total
2792
- };
2793
- }
2794
- catch (e) {
2795
- if (e.status === 401) {
2796
- // FIXME: logout and notify user
2797
- return Promise.reject(new Error(`${e.statusText || 'Unauthorized'}, please login`));
2798
- }
2799
- }
2800
- }
2801
- async function getTicketItemDrawResult({ endpoint, gameId, drawId }) {
2802
- try {
2803
- const res = await fetchRequest(`${endpoint}/games/${gameId}/draws/${drawId}`, 'GET', {});
2804
- return res || {};
2805
- }
2806
- catch (e) {
2807
- console.log(e);
2808
- }
2809
- }
2810
- async function buildDrawResults({ endpoint, gameId, drawResults }) {
2811
- const drawIds = drawResults.map((drawResult) => drawResult.drawId);
2812
- for (let i = 0; i < drawIds.length; i++) {
2813
- const res = await getTicketItemDrawResult({ endpoint: endpoint, gameId: gameId, drawId: drawIds[i] });
2814
- drawResults[i].tempDrawData = res;
2815
- drawResults[i].prizeDetails = displayPrizeCategory(drawResults[i].details);
2816
- }
2817
- return drawResults;
2818
- }
2819
- function displayPrizeCategory(details) {
2820
- const prizeMap = new Map();
2821
- details.forEach((detail) => {
2822
- let prizeName = detail.divisionDisplayName;
2823
- let amount = detail.amount;
2824
- let currency = detail.currency;
2825
- if (prizeName && prizeName != 'None') {
2826
- if (prizeMap.has(prizeName)) {
2827
- prizeMap.set(prizeName, {
2828
- amount: prizeMap.get(prizeName)['amount'] + amount,
2829
- currency,
2830
- times: prizeMap.get(prizeName)['times'] + 1
2831
- });
2832
- }
2833
- else {
2834
- prizeMap.set(prizeName, { amount, currency, times: 1 });
2835
- }
2836
- }
2837
- });
2838
- const resultArr = [];
2839
- for (let [key, val] of prizeMap.entries()) {
2840
- resultArr.push({ prizeName: key, amount: val['amount'], currency: val['currency'], times: val['times'] });
2841
- }
2842
- resultArr.sort((p1, p2) => p2.prizeName.localeCompare(p1.prizeName));
2843
- return resultArr;
2844
- }
2845
-
2846
- const DEFAULT_LANGUAGE = 'en';
2847
- const SUPPORTED_LANGUAGES = ['ro', 'en', 'fr', 'ar', 'hr'];
2848
- const TRANSLATIONS = {
2849
- en: {
2850
- win: 'Win',
2851
- lose: 'Lose',
2852
- normal: 'Normal',
2853
- subscription: 'Subscription',
2854
- syndicate: 'Syndicate',
2855
- ticketResult: 'Ticket Result:',
2856
- drawId: 'Draw ID:',
2857
- drawDate: 'Draw Date:',
2858
- result: 'Result:',
2859
- prize: 'Prize:',
2860
- bettingType: 'Betting Type:',
2861
- seeDetails: 'See Details',
2862
- noData: 'No data Avaliable.',
2863
- ticketId: 'Ticket ID:',
2864
- ticketType: 'Ticket Type:',
2865
- ticketAmount: 'Ticket Amount:',
2866
- lineDetail: 'Line Detail:',
2867
- numberOfDraw: 'Number of Draw:',
2868
- filter: 'Filter',
2869
- clear: 'Clear',
2870
- perPage: '1',
2871
- searchByTicketId: 'Search by Ticket ID',
2872
- enterTicketId: 'Enter Ticket ID',
2873
- searchByTicketType: 'Search by Ticket Type',
2874
- selectTicketType: 'Select Ticket Type',
2875
- searchByDate: 'Search by Date',
2876
- from: 'From',
2877
- to: 'To',
2878
- ticketsHistory: 'Tickets History',
2879
- settled: 'Settled',
2880
- purchased: 'Purchased',
2881
- canceled: 'Canceled',
2882
- pleaseSelectADate: 'Please select a date'
2883
- }
2884
- };
2885
- const translate = (key, customLang, replacements) => {
2886
- const lang = customLang;
2887
- let translation = TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
2888
- if (replacements) {
2889
- Object.keys(replacements).forEach((placeholder) => {
2890
- translation = translation === null || translation === void 0 ? void 0 : translation.replace(`{${placeholder}}`, replacements[placeholder]);
2891
- });
2892
- }
2893
- return translation;
2894
- };
2895
- const getTranslations = (data) => {
2896
- Object.keys(data).forEach((item) => {
2897
- for (let key in data[item]) {
2898
- TRANSLATIONS[item][key] = data[item][key];
2899
- }
2900
- });
2901
- };
2902
- const resolveTranslationUrl = async (translationUrl) => {
2903
- if (translationUrl) {
2904
- try {
2905
- const response = await fetch(translationUrl);
2906
- if (!response.ok) {
2907
- throw new Error(`HTTP error! status: ${response.status}`);
2908
- }
2909
- const translations = await response.json();
2910
- getTranslations(translations);
2911
- }
2912
- catch (error) {
2913
- console.error('Failed to fetch or parse translations from URL:', error);
2914
- }
2915
- }
2916
- };
2917
-
2918
- const lotteryOddsbomTicketHistoryCss = "@keyframes skeleton-loading {\n 0% {\n background-position: 200% 0;\n }\n 100% {\n background-position: -200% 0;\n }\n}\n.lottery-oddsbom-ticket-history-container {\n container-type: inline-size;\n container-name: myContainer;\n color: var(--emw--color-typography, #000);\n background-color: var(--emw--color-background, #fff);\n height: 100%;\n width: 100%;\n}\n.lottery-oddsbom-ticket-history-container .lottery-oddsbom-ticket-history-wrapper {\n padding: 12px;\n margin: 0 auto;\n max-width: 800px;\n background-color: var(--emw--color-background, #fff);\n}\n.lottery-oddsbom-ticket-history-container__title {\n margin: 20px 0;\n text-align: center;\n font-size: 20px;\n font-weight: 700;\n color: var(--emw--color-typography, #000);\n}\n.lottery-oddsbom-ticket-history-container .pagination-wrap {\n margin-top: 20px;\n display: flex;\n justify-content: flex-end;\n}\n\n.pagination-wrap {\n margin-top: 20px;\n display: flex;\n justify-content: flex-end;\n}\n\n@container myContainer (min-width: 1200px) {\n .lottery-oddsbom-ticket-history-wrapper {\n padding: 24px;\n margin: 0 auto;\n }\n}\n@container myContainer (max-width: 480px) {\n .lottery-oddsbom-ticket-history-wrapper {\n padding: 2px;\n }\n .lottery-oddsbom-ticket-history-container .filter-wrap .filter-status {\n gap: 4px;\n }\n}\n.error-red {\n color: var(--emw--color-error, red);\n}\n\n.text-center {\n text-align: center;\n}\n\n.mt-12 {\n margin-top: 48px;\n}";
2919
- const LotteryOddsbomTicketHistoryStyle0 = lotteryOddsbomTicketHistoryCss;
2920
-
2921
- const LotteryOddsbomTicketHistory = class {
2922
- constructor(hostRef) {
2923
- registerInstance(this, hostRef);
2924
- this.handlePageSizeChange = (event) => {
2925
- this.filterData.limit = event.detail;
2926
- this.filterData.offset = 0;
2927
- this.fetchTicketList();
2928
- };
2929
- this.mbSource = undefined;
2930
- this.clientStyling = undefined;
2931
- this.clientStylingUrl = undefined;
2932
- this.translationUrl = '';
2933
- this.language = 'en';
2934
- this.endpoint = undefined;
2935
- this.gameId = undefined;
2936
- this.playerId = undefined;
2937
- this.sessionId = '';
2938
- this.isLoading = false;
2939
- this.errorConfig = { isError: false };
2940
- this.filterData = {
2941
- offset: 0,
2942
- limit: 10,
2943
- vendorGameType: GameType.PoolGame,
2944
- vendorGameBettingObject: GameBettingObject.Oddsbomben
2945
- };
2946
- this.ticketHistoryRes = {
2947
- dataSource: [],
2948
- total: 0
2949
- };
2950
- }
2951
- handleClientStylingChange(newValue, oldValue) {
2952
- if (newValue !== oldValue) {
2953
- setClientStyling(this.stylingContainer, this.clientStyling);
2954
- }
2955
- }
2956
- handleClientStylingUrlChange(newValue, oldValue) {
2957
- if (newValue !== oldValue) {
2958
- setClientStylingURL(this.stylingContainer, this.clientStylingUrl);
2959
- }
2960
- }
2961
- handleMbSourceChange(newValue, oldValue) {
2962
- if (newValue !== oldValue) {
2963
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
2964
- }
2965
- }
2966
- componentDidLoad() {
2967
- if (this.stylingContainer) {
2968
- if (this.mbSource)
2969
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
2970
- if (this.clientStyling)
2971
- setClientStyling(this.stylingContainer, this.clientStyling);
2972
- if (this.clientStylingUrl)
2973
- setClientStylingURL(this.stylingContainer, this.clientStylingUrl);
2974
- }
2975
- }
2976
- disconnectedCallback() {
2977
- this.stylingSubscription && this.stylingSubscription.unsubscribe();
2978
- }
2979
- componentWillLoad() {
2980
- this.fetchTicketList();
2981
- }
2982
- async fetchTicketList() {
2983
- if (!this.endpoint || !this.sessionId) {
2984
- console.error('endpoint and sessionId are required');
2985
- return;
2986
- }
2987
- try {
2988
- this.isLoading = true;
2989
- const data = await fetchTicketList({
2990
- endpoint: this.endpoint,
2991
- filterData: this.filterData,
2992
- sessionId: this.sessionId
2993
- });
2994
- this.ticketHistoryRes = data;
2995
- }
2996
- catch (err) {
2997
- this.errorConfig = {
2998
- isError: true,
2999
- message: err.message || err.msg
3000
- };
3001
- }
3002
- finally {
3003
- this.isLoading = false;
3004
- }
3005
- }
3006
- renderError() {
3007
- return h("div", { class: "error-red text-center mt-12" }, this.errorConfig.message);
3008
- }
3009
- handleFilterChange(event) {
3010
- this.filterData = Object.assign({}, {
3011
- offset: this.filterData.offset,
3012
- limit: this.filterData.limit,
3013
- vendorGameType: this.filterData.vendorGameType,
3014
- vendorGameBettingObject: this.filterData.vendorGameBettingObject
3015
- }, event.detail);
3016
- this.fetchTicketList();
3017
- }
3018
- handlePageChange(e) {
3019
- this.filterData.offset = (e.detail - 1) * this.filterData.limit;
3020
- this.fetchTicketList();
3021
- }
3022
- render() {
3023
- var _a, _b;
3024
- return (h("div", { key: '719a01651d21198644d4ace48e8b304e7165ab76', ref: (el) => (this.stylingContainer = el), class: "lottery-oddsbom-ticket-history-container" }, h("div", { key: '3086e38de3068a0af5da6ef631e657a2a460f774', class: "lottery-oddsbom-ticket-history-wrapper" }, h("div", { key: '6c06470b63b983ad75a400d49ae72c6becb25243', class: "lottery-oddsbom-ticket-history-container__title" }, translate('ticketsHistory', this.language)), h("filter-group", { key: '225778b4daa5adf2f508a8d3c8590f6802669488', language: this.language, "mb-source": this.mbSource, "client-styling": this.clientStyling, "client-styling-url": this.clientStylingUrl, "translation-url": this.translationUrl, onFilterChange: this.handleFilterChange.bind(this) }), this.errorConfig.isError ? (this.renderError()) : (h("history-list", { language: this.language, "mb-source": this.mbSource, "client-styling": this.clientStyling, "client-styling-url": this.clientStylingUrl, "translation-url": this.translationUrl, "game-id": this.gameId, endpoint: this.endpoint, "is-loading": this.isLoading, "default-ticket-history": JSON.stringify(((_a = this.ticketHistoryRes) === null || _a === void 0 ? void 0 : _a.dataSource) || []) })), h("div", { key: '0cfa07e6daab06253e2bd1d570dea052547fbbb0', class: "pagination-wrap" }, h("general-pagination", { key: 'd2025ebae912d339ba35c6df5ed3c68d5031201d', total: ((_b = this.ticketHistoryRes) === null || _b === void 0 ? void 0 : _b.total) || 0, language: this.language, "mb-source": this.mbSource, "client-styling": this.clientStyling, "client-styling-url": this.clientStylingUrl, "translation-url": this.translationUrl, onPageChange: this.handlePageChange.bind(this), onPageSizeChange: this.handlePageSizeChange.bind(this) })))));
3025
- }
3026
- static get watchers() { return {
3027
- "clientStyling": ["handleClientStylingChange"],
3028
- "clientStylingUrl": ["handleClientStylingUrlChange"],
3029
- "mbSource": ["handleMbSourceChange"]
3030
- }; }
3031
- };
3032
- LotteryOddsbomTicketHistory.style = LotteryOddsbomTicketHistoryStyle0;
3033
-
3034
- export { DrawResult as D, LotteryOddsbomTicketHistory as L, setClientStylingURL as a, setStreamStyling as b, setDateFormate as c, getDrawResults as d, buildDrawResults as e, formatDateToCustomFormat as f, getTicketResults as g, format as h, isMobile as i, thousandSeparator as j, parseISO as p, resolveTranslationUrl as r, setClientStyling as s, translate as t };