@sparkle-learning/core 0.0.62 → 0.0.64

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