@sparkle-learning/core 0.0.61 → 0.0.63

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 (36) hide show
  1. package/dist/cjs/{appdata.service-c8d71e05.js → appdata.service-ab6bfcc8.js} +1 -1
  2. package/dist/cjs/header-mobile-collapse_61.cjs.entry.js +49 -23
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/sparkle-animation-player.cjs.entry.js +1 -1
  5. package/dist/cjs/sparkle-core.cjs.js +1 -1
  6. package/dist/cjs/sparkle-feed-post.cjs.entry.js +1 -1
  7. package/dist/cjs/sparkle-goal-form.cjs.entry.js +2 -2
  8. package/dist/cjs/util-9035404f.js +52 -0
  9. package/dist/collection/components/layout/facilitator/facilitator-page.js +1 -1
  10. package/dist/collection/components/mini-apps/sparkle-gww/sparkle-gww-item/sparkle-gww-item.css +8 -1
  11. package/dist/collection/components/mini-apps/sparkle-gww/sparkle-gww-item/sparkle-gww-item.js +29 -27
  12. package/dist/collection/components/mini-apps/sparkle-health/sparkle-health.js +0 -1
  13. package/dist/collection/components/sparkle-login/sparkle-login.js +48 -13
  14. package/dist/collection/util.js +4 -3
  15. package/dist/esm/{appdata.service-2e84e167.js → appdata.service-4497cdd5.js} +1 -1
  16. package/dist/esm/header-mobile-collapse_61.entry.js +49 -23
  17. package/dist/esm/loader.js +1 -1
  18. package/dist/esm/sparkle-animation-player.entry.js +1 -1
  19. package/dist/esm/sparkle-core.js +1 -1
  20. package/dist/esm/sparkle-feed-post.entry.js +1 -1
  21. package/dist/esm/sparkle-goal-form.entry.js +2 -2
  22. package/dist/esm/util-458c62fb.js +41 -0
  23. package/dist/sparkle-core/{p-5c6ecdbe.entry.js → p-257f7bfd.entry.js} +2 -2
  24. package/dist/sparkle-core/p-2f82efaa.js +1 -0
  25. package/dist/sparkle-core/{p-85d4cd5c.entry.js → p-40b54460.entry.js} +1 -1
  26. package/dist/sparkle-core/{p-da391f3f.js → p-4a0ab315.js} +1 -1
  27. package/dist/sparkle-core/{p-2caed39f.entry.js → p-517d51cc.entry.js} +1 -1
  28. package/dist/sparkle-core/{p-42ed7d5f.entry.js → p-d0687f56.entry.js} +1 -1
  29. package/dist/sparkle-core/sparkle-core.esm.js +1 -1
  30. package/dist/types/components/mini-apps/sparkle-gww/sparkle-gww-item/sparkle-gww-item.d.ts +1 -1
  31. package/dist/types/components/sparkle-login/sparkle-login.d.ts +4 -1
  32. package/dist/types/util.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/dist/cjs/util-47e320b2.js +0 -2462
  35. package/dist/esm/util-57cc8006.js +0 -2451
  36. package/dist/sparkle-core/p-8b56f734.js +0 -1
