@everymatrix/lottery-tipping-ticket-controller 1.85.14 → 1.85.16

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