@@ -1,2451 +0,0 @@
1
- function toInteger(dirtyNumber) {
2
- if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
3
- return NaN;
4
- }
5
-
6
- var number = Number(dirtyNumber);
7
-
8
- if (isNaN(number)) {
9
- return number;
10
- }
11
-
12
- return number < 0 ? Math.ceil(number) : Math.floor(number);
13
- }
14
-
15
- function requiredArgs(required, args) {
16
- if (args.length < required) {
17
- throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
18
- }
19
- }
20
-
21
- /**
22
- * @name toDate
23
- * @category Common Helpers
24
- * @summary Convert the given argument to an instance of Date.
25
- *
26
- * @description
27
- * Convert the given argument to an instance of Date.
28
- *
29
- * If the argument is an instance of Date, the function returns its clone.
30
- *
31
- * If the argument is a number, it is treated as a timestamp.
32
- *
33
- * If the argument is none of the above, the function returns Invalid Date.
34
- *
35
- * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
36
- *
37
- * @param {Date|Number} argument - the value to convert
38
- * @returns {Date} the parsed date in the local time zone
39
- * @throws {TypeError} 1 argument required
40
- *
41
- * @example
42
- * // Clone the date:
43
- * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
44
- * //=> Tue Feb 11 2014 11:30:30
45
- *
46
- * @example
47
- * // Convert the timestamp to date:
48
- * const result = toDate(1392098430000)
49
- * //=> Tue Feb 11 2014 11:30:30
50
- */
51
-
52
- function toDate(argument) {
53
- requiredArgs(1, arguments);
54
- var argStr = Object.prototype.toString.call(argument); // Clone the date
55
-
56
- if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') {
57
- // Prevent the date to lose the milliseconds when passed to new Date() in IE10
58
- return new Date(argument.getTime());
59
- } else if (typeof argument === 'number' || argStr === '[object Number]') {
60
- return new Date(argument);
61
- } else {
62
- if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {
63
- // eslint-disable-next-line no-console
64
- 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://git.io/fjule"); // eslint-disable-next-line no-console
65
-
66
- console.warn(new Error().stack);
67
- }
68
-
69
- return new Date(NaN);
70
- }
71
- }
72
-
73
- /**
74
- * @name addMilliseconds
75
- * @category Millisecond Helpers
76
- * @summary Add the specified number of milliseconds to the given date.
77
- *
78
- * @description
79
- * Add the specified number of milliseconds to the given date.
80
- *
81
- * ### v2.0.0 breaking changes:
82
- *
83
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
84
- *
85
- * @param {Date|Number} date - the date to be changed
86
- * @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`.
87
- * @returns {Date} the new date with the milliseconds added
88
- * @throws {TypeError} 2 arguments required
89
- *
90
- * @example
91
- * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
92
- * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
93
- * //=> Thu Jul 10 2014 12:45:30.750
94
- */
95
-
96
- function addMilliseconds(dirtyDate, dirtyAmount) {
97
- requiredArgs(2, arguments);
98
- var timestamp = toDate(dirtyDate).getTime();
99
- var amount = toInteger(dirtyAmount);
100
- return new Date(timestamp + amount);
101
- }
102
-
103
- /**
104
- * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
105
- * They usually appear for dates that denote time before the timezones were introduced
106
- * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
107
- * and GMT+01:00:00 after that date)
108
- *
109
- * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
110
- * which would lead to incorrect calculations.
111
- *
112
- * This function returns the timezone offset in milliseconds that takes seconds in account.
113
- */
114
- function getTimezoneOffsetInMilliseconds(date) {
115
- var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
116
- utcDate.setUTCFullYear(date.getFullYear());
117
- return date.getTime() - utcDate.getTime();
118
- }
119
-
120
- /**
121
- * @name isDate
122
- * @category Common Helpers
123
- * @summary Is the given value a date?
124
- *
125
- * @description
126
- * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
127
- *
128
- * ### v2.0.0 breaking changes:
129
- *
130
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
131
- *
132
- * @param {*} value - the value to check
133
- * @returns {boolean} true if the given value is a date
134
- * @throws {TypeError} 1 arguments required
135
- *
136
- * @example
137
- * // For a valid date:
138
- * const result = isDate(new Date())
139
- * //=> true
140
- *
141
- * @example
142
- * // For an invalid date:
143
- * const result = isDate(new Date(NaN))
144
- * //=> true
145
- *
146
- * @example
147
- * // For some value:
148
- * const result = isDate('2014-02-31')
149
- * //=> false
150
- *
151
- * @example
152
- * // For an object:
153
- * const result = isDate({})
154
- * //=> false
155
- */
156
-
157
- function isDate(value) {
158
- requiredArgs(1, arguments);
159
- return value instanceof Date || typeof value === 'object' && Object.prototype.toString.call(value) === '[object Date]';
160
- }
161
-
162
- /**
163
- * @name isValid
164
- * @category Common Helpers
165
- * @summary Is the given date valid?
166
- *
167
- * @description
168
- * Returns false if argument is Invalid Date and true otherwise.
169
- * Argument is converted to Date using `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
170
- * Invalid Date is a Date, whose time value is NaN.
171
- *
172
- * Time value of Date: http://es5.github.io/#x15.9.1.1
173
- *
174
- * ### v2.0.0 breaking changes:
175
- *
176
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
177
- *
178
- * - Now `isValid` doesn't throw an exception
179
- * if the first argument is not an instance of Date.
180
- * Instead, argument is converted beforehand using `toDate`.
181
- *
182
- * Examples:
183
- *
184
- * | `isValid` argument | Before v2.0.0 | v2.0.0 onward |
185
- * |---------------------------|---------------|---------------|
186
- * | `new Date()` | `true` | `true` |
187
- * | `new Date('2016-01-01')` | `true` | `true` |
188
- * | `new Date('')` | `false` | `false` |
189
- * | `new Date(1488370835081)` | `true` | `true` |
190
- * | `new Date(NaN)` | `false` | `false` |
191
- * | `'2016-01-01'` | `TypeError` | `false` |
192
- * | `''` | `TypeError` | `false` |
193
- * | `1488370835081` | `TypeError` | `true` |
194
- * | `NaN` | `TypeError` | `false` |
195
- *
196
- * We introduce this change to make *date-fns* consistent with ECMAScript behavior
197
- * that try to coerce arguments to the expected type
198
- * (which is also the case with other *date-fns* functions).
199
- *
200
- * @param {*} date - the date to check
201
- * @returns {Boolean} the date is valid
202
- * @throws {TypeError} 1 argument required
203
- *
204
- * @example
205
- * // For the valid date:
206
- * const result = isValid(new Date(2014, 1, 31))
207
- * //=> true
208
- *
209
- * @example
210
- * // For the value, convertable into a date:
211
- * const result = isValid(1393804800000)
212
- * //=> true
213
- *
214
- * @example
215
- * // For the invalid date:
216
- * const result = isValid(new Date(''))
217
- * //=> false
218
- */
219
-
220
- function isValid(dirtyDate) {
221
- requiredArgs(1, arguments);
222
-
223
- if (!isDate(dirtyDate) && typeof dirtyDate !== 'number') {
224
- return false;
225
- }
226
-
227
- var date = toDate(dirtyDate);
228
- return !isNaN(Number(date));
229
- }
230
-
231
- var formatDistanceLocale = {
232
- lessThanXSeconds: {
233
- one: 'less than a second',
234
- other: 'less than {{count}} seconds'
235
- },
236
- xSeconds: {
237
- one: '1 second',
238
- other: '{{count}} seconds'
239
- },
240
- halfAMinute: 'half a minute',
241
- lessThanXMinutes: {
242
- one: 'less than a minute',
243
- other: 'less than {{count}} minutes'
244
- },
245
- xMinutes: {
246
- one: '1 minute',
247
- other: '{{count}} minutes'
248
- },
249
- aboutXHours: {
250
- one: 'about 1 hour',
251
- other: 'about {{count}} hours'
252
- },
253
- xHours: {
254
- one: '1 hour',
255
- other: '{{count}} hours'
256
- },
257
- xDays: {
258
- one: '1 day',
259
- other: '{{count}} days'
260
- },
261
- aboutXWeeks: {
262
- one: 'about 1 week',
263
- other: 'about {{count}} weeks'
264
- },
265
- xWeeks: {
266
- one: '1 week',
267
- other: '{{count}} weeks'
268
- },
269
- aboutXMonths: {
270
- one: 'about 1 month',
271
- other: 'about {{count}} months'
272
- },
273
- xMonths: {
274
- one: '1 month',
275
- other: '{{count}} months'
276
- },
277
- aboutXYears: {
278
- one: 'about 1 year',
279
- other: 'about {{count}} years'
280
- },
281
- xYears: {
282
- one: '1 year',
283
- other: '{{count}} years'
284
- },
285
- overXYears: {
286
- one: 'over 1 year',
287
- other: 'over {{count}} years'
288
- },
289
- almostXYears: {
290
- one: 'almost 1 year',
291
- other: 'almost {{count}} years'
292
- }
293
- };
294
-
295
- var formatDistance = function (token, count, options) {
296
- var result;
297
- var tokenValue = formatDistanceLocale[token];
298
-
299
- if (typeof tokenValue === 'string') {
300
- result = tokenValue;
301
- } else if (count === 1) {
302
- result = tokenValue.one;
303
- } else {
304
- result = tokenValue.other.replace('{{count}}', count.toString());
305
- }
306
-
307
- if (options !== null && options !== void 0 && options.addSuffix) {
308
- if (options.comparison && options.comparison > 0) {
309
- return 'in ' + result;
310
- } else {
311
- return result + ' ago';
312
- }
313
- }
314
-
315
- return result;
316
- };
317
-
318
- function buildFormatLongFn(args) {
319
- return function () {
320
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
321
- // TODO: Remove String()
322
- var width = options.width ? String(options.width) : args.defaultWidth;
323
- var format = args.formats[width] || args.formats[args.defaultWidth];
324
- return format;
325
- };
326
- }
327
-
328
- var dateFormats = {
329
- full: 'EEEE, MMMM do, y',
330
- long: 'MMMM do, y',
331
- medium: 'MMM d, y',
332
- short: 'MM/dd/yyyy'
333
- };
334
- var timeFormats = {
335
- full: 'h:mm:ss a zzzz',
336
- long: 'h:mm:ss a z',
337
- medium: 'h:mm:ss a',
338
- short: 'h:mm a'
339
- };
340
- var dateTimeFormats = {
341
- full: "{{date}} 'at' {{time}}",
342
- long: "{{date}} 'at' {{time}}",
343
- medium: '{{date}}, {{time}}',
344
- short: '{{date}}, {{time}}'
345
- };
346
- var formatLong = {
347
- date: buildFormatLongFn({
348
- formats: dateFormats,
349
- defaultWidth: 'full'
350
- }),
351
- time: buildFormatLongFn({
352
- formats: timeFormats,
353
- defaultWidth: 'full'
354
- }),
355
- dateTime: buildFormatLongFn({
356
- formats: dateTimeFormats,
357
- defaultWidth: 'full'
358
- })
359
- };
360
-
361
- var formatRelativeLocale = {
362
- lastWeek: "'last' eeee 'at' p",
363
- yesterday: "'yesterday at' p",
364
- today: "'today at' p",
365
- tomorrow: "'tomorrow at' p",
366
- nextWeek: "eeee 'at' p",
367
- other: 'P'
368
- };
369
-
370
- var formatRelative = function (token, _date, _baseDate, _options) {
371
- return formatRelativeLocale[token];
372
- };
373
-
374
- function buildLocalizeFn(args) {
375
- return function (dirtyIndex, dirtyOptions) {
376
- var options = dirtyOptions || {};
377
- var context = options.context ? String(options.context) : 'standalone';
378
- var valuesArray;
379
-
380
- if (context === 'formatting' && args.formattingValues) {
381
- var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
382
- var width = options.width ? String(options.width) : defaultWidth;
383
- valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
384
- } else {
385
- var _defaultWidth = args.defaultWidth;
386
-
387
- var _width = options.width ? String(options.width) : args.defaultWidth;
388
-
389
- valuesArray = args.values[_width] || args.values[_defaultWidth];
390
- }
391
-
392
- var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
393
-
394
- return valuesArray[index];
395
- };
396
- }
397
-
398
- var eraValues = {
399
- narrow: ['B', 'A'],
400
- abbreviated: ['BC', 'AD'],
401
- wide: ['Before Christ', 'Anno Domini']
402
- };
403
- var quarterValues = {
404
- narrow: ['1', '2', '3', '4'],
405
- abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
406
- wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter']
407
- }; // Note: in English, the names of days of the week and months are capitalized.
408
- // If you are making a new locale based on this one, check if the same is true for the language you're working on.
409
- // Generally, formatted dates should look like they are in the middle of a sentence,
410
- // e.g. in Spanish language the weekdays and months should be in the lowercase.
411
-
412
- var monthValues = {
413
- narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
414
- abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
415
- wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
416
- };
417
- var dayValues = {
418
- narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
419
- short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
420
- abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
421
- wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
422
- };
423
- var dayPeriodValues = {
424
- narrow: {
425
- am: 'a',
426
- pm: 'p',
427
- midnight: 'mi',
428
- noon: 'n',
429
- morning: 'morning',
430
- afternoon: 'afternoon',
431
- evening: 'evening',
432
- night: 'night'
433
- },
434
- abbreviated: {
435
- am: 'AM',
436
- pm: 'PM',
437
- midnight: 'midnight',
438
- noon: 'noon',
439
- morning: 'morning',
440
- afternoon: 'afternoon',
441
- evening: 'evening',
442
- night: 'night'
443
- },
444
- wide: {
445
- am: 'a.m.',
446
- pm: 'p.m.',
447
- midnight: 'midnight',
448
- noon: 'noon',
449
- morning: 'morning',
450
- afternoon: 'afternoon',
451
- evening: 'evening',
452
- night: 'night'
453
- }
454
- };
455
- var formattingDayPeriodValues = {
456
- narrow: {
457
- am: 'a',
458
- pm: 'p',
459
- midnight: 'mi',
460
- noon: 'n',
461
- morning: 'in the morning',
462
- afternoon: 'in the afternoon',
463
- evening: 'in the evening',
464
- night: 'at night'
465
- },
466
- abbreviated: {
467
- am: 'AM',
468
- pm: 'PM',
469
- midnight: 'midnight',
470
- noon: 'noon',
471
- morning: 'in the morning',
472
- afternoon: 'in the afternoon',
473
- evening: 'in the evening',
474
- night: 'at night'
475
- },
476
- wide: {
477
- am: 'a.m.',
478
- pm: 'p.m.',
479
- midnight: 'midnight',
480
- noon: 'noon',
481
- morning: 'in the morning',
482
- afternoon: 'in the afternoon',
483
- evening: 'in the evening',
484
- night: 'at night'
485
- }
486
- };
487
-
488
- var ordinalNumber = function (dirtyNumber, _options) {
489
- var number = Number(dirtyNumber); // If ordinal numbers depend on context, for example,
490
- // if they are different for different grammatical genders,
491
- // use `options.unit`.
492
- //
493
- // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
494
- // 'day', 'hour', 'minute', 'second'.
495
-
496
- var rem100 = number % 100;
497
-
498
- if (rem100 > 20 || rem100 < 10) {
499
- switch (rem100 % 10) {
500
- case 1:
501
- return number + 'st';
502
-
503
- case 2:
504
- return number + 'nd';
505
-
506
- case 3:
507
- return number + 'rd';
508
- }
509
- }
510
-
511
- return number + 'th';
512
- };
513
-
514
- var localize = {
515
- ordinalNumber: ordinalNumber,
516
- era: buildLocalizeFn({
517
- values: eraValues,
518
- defaultWidth: 'wide'
519
- }),
520
- quarter: buildLocalizeFn({
521
- values: quarterValues,
522
- defaultWidth: 'wide',
523
- argumentCallback: function (quarter) {
524
- return quarter - 1;
525
- }
526
- }),
527
- month: buildLocalizeFn({
528
- values: monthValues,
529
- defaultWidth: 'wide'
530
- }),
531
- day: buildLocalizeFn({
532
- values: dayValues,
533
- defaultWidth: 'wide'
534
- }),
535
- dayPeriod: buildLocalizeFn({
536
- values: dayPeriodValues,
537
- defaultWidth: 'wide',
538
- formattingValues: formattingDayPeriodValues,
539
- defaultFormattingWidth: 'wide'
540
- })
541
- };
542
-
543
- function buildMatchFn(args) {
544
- return function (string) {
545
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
546
- var width = options.width;
547
- var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
548
- var matchResult = string.match(matchPattern);
549
-
550
- if (!matchResult) {
551
- return null;
552
- }
553
-
554
- var matchedString = matchResult[0];
555
- var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
556
- var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) {
557
- return pattern.test(matchedString);
558
- }) : findKey(parsePatterns, function (pattern) {
559
- return pattern.test(matchedString);
560
- });
561
- var value;
562
- value = args.valueCallback ? args.valueCallback(key) : key;
563
- value = options.valueCallback ? options.valueCallback(value) : value;
564
- var rest = string.slice(matchedString.length);
565
- return {
566
- value: value,
567
- rest: rest
568
- };
569
- };
570
- }
571
-
572
- function findKey(object, predicate) {
573
- for (var key in object) {
574
- if (object.hasOwnProperty(key) && predicate(object[key])) {
575
- return key;
576
- }
577
- }
578
-
579
- return undefined;
580
- }
581
-
582
- function findIndex(array, predicate) {
583
- for (var key = 0; key < array.length; key++) {
584
- if (predicate(array[key])) {
585
- return key;
586
- }
587
- }
588
-
589
- return undefined;
590
- }
591
-
592
- function buildMatchPatternFn(args) {
593
- return function (string) {
594
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
595
- var matchResult = string.match(args.matchPattern);
596
- if (!matchResult) return null;
597
- var matchedString = matchResult[0];
598
- var parseResult = string.match(args.parsePattern);
599
- if (!parseResult) return null;
600
- var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
601
- value = options.valueCallback ? options.valueCallback(value) : value;
602
- var rest = string.slice(matchedString.length);
603
- return {
604
- value: value,
605
- rest: rest
606
- };
607
- };
608
- }
609
-
610
- var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
611
- var parseOrdinalNumberPattern = /\d+/i;
612
- var matchEraPatterns = {
613
- narrow: /^(b|a)/i,
614
- abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
615
- wide: /^(before christ|before common era|anno domini|common era)/i
616
- };
617
- var parseEraPatterns = {
618
- any: [/^b/i, /^(a|c)/i]
619
- };
620
- var matchQuarterPatterns = {
621
- narrow: /^[1234]/i,
622
- abbreviated: /^q[1234]/i,
623
- wide: /^[1234](th|st|nd|rd)? quarter/i
624
- };
625
- var parseQuarterPatterns = {
626
- any: [/1/i, /2/i, /3/i, /4/i]
627
- };
628
- var matchMonthPatterns = {
629
- narrow: /^[jfmasond]/i,
630
- abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
631
- wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
632
- };
633
- var parseMonthPatterns = {
634
- 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],
635
- 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]
636
- };
637
- var matchDayPatterns = {
638
- narrow: /^[smtwf]/i,
639
- short: /^(su|mo|tu|we|th|fr|sa)/i,
640
- abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
641
- wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
642
- };
643
- var parseDayPatterns = {
644
- narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
645
- any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
646
- };
647
- var matchDayPeriodPatterns = {
648
- narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
649
- any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
650
- };
651
- var parseDayPeriodPatterns = {
652
- any: {
653
- am: /^a/i,
654
- pm: /^p/i,
655
- midnight: /^mi/i,
656
- noon: /^no/i,
657
- morning: /morning/i,
658
- afternoon: /afternoon/i,
659
- evening: /evening/i,
660
- night: /night/i
661
- }
662
- };
663
- var match = {
664
- ordinalNumber: buildMatchPatternFn({
665
- matchPattern: matchOrdinalNumberPattern,
666
- parsePattern: parseOrdinalNumberPattern,
667
- valueCallback: function (value) {
668
- return parseInt(value, 10);
669
- }
670
- }),
671
- era: buildMatchFn({
672
- matchPatterns: matchEraPatterns,
673
- defaultMatchWidth: 'wide',
674
- parsePatterns: parseEraPatterns,
675
- defaultParseWidth: 'any'
676
- }),
677
- quarter: buildMatchFn({
678
- matchPatterns: matchQuarterPatterns,
679
- defaultMatchWidth: 'wide',
680
- parsePatterns: parseQuarterPatterns,
681
- defaultParseWidth: 'any',
682
- valueCallback: function (index) {
683
- return index + 1;
684
- }
685
- }),
686
- month: buildMatchFn({
687
- matchPatterns: matchMonthPatterns,
688
- defaultMatchWidth: 'wide',
689
- parsePatterns: parseMonthPatterns,
690
- defaultParseWidth: 'any'
691
- }),
692
- day: buildMatchFn({
693
- matchPatterns: matchDayPatterns,
694
- defaultMatchWidth: 'wide',
695
- parsePatterns: parseDayPatterns,
696
- defaultParseWidth: 'any'
697
- }),
698
- dayPeriod: buildMatchFn({
699
- matchPatterns: matchDayPeriodPatterns,
700
- defaultMatchWidth: 'any',
701
- parsePatterns: parseDayPeriodPatterns,
702
- defaultParseWidth: 'any'
703
- })
704
- };
705
-
706
- /**
707
- * @type {Locale}
708
- * @category Locales
709
- * @summary English locale (United States).
710
- * @language English
711
- * @iso-639-2 eng
712
- * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}
713
- * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}
714
- */
715
- var locale = {
716
- code: 'en-US',
717
- formatDistance: formatDistance,
718
- formatLong: formatLong,
719
- formatRelative: formatRelative,
720
- localize: localize,
721
- match: match,
722
- options: {
723
- weekStartsOn: 0
724
- /* Sunday */
725
- ,
726
- firstWeekContainsDate: 1
727
- }
728
- };
729
-
730
- /**
731
- * @name subMilliseconds
732
- * @category Millisecond Helpers
733
- * @summary Subtract the specified number of milliseconds from the given date.
734
- *
735
- * @description
736
- * Subtract the specified number of milliseconds from the given date.
737
- *
738
- * ### v2.0.0 breaking changes:
739
- *
740
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
741
- *
742
- * @param {Date|Number} date - the date to be changed
743
- * @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`.
744
- * @returns {Date} the new date with the milliseconds subtracted
745
- * @throws {TypeError} 2 arguments required
746
- *
747
- * @example
748
- * // Subtract 750 milliseconds from 10 July 2014 12:45:30.000:
749
- * const result = subMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
750
- * //=> Thu Jul 10 2014 12:45:29.250
751
- */
752
-
753
- function subMilliseconds(dirtyDate, dirtyAmount) {
754
- requiredArgs(2, arguments);
755
- var amount = toInteger(dirtyAmount);
756
- return addMilliseconds(dirtyDate, -amount);
757
- }
758
-
759
- var MILLISECONDS_IN_DAY = 86400000; // This function will be a part of public API when UTC function will be implemented.
760
- // See issue: https://github.com/date-fns/date-fns/issues/376
761
-
762
- function getUTCDayOfYear(dirtyDate) {
763
- requiredArgs(1, arguments);
764
- var date = toDate(dirtyDate);
765
- var timestamp = date.getTime();
766
- date.setUTCMonth(0, 1);
767
- date.setUTCHours(0, 0, 0, 0);
768
- var startOfYearTimestamp = date.getTime();
769
- var difference = timestamp - startOfYearTimestamp;
770
- return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
771
- }
772
-
773
- // See issue: https://github.com/date-fns/date-fns/issues/376
774
-
775
- function startOfUTCISOWeek(dirtyDate) {
776
- requiredArgs(1, arguments);
777
- var weekStartsOn = 1;
778
- var date = toDate(dirtyDate);
779
- var day = date.getUTCDay();
780
- var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
781
- date.setUTCDate(date.getUTCDate() - diff);
782
- date.setUTCHours(0, 0, 0, 0);
783
- return date;
784
- }
785
-
786
- // See issue: https://github.com/date-fns/date-fns/issues/376
787
-
788
- function getUTCISOWeekYear(dirtyDate) {
789
- requiredArgs(1, arguments);
790
- var date = toDate(dirtyDate);
791
- var year = date.getUTCFullYear();
792
- var fourthOfJanuaryOfNextYear = new Date(0);
793
- fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
794
- fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
795
- var startOfNextYear = startOfUTCISOWeek(fourthOfJanuaryOfNextYear);
796
- var fourthOfJanuaryOfThisYear = new Date(0);
797
- fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
798
- fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
799
- var startOfThisYear = startOfUTCISOWeek(fourthOfJanuaryOfThisYear);
800
-
801
- if (date.getTime() >= startOfNextYear.getTime()) {
802
- return year + 1;
803
- } else if (date.getTime() >= startOfThisYear.getTime()) {
804
- return year;
805
- } else {
806
- return year - 1;
807
- }
808
- }
809
-
810
- // See issue: https://github.com/date-fns/date-fns/issues/376
811
-
812
- function startOfUTCISOWeekYear(dirtyDate) {
813
- requiredArgs(1, arguments);
814
- var year = getUTCISOWeekYear(dirtyDate);
815
- var fourthOfJanuary = new Date(0);
816
- fourthOfJanuary.setUTCFullYear(year, 0, 4);
817
- fourthOfJanuary.setUTCHours(0, 0, 0, 0);
818
- var date = startOfUTCISOWeek(fourthOfJanuary);
819
- return date;
820
- }
821
-
822
- var MILLISECONDS_IN_WEEK$1 = 604800000; // This function will be a part of public API when UTC function will be implemented.
823
- // See issue: https://github.com/date-fns/date-fns/issues/376
824
-
825
- function getUTCISOWeek(dirtyDate) {
826
- requiredArgs(1, arguments);
827
- var date = toDate(dirtyDate);
828
- var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime(); // Round the number of days to the nearest integer
829
- // because the number of milliseconds in a week is not constant
830
- // (e.g. it's different in the week of the daylight saving time clock shift)
831
-
832
- return Math.round(diff / MILLISECONDS_IN_WEEK$1) + 1;
833
- }
834
-
835
- // See issue: https://github.com/date-fns/date-fns/issues/376
836
-
837
- function startOfUTCWeek(dirtyDate, dirtyOptions) {
838
- requiredArgs(1, arguments);
839
- var options = dirtyOptions || {};
840
- var locale = options.locale;
841
- var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn;
842
- var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn);
843
- var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
844
-
845
- if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
846
- throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
847
- }
848
-
849
- var date = toDate(dirtyDate);
850
- var day = date.getUTCDay();
851
- var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
852
- date.setUTCDate(date.getUTCDate() - diff);
853
- date.setUTCHours(0, 0, 0, 0);
854
- return date;
855
- }
856
-
857
- // See issue: https://github.com/date-fns/date-fns/issues/376
858
-
859
- function getUTCWeekYear(dirtyDate, dirtyOptions) {
860
- requiredArgs(1, arguments);
861
- var date = toDate(dirtyDate);
862
- var year = date.getUTCFullYear();
863
- var options = dirtyOptions || {};
864
- var locale = options.locale;
865
- var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
866
- var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate);
867
- var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
868
-
869
- if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
870
- throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
871
- }
872
-
873
- var firstWeekOfNextYear = new Date(0);
874
- firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate);
875
- firstWeekOfNextYear.setUTCHours(0, 0, 0, 0);
876
- var startOfNextYear = startOfUTCWeek(firstWeekOfNextYear, dirtyOptions);
877
- var firstWeekOfThisYear = new Date(0);
878
- firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
879
- firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
880
- var startOfThisYear = startOfUTCWeek(firstWeekOfThisYear, dirtyOptions);
881
-
882
- if (date.getTime() >= startOfNextYear.getTime()) {
883
- return year + 1;
884
- } else if (date.getTime() >= startOfThisYear.getTime()) {
885
- return year;
886
- } else {
887
- return year - 1;
888
- }
889
- }
890
-
891
- // See issue: https://github.com/date-fns/date-fns/issues/376
892
-
893
- function startOfUTCWeekYear(dirtyDate, dirtyOptions) {
894
- requiredArgs(1, arguments);
895
- var options = dirtyOptions || {};
896
- var locale = options.locale;
897
- var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
898
- var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate);
899
- var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate);
900
- var year = getUTCWeekYear(dirtyDate, dirtyOptions);
901
- var firstWeek = new Date(0);
902
- firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
903
- firstWeek.setUTCHours(0, 0, 0, 0);
904
- var date = startOfUTCWeek(firstWeek, dirtyOptions);
905
- return date;
906
- }
907
-
908
- var MILLISECONDS_IN_WEEK = 604800000; // This function will be a part of public API when UTC function will be implemented.
909
- // See issue: https://github.com/date-fns/date-fns/issues/376
910
-
911
- function getUTCWeek(dirtyDate, options) {
912
- requiredArgs(1, arguments);
913
- var date = toDate(dirtyDate);
914
- var diff = startOfUTCWeek(date, options).getTime() - startOfUTCWeekYear(date, options).getTime(); // Round the number of days to the nearest integer
915
- // because the number of milliseconds in a week is not constant
916
- // (e.g. it's different in the week of the daylight saving time clock shift)
917
-
918
- return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
919
- }
920
-
921
- function addLeadingZeros(number, targetLength) {
922
- var sign = number < 0 ? '-' : '';
923
- var output = Math.abs(number).toString();
924
-
925
- while (output.length < targetLength) {
926
- output = '0' + output;
927
- }
928
-
929
- return sign + output;
930
- }
931
-
932
- /*
933
- * | | Unit | | Unit |
934
- * |-----|--------------------------------|-----|--------------------------------|
935
- * | a | AM, PM | A* | |
936
- * | d | Day of month | D | |
937
- * | h | Hour [1-12] | H | Hour [0-23] |
938
- * | m | Minute | M | Month |
939
- * | s | Second | S | Fraction of second |
940
- * | y | Year (abs) | Y | |
941
- *
942
- * Letters marked by * are not implemented but reserved by Unicode standard.
943
- */
944
-
945
- var formatters$1 = {
946
- // Year
947
- y: function (date, token) {
948
- // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
949
- // | Year | y | yy | yyy | yyyy | yyyyy |
950
- // |----------|-------|----|-------|-------|-------|
951
- // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
952
- // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
953
- // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
954
- // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
955
- // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
956
- var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript)
957
-
958
- var year = signedYear > 0 ? signedYear : 1 - signedYear;
959
- return addLeadingZeros(token === 'yy' ? year % 100 : year, token.length);
960
- },
961
- // Month
962
- M: function (date, token) {
963
- var month = date.getUTCMonth();
964
- return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2);
965
- },
966
- // Day of the month
967
- d: function (date, token) {
968
- return addLeadingZeros(date.getUTCDate(), token.length);
969
- },
970
- // AM or PM
971
- a: function (date, token) {
972
- var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
973
-
974
- switch (token) {
975
- case 'a':
976
- case 'aa':
977
- return dayPeriodEnumValue.toUpperCase();
978
-
979
- case 'aaa':
980
- return dayPeriodEnumValue;
981
-
982
- case 'aaaaa':
983
- return dayPeriodEnumValue[0];
984
-
985
- case 'aaaa':
986
- default:
987
- return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
988
- }
989
- },
990
- // Hour [1-12]
991
- h: function (date, token) {
992
- return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length);
993
- },
994
- // Hour [0-23]
995
- H: function (date, token) {
996
- return addLeadingZeros(date.getUTCHours(), token.length);
997
- },
998
- // Minute
999
- m: function (date, token) {
1000
- return addLeadingZeros(date.getUTCMinutes(), token.length);
1001
- },
1002
- // Second
1003
- s: function (date, token) {
1004
- return addLeadingZeros(date.getUTCSeconds(), token.length);
1005
- },
1006
- // Fraction of second
1007
- S: function (date, token) {
1008
- var numberOfDigits = token.length;
1009
- var milliseconds = date.getUTCMilliseconds();
1010
- var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
1011
- return addLeadingZeros(fractionalSeconds, token.length);
1012
- }
1013
- };
1014
-
1015
- var dayPeriodEnum = {
1016
- am: 'am',
1017
- pm: 'pm',
1018
- midnight: 'midnight',
1019
- noon: 'noon',
1020
- morning: 'morning',
1021
- afternoon: 'afternoon',
1022
- evening: 'evening',
1023
- night: 'night'
1024
- };
1025
- /*
1026
- * | | Unit | | Unit |
1027
- * |-----|--------------------------------|-----|--------------------------------|
1028
- * | a | AM, PM | A* | Milliseconds in day |
1029
- * | b | AM, PM, noon, midnight | B | Flexible day period |
1030
- * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
1031
- * | d | Day of month | D | Day of year |
1032
- * | e | Local day of week | E | Day of week |
1033
- * | f | | F* | Day of week in month |
1034
- * | g* | Modified Julian day | G | Era |
1035
- * | h | Hour [1-12] | H | Hour [0-23] |
1036
- * | i! | ISO day of week | I! | ISO week of year |
1037
- * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
1038
- * | k | Hour [1-24] | K | Hour [0-11] |
1039
- * | l* | (deprecated) | L | Stand-alone month |
1040
- * | m | Minute | M | Month |
1041
- * | n | | N | |
1042
- * | o! | Ordinal number modifier | O | Timezone (GMT) |
1043
- * | p! | Long localized time | P! | Long localized date |
1044
- * | q | Stand-alone quarter | Q | Quarter |
1045
- * | r* | Related Gregorian year | R! | ISO week-numbering year |
1046
- * | s | Second | S | Fraction of second |
1047
- * | t! | Seconds timestamp | T! | Milliseconds timestamp |
1048
- * | u | Extended year | U* | Cyclic year |
1049
- * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
1050
- * | w | Local week of year | W* | Week of month |
1051
- * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
1052
- * | y | Year (abs) | Y | Local week-numbering year |
1053
- * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
1054
- *
1055
- * Letters marked by * are not implemented but reserved by Unicode standard.
1056
- *
1057
- * Letters marked by ! are non-standard, but implemented by date-fns:
1058
- * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
1059
- * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
1060
- * i.e. 7 for Sunday, 1 for Monday, etc.
1061
- * - `I` is ISO week of year, as opposed to `w` which is local week of year.
1062
- * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
1063
- * `R` is supposed to be used in conjunction with `I` and `i`
1064
- * for universal ISO week-numbering date, whereas
1065
- * `Y` is supposed to be used in conjunction with `w` and `e`
1066
- * for week-numbering date specific to the locale.
1067
- * - `P` is long localized date format
1068
- * - `p` is long localized time format
1069
- */
1070
-
1071
- var formatters = {
1072
- // Era
1073
- G: function (date, token, localize) {
1074
- var era = date.getUTCFullYear() > 0 ? 1 : 0;
1075
-
1076
- switch (token) {
1077
- // AD, BC
1078
- case 'G':
1079
- case 'GG':
1080
- case 'GGG':
1081
- return localize.era(era, {
1082
- width: 'abbreviated'
1083
- });
1084
- // A, B
1085
-
1086
- case 'GGGGG':
1087
- return localize.era(era, {
1088
- width: 'narrow'
1089
- });
1090
- // Anno Domini, Before Christ
1091
-
1092
- case 'GGGG':
1093
- default:
1094
- return localize.era(era, {
1095
- width: 'wide'
1096
- });
1097
- }
1098
- },
1099
- // Year
1100
- y: function (date, token, localize) {
1101
- // Ordinal number
1102
- if (token === 'yo') {
1103
- var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript)
1104
-
1105
- var year = signedYear > 0 ? signedYear : 1 - signedYear;
1106
- return localize.ordinalNumber(year, {
1107
- unit: 'year'
1108
- });
1109
- }
1110
-
1111
- return formatters$1.y(date, token);
1112
- },
1113
- // Local week-numbering year
1114
- Y: function (date, token, localize, options) {
1115
- var signedWeekYear = getUTCWeekYear(date, options); // Returns 1 for 1 BC (which is year 0 in JavaScript)
1116
-
1117
- var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear; // Two digit year
1118
-
1119
- if (token === 'YY') {
1120
- var twoDigitYear = weekYear % 100;
1121
- return addLeadingZeros(twoDigitYear, 2);
1122
- } // Ordinal number
1123
-
1124
-
1125
- if (token === 'Yo') {
1126
- return localize.ordinalNumber(weekYear, {
1127
- unit: 'year'
1128
- });
1129
- } // Padding
1130
-
1131
-
1132
- return addLeadingZeros(weekYear, token.length);
1133
- },
1134
- // ISO week-numbering year
1135
- R: function (date, token) {
1136
- var isoWeekYear = getUTCISOWeekYear(date); // Padding
1137
-
1138
- return addLeadingZeros(isoWeekYear, token.length);
1139
- },
1140
- // Extended year. This is a single number designating the year of this calendar system.
1141
- // The main difference between `y` and `u` localizers are B.C. years:
1142
- // | Year | `y` | `u` |
1143
- // |------|-----|-----|
1144
- // | AC 1 | 1 | 1 |
1145
- // | BC 1 | 1 | 0 |
1146
- // | BC 2 | 2 | -1 |
1147
- // Also `yy` always returns the last two digits of a year,
1148
- // while `uu` pads single digit years to 2 characters and returns other years unchanged.
1149
- u: function (date, token) {
1150
- var year = date.getUTCFullYear();
1151
- return addLeadingZeros(year, token.length);
1152
- },
1153
- // Quarter
1154
- Q: function (date, token, localize) {
1155
- var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
1156
-
1157
- switch (token) {
1158
- // 1, 2, 3, 4
1159
- case 'Q':
1160
- return String(quarter);
1161
- // 01, 02, 03, 04
1162
-
1163
- case 'QQ':
1164
- return addLeadingZeros(quarter, 2);
1165
- // 1st, 2nd, 3rd, 4th
1166
-
1167
- case 'Qo':
1168
- return localize.ordinalNumber(quarter, {
1169
- unit: 'quarter'
1170
- });
1171
- // Q1, Q2, Q3, Q4
1172
-
1173
- case 'QQQ':
1174
- return localize.quarter(quarter, {
1175
- width: 'abbreviated',
1176
- context: 'formatting'
1177
- });
1178
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
1179
-
1180
- case 'QQQQQ':
1181
- return localize.quarter(quarter, {
1182
- width: 'narrow',
1183
- context: 'formatting'
1184
- });
1185
- // 1st quarter, 2nd quarter, ...
1186
-
1187
- case 'QQQQ':
1188
- default:
1189
- return localize.quarter(quarter, {
1190
- width: 'wide',
1191
- context: 'formatting'
1192
- });
1193
- }
1194
- },
1195
- // Stand-alone quarter
1196
- q: function (date, token, localize) {
1197
- var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
1198
-
1199
- switch (token) {
1200
- // 1, 2, 3, 4
1201
- case 'q':
1202
- return String(quarter);
1203
- // 01, 02, 03, 04
1204
-
1205
- case 'qq':
1206
- return addLeadingZeros(quarter, 2);
1207
- // 1st, 2nd, 3rd, 4th
1208
-
1209
- case 'qo':
1210
- return localize.ordinalNumber(quarter, {
1211
- unit: 'quarter'
1212
- });
1213
- // Q1, Q2, Q3, Q4
1214
-
1215
- case 'qqq':
1216
- return localize.quarter(quarter, {
1217
- width: 'abbreviated',
1218
- context: 'standalone'
1219
- });
1220
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
1221
-
1222
- case 'qqqqq':
1223
- return localize.quarter(quarter, {
1224
- width: 'narrow',
1225
- context: 'standalone'
1226
- });
1227
- // 1st quarter, 2nd quarter, ...
1228
-
1229
- case 'qqqq':
1230
- default:
1231
- return localize.quarter(quarter, {
1232
- width: 'wide',
1233
- context: 'standalone'
1234
- });
1235
- }
1236
- },
1237
- // Month
1238
- M: function (date, token, localize) {
1239
- var month = date.getUTCMonth();
1240
-
1241
- switch (token) {
1242
- case 'M':
1243
- case 'MM':
1244
- return formatters$1.M(date, token);
1245
- // 1st, 2nd, ..., 12th
1246
-
1247
- case 'Mo':
1248
- return localize.ordinalNumber(month + 1, {
1249
- unit: 'month'
1250
- });
1251
- // Jan, Feb, ..., Dec
1252
-
1253
- case 'MMM':
1254
- return localize.month(month, {
1255
- width: 'abbreviated',
1256
- context: 'formatting'
1257
- });
1258
- // J, F, ..., D
1259
-
1260
- case 'MMMMM':
1261
- return localize.month(month, {
1262
- width: 'narrow',
1263
- context: 'formatting'
1264
- });
1265
- // January, February, ..., December
1266
-
1267
- case 'MMMM':
1268
- default:
1269
- return localize.month(month, {
1270
- width: 'wide',
1271
- context: 'formatting'
1272
- });
1273
- }
1274
- },
1275
- // Stand-alone month
1276
- L: function (date, token, localize) {
1277
- var month = date.getUTCMonth();
1278
-
1279
- switch (token) {
1280
- // 1, 2, ..., 12
1281
- case 'L':
1282
- return String(month + 1);
1283
- // 01, 02, ..., 12
1284
-
1285
- case 'LL':
1286
- return addLeadingZeros(month + 1, 2);
1287
- // 1st, 2nd, ..., 12th
1288
-
1289
- case 'Lo':
1290
- return localize.ordinalNumber(month + 1, {
1291
- unit: 'month'
1292
- });
1293
- // Jan, Feb, ..., Dec
1294
-
1295
- case 'LLL':
1296
- return localize.month(month, {
1297
- width: 'abbreviated',
1298
- context: 'standalone'
1299
- });
1300
- // J, F, ..., D
1301
-
1302
- case 'LLLLL':
1303
- return localize.month(month, {
1304
- width: 'narrow',
1305
- context: 'standalone'
1306
- });
1307
- // January, February, ..., December
1308
-
1309
- case 'LLLL':
1310
- default:
1311
- return localize.month(month, {
1312
- width: 'wide',
1313
- context: 'standalone'
1314
- });
1315
- }
1316
- },
1317
- // Local week of year
1318
- w: function (date, token, localize, options) {
1319
- var week = getUTCWeek(date, options);
1320
-
1321
- if (token === 'wo') {
1322
- return localize.ordinalNumber(week, {
1323
- unit: 'week'
1324
- });
1325
- }
1326
-
1327
- return addLeadingZeros(week, token.length);
1328
- },
1329
- // ISO week of year
1330
- I: function (date, token, localize) {
1331
- var isoWeek = getUTCISOWeek(date);
1332
-
1333
- if (token === 'Io') {
1334
- return localize.ordinalNumber(isoWeek, {
1335
- unit: 'week'
1336
- });
1337
- }
1338
-
1339
- return addLeadingZeros(isoWeek, token.length);
1340
- },
1341
- // Day of the month
1342
- d: function (date, token, localize) {
1343
- if (token === 'do') {
1344
- return localize.ordinalNumber(date.getUTCDate(), {
1345
- unit: 'date'
1346
- });
1347
- }
1348
-
1349
- return formatters$1.d(date, token);
1350
- },
1351
- // Day of year
1352
- D: function (date, token, localize) {
1353
- var dayOfYear = getUTCDayOfYear(date);
1354
-
1355
- if (token === 'Do') {
1356
- return localize.ordinalNumber(dayOfYear, {
1357
- unit: 'dayOfYear'
1358
- });
1359
- }
1360
-
1361
- return addLeadingZeros(dayOfYear, token.length);
1362
- },
1363
- // Day of week
1364
- E: function (date, token, localize) {
1365
- var dayOfWeek = date.getUTCDay();
1366
-
1367
- switch (token) {
1368
- // Tue
1369
- case 'E':
1370
- case 'EE':
1371
- case 'EEE':
1372
- return localize.day(dayOfWeek, {
1373
- width: 'abbreviated',
1374
- context: 'formatting'
1375
- });
1376
- // T
1377
-
1378
- case 'EEEEE':
1379
- return localize.day(dayOfWeek, {
1380
- width: 'narrow',
1381
- context: 'formatting'
1382
- });
1383
- // Tu
1384
-
1385
- case 'EEEEEE':
1386
- return localize.day(dayOfWeek, {
1387
- width: 'short',
1388
- context: 'formatting'
1389
- });
1390
- // Tuesday
1391
-
1392
- case 'EEEE':
1393
- default:
1394
- return localize.day(dayOfWeek, {
1395
- width: 'wide',
1396
- context: 'formatting'
1397
- });
1398
- }
1399
- },
1400
- // Local day of week
1401
- e: function (date, token, localize, options) {
1402
- var dayOfWeek = date.getUTCDay();
1403
- var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1404
-
1405
- switch (token) {
1406
- // Numerical value (Nth day of week with current locale or weekStartsOn)
1407
- case 'e':
1408
- return String(localDayOfWeek);
1409
- // Padded numerical value
1410
-
1411
- case 'ee':
1412
- return addLeadingZeros(localDayOfWeek, 2);
1413
- // 1st, 2nd, ..., 7th
1414
-
1415
- case 'eo':
1416
- return localize.ordinalNumber(localDayOfWeek, {
1417
- unit: 'day'
1418
- });
1419
-
1420
- case 'eee':
1421
- return localize.day(dayOfWeek, {
1422
- width: 'abbreviated',
1423
- context: 'formatting'
1424
- });
1425
- // T
1426
-
1427
- case 'eeeee':
1428
- return localize.day(dayOfWeek, {
1429
- width: 'narrow',
1430
- context: 'formatting'
1431
- });
1432
- // Tu
1433
-
1434
- case 'eeeeee':
1435
- return localize.day(dayOfWeek, {
1436
- width: 'short',
1437
- context: 'formatting'
1438
- });
1439
- // Tuesday
1440
-
1441
- case 'eeee':
1442
- default:
1443
- return localize.day(dayOfWeek, {
1444
- width: 'wide',
1445
- context: 'formatting'
1446
- });
1447
- }
1448
- },
1449
- // Stand-alone local day of week
1450
- c: function (date, token, localize, options) {
1451
- var dayOfWeek = date.getUTCDay();
1452
- var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1453
-
1454
- switch (token) {
1455
- // Numerical value (same as in `e`)
1456
- case 'c':
1457
- return String(localDayOfWeek);
1458
- // Padded numerical value
1459
-
1460
- case 'cc':
1461
- return addLeadingZeros(localDayOfWeek, token.length);
1462
- // 1st, 2nd, ..., 7th
1463
-
1464
- case 'co':
1465
- return localize.ordinalNumber(localDayOfWeek, {
1466
- unit: 'day'
1467
- });
1468
-
1469
- case 'ccc':
1470
- return localize.day(dayOfWeek, {
1471
- width: 'abbreviated',
1472
- context: 'standalone'
1473
- });
1474
- // T
1475
-
1476
- case 'ccccc':
1477
- return localize.day(dayOfWeek, {
1478
- width: 'narrow',
1479
- context: 'standalone'
1480
- });
1481
- // Tu
1482
-
1483
- case 'cccccc':
1484
- return localize.day(dayOfWeek, {
1485
- width: 'short',
1486
- context: 'standalone'
1487
- });
1488
- // Tuesday
1489
-
1490
- case 'cccc':
1491
- default:
1492
- return localize.day(dayOfWeek, {
1493
- width: 'wide',
1494
- context: 'standalone'
1495
- });
1496
- }
1497
- },
1498
- // ISO day of week
1499
- i: function (date, token, localize) {
1500
- var dayOfWeek = date.getUTCDay();
1501
- var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
1502
-
1503
- switch (token) {
1504
- // 2
1505
- case 'i':
1506
- return String(isoDayOfWeek);
1507
- // 02
1508
-
1509
- case 'ii':
1510
- return addLeadingZeros(isoDayOfWeek, token.length);
1511
- // 2nd
1512
-
1513
- case 'io':
1514
- return localize.ordinalNumber(isoDayOfWeek, {
1515
- unit: 'day'
1516
- });
1517
- // Tue
1518
-
1519
- case 'iii':
1520
- return localize.day(dayOfWeek, {
1521
- width: 'abbreviated',
1522
- context: 'formatting'
1523
- });
1524
- // T
1525
-
1526
- case 'iiiii':
1527
- return localize.day(dayOfWeek, {
1528
- width: 'narrow',
1529
- context: 'formatting'
1530
- });
1531
- // Tu
1532
-
1533
- case 'iiiiii':
1534
- return localize.day(dayOfWeek, {
1535
- width: 'short',
1536
- context: 'formatting'
1537
- });
1538
- // Tuesday
1539
-
1540
- case 'iiii':
1541
- default:
1542
- return localize.day(dayOfWeek, {
1543
- width: 'wide',
1544
- context: 'formatting'
1545
- });
1546
- }
1547
- },
1548
- // AM or PM
1549
- a: function (date, token, localize) {
1550
- var hours = date.getUTCHours();
1551
- var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1552
-
1553
- switch (token) {
1554
- case 'a':
1555
- case 'aa':
1556
- return localize.dayPeriod(dayPeriodEnumValue, {
1557
- width: 'abbreviated',
1558
- context: 'formatting'
1559
- });
1560
-
1561
- case 'aaa':
1562
- return localize.dayPeriod(dayPeriodEnumValue, {
1563
- width: 'abbreviated',
1564
- context: 'formatting'
1565
- }).toLowerCase();
1566
-
1567
- case 'aaaaa':
1568
- return localize.dayPeriod(dayPeriodEnumValue, {
1569
- width: 'narrow',
1570
- context: 'formatting'
1571
- });
1572
-
1573
- case 'aaaa':
1574
- default:
1575
- return localize.dayPeriod(dayPeriodEnumValue, {
1576
- width: 'wide',
1577
- context: 'formatting'
1578
- });
1579
- }
1580
- },
1581
- // AM, PM, midnight, noon
1582
- b: function (date, token, localize) {
1583
- var hours = date.getUTCHours();
1584
- var dayPeriodEnumValue;
1585
-
1586
- if (hours === 12) {
1587
- dayPeriodEnumValue = dayPeriodEnum.noon;
1588
- } else if (hours === 0) {
1589
- dayPeriodEnumValue = dayPeriodEnum.midnight;
1590
- } else {
1591
- dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1592
- }
1593
-
1594
- switch (token) {
1595
- case 'b':
1596
- case 'bb':
1597
- return localize.dayPeriod(dayPeriodEnumValue, {
1598
- width: 'abbreviated',
1599
- context: 'formatting'
1600
- });
1601
-
1602
- case 'bbb':
1603
- return localize.dayPeriod(dayPeriodEnumValue, {
1604
- width: 'abbreviated',
1605
- context: 'formatting'
1606
- }).toLowerCase();
1607
-
1608
- case 'bbbbb':
1609
- return localize.dayPeriod(dayPeriodEnumValue, {
1610
- width: 'narrow',
1611
- context: 'formatting'
1612
- });
1613
-
1614
- case 'bbbb':
1615
- default:
1616
- return localize.dayPeriod(dayPeriodEnumValue, {
1617
- width: 'wide',
1618
- context: 'formatting'
1619
- });
1620
- }
1621
- },
1622
- // in the morning, in the afternoon, in the evening, at night
1623
- B: function (date, token, localize) {
1624
- var hours = date.getUTCHours();
1625
- var dayPeriodEnumValue;
1626
-
1627
- if (hours >= 17) {
1628
- dayPeriodEnumValue = dayPeriodEnum.evening;
1629
- } else if (hours >= 12) {
1630
- dayPeriodEnumValue = dayPeriodEnum.afternoon;
1631
- } else if (hours >= 4) {
1632
- dayPeriodEnumValue = dayPeriodEnum.morning;
1633
- } else {
1634
- dayPeriodEnumValue = dayPeriodEnum.night;
1635
- }
1636
-
1637
- switch (token) {
1638
- case 'B':
1639
- case 'BB':
1640
- case 'BBB':
1641
- return localize.dayPeriod(dayPeriodEnumValue, {
1642
- width: 'abbreviated',
1643
- context: 'formatting'
1644
- });
1645
-
1646
- case 'BBBBB':
1647
- return localize.dayPeriod(dayPeriodEnumValue, {
1648
- width: 'narrow',
1649
- context: 'formatting'
1650
- });
1651
-
1652
- case 'BBBB':
1653
- default:
1654
- return localize.dayPeriod(dayPeriodEnumValue, {
1655
- width: 'wide',
1656
- context: 'formatting'
1657
- });
1658
- }
1659
- },
1660
- // Hour [1-12]
1661
- h: function (date, token, localize) {
1662
- if (token === 'ho') {
1663
- var hours = date.getUTCHours() % 12;
1664
- if (hours === 0) hours = 12;
1665
- return localize.ordinalNumber(hours, {
1666
- unit: 'hour'
1667
- });
1668
- }
1669
-
1670
- return formatters$1.h(date, token);
1671
- },
1672
- // Hour [0-23]
1673
- H: function (date, token, localize) {
1674
- if (token === 'Ho') {
1675
- return localize.ordinalNumber(date.getUTCHours(), {
1676
- unit: 'hour'
1677
- });
1678
- }
1679
-
1680
- return formatters$1.H(date, token);
1681
- },
1682
- // Hour [0-11]
1683
- K: function (date, token, localize) {
1684
- var hours = date.getUTCHours() % 12;
1685
-
1686
- if (token === 'Ko') {
1687
- return localize.ordinalNumber(hours, {
1688
- unit: 'hour'
1689
- });
1690
- }
1691
-
1692
- return addLeadingZeros(hours, token.length);
1693
- },
1694
- // Hour [1-24]
1695
- k: function (date, token, localize) {
1696
- var hours = date.getUTCHours();
1697
- if (hours === 0) hours = 24;
1698
-
1699
- if (token === 'ko') {
1700
- return localize.ordinalNumber(hours, {
1701
- unit: 'hour'
1702
- });
1703
- }
1704
-
1705
- return addLeadingZeros(hours, token.length);
1706
- },
1707
- // Minute
1708
- m: function (date, token, localize) {
1709
- if (token === 'mo') {
1710
- return localize.ordinalNumber(date.getUTCMinutes(), {
1711
- unit: 'minute'
1712
- });
1713
- }
1714
-
1715
- return formatters$1.m(date, token);
1716
- },
1717
- // Second
1718
- s: function (date, token, localize) {
1719
- if (token === 'so') {
1720
- return localize.ordinalNumber(date.getUTCSeconds(), {
1721
- unit: 'second'
1722
- });
1723
- }
1724
-
1725
- return formatters$1.s(date, token);
1726
- },
1727
- // Fraction of second
1728
- S: function (date, token) {
1729
- return formatters$1.S(date, token);
1730
- },
1731
- // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
1732
- X: function (date, token, _localize, options) {
1733
- var originalDate = options._originalDate || date;
1734
- var timezoneOffset = originalDate.getTimezoneOffset();
1735
-
1736
- if (timezoneOffset === 0) {
1737
- return 'Z';
1738
- }
1739
-
1740
- switch (token) {
1741
- // Hours and optional minutes
1742
- case 'X':
1743
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
1744
- // Hours, minutes and optional seconds without `:` delimiter
1745
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1746
- // so this token always has the same output as `XX`
1747
-
1748
- case 'XXXX':
1749
- case 'XX':
1750
- // Hours and minutes without `:` delimiter
1751
- return formatTimezone(timezoneOffset);
1752
- // Hours, minutes and optional seconds with `:` delimiter
1753
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1754
- // so this token always has the same output as `XXX`
1755
-
1756
- case 'XXXXX':
1757
- case 'XXX': // Hours and minutes with `:` delimiter
1758
-
1759
- default:
1760
- return formatTimezone(timezoneOffset, ':');
1761
- }
1762
- },
1763
- // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
1764
- x: function (date, token, _localize, options) {
1765
- var originalDate = options._originalDate || date;
1766
- var timezoneOffset = originalDate.getTimezoneOffset();
1767
-
1768
- switch (token) {
1769
- // Hours and optional minutes
1770
- case 'x':
1771
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
1772
- // Hours, minutes and optional seconds without `:` delimiter
1773
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1774
- // so this token always has the same output as `xx`
1775
-
1776
- case 'xxxx':
1777
- case 'xx':
1778
- // Hours and minutes without `:` delimiter
1779
- return formatTimezone(timezoneOffset);
1780
- // Hours, minutes and optional seconds with `:` delimiter
1781
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1782
- // so this token always has the same output as `xxx`
1783
-
1784
- case 'xxxxx':
1785
- case 'xxx': // Hours and minutes with `:` delimiter
1786
-
1787
- default:
1788
- return formatTimezone(timezoneOffset, ':');
1789
- }
1790
- },
1791
- // Timezone (GMT)
1792
- O: function (date, token, _localize, options) {
1793
- var originalDate = options._originalDate || date;
1794
- var timezoneOffset = originalDate.getTimezoneOffset();
1795
-
1796
- switch (token) {
1797
- // Short
1798
- case 'O':
1799
- case 'OO':
1800
- case 'OOO':
1801
- return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1802
- // Long
1803
-
1804
- case 'OOOO':
1805
- default:
1806
- return 'GMT' + formatTimezone(timezoneOffset, ':');
1807
- }
1808
- },
1809
- // Timezone (specific non-location)
1810
- z: function (date, token, _localize, options) {
1811
- var originalDate = options._originalDate || date;
1812
- var timezoneOffset = originalDate.getTimezoneOffset();
1813
-
1814
- switch (token) {
1815
- // Short
1816
- case 'z':
1817
- case 'zz':
1818
- case 'zzz':
1819
- return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1820
- // Long
1821
-
1822
- case 'zzzz':
1823
- default:
1824
- return 'GMT' + formatTimezone(timezoneOffset, ':');
1825
- }
1826
- },
1827
- // Seconds timestamp
1828
- t: function (date, token, _localize, options) {
1829
- var originalDate = options._originalDate || date;
1830
- var timestamp = Math.floor(originalDate.getTime() / 1000);
1831
- return addLeadingZeros(timestamp, token.length);
1832
- },
1833
- // Milliseconds timestamp
1834
- T: function (date, token, _localize, options) {
1835
- var originalDate = options._originalDate || date;
1836
- var timestamp = originalDate.getTime();
1837
- return addLeadingZeros(timestamp, token.length);
1838
- }
1839
- };
1840
-
1841
- function formatTimezoneShort(offset, dirtyDelimiter) {
1842
- var sign = offset > 0 ? '-' : '+';
1843
- var absOffset = Math.abs(offset);
1844
- var hours = Math.floor(absOffset / 60);
1845
- var minutes = absOffset % 60;
1846
-
1847
- if (minutes === 0) {
1848
- return sign + String(hours);
1849
- }
1850
-
1851
- var delimiter = dirtyDelimiter || '';
1852
- return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
1853
- }
1854
-
1855
- function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
1856
- if (offset % 60 === 0) {
1857
- var sign = offset > 0 ? '-' : '+';
1858
- return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
1859
- }
1860
-
1861
- return formatTimezone(offset, dirtyDelimiter);
1862
- }
1863
-
1864
- function formatTimezone(offset, dirtyDelimiter) {
1865
- var delimiter = dirtyDelimiter || '';
1866
- var sign = offset > 0 ? '-' : '+';
1867
- var absOffset = Math.abs(offset);
1868
- var hours = addLeadingZeros(Math.floor(absOffset / 60), 2);
1869
- var minutes = addLeadingZeros(absOffset % 60, 2);
1870
- return sign + hours + delimiter + minutes;
1871
- }
1872
-
1873
- function dateLongFormatter(pattern, formatLong) {
1874
- switch (pattern) {
1875
- case 'P':
1876
- return formatLong.date({
1877
- width: 'short'
1878
- });
1879
-
1880
- case 'PP':
1881
- return formatLong.date({
1882
- width: 'medium'
1883
- });
1884
-
1885
- case 'PPP':
1886
- return formatLong.date({
1887
- width: 'long'
1888
- });
1889
-
1890
- case 'PPPP':
1891
- default:
1892
- return formatLong.date({
1893
- width: 'full'
1894
- });
1895
- }
1896
- }
1897
-
1898
- function timeLongFormatter(pattern, formatLong) {
1899
- switch (pattern) {
1900
- case 'p':
1901
- return formatLong.time({
1902
- width: 'short'
1903
- });
1904
-
1905
- case 'pp':
1906
- return formatLong.time({
1907
- width: 'medium'
1908
- });
1909
-
1910
- case 'ppp':
1911
- return formatLong.time({
1912
- width: 'long'
1913
- });
1914
-
1915
- case 'pppp':
1916
- default:
1917
- return formatLong.time({
1918
- width: 'full'
1919
- });
1920
- }
1921
- }
1922
-
1923
- function dateTimeLongFormatter(pattern, formatLong) {
1924
- var matchResult = pattern.match(/(P+)(p+)?/) || [];
1925
- var datePattern = matchResult[1];
1926
- var timePattern = matchResult[2];
1927
-
1928
- if (!timePattern) {
1929
- return dateLongFormatter(pattern, formatLong);
1930
- }
1931
-
1932
- var dateTimeFormat;
1933
-
1934
- switch (datePattern) {
1935
- case 'P':
1936
- dateTimeFormat = formatLong.dateTime({
1937
- width: 'short'
1938
- });
1939
- break;
1940
-
1941
- case 'PP':
1942
- dateTimeFormat = formatLong.dateTime({
1943
- width: 'medium'
1944
- });
1945
- break;
1946
-
1947
- case 'PPP':
1948
- dateTimeFormat = formatLong.dateTime({
1949
- width: 'long'
1950
- });
1951
- break;
1952
-
1953
- case 'PPPP':
1954
- default:
1955
- dateTimeFormat = formatLong.dateTime({
1956
- width: 'full'
1957
- });
1958
- break;
1959
- }
1960
-
1961
- return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
1962
- }
1963
-
1964
- var longFormatters = {
1965
- p: timeLongFormatter,
1966
- P: dateTimeLongFormatter
1967
- };
1968
-
1969
- var protectedDayOfYearTokens = ['D', 'DD'];
1970
- var protectedWeekYearTokens = ['YY', 'YYYY'];
1971
- function isProtectedDayOfYearToken(token) {
1972
- return protectedDayOfYearTokens.indexOf(token) !== -1;
1973
- }
1974
- function isProtectedWeekYearToken(token) {
1975
- return protectedWeekYearTokens.indexOf(token) !== -1;
1976
- }
1977
- function throwProtectedError(token, format, input) {
1978
- if (token === 'YYYY') {
1979
- throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://git.io/fxCyr"));
1980
- } else if (token === 'YY') {
1981
- throw new RangeError("Use `yy` instead of `YY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://git.io/fxCyr"));
1982
- } else if (token === 'D') {
1983
- throw new RangeError("Use `d` instead of `D` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://git.io/fxCyr"));
1984
- } else if (token === 'DD') {
1985
- throw new RangeError("Use `dd` instead of `DD` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://git.io/fxCyr"));
1986
- }
1987
- }
1988
-
1989
- // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
1990
- // (one of the certain letters followed by `o`)
1991
- // - (\w)\1* matches any sequences of the same letter
1992
- // - '' matches two quote characters in a row
1993
- // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
1994
- // except a single quote symbol, which ends the sequence.
1995
- // Two quote characters do not end the sequence.
1996
- // If there is no matching single quote
1997
- // then the sequence will continue until the end of the string.
1998
- // - . matches any single character unmatched by previous parts of the RegExps
1999
-
2000
- var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g; // This RegExp catches symbols escaped by quotes, and also
2001
- // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
2002
-
2003
- var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
2004
- var escapedStringRegExp = /^'([^]*?)'?$/;
2005
- var doubleQuoteRegExp = /''/g;
2006
- var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
2007
- /**
2008
- * @name format
2009
- * @category Common Helpers
2010
- * @summary Format the date.
2011
- *
2012
- * @description
2013
- * Return the formatted date string in the given format. The result may vary by locale.
2014
- *
2015
- * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
2016
- * > See: https://git.io/fxCyr
2017
- *
2018
- * The characters wrapped between two single quotes characters (') are escaped.
2019
- * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
2020
- * (see the last example)
2021
- *
2022
- * Format of the string is based on Unicode Technical Standard #35:
2023
- * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
2024
- * with a few additions (see note 7 below the table).
2025
- *
2026
- * Accepted patterns:
2027
- * | Unit | Pattern | Result examples | Notes |
2028
- * |---------------------------------|---------|-----------------------------------|-------|
2029
- * | Era | G..GGG | AD, BC | |
2030
- * | | GGGG | Anno Domini, Before Christ | 2 |
2031
- * | | GGGGG | A, B | |
2032
- * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
2033
- * | | yo | 44th, 1st, 0th, 17th | 5,7 |
2034
- * | | yy | 44, 01, 00, 17 | 5 |
2035
- * | | yyy | 044, 001, 1900, 2017 | 5 |
2036
- * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
2037
- * | | yyyyy | ... | 3,5 |
2038
- * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
2039
- * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
2040
- * | | YY | 44, 01, 00, 17 | 5,8 |
2041
- * | | YYY | 044, 001, 1900, 2017 | 5 |
2042
- * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
2043
- * | | YYYYY | ... | 3,5 |
2044
- * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
2045
- * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
2046
- * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
2047
- * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
2048
- * | | RRRRR | ... | 3,5,7 |
2049
- * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
2050
- * | | uu | -43, 01, 1900, 2017 | 5 |
2051
- * | | uuu | -043, 001, 1900, 2017 | 5 |
2052
- * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
2053
- * | | uuuuu | ... | 3,5 |
2054
- * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
2055
- * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
2056
- * | | QQ | 01, 02, 03, 04 | |
2057
- * | | QQQ | Q1, Q2, Q3, Q4 | |
2058
- * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
2059
- * | | QQQQQ | 1, 2, 3, 4 | 4 |
2060
- * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
2061
- * | | qo | 1st, 2nd, 3rd, 4th | 7 |
2062
- * | | qq | 01, 02, 03, 04 | |
2063
- * | | qqq | Q1, Q2, Q3, Q4 | |
2064
- * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
2065
- * | | qqqqq | 1, 2, 3, 4 | 4 |
2066
- * | Month (formatting) | M | 1, 2, ..., 12 | |
2067
- * | | Mo | 1st, 2nd, ..., 12th | 7 |
2068
- * | | MM | 01, 02, ..., 12 | |
2069
- * | | MMM | Jan, Feb, ..., Dec | |
2070
- * | | MMMM | January, February, ..., December | 2 |
2071
- * | | MMMMM | J, F, ..., D | |
2072
- * | Month (stand-alone) | L | 1, 2, ..., 12 | |
2073
- * | | Lo | 1st, 2nd, ..., 12th | 7 |
2074
- * | | LL | 01, 02, ..., 12 | |
2075
- * | | LLL | Jan, Feb, ..., Dec | |
2076
- * | | LLLL | January, February, ..., December | 2 |
2077
- * | | LLLLL | J, F, ..., D | |
2078
- * | Local week of year | w | 1, 2, ..., 53 | |
2079
- * | | wo | 1st, 2nd, ..., 53th | 7 |
2080
- * | | ww | 01, 02, ..., 53 | |
2081
- * | ISO week of year | I | 1, 2, ..., 53 | 7 |
2082
- * | | Io | 1st, 2nd, ..., 53th | 7 |
2083
- * | | II | 01, 02, ..., 53 | 7 |
2084
- * | Day of month | d | 1, 2, ..., 31 | |
2085
- * | | do | 1st, 2nd, ..., 31st | 7 |
2086
- * | | dd | 01, 02, ..., 31 | |
2087
- * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
2088
- * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
2089
- * | | DD | 01, 02, ..., 365, 366 | 9 |
2090
- * | | DDD | 001, 002, ..., 365, 366 | |
2091
- * | | DDDD | ... | 3 |
2092
- * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
2093
- * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
2094
- * | | EEEEE | M, T, W, T, F, S, S | |
2095
- * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
2096
- * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
2097
- * | | io | 1st, 2nd, ..., 7th | 7 |
2098
- * | | ii | 01, 02, ..., 07 | 7 |
2099
- * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
2100
- * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
2101
- * | | iiiii | M, T, W, T, F, S, S | 7 |
2102
- * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
2103
- * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
2104
- * | | eo | 2nd, 3rd, ..., 1st | 7 |
2105
- * | | ee | 02, 03, ..., 01 | |
2106
- * | | eee | Mon, Tue, Wed, ..., Sun | |
2107
- * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
2108
- * | | eeeee | M, T, W, T, F, S, S | |
2109
- * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
2110
- * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
2111
- * | | co | 2nd, 3rd, ..., 1st | 7 |
2112
- * | | cc | 02, 03, ..., 01 | |
2113
- * | | ccc | Mon, Tue, Wed, ..., Sun | |
2114
- * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
2115
- * | | ccccc | M, T, W, T, F, S, S | |
2116
- * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
2117
- * | AM, PM | a..aa | AM, PM | |
2118
- * | | aaa | am, pm | |
2119
- * | | aaaa | a.m., p.m. | 2 |
2120
- * | | aaaaa | a, p | |
2121
- * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
2122
- * | | bbb | am, pm, noon, midnight | |
2123
- * | | bbbb | a.m., p.m., noon, midnight | 2 |
2124
- * | | bbbbb | a, p, n, mi | |
2125
- * | Flexible day period | B..BBB | at night, in the morning, ... | |
2126
- * | | BBBB | at night, in the morning, ... | 2 |
2127
- * | | BBBBB | at night, in the morning, ... | |
2128
- * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
2129
- * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
2130
- * | | hh | 01, 02, ..., 11, 12 | |
2131
- * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
2132
- * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
2133
- * | | HH | 00, 01, 02, ..., 23 | |
2134
- * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
2135
- * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
2136
- * | | KK | 01, 02, ..., 11, 00 | |
2137
- * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
2138
- * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
2139
- * | | kk | 24, 01, 02, ..., 23 | |
2140
- * | Minute | m | 0, 1, ..., 59 | |
2141
- * | | mo | 0th, 1st, ..., 59th | 7 |
2142
- * | | mm | 00, 01, ..., 59 | |
2143
- * | Second | s | 0, 1, ..., 59 | |
2144
- * | | so | 0th, 1st, ..., 59th | 7 |
2145
- * | | ss | 00, 01, ..., 59 | |
2146
- * | Fraction of second | S | 0, 1, ..., 9 | |
2147
- * | | SS | 00, 01, ..., 99 | |
2148
- * | | SSS | 000, 001, ..., 999 | |
2149
- * | | SSSS | ... | 3 |
2150
- * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
2151
- * | | XX | -0800, +0530, Z | |
2152
- * | | XXX | -08:00, +05:30, Z | |
2153
- * | | XXXX | -0800, +0530, Z, +123456 | 2 |
2154
- * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
2155
- * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
2156
- * | | xx | -0800, +0530, +0000 | |
2157
- * | | xxx | -08:00, +05:30, +00:00 | 2 |
2158
- * | | xxxx | -0800, +0530, +0000, +123456 | |
2159
- * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
2160
- * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
2161
- * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
2162
- * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
2163
- * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
2164
- * | Seconds timestamp | t | 512969520 | 7 |
2165
- * | | tt | ... | 3,7 |
2166
- * | Milliseconds timestamp | T | 512969520900 | 7 |
2167
- * | | TT | ... | 3,7 |
2168
- * | Long localized date | P | 04/29/1453 | 7 |
2169
- * | | PP | Apr 29, 1453 | 7 |
2170
- * | | PPP | April 29th, 1453 | 7 |
2171
- * | | PPPP | Friday, April 29th, 1453 | 2,7 |
2172
- * | Long localized time | p | 12:00 AM | 7 |
2173
- * | | pp | 12:00:00 AM | 7 |
2174
- * | | ppp | 12:00:00 AM GMT+2 | 7 |
2175
- * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
2176
- * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
2177
- * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
2178
- * | | PPPppp | April 29th, 1453 at ... | 7 |
2179
- * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
2180
- * Notes:
2181
- * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
2182
- * are the same as "stand-alone" units, but are different in some languages.
2183
- * "Formatting" units are declined according to the rules of the language
2184
- * in the context of a date. "Stand-alone" units are always nominative singular:
2185
- *
2186
- * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
2187
- *
2188
- * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
2189
- *
2190
- * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
2191
- * the single quote characters (see below).
2192
- * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
2193
- * the output will be the same as default pattern for this unit, usually
2194
- * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
2195
- * are marked with "2" in the last column of the table.
2196
- *
2197
- * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
2198
- *
2199
- * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
2200
- *
2201
- * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
2202
- *
2203
- * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
2204
- *
2205
- * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
2206
- *
2207
- * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
2208
- * The output will be padded with zeros to match the length of the pattern.
2209
- *
2210
- * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
2211
- *
2212
- * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
2213
- * These tokens represent the shortest form of the quarter.
2214
- *
2215
- * 5. The main difference between `y` and `u` patterns are B.C. years:
2216
- *
2217
- * | Year | `y` | `u` |
2218
- * |------|-----|-----|
2219
- * | AC 1 | 1 | 1 |
2220
- * | BC 1 | 1 | 0 |
2221
- * | BC 2 | 2 | -1 |
2222
- *
2223
- * Also `yy` always returns the last two digits of a year,
2224
- * while `uu` pads single digit years to 2 characters and returns other years unchanged:
2225
- *
2226
- * | Year | `yy` | `uu` |
2227
- * |------|------|------|
2228
- * | 1 | 01 | 01 |
2229
- * | 14 | 14 | 14 |
2230
- * | 376 | 76 | 376 |
2231
- * | 1453 | 53 | 1453 |
2232
- *
2233
- * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
2234
- * except local week-numbering years are dependent on `options.weekStartsOn`
2235
- * and `options.firstWeekContainsDate` (compare [getISOWeekYear]{@link https://date-fns.org/docs/getISOWeekYear}
2236
- * and [getWeekYear]{@link https://date-fns.org/docs/getWeekYear}).
2237
- *
2238
- * 6. Specific non-location timezones are currently unavailable in `date-fns`,
2239
- * so right now these tokens fall back to GMT timezones.
2240
- *
2241
- * 7. These patterns are not in the Unicode Technical Standard #35:
2242
- * - `i`: ISO day of week
2243
- * - `I`: ISO week of year
2244
- * - `R`: ISO week-numbering year
2245
- * - `t`: seconds timestamp
2246
- * - `T`: milliseconds timestamp
2247
- * - `o`: ordinal number modifier
2248
- * - `P`: long localized date
2249
- * - `p`: long localized time
2250
- *
2251
- * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
2252
- * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://git.io/fxCyr
2253
- *
2254
- * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
2255
- * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://git.io/fxCyr
2256
- *
2257
- * ### v2.0.0 breaking changes:
2258
- *
2259
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
2260
- *
2261
- * - The second argument is now required for the sake of explicitness.
2262
- *
2263
- * ```javascript
2264
- * // Before v2.0.0
2265
- * format(new Date(2016, 0, 1))
2266
- *
2267
- * // v2.0.0 onward
2268
- * format(new Date(2016, 0, 1), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")
2269
- * ```
2270
- *
2271
- * - New format string API for `format` function
2272
- * which is based on [Unicode Technical Standard #35](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table).
2273
- * See [this post](https://blog.date-fns.org/post/unicode-tokens-in-date-fns-v2-sreatyki91jg) for more details.
2274
- *
2275
- * - Characters are now escaped using single quote symbols (`'`) instead of square brackets.
2276
- *
2277
- * @param {Date|Number} date - the original date
2278
- * @param {String} format - the string of tokens
2279
- * @param {Object} [options] - an object with options.
2280
- * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
2281
- * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
2282
- * @param {Number} [options.firstWeekContainsDate=1] - the day of January, which is
2283
- * @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`;
2284
- * see: https://git.io/fxCyr
2285
- * @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`;
2286
- * see: https://git.io/fxCyr
2287
- * @returns {String} the formatted date string
2288
- * @throws {TypeError} 2 arguments required
2289
- * @throws {RangeError} `date` must not be Invalid Date
2290
- * @throws {RangeError} `options.locale` must contain `localize` property
2291
- * @throws {RangeError} `options.locale` must contain `formatLong` property
2292
- * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
2293
- * @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7
2294
- * @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://git.io/fxCyr
2295
- * @throws {RangeError} use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://git.io/fxCyr
2296
- * @throws {RangeError} use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://git.io/fxCyr
2297
- * @throws {RangeError} use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://git.io/fxCyr
2298
- * @throws {RangeError} format string contains an unescaped latin alphabet character
2299
- *
2300
- * @example
2301
- * // Represent 11 February 2014 in middle-endian format:
2302
- * var result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
2303
- * //=> '02/11/2014'
2304
- *
2305
- * @example
2306
- * // Represent 2 July 2014 in Esperanto:
2307
- * import { eoLocale } from 'date-fns/locale/eo'
2308
- * var result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
2309
- * locale: eoLocale
2310
- * })
2311
- * //=> '2-a de julio 2014'
2312
- *
2313
- * @example
2314
- * // Escape string by single quote characters:
2315
- * var result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
2316
- * //=> "3 o'clock"
2317
- */
2318
-
2319
- function format(dirtyDate, dirtyFormatStr, dirtyOptions) {
2320
- requiredArgs(2, arguments);
2321
- var formatStr = String(dirtyFormatStr);
2322
- var options = dirtyOptions || {};
2323
- var locale$1 = options.locale || locale;
2324
- var localeFirstWeekContainsDate = locale$1.options && locale$1.options.firstWeekContainsDate;
2325
- var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate);
2326
- var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
2327
-
2328
- if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
2329
- throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
2330
- }
2331
-
2332
- var localeWeekStartsOn = locale$1.options && locale$1.options.weekStartsOn;
2333
- var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn);
2334
- var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
2335
-
2336
- if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
2337
- throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
2338
- }
2339
-
2340
- if (!locale$1.localize) {
2341
- throw new RangeError('locale must contain localize property');
2342
- }
2343
-
2344
- if (!locale$1.formatLong) {
2345
- throw new RangeError('locale must contain formatLong property');
2346
- }
2347
-
2348
- var originalDate = toDate(dirtyDate);
2349
-
2350
- if (!isValid(originalDate)) {
2351
- throw new RangeError('Invalid time value');
2352
- } // Convert the date in system timezone to the same date in UTC+00:00 timezone.
2353
- // This ensures that when UTC functions will be implemented, locales will be compatible with them.
2354
- // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376
2355
-
2356
-
2357
- var timezoneOffset = getTimezoneOffsetInMilliseconds(originalDate);
2358
- var utcDate = subMilliseconds(originalDate, timezoneOffset);
2359
- var formatterOptions = {
2360
- firstWeekContainsDate: firstWeekContainsDate,
2361
- weekStartsOn: weekStartsOn,
2362
- locale: locale$1,
2363
- _originalDate: originalDate
2364
- };
2365
- var result = formatStr.match(longFormattingTokensRegExp).map(function (substring) {
2366
- var firstCharacter = substring[0];
2367
-
2368
- if (firstCharacter === 'p' || firstCharacter === 'P') {
2369
- var longFormatter = longFormatters[firstCharacter];
2370
- return longFormatter(substring, locale$1.formatLong, formatterOptions);
2371
- }
2372
-
2373
- return substring;
2374
- }).join('').match(formattingTokensRegExp).map(function (substring) {
2375
- // Replace two single quote characters with one single quote character
2376
- if (substring === "''") {
2377
- return "'";
2378
- }
2379
-
2380
- var firstCharacter = substring[0];
2381
-
2382
- if (firstCharacter === "'") {
2383
- return cleanEscapedString(substring);
2384
- }
2385
-
2386
- var formatter = formatters[firstCharacter];
2387
-
2388
- if (formatter) {
2389
- if (!options.useAdditionalWeekYearTokens && isProtectedWeekYearToken(substring)) {
2390
- throwProtectedError(substring, dirtyFormatStr, dirtyDate);
2391
- }
2392
-
2393
- if (!options.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(substring)) {
2394
- throwProtectedError(substring, dirtyFormatStr, dirtyDate);
2395
- }
2396
-
2397
- return formatter(utcDate, substring, locale$1.localize, formatterOptions);
2398
- }
2399
-
2400
- if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
2401
- throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`');
2402
- }
2403
-
2404
- return substring;
2405
- }).join('');
2406
- return result;
2407
- }
2408
-
2409
- function cleanEscapedString(input) {
2410
- return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
2411
- }
2412
-
2413
- const sample = (array) => array[Math.floor(Math.random() * array.length)];
2414
- function GetGoalAppData(title, description, category, percentage, goalText) {
2415
- return {
2416
- Name: title,
2417
- Description: description,
2418
- Category: category,
2419
- Percentage: percentage,
2420
- GoalText: goalText,
2421
- };
2422
- }
2423
- function MyMoodTemplate(feeling, intensity, location) {
2424
- return `Mood : ${feeling} and Level: ${intensity} <img src="${location}" />`;
2425
- }
2426
- function MyMoodTemplateJSON(feeling, intensity, location) {
2427
- return JSON.stringify({ Mood: feeling, Level: intensity, MoodImage: location });
2428
- }
2429
- function MyHealthTemplate(heartRate) {
2430
- return `Heart rate ${heartRate} bpm`;
2431
- }
2432
- function MyHealthTemplateJSON(heartRate) {
2433
- return JSON.stringify({ HearthRate: heartRate });
2434
- }
2435
- function MyGoalTemplate(goalName, text, progress) {
2436
- return `Goal update: ${goalName} ${text} Progress: ${progress}`;
2437
- }
2438
- function MyGoalTemplateJSON(goalName, goalUpdateText, progress) {
2439
- return JSON.stringify({ GoalTitle: goalName, GoalText: goalUpdateText, GoalProgress: progress });
2440
- }
2441
- class SparkleGlobal {
2442
- }
2443
- SparkleGlobal.MY_GOALS_APP_ID = 1;
2444
- SparkleGlobal.MY_HEALTH_APP_ID = 2;
2445
- SparkleGlobal.MY_MOOD_APP_ID = 3;
2446
- SparkleGlobal.LOCALSTORAGE_CLASSROOM_MODE = 'SPARKLE_CLASSROOM_MODE';
2447
- function date(date) {
2448
- return format(new Date(date), 'DD MMM YYYY');
2449
- }
2450
-
2451
- export { GetGoalAppData as G, MyHealthTemplate as M, SparkleGlobal as S, MyHealthTemplateJSON as a, MyMoodTemplate as b, MyMoodTemplateJSON as c, date as d, MyGoalTemplate as e, MyGoalTemplateJSON as f, sample as s };