vendor: 220,817 bytes, lines 1-6322
1(function (global, factory) { 2typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('chart.js')) : 3typeof define === 'function' && define.amd ? define(['chart.js'], factory) : 4(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Chart)); 5})(this, (function (chart_js) { 'use strict'; 6 7function toInteger(dirtyNumber) { 8 if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { 9 return NaN; 10 } 11 12 var number = Number(dirtyNumber); 13 14 if (isNaN(number)) { 15 return number; 16 } 17 18 return number < 0 ? Math.ceil(number) : Math.floor(number); 19} 20 21function requiredArgs(required, args) { 22 if (args.length < required) { 23 throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present'); 24 } 25} 26 27/** 28 * @name toDate 29 * @category Common Helpers 30 * @summary Convert the given argument to an instance of Date. 31 * 32 * @description 33 * Convert the given argument to an instance of Date. 34 * 35 * If the argument is an instance of Date, the function returns its clone. 36 * 37 * If the argument is a number, it is treated as a timestamp. 38 * 39 * If the argument is none of the above, the function returns Invalid Date. 40 * 41 * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`. 42 * 43 * @param {Date|Number} argument - the value to convert 44 * @returns {Date} the parsed date in the local time zone 45 * @throws {TypeError} 1 argument required 46 * 47 * @example 48 * // Clone the date: 49 * const result = toDate(new Date(2014, 1, 11, 11, 30, 30)) 50 * //=> Tue Feb 11 2014 11:30:30 51 * 52 * @example 53 * // Convert the timestamp to date: 54 * const result = toDate(1392098430000) 55 * //=> Tue Feb 11 2014 11:30:30 56 */ 57 58function toDate(argument) { 59 requiredArgs(1, arguments); 60 var argStr = Object.prototype.toString.call(argument); // Clone the date 61 62 if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') { 63 // Prevent the date to lose the milliseconds when passed to new Date() in IE10 64 return new Date(argument.getTime()); 65 } else if (typeof argument === 'number' || argStr === '[object Number]') { 66 return new Date(argument); 67 } else { 68 if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') { 69 // eslint-disable-next-line no-console 70 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 71 72 console.warn(new Error().stack); 73 } 74 75 return new Date(NaN); 76 } 77} 78 79/** 80 * @name addDays 81 * @category Day Helpers 82 * @summary Add the specified number of days to the given date. 83 * 84 * @description 85 * Add the specified number of days to the given date. 86 * 87 * ### v2.0.0 breaking changes: 88 * 89 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 90 * 91 * @param {Date|Number} date - the date to be changed 92 * @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. 93 * @returns {Date} the new date with the days added 94 * @throws {TypeError} 2 arguments required 95 * 96 * @example 97 * // Add 10 days to 1 September 2014: 98 * const result = addDays(new Date(2014, 8, 1), 10) 99 * //=> Thu Sep 11 2014 00:00:00 100 */ 101 102function addDays(dirtyDate, dirtyAmount) { 103 requiredArgs(2, arguments); 104 var date = toDate(dirtyDate); 105 var amount = toInteger(dirtyAmount); 106 107 if (isNaN(amount)) { 108 return new Date(NaN); 109 } 110 111 if (!amount) { 112 // If 0 days, no-op to avoid changing times in the hour before end of DST 113 return date; 114 } 115 116 date.setDate(date.getDate() + amount); 117 return date; 118} 119 120/** 121 * @name addMonths 122 * @category Month Helpers 123 * @summary Add the specified number of months to the given date. 124 * 125 * @description 126 * Add the specified number of months to the given date. 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 {Date|Number} date - the date to be changed 133 * @param {Number} amount - the amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. 134 * @returns {Date} the new date with the months added 135 * @throws {TypeError} 2 arguments required 136 * 137 * @example 138 * // Add 5 months to 1 September 2014: 139 * const result = addMonths(new Date(2014, 8, 1), 5) 140 * //=> Sun Feb 01 2015 00:00:00 141 */ 142 143function addMonths(dirtyDate, dirtyAmount) { 144 requiredArgs(2, arguments); 145 var date = toDate(dirtyDate); 146 var amount = toInteger(dirtyAmount); 147 148 if (isNaN(amount)) { 149 return new Date(NaN); 150 } 151 152 if (!amount) { 153 // If 0 months, no-op to avoid changing times in the hour before end of DST 154 return date; 155 } 156 157 var dayOfMonth = date.getDate(); // The JS Date object supports date math by accepting out-of-bounds values for 158 // month, day, etc. For example, new Date(2020, 1, 0) returns 31 Dec 2019 and 159 // new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we 160 // want except that dates will wrap around the end of a month, meaning that 161 // new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So 162 // we'll default to the end of the desired month by adding 1 to the desired 163 // month and using a date of 0 to back up one day to the end of the desired 164 // month. 165 166 var endOfDesiredMonth = new Date(date.getTime()); 167 endOfDesiredMonth.setMonth(date.getMonth() + amount + 1, 0); 168 var daysInMonth = endOfDesiredMonth.getDate(); 169 170 if (dayOfMonth >= daysInMonth) { 171 // If we're already at the end of the month, then this is the correct date 172 // and we're done. 173 return endOfDesiredMonth; 174 } else { 175 // Otherwise, we now know that setting the original day-of-month value won't 176 // cause an overflow, so set the desired day-of-month. Note that we can't 177 // just set the date of `endOfDesiredMonth` because that object may have had 178 // its time changed in the unusual case where where a DST transition was on 179 // the last day of the month and its local time was in the hour skipped or 180 // repeated next to a DST transition. So we use `date` instead which is 181 // guaranteed to still have the original time. 182 date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth); 183 return date; 184 } 185} 186 187/** 188 * @name addMilliseconds 189 * @category Millisecond Helpers 190 * @summary Add the specified number of milliseconds to the given date. 191 * 192 * @description 193 * Add the specified number of milliseconds to the given date. 194 * 195 * ### v2.0.0 breaking changes: 196 * 197 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 198 * 199 * @param {Date|Number} date - the date to be changed 200 * @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`. 201 * @returns {Date} the new date with the milliseconds added 202 * @throws {TypeError} 2 arguments required 203 * 204 * @example 205 * // Add 750 milliseconds to 10 July 2014 12:45:30.000: 206 * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750) 207 * //=> Thu Jul 10 2014 12:45:30.750 208 */ 209 210function addMilliseconds(dirtyDate, dirtyAmount) { 211 requiredArgs(2, arguments); 212 var timestamp = toDate(dirtyDate).getTime(); 213 var amount = toInteger(dirtyAmount); 214 return new Date(timestamp + amount); 215} 216 217var MILLISECONDS_IN_HOUR$3 = 3600000; 218/** 219 * @name addHours 220 * @category Hour Helpers 221 * @summary Add the specified number of hours to the given date. 222 * 223 * @description 224 * Add the specified number of hours to the given date. 225 * 226 * ### v2.0.0 breaking changes: 227 * 228 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 229 * 230 * @param {Date|Number} date - the date to be changed 231 * @param {Number} amount - the amount of hours to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. 232 * @returns {Date} the new date with the hours added 233 * @throws {TypeError} 2 arguments required 234 * 235 * @example 236 * // Add 2 hours to 10 July 2014 23:00:00: 237 * const result = addHours(new Date(2014, 6, 10, 23, 0), 2) 238 * //=> Fri Jul 11 2014 01:00:00 239 */ 240 241function addHours(dirtyDate, dirtyAmount) { 242 requiredArgs(2, arguments); 243 var amount = toInteger(dirtyAmount); 244 return addMilliseconds(dirtyDate, amount * MILLISECONDS_IN_HOUR$3); 245} 246 247/** 248 * @name startOfWeek 249 * @category Week Helpers 250 * @summary Return the start of a week for the given date. 251 * 252 * @description 253 * Return the start of a week for the given date. 254 * The result will be in the local timezone. 255 * 256 * ### v2.0.0 breaking changes: 257 * 258 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 259 * 260 * @param {Date|Number} date - the original date 261 * @param {Object} [options] - an object with options. 262 * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} 263 * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday) 264 * @returns {Date} the start of a week 265 * @throws {TypeError} 1 argument required 266 * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6 267 * 268 * @example 269 * // The start of a week for 2 September 2014 11:55:00: 270 * var result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0)) 271 * //=> Sun Aug 31 2014 00:00:00 272 * 273 * @example 274 * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00: 275 * var result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 }) 276 * //=> Mon Sep 01 2014 00:00:00 277 */ 278 279function startOfWeek(dirtyDate, dirtyOptions) { 280 requiredArgs(1, arguments); 281 var options = dirtyOptions || {}; 282 var locale = options.locale; 283 var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; 284 var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); 285 var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN 286 287 if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { 288 throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); 289 } 290 291 var date = toDate(dirtyDate); 292 var day = date.getDay(); 293 var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; 294 date.setDate(date.getDate() - diff); 295 date.setHours(0, 0, 0, 0); 296 return date; 297} 298 299/** 300 * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. 301 * They usually appear for dates that denote time before the timezones were introduced 302 * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891 303 * and GMT+01:00:00 after that date) 304 * 305 * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above, 306 * which would lead to incorrect calculations. 307 * 308 * This function returns the timezone offset in milliseconds that takes seconds in account. 309 */ 310function getTimezoneOffsetInMilliseconds(date) { 311 var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())); 312 utcDate.setUTCFullYear(date.getFullYear()); 313 return date.getTime() - utcDate.getTime(); 314} 315 316/** 317 * @name startOfDay 318 * @category Day Helpers 319 * @summary Return the start of a day for the given date. 320 * 321 * @description 322 * Return the start of a day for the given date. 323 * The result will be in the local timezone. 324 * 325 * ### v2.0.0 breaking changes: 326 * 327 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 328 * 329 * @param {Date|Number} date - the original date 330 * @returns {Date} the start of a day 331 * @throws {TypeError} 1 argument required 332 * 333 * @example 334 * // The start of a day for 2 September 2014 11:55:00: 335 * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0)) 336 * //=> Tue Sep 02 2014 00:00:00 337 */ 338 339function startOfDay(dirtyDate) { 340 requiredArgs(1, arguments); 341 var date = toDate(dirtyDate); 342 date.setHours(0, 0, 0, 0); 343 return date; 344} 345 346var MILLISECONDS_IN_DAY$1 = 86400000; 347/** 348 * @name differenceInCalendarDays 349 * @category Day Helpers 350 * @summary Get the number of calendar days between the given dates. 351 * 352 * @description 353 * Get the number of calendar days between the given dates. This means that the times are removed 354 * from the dates and then the difference in days is calculated. 355 * 356 * ### v2.0.0 breaking changes: 357 * 358 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 359 * 360 * @param {Date|Number} dateLeft - the later date 361 * @param {Date|Number} dateRight - the earlier date 362 * @returns {Number} the number of calendar days 363 * @throws {TypeError} 2 arguments required 364 * 365 * @example 366 * // How many calendar days are between 367 * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00? 368 * var result = differenceInCalendarDays( 369 * new Date(2012, 6, 2, 0, 0), 370 * new Date(2011, 6, 2, 23, 0) 371 * ) 372 * //=> 366 373 * // How many calendar days are between 374 * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00? 375 * var result = differenceInCalendarDays( 376 * new Date(2011, 6, 3, 0, 1), 377 * new Date(2011, 6, 2, 23, 59) 378 * ) 379 * //=> 1 380 */ 381 382function differenceInCalendarDays(dirtyDateLeft, dirtyDateRight) { 383 requiredArgs(2, arguments); 384 var startOfDayLeft = startOfDay(dirtyDateLeft); 385 var startOfDayRight = startOfDay(dirtyDateRight); 386 var timestampLeft = startOfDayLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfDayLeft); 387 var timestampRight = startOfDayRight.getTime() - getTimezoneOffsetInMilliseconds(startOfDayRight); // Round the number of days to the nearest integer 388 // because the number of milliseconds in a day is not constant 389 // (e.g. it's different in the day of the daylight saving time clock shift) 390 391 return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_DAY$1); 392} 393 394var MILLISECONDS_IN_MINUTE$3 = 60000; 395/** 396 * @name addMinutes 397 * @category Minute Helpers 398 * @summary Add the specified number of minutes to the given date. 399 * 400 * @description 401 * Add the specified number of minutes to the given date. 402 * 403 * ### v2.0.0 breaking changes: 404 * 405 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 406 * 407 * @param {Date|Number} date - the date to be changed 408 * @param {Number} amount - the amount of minutes to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. 409 * @returns {Date} the new date with the minutes added 410 * @throws {TypeError} 2 arguments required 411 * 412 * @example 413 * // Add 30 minutes to 10 July 2014 12:00:00: 414 * const result = addMinutes(new Date(2014, 6, 10, 12, 0), 30) 415 * //=> Thu Jul 10 2014 12:30:00 416 */ 417 418function addMinutes(dirtyDate, dirtyAmount) { 419 requiredArgs(2, arguments); 420 var amount = toInteger(dirtyAmount); 421 return addMilliseconds(dirtyDate, amount * MILLISECONDS_IN_MINUTE$3); 422} 423 424/** 425 * @name addQuarters 426 * @category Quarter Helpers 427 * @summary Add the specified number of year quarters to the given date. 428 * 429 * @description 430 * Add the specified number of year quarters to the given date. 431 * 432 * ### v2.0.0 breaking changes: 433 * 434 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 435 * 436 * @param {Date|Number} date - the date to be changed 437 * @param {Number} amount - the amount of quarters to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. 438 * @returns {Date} the new date with the quarters added 439 * @throws {TypeError} 2 arguments required 440 * 441 * @example 442 * // Add 1 quarter to 1 September 2014: 443 * const result = addQuarters(new Date(2014, 8, 1), 1) 444 * //=> Mon Dec 01 2014 00:00:00 445 */ 446 447function addQuarters(dirtyDate, dirtyAmount) { 448 requiredArgs(2, arguments); 449 var amount = toInteger(dirtyAmount); 450 var months = amount * 3; 451 return addMonths(dirtyDate, months); 452} 453 454/** 455 * @name addSeconds 456 * @category Second Helpers 457 * @summary Add the specified number of seconds to the given date. 458 * 459 * @description 460 * Add the specified number of seconds to the given date. 461 * 462 * ### v2.0.0 breaking changes: 463 * 464 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 465 * 466 * @param {Date|Number} date - the date to be changed 467 * @param {Number} amount - the amount of seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. 468 * @returns {Date} the new date with the seconds added 469 * @throws {TypeError} 2 arguments required 470 * 471 * @example 472 * // Add 30 seconds to 10 July 2014 12:45:00: 473 * const result = addSeconds(new Date(2014, 6, 10, 12, 45, 0), 30) 474 * //=> Thu Jul 10 2014 12:45:30 475 */ 476 477function addSeconds(dirtyDate, dirtyAmount) { 478 requiredArgs(2, arguments); 479 var amount = toInteger(dirtyAmount); 480 return addMilliseconds(dirtyDate, amount * 1000); 481} 482 483/** 484 * @name addWeeks 485 * @category Week Helpers 486 * @summary Add the specified number of weeks to the given date. 487 * 488 * @description 489 * Add the specified number of week to the given date. 490 * 491 * ### v2.0.0 breaking changes: 492 * 493 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 494 * 495 * @param {Date|Number} date - the date to be changed 496 * @param {Number} amount - the amount of weeks to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. 497 * @returns {Date} the new date with the weeks added 498 * @throws {TypeError} 2 arguments required 499 * 500 * @example 501 * // Add 4 weeks to 1 September 2014: 502 * const result = addWeeks(new Date(2014, 8, 1), 4) 503 * //=> Mon Sep 29 2014 00:00:00 504 */ 505 506function addWeeks(dirtyDate, dirtyAmount) { 507 requiredArgs(2, arguments); 508 var amount = toInteger(dirtyAmount); 509 var days = amount * 7; 510 return addDays(dirtyDate, days); 511} 512 513/** 514 * @name addYears 515 * @category Year Helpers 516 * @summary Add the specified number of years to the given date. 517 * 518 * @description 519 * Add the specified number of years to the given date. 520 * 521 * ### v2.0.0 breaking changes: 522 * 523 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 524 * 525 * @param {Date|Number} date - the date to be changed 526 * @param {Number} amount - the amount of years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. 527 * @returns {Date} the new date with the years added 528 * @throws {TypeError} 2 arguments required 529 * 530 * @example 531 * // Add 5 years to 1 September 2014: 532 * const result = addYears(new Date(2014, 8, 1), 5) 533 * //=> Sun Sep 01 2019 00:00:00 534 */ 535 536function addYears(dirtyDate, dirtyAmount) { 537 requiredArgs(2, arguments); 538 var amount = toInteger(dirtyAmount); 539 return addMonths(dirtyDate, amount * 12); 540} 541 542/** 543 * @name compareAsc 544 * @category Common Helpers 545 * @summary Compare the two dates and return -1, 0 or 1. 546 * 547 * @description 548 * Compare the two dates and return 1 if the first date is after the second, 549 * -1 if the first date is before the second or 0 if dates are equal. 550 * 551 * ### v2.0.0 breaking changes: 552 * 553 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 554 * 555 * @param {Date|Number} dateLeft - the first date to compare 556 * @param {Date|Number} dateRight - the second date to compare 557 * @returns {Number} the result of the comparison 558 * @throws {TypeError} 2 arguments required 559 * 560 * @example 561 * // Compare 11 February 1987 and 10 July 1989: 562 * const result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) 563 * //=> -1 564 * 565 * @example 566 * // Sort the array of dates: 567 * const result = [ 568 * new Date(1995, 6, 2), 569 * new Date(1987, 1, 11), 570 * new Date(1989, 6, 10) 571 * ].sort(compareAsc) 572 * //=> [ 573 * // Wed Feb 11 1987 00:00:00, 574 * // Mon Jul 10 1989 00:00:00, 575 * // Sun Jul 02 1995 00:00:00 576 * // ] 577 */ 578 579function compareAsc(dirtyDateLeft, dirtyDateRight) { 580 requiredArgs(2, arguments); 581 var dateLeft = toDate(dirtyDateLeft); 582 var dateRight = toDate(dirtyDateRight); 583 var diff = dateLeft.getTime() - dateRight.getTime(); 584 585 if (diff < 0) { 586 return -1; 587 } else if (diff > 0) { 588 return 1; // Return 0 if diff is 0; return NaN if diff is NaN 589 } else { 590 return diff; 591 } 592} 593 594/** 595 * @name isValid 596 * @category Common Helpers 597 * @summary Is the given date valid? 598 * 599 * @description 600 * Returns false if argument is Invalid Date and true otherwise. 601 * Argument is converted to Date using `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate} 602 * Invalid Date is a Date, whose time value is NaN. 603 * 604 * Time value of Date: http://es5.github.io/#x15.9.1.1 605 * 606 * ### v2.0.0 breaking changes: 607 * 608 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 609 * 610 * - Now `isValid` doesn't throw an exception 611 * if the first argument is not an instance of Date. 612 * Instead, argument is converted beforehand using `toDate`. 613 * 614 * Examples: 615 * 616 * | `isValid` argument | Before v2.0.0 | v2.0.0 onward | 617 * |---------------------------|---------------|---------------| 618 * | `new Date()` | `true` | `true` | 619 * | `new Date('2016-01-01')` | `true` | `true` | 620 * | `new Date('')` | `false` | `false` | 621 * | `new Date(1488370835081)` | `true` | `true` | 622 * | `new Date(NaN)` | `false` | `false` | 623 * | `'2016-01-01'` | `TypeError` | `false` | 624 * | `''` | `TypeError` | `false` | 625 * | `1488370835081` | `TypeError` | `true` | 626 * | `NaN` | `TypeError` | `false` | 627 * 628 * We introduce this change to make *date-fns* consistent with ECMAScript behavior 629 * that try to coerce arguments to the expected type 630 * (which is also the case with other *date-fns* functions). 631 * 632 * @param {*} date - the date to check 633 * @returns {Boolean} the date is valid 634 * @throws {TypeError} 1 argument required 635 * 636 * @example 637 * // For the valid date: 638 * var result = isValid(new Date(2014, 1, 31)) 639 * //=> true 640 * 641 * @example 642 * // For the value, convertable into a date: 643 * var result = isValid(1393804800000) 644 * //=> true 645 * 646 * @example 647 * // For the invalid date: 648 * var result = isValid(new Date('')) 649 * //=> false 650 */ 651 652function isValid(dirtyDate) { 653 requiredArgs(1, arguments); 654 var date = toDate(dirtyDate); 655 return !isNaN(date); 656} 657 658/** 659 * @name differenceInCalendarMonths 660 * @category Month Helpers 661 * @summary Get the number of calendar months between the given dates. 662 * 663 * @description 664 * Get the number of calendar months between the given dates. 665 * 666 * ### v2.0.0 breaking changes: 667 * 668 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 669 * 670 * @param {Date|Number} dateLeft - the later date 671 * @param {Date|Number} dateRight - the earlier date 672 * @returns {Number} the number of calendar months 673 * @throws {TypeError} 2 arguments required 674 * 675 * @example 676 * // How many calendar months are between 31 January 2014 and 1 September 2014? 677 * var result = differenceInCalendarMonths( 678 * new Date(2014, 8, 1), 679 * new Date(2014, 0, 31) 680 * ) 681 * //=> 8 682 */ 683 684function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { 685 requiredArgs(2, arguments); 686 var dateLeft = toDate(dirtyDateLeft); 687 var dateRight = toDate(dirtyDateRight); 688 var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); 689 var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); 690 return yearDiff * 12 + monthDiff; 691} 692 693/** 694 * @name differenceInCalendarYears 695 * @category Year Helpers 696 * @summary Get the number of calendar years between the given dates. 697 * 698 * @description 699 * Get the number of calendar years between the given dates. 700 * 701 * ### v2.0.0 breaking changes: 702 * 703 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 704 * 705 * @param {Date|Number} dateLeft - the later date 706 * @param {Date|Number} dateRight - the earlier date 707 * @returns {Number} the number of calendar years 708 * @throws {TypeError} 2 arguments required 709 * 710 * @example 711 * // How many calendar years are between 31 December 2013 and 11 February 2015? 712 * var result = differenceInCalendarYears( 713 * new Date(2015, 1, 11), 714 * new Date(2013, 11, 31) 715 * ) 716 * //=> 2 717 */ 718 719function differenceInCalendarYears(dirtyDateLeft, dirtyDateRight) { 720 requiredArgs(2, arguments); 721 var dateLeft = toDate(dirtyDateLeft); 722 var dateRight = toDate(dirtyDateRight); 723 return dateLeft.getFullYear() - dateRight.getFullYear(); 724} 725 726// for accurate equality comparisons of UTC timestamps that end up 727// having the same representation in local time, e.g. one hour before 728// DST ends vs. the instant that DST ends. 729 730function compareLocalAsc(dateLeft, dateRight) { 731 var diff = dateLeft.getFullYear() - dateRight.getFullYear() || dateLeft.getMonth() - dateRight.getMonth() || dateLeft.getDate() - dateRight.getDate() || dateLeft.getHours() - dateRight.getHours() || dateLeft.getMinutes() - dateRight.getMinutes() || dateLeft.getSeconds() - dateRight.getSeconds() || dateLeft.getMilliseconds() - dateRight.getMilliseconds(); 732 733 if (diff < 0) { 734 return -1; 735 } else if (diff > 0) { 736 return 1; // Return 0 if diff is 0; return NaN if diff is NaN 737 } else { 738 return diff; 739 } 740} 741/** 742 * @name differenceInDays 743 * @category Day Helpers 744 * @summary Get the number of full days between the given dates. 745 * 746 * @description 747 * Get the number of full day periods between two dates. Fractional days are 748 * truncated towards zero. 749 * 750 * One "full day" is the distance between a local time in one day to the same 751 * local time on the next or previous day. A full day can sometimes be less than 752 * or more than 24 hours if a daylight savings change happens between two dates. 753 * 754 * To ignore DST and only measure exact 24-hour periods, use this instead: 755 * `Math.floor(differenceInHours(dateLeft, dateRight)/24)|0`. 756 * 757 * 758 * ### v2.0.0 breaking changes: 759 * 760 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 761 * 762 * @param {Date|Number} dateLeft - the later date 763 * @param {Date|Number} dateRight - the earlier date 764 * @returns {Number} the number of full days according to the local timezone 765 * @throws {TypeError} 2 arguments required 766 * 767 * @example 768 * // How many full days are between 769 * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00? 770 * var result = differenceInDays( 771 * new Date(2012, 6, 2, 0, 0), 772 * new Date(2011, 6, 2, 23, 0) 773 * ) 774 * //=> 365 775 * // How many full days are between 776 * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00? 777 * var result = differenceInDays( 778 * new Date(2011, 6, 3, 0, 1), 779 * new Date(2011, 6, 2, 23, 59) 780 * ) 781 * //=> 0 782 * // How many full days are between 783 * // 1 March 2020 0:00 and 1 June 2020 0:00 ? 784 * // Note: because local time is used, the 785 * // result will always be 92 days, even in 786 * // time zones where DST starts and the 787 * // period has only 92*24-1 hours. 788 * var result = differenceInDays( 789 * new Date(2020, 5, 1), 790 * new Date(2020, 2, 1) 791 * ) 792//=> 92 793 */ 794 795 796function differenceInDays(dirtyDateLeft, dirtyDateRight) { 797 requiredArgs(2, arguments); 798 var dateLeft = toDate(dirtyDateLeft); 799 var dateRight = toDate(dirtyDateRight); 800 var sign = compareLocalAsc(dateLeft, dateRight); 801 var difference = Math.abs(differenceInCalendarDays(dateLeft, dateRight)); 802 dateLeft.setDate(dateLeft.getDate() - sign * difference); // Math.abs(diff in full days - diff in calendar days) === 1 if last calendar day is not full 803 // If so, result must be decreased by 1 in absolute value 804 805 var isLastDayNotFull = compareLocalAsc(dateLeft, dateRight) === -sign; 806 var result = sign * (difference - isLastDayNotFull); // Prevent negative zero 807 808 return result === 0 ? 0 : result; 809} 810 811/** 812 * @name differenceInMilliseconds 813 * @category Millisecond Helpers 814 * @summary Get the number of milliseconds between the given dates. 815 * 816 * @description 817 * Get the number of milliseconds between the given dates. 818 * 819 * ### v2.0.0 breaking changes: 820 * 821 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 822 * 823 * @param {Date|Number} dateLeft - the later date 824 * @param {Date|Number} dateRight - the earlier date 825 * @returns {Number} the number of milliseconds 826 * @throws {TypeError} 2 arguments required 827 * 828 * @example 829 * // How many milliseconds are between 830 * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? 831 * var result = differenceInMilliseconds( 832 * new Date(2014, 6, 2, 12, 30, 21, 700), 833 * new Date(2014, 6, 2, 12, 30, 20, 600) 834 * ) 835 * //=> 1100 836 */ 837 838function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) { 839 requiredArgs(2, arguments); 840 var dateLeft = toDate(dirtyDateLeft); 841 var dateRight = toDate(dirtyDateRight); 842 return dateLeft.getTime() - dateRight.getTime(); 843} 844 845var MILLISECONDS_IN_HOUR$2 = 3600000; 846/** 847 * @name differenceInHours 848 * @category Hour Helpers 849 * @summary Get the number of hours between the given dates. 850 * 851 * @description 852 * Get the number of hours between the given dates. 853 * 854 * ### v2.0.0 breaking changes: 855 * 856 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 857 * 858 * @param {Date|Number} dateLeft - the later date 859 * @param {Date|Number} dateRight - the earlier date 860 * @returns {Number} the number of hours 861 * @throws {TypeError} 2 arguments required 862 * 863 * @example 864 * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00? 865 * var result = differenceInHours( 866 * new Date(2014, 6, 2, 19, 0), 867 * new Date(2014, 6, 2, 6, 50) 868 * ) 869 * //=> 12 870 */ 871 872function differenceInHours(dirtyDateLeft, dirtyDateRight) { 873 requiredArgs(2, arguments); 874 var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR$2; 875 return diff > 0 ? Math.floor(diff) : Math.ceil(diff); 876} 877 878var MILLISECONDS_IN_MINUTE$2 = 60000; 879/** 880 * @name differenceInMinutes 881 * @category Minute Helpers 882 * @summary Get the number of minutes between the given dates. 883 * 884 * @description 885 * Get the signed number of full (rounded towards 0) minutes between the given dates. 886 * 887 * ### v2.0.0 breaking changes: 888 * 889 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 890 * 891 * @param {Date|Number} dateLeft - the later date 892 * @param {Date|Number} dateRight - the earlier date 893 * @returns {Number} the number of minutes 894 * @throws {TypeError} 2 arguments required 895 * 896 * @example 897 * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00? 898 * var result = differenceInMinutes( 899 * new Date(2014, 6, 2, 12, 20, 0), 900 * new Date(2014, 6, 2, 12, 7, 59) 901 * ) 902 * //=> 12 903 * 904 * @example 905 * // How many minutes are from 10:01:59 to 10:00:00 906 * var result = differenceInMinutes( 907 * new Date(2000, 0, 1, 10, 0, 0), 908 * new Date(2000, 0, 1, 10, 1, 59) 909 * ) 910 * //=> -1 911 */ 912 913function differenceInMinutes(dirtyDateLeft, dirtyDateRight) { 914 requiredArgs(2, arguments); 915 var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_MINUTE$2; 916 return diff > 0 ? Math.floor(diff) : Math.ceil(diff); 917} 918 919/** 920 * @name endOfDay 921 * @category Day Helpers 922 * @summary Return the end of a day for the given date. 923 * 924 * @description 925 * Return the end of a day for the given date. 926 * The result will be in the local timezone. 927 * 928 * ### v2.0.0 breaking changes: 929 * 930 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 931 * 932 * @param {Date|Number} date - the original date 933 * @returns {Date} the end of a day 934 * @throws {TypeError} 1 argument required 935 * 936 * @example 937 * // The end of a day for 2 September 2014 11:55:00: 938 * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0)) 939 * //=> Tue Sep 02 2014 23:59:59.999 940 */ 941 942function endOfDay(dirtyDate) { 943 requiredArgs(1, arguments); 944 var date = toDate(dirtyDate); 945 date.setHours(23, 59, 59, 999); 946 return date; 947} 948 949/** 950 * @name endOfMonth 951 * @category Month Helpers 952 * @summary Return the end of a month for the given date. 953 * 954 * @description 955 * Return the end of a month for the given date. 956 * The result will be in the local timezone. 957 * 958 * ### v2.0.0 breaking changes: 959 * 960 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 961 * 962 * @param {Date|Number} date - the original date 963 * @returns {Date} the end of a month 964 * @throws {TypeError} 1 argument required 965 * 966 * @example 967 * // The end of a month for 2 September 2014 11:55:00: 968 * const result = endOfMonth(new Date(2014, 8, 2, 11, 55, 0)) 969 * //=> Tue Sep 30 2014 23:59:59.999 970 */ 971 972function endOfMonth(dirtyDate) { 973 requiredArgs(1, arguments); 974 var date = toDate(dirtyDate); 975 var month = date.getMonth(); 976 date.setFullYear(date.getFullYear(), month + 1, 0); 977 date.setHours(23, 59, 59, 999); 978 return date; 979} 980 981/** 982 * @name isLastDayOfMonth 983 * @category Month Helpers 984 * @summary Is the given date the last day of a month? 985 * 986 * @description 987 * Is the given date the last day of a month? 988 * 989 * ### v2.0.0 breaking changes: 990 * 991 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 992 * 993 * @param {Date|Number} date - the date to check 994 * @returns {Boolean} the date is the last day of a month 995 * @throws {TypeError} 1 argument required 996 * 997 * @example 998 * // Is 28 February 2014 the last day of a month? 999 * var result = isLastDayOfMonth(new Date(2014, 1, 28)) 1000 * //=> true 1001 */ 1002 1003function isLastDayOfMonth(dirtyDate) { 1004 requiredArgs(1, arguments); 1005 var date = toDate(dirtyDate); 1006 return endOfDay(date).getTime() === endOfMonth(date).getTime(); 1007} 1008 1009/** 1010 * @name differenceInMonths 1011 * @category Month Helpers 1012 * @summary Get the number of full months between the given dates. 1013 * 1014 * @description 1015 * Get the number of full months between the given dates. 1016 * 1017 * ### v2.0.0 breaking changes: 1018 * 1019 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1020 * 1021 * @param {Date|Number} dateLeft - the later date 1022 * @param {Date|Number} dateRight - the earlier date 1023 * @returns {Number} the number of full months 1024 * @throws {TypeError} 2 arguments required 1025 * 1026 * @example 1027 * // How many full months are between 31 January 2014 and 1 September 2014? 1028 * var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) 1029 * //=> 7 1030 */ 1031 1032function differenceInMonths(dirtyDateLeft, dirtyDateRight) { 1033 requiredArgs(2, arguments); 1034 var dateLeft = toDate(dirtyDateLeft); 1035 var dateRight = toDate(dirtyDateRight); 1036 var sign = compareAsc(dateLeft, dateRight); 1037 var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); 1038 var result; // Check for the difference of less than month 1039 1040 if (difference < 1) { 1041 result = 0; 1042 } else { 1043 if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) { 1044 // This will check if the date is end of Feb and assign a higher end of month date 1045 // to compare it with Jan 1046 dateLeft.setDate(30); 1047 } 1048 1049 dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full 1050 // If so, result must be decreased by 1 in absolute value 1051 1052 var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; // Check for cases of one full calendar month 1053 1054 if (isLastDayOfMonth(toDate(dirtyDateLeft)) && difference === 1 && compareAsc(dirtyDateLeft, dateRight) === 1) { 1055 isLastMonthNotFull = false; 1056 } 1057 1058 result = sign * (difference - isLastMonthNotFull); 1059 } // Prevent negative zero 1060 1061 1062 return result === 0 ? 0 : result; 1063} 1064 1065/** 1066 * @name differenceInQuarters 1067 * @category Quarter Helpers 1068 * @summary Get the number of full quarters between the given dates. 1069 * 1070 * @description 1071 * Get the number of full quarters between the given dates. 1072 * 1073 * ### v2.0.0 breaking changes: 1074 * 1075 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1076 * 1077 * @param {Date|Number} dateLeft - the later date 1078 * @param {Date|Number} dateRight - the earlier date 1079 * @returns {Number} the number of full quarters 1080 * @throws {TypeError} 2 arguments required 1081 * 1082 * @example 1083 * // How many full quarters are between 31 December 2013 and 2 July 2014? 1084 * var result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31)) 1085 * //=> 2 1086 */ 1087 1088function differenceInQuarters(dirtyDateLeft, dirtyDateRight) { 1089 requiredArgs(2, arguments); 1090 var diff = differenceInMonths(dirtyDateLeft, dirtyDateRight) / 3; 1091 return diff > 0 ? Math.floor(diff) : Math.ceil(diff); 1092} 1093 1094/** 1095 * @name differenceInSeconds 1096 * @category Second Helpers 1097 * @summary Get the number of seconds between the given dates. 1098 * 1099 * @description 1100 * Get the number of seconds between the given dates. 1101 * 1102 * ### v2.0.0 breaking changes: 1103 * 1104 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1105 * 1106 * @param {Date|Number} dateLeft - the later date 1107 * @param {Date|Number} dateRight - the earlier date 1108 * @returns {Number} the number of seconds 1109 * @throws {TypeError} 2 arguments required 1110 * 1111 * @example 1112 * // How many seconds are between 1113 * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? 1114 * var result = differenceInSeconds( 1115 * new Date(2014, 6, 2, 12, 30, 20, 0), 1116 * new Date(2014, 6, 2, 12, 30, 7, 999) 1117 * ) 1118 * //=> 12 1119 */ 1120 1121function differenceInSeconds(dirtyDateLeft, dirtyDateRight) { 1122 requiredArgs(2, arguments); 1123 var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000; 1124 return diff > 0 ? Math.floor(diff) : Math.ceil(diff); 1125} 1126 1127/** 1128 * @name differenceInWeeks 1129 * @category Week Helpers 1130 * @summary Get the number of full weeks between the given dates. 1131 * 1132 * @description 1133 * Get the number of full weeks between two dates. Fractional weeks are 1134 * truncated towards zero. 1135 * 1136 * One "full week" is the distance between a local time in one day to the same 1137 * local time 7 days earlier or later. A full week can sometimes be less than 1138 * or more than 7*24 hours if a daylight savings change happens between two dates. 1139 * 1140 * To ignore DST and only measure exact 7*24-hour periods, use this instead: 1141 * `Math.floor(differenceInHours(dateLeft, dateRight)/(7*24))|0`. 1142 * 1143 * 1144 * ### v2.0.0 breaking changes: 1145 * 1146 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1147 * 1148 * @param {Date|Number} dateLeft - the later date 1149 * @param {Date|Number} dateRight - the earlier date 1150 * @returns {Number} the number of full weeks 1151 * @throws {TypeError} 2 arguments required 1152 * 1153 * @example 1154 * // How many full weeks are between 5 July 2014 and 20 July 2014? 1155 * var result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5)) 1156 * //=> 2 1157 * 1158 * // How many full weeks are between 1159 * // 1 March 2020 0:00 and 6 June 2020 0:00 ? 1160 * // Note: because local time is used, the 1161 * // result will always be 8 weeks (54 days), 1162 * // even if DST starts and the period has 1163 * // only 54*24-1 hours. 1164 * var result = differenceInWeeks( 1165 * new Date(2020, 5, 1), 1166 * new Date(2020, 2, 6) 1167 * ) 1168 * //=> 8 1169 */ 1170 1171function differenceInWeeks(dirtyDateLeft, dirtyDateRight) { 1172 requiredArgs(2, arguments); 1173 var diff = differenceInDays(dirtyDateLeft, dirtyDateRight) / 7; 1174 return diff > 0 ? Math.floor(diff) : Math.ceil(diff); 1175} 1176 1177/** 1178 * @name differenceInYears 1179 * @category Year Helpers 1180 * @summary Get the number of full years between the given dates. 1181 * 1182 * @description 1183 * Get the number of full years between the given dates. 1184 * 1185 * ### v2.0.0 breaking changes: 1186 * 1187 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1188 * 1189 * @param {Date|Number} dateLeft - the later date 1190 * @param {Date|Number} dateRight - the earlier date 1191 * @returns {Number} the number of full years 1192 * @throws {TypeError} 2 arguments required 1193 * 1194 * @example 1195 * // How many full years are between 31 December 2013 and 11 February 2015? 1196 * var result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31)) 1197 * //=> 1 1198 */ 1199 1200function differenceInYears(dirtyDateLeft, dirtyDateRight) { 1201 requiredArgs(2, arguments); 1202 var dateLeft = toDate(dirtyDateLeft); 1203 var dateRight = toDate(dirtyDateRight); 1204 var sign = compareAsc(dateLeft, dateRight); 1205 var difference = Math.abs(differenceInCalendarYears(dateLeft, dateRight)); // Set both dates to a valid leap year for accurate comparison when dealing 1206 // with leap days 1207 1208 dateLeft.setFullYear('1584'); 1209 dateRight.setFullYear('1584'); // Math.abs(diff in full years - diff in calendar years) === 1 if last calendar year is not full 1210 // If so, result must be decreased by 1 in absolute value 1211 1212 var isLastYearNotFull = compareAsc(dateLeft, dateRight) === -sign; 1213 var result = sign * (difference - isLastYearNotFull); // Prevent negative zero 1214 1215 return result === 0 ? 0 : result; 1216} 1217 1218/** 1219 * @name startOfQuarter 1220 * @category Quarter Helpers 1221 * @summary Return the start of a year quarter for the given date. 1222 * 1223 * @description 1224 * Return the start of a year quarter for the given date. 1225 * The result will be in the local timezone. 1226 * 1227 * ### v2.0.0 breaking changes: 1228 * 1229 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1230 * 1231 * @param {Date|Number} date - the original date 1232 * @returns {Date} the start of a quarter 1233 * @throws {TypeError} 1 argument required 1234 * 1235 * @example 1236 * // The start of a quarter for 2 September 2014 11:55:00: 1237 * const result = startOfQuarter(new Date(2014, 8, 2, 11, 55, 0)) 1238 * //=> Tue Jul 01 2014 00:00:00 1239 */ 1240 1241function startOfQuarter(dirtyDate) { 1242 requiredArgs(1, arguments); 1243 var date = toDate(dirtyDate); 1244 var currentMonth = date.getMonth(); 1245 var month = currentMonth - currentMonth % 3; 1246 date.setMonth(month, 1); 1247 date.setHours(0, 0, 0, 0); 1248 return date; 1249} 1250 1251/** 1252 * @name startOfMonth 1253 * @category Month Helpers 1254 * @summary Return the start of a month for the given date. 1255 * 1256 * @description 1257 * Return the start of a month for the given date. 1258 * The result will be in the local timezone. 1259 * 1260 * ### v2.0.0 breaking changes: 1261 * 1262 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1263 * 1264 * @param {Date|Number} date - the original date 1265 * @returns {Date} the start of a month 1266 * @throws {TypeError} 1 argument required 1267 * 1268 * @example 1269 * // The start of a month for 2 September 2014 11:55:00: 1270 * const result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0)) 1271 * //=> Mon Sep 01 2014 00:00:00 1272 */ 1273 1274function startOfMonth(dirtyDate) { 1275 requiredArgs(1, arguments); 1276 var date = toDate(dirtyDate); 1277 date.setDate(1); 1278 date.setHours(0, 0, 0, 0); 1279 return date; 1280} 1281 1282/** 1283 * @name startOfYear 1284 * @category Year Helpers 1285 * @summary Return the start of a year for the given date. 1286 * 1287 * @description 1288 * Return the start of a year for the given date. 1289 * The result will be in the local timezone. 1290 * 1291 * ### v2.0.0 breaking changes: 1292 * 1293 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1294 * 1295 * @param {Date|Number} date - the original date 1296 * @returns {Date} the start of a year 1297 * @throws {TypeError} 1 argument required 1298 * 1299 * @example 1300 * // The start of a year for 2 September 2014 11:55:00: 1301 * const result = startOfYear(new Date(2014, 8, 2, 11, 55, 00)) 1302 * //=> Wed Jan 01 2014 00:00:00 1303 */ 1304 1305function startOfYear(dirtyDate) { 1306 requiredArgs(1, arguments); 1307 var cleanDate = toDate(dirtyDate); 1308 var date = new Date(0); 1309 date.setFullYear(cleanDate.getFullYear(), 0, 1); 1310 date.setHours(0, 0, 0, 0); 1311 return date; 1312} 1313 1314/** 1315 * @name endOfYear 1316 * @category Year Helpers 1317 * @summary Return the end of a year for the given date. 1318 * 1319 * @description 1320 * Return the end of a year for the given date. 1321 * The result will be in the local timezone. 1322 * 1323 * ### v2.0.0 breaking changes: 1324 * 1325 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1326 * 1327 * @param {Date|Number} date - the original date 1328 * @returns {Date} the end of a year 1329 * @throws {TypeError} 1 argument required 1330 * 1331 * @example 1332 * // The end of a year for 2 September 2014 11:55:00: 1333 * var result = endOfYear(new Date(2014, 8, 2, 11, 55, 00)) 1334 * //=> Wed Dec 31 2014 23:59:59.999 1335 */ 1336 1337function endOfYear(dirtyDate) { 1338 requiredArgs(1, arguments); 1339 var date = toDate(dirtyDate); 1340 var year = date.getFullYear(); 1341 date.setFullYear(year + 1, 0, 0); 1342 date.setHours(23, 59, 59, 999); 1343 return date; 1344} 1345 1346/** 1347 * @name endOfHour 1348 * @category Hour Helpers 1349 * @summary Return the end of an hour for the given date. 1350 * 1351 * @description 1352 * Return the end of an hour for the given date. 1353 * The result will be in the local timezone. 1354 * 1355 * ### v2.0.0 breaking changes: 1356 * 1357 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1358 * 1359 * @param {Date|Number} date - the original date 1360 * @returns {Date} the end of an hour 1361 * @throws {TypeError} 1 argument required 1362 * 1363 * @example 1364 * // The end of an hour for 2 September 2014 11:55:00: 1365 * const result = endOfHour(new Date(2014, 8, 2, 11, 55)) 1366 * //=> Tue Sep 02 2014 11:59:59.999 1367 */ 1368 1369function endOfHour(dirtyDate) { 1370 requiredArgs(1, arguments); 1371 var date = toDate(dirtyDate); 1372 date.setMinutes(59, 59, 999); 1373 return date; 1374} 1375 1376/** 1377 * @name endOfWeek 1378 * @category Week Helpers 1379 * @summary Return the end of a week for the given date. 1380 * 1381 * @description 1382 * Return the end of a week for the given date. 1383 * The result will be in the local timezone. 1384 * 1385 * ### v2.0.0 breaking changes: 1386 * 1387 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1388 * 1389 * @param {Date|Number} date - the original date 1390 * @param {Object} [options] - an object with options. 1391 * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} 1392 * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday) 1393 * @returns {Date} the end of a week 1394 * @throws {TypeError} 1 argument required 1395 * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6 1396 * 1397 * @example 1398 * // The end of a week for 2 September 2014 11:55:00: 1399 * const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0)) 1400 * //=> Sat Sep 06 2014 23:59:59.999 1401 * 1402 * @example 1403 * // If the week starts on Monday, the end of the week for 2 September 2014 11:55:00: 1404 * const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 }) 1405 * //=> Sun Sep 07 2014 23:59:59.999 1406 */ 1407function endOfWeek(dirtyDate, dirtyOptions) { 1408 requiredArgs(1, arguments); 1409 var options = dirtyOptions || {}; 1410 var locale = options.locale; 1411 var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; 1412 var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); 1413 var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN 1414 1415 if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { 1416 throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); 1417 } 1418 1419 var date = toDate(dirtyDate); 1420 var day = date.getDay(); 1421 var diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn); 1422 date.setDate(date.getDate() + diff); 1423 date.setHours(23, 59, 59, 999); 1424 return date; 1425} 1426 1427/** 1428 * @name endOfMinute 1429 * @category Minute Helpers 1430 * @summary Return the end of a minute for the given date. 1431 * 1432 * @description 1433 * Return the end of a minute for the given date. 1434 * The result will be in the local timezone. 1435 * 1436 * ### v2.0.0 breaking changes: 1437 * 1438 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1439 * 1440 * @param {Date|Number} date - the original date 1441 * @returns {Date} the end of a minute 1442 * @throws {TypeError} 1 argument required 1443 * 1444 * @example 1445 * // The end of a minute for 1 December 2014 22:15:45.400: 1446 * const result = endOfMinute(new Date(2014, 11, 1, 22, 15, 45, 400)) 1447 * //=> Mon Dec 01 2014 22:15:59.999 1448 */ 1449 1450function endOfMinute(dirtyDate) { 1451 requiredArgs(1, arguments); 1452 var date = toDate(dirtyDate); 1453 date.setSeconds(59, 999); 1454 return date; 1455} 1456 1457/** 1458 * @name endOfQuarter 1459 * @category Quarter Helpers 1460 * @summary Return the end of a year quarter for the given date. 1461 * 1462 * @description 1463 * Return the end of a year quarter for the given date. 1464 * The result will be in the local timezone. 1465 * 1466 * ### v2.0.0 breaking changes: 1467 * 1468 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1469 * 1470 * @param {Date|Number} date - the original date 1471 * @returns {Date} the end of a quarter 1472 * @throws {TypeError} 1 argument required 1473 * 1474 * @example 1475 * // The end of a quarter for 2 September 2014 11:55:00: 1476 * const result = endOfQuarter(new Date(2014, 8, 2, 11, 55, 0)) 1477 * //=> Tue Sep 30 2014 23:59:59.999 1478 */ 1479 1480function endOfQuarter(dirtyDate) { 1481 requiredArgs(1, arguments); 1482 var date = toDate(dirtyDate); 1483 var currentMonth = date.getMonth(); 1484 var month = currentMonth - currentMonth % 3 + 3; 1485 date.setMonth(month, 0); 1486 date.setHours(23, 59, 59, 999); 1487 return date; 1488} 1489 1490/** 1491 * @name endOfSecond 1492 * @category Second Helpers 1493 * @summary Return the end of a second for the given date. 1494 * 1495 * @description 1496 * Return the end of a second for the given date. 1497 * The result will be in the local timezone. 1498 * 1499 * ### v2.0.0 breaking changes: 1500 * 1501 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1502 * 1503 * @param {Date|Number} date - the original date 1504 * @returns {Date} the end of a second 1505 * @throws {TypeError} 1 argument required 1506 * 1507 * @example 1508 * // The end of a second for 1 December 2014 22:15:45.400: 1509 * const result = endOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400)) 1510 * //=> Mon Dec 01 2014 22:15:45.999 1511 */ 1512 1513function endOfSecond(dirtyDate) { 1514 requiredArgs(1, arguments); 1515 var date = toDate(dirtyDate); 1516 date.setMilliseconds(999); 1517 return date; 1518} 1519 1520var formatDistanceLocale = { 1521 lessThanXSeconds: { 1522 one: 'less than a second', 1523 other: 'less than {{count}} seconds' 1524 }, 1525 xSeconds: { 1526 one: '1 second', 1527 other: '{{count}} seconds' 1528 }, 1529 halfAMinute: 'half a minute', 1530 lessThanXMinutes: { 1531 one: 'less than a minute', 1532 other: 'less than {{count}} minutes' 1533 }, 1534 xMinutes: { 1535 one: '1 minute', 1536 other: '{{count}} minutes' 1537 }, 1538 aboutXHours: { 1539 one: 'about 1 hour', 1540 other: 'about {{count}} hours' 1541 }, 1542 xHours: { 1543 one: '1 hour', 1544 other: '{{count}} hours' 1545 }, 1546 xDays: { 1547 one: '1 day', 1548 other: '{{count}} days' 1549 }, 1550 aboutXWeeks: { 1551 one: 'about 1 week', 1552 other: 'about {{count}} weeks' 1553 }, 1554 xWeeks: { 1555 one: '1 week', 1556 other: '{{count}} weeks' 1557 }, 1558 aboutXMonths: { 1559 one: 'about 1 month', 1560 other: 'about {{count}} months' 1561 }, 1562 xMonths: { 1563 one: '1 month', 1564 other: '{{count}} months' 1565 }, 1566 aboutXYears: { 1567 one: 'about 1 year', 1568 other: 'about {{count}} years' 1569 }, 1570 xYears: { 1571 one: '1 year', 1572 other: '{{count}} years' 1573 }, 1574 overXYears: { 1575 one: 'over 1 year', 1576 other: 'over {{count}} years' 1577 }, 1578 almostXYears: { 1579 one: 'almost 1 year', 1580 other: 'almost {{count}} years' 1581 } 1582}; 1583function formatDistance(token, count, options) { 1584 options = options || {}; 1585 var result; 1586 1587 if (typeof formatDistanceLocale[token] === 'string') { 1588 result = formatDistanceLocale[token]; 1589 } else if (count === 1) { 1590 result = formatDistanceLocale[token].one; 1591 } else { 1592 result = formatDistanceLocale[token].other.replace('{{count}}', count); 1593 } 1594 1595 if (options.addSuffix) { 1596 if (options.comparison > 0) { 1597 return 'in ' + result; 1598 } else { 1599 return result + ' ago'; 1600 } 1601 } 1602 1603 return result; 1604} 1605 1606function buildFormatLongFn(args) { 1607 return function (dirtyOptions) { 1608 var options = dirtyOptions || {}; 1609 var width = options.width ? String(options.width) : args.defaultWidth; 1610 var format = args.formats[width] || args.formats[args.defaultWidth]; 1611 return format; 1612 }; 1613} 1614 1615var dateFormats = { 1616 full: 'EEEE, MMMM do, y', 1617 long: 'MMMM do, y', 1618 medium: 'MMM d, y', 1619 short: 'MM/dd/yyyy' 1620}; 1621var timeFormats = { 1622 full: 'h:mm:ss a zzzz', 1623 long: 'h:mm:ss a z', 1624 medium: 'h:mm:ss a', 1625 short: 'h:mm a' 1626}; 1627var dateTimeFormats = { 1628 full: "{{date}} 'at' {{time}}", 1629 long: "{{date}} 'at' {{time}}", 1630 medium: '{{date}}, {{time}}', 1631 short: '{{date}}, {{time}}' 1632}; 1633var formatLong = { 1634 date: buildFormatLongFn({ 1635 formats: dateFormats, 1636 defaultWidth: 'full' 1637 }), 1638 time: buildFormatLongFn({ 1639 formats: timeFormats, 1640 defaultWidth: 'full' 1641 }), 1642 dateTime: buildFormatLongFn({ 1643 formats: dateTimeFormats, 1644 defaultWidth: 'full' 1645 }) 1646}; 1647var formatLong$1 = formatLong; 1648 1649var formatRelativeLocale = { 1650 lastWeek: "'last' eeee 'at' p", 1651 yesterday: "'yesterday at' p", 1652 today: "'today at' p", 1653 tomorrow: "'tomorrow at' p", 1654 nextWeek: "eeee 'at' p", 1655 other: 'P' 1656}; 1657function formatRelative(token, _date, _baseDate, _options) { 1658 return formatRelativeLocale[token]; 1659} 1660 1661function buildLocalizeFn(args) { 1662 return function (dirtyIndex, dirtyOptions) { 1663 var options = dirtyOptions || {}; 1664 var context = options.context ? String(options.context) : 'standalone'; 1665 var valuesArray; 1666 1667 if (context === 'formatting' && args.formattingValues) { 1668 var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; 1669 var width = options.width ? String(options.width) : defaultWidth; 1670 valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; 1671 } else { 1672 var _defaultWidth = args.defaultWidth; 1673 1674 var _width = options.width ? String(options.width) : args.defaultWidth; 1675 1676 valuesArray = args.values[_width] || args.values[_defaultWidth]; 1677 } 1678 1679 var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; 1680 return valuesArray[index]; 1681 }; 1682} 1683 1684var eraValues = { 1685 narrow: ['B', 'A'], 1686 abbreviated: ['BC', 'AD'], 1687 wide: ['Before Christ', 'Anno Domini'] 1688}; 1689var quarterValues = { 1690 narrow: ['1', '2', '3', '4'], 1691 abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'], 1692 wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter'] // Note: in English, the names of days of the week and months are capitalized. 1693 // If you are making a new locale based on this one, check if the same is true for the language you're working on. 1694 // Generally, formatted dates should look like they are in the middle of a sentence, 1695 // e.g. in Spanish language the weekdays and months should be in the lowercase. 1696 1697}; 1698var monthValues = { 1699 narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'], 1700 abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 1701 wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 1702}; 1703var dayValues = { 1704 narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'], 1705 short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], 1706 abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], 1707 wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] 1708}; 1709var dayPeriodValues = { 1710 narrow: { 1711 am: 'a', 1712 pm: 'p', 1713 midnight: 'mi', 1714 noon: 'n', 1715 morning: 'morning', 1716 afternoon: 'afternoon', 1717 evening: 'evening', 1718 night: 'night' 1719 }, 1720 abbreviated: { 1721 am: 'AM', 1722 pm: 'PM', 1723 midnight: 'midnight', 1724 noon: 'noon', 1725 morning: 'morning', 1726 afternoon: 'afternoon', 1727 evening: 'evening', 1728 night: 'night' 1729 }, 1730 wide: { 1731 am: 'a.m.', 1732 pm: 'p.m.', 1733 midnight: 'midnight', 1734 noon: 'noon', 1735 morning: 'morning', 1736 afternoon: 'afternoon', 1737 evening: 'evening', 1738 night: 'night' 1739 } 1740}; 1741var formattingDayPeriodValues = { 1742 narrow: { 1743 am: 'a', 1744 pm: 'p', 1745 midnight: 'mi', 1746 noon: 'n', 1747 morning: 'in the morning', 1748 afternoon: 'in the afternoon', 1749 evening: 'in the evening', 1750 night: 'at night' 1751 }, 1752 abbreviated: { 1753 am: 'AM', 1754 pm: 'PM', 1755 midnight: 'midnight', 1756 noon: 'noon', 1757 morning: 'in the morning', 1758 afternoon: 'in the afternoon', 1759 evening: 'in the evening', 1760 night: 'at night' 1761 }, 1762 wide: { 1763 am: 'a.m.', 1764 pm: 'p.m.', 1765 midnight: 'midnight', 1766 noon: 'noon', 1767 morning: 'in the morning', 1768 afternoon: 'in the afternoon', 1769 evening: 'in the evening', 1770 night: 'at night' 1771 } 1772}; 1773 1774function ordinalNumber(dirtyNumber, _dirtyOptions) { 1775 var number = Number(dirtyNumber); // If ordinal numbers depend on context, for example, 1776 // if they are different for different grammatical genders, 1777 // use `options.unit`: 1778 // 1779 // var options = dirtyOptions || {} 1780 // var unit = String(options.unit) 1781 // 1782 // where `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear', 1783 // 'day', 'hour', 'minute', 'second' 1784 1785 var rem100 = number % 100; 1786 1787 if (rem100 > 20 || rem100 < 10) { 1788 switch (rem100 % 10) { 1789 case 1: 1790 return number + 'st'; 1791 1792 case 2: 1793 return number + 'nd'; 1794 1795 case 3: 1796 return number + 'rd'; 1797 } 1798 } 1799 1800 return number + 'th'; 1801} 1802 1803var localize = { 1804 ordinalNumber: ordinalNumber, 1805 era: buildLocalizeFn({ 1806 values: eraValues, 1807 defaultWidth: 'wide' 1808 }), 1809 quarter: buildLocalizeFn({ 1810 values: quarterValues, 1811 defaultWidth: 'wide', 1812 argumentCallback: function (quarter) { 1813 return Number(quarter) - 1; 1814 } 1815 }), 1816 month: buildLocalizeFn({ 1817 values: monthValues, 1818 defaultWidth: 'wide' 1819 }), 1820 day: buildLocalizeFn({ 1821 values: dayValues, 1822 defaultWidth: 'wide' 1823 }), 1824 dayPeriod: buildLocalizeFn({ 1825 values: dayPeriodValues, 1826 defaultWidth: 'wide', 1827 formattingValues: formattingDayPeriodValues, 1828 defaultFormattingWidth: 'wide' 1829 }) 1830}; 1831var localize$1 = localize; 1832 1833function buildMatchPatternFn(args) { 1834 return function (dirtyString, dirtyOptions) { 1835 var string = String(dirtyString); 1836 var options = dirtyOptions || {}; 1837 var matchResult = string.match(args.matchPattern); 1838 1839 if (!matchResult) { 1840 return null; 1841 } 1842 1843 var matchedString = matchResult[0]; 1844 var parseResult = string.match(args.parsePattern); 1845 1846 if (!parseResult) { 1847 return null; 1848 } 1849 1850 var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; 1851 value = options.valueCallback ? options.valueCallback(value) : value; 1852 return { 1853 value: value, 1854 rest: string.slice(matchedString.length) 1855 }; 1856 }; 1857} 1858 1859function buildMatchFn(args) { 1860 return function (dirtyString, dirtyOptions) { 1861 var string = String(dirtyString); 1862 var options = dirtyOptions || {}; 1863 var width = options.width; 1864 var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; 1865 var matchResult = string.match(matchPattern); 1866 1867 if (!matchResult) { 1868 return null; 1869 } 1870 1871 var matchedString = matchResult[0]; 1872 var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; 1873 var value; 1874 1875 if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { 1876 value = findIndex(parsePatterns, function (pattern) { 1877 return pattern.test(matchedString); 1878 }); 1879 } else { 1880 value = findKey(parsePatterns, function (pattern) { 1881 return pattern.test(matchedString); 1882 }); 1883 } 1884 1885 value = args.valueCallback ? args.valueCallback(value) : value; 1886 value = options.valueCallback ? options.valueCallback(value) : value; 1887 return { 1888 value: value, 1889 rest: string.slice(matchedString.length) 1890 }; 1891 }; 1892} 1893 1894function findKey(object, predicate) { 1895 for (var key in object) { 1896 if (object.hasOwnProperty(key) && predicate(object[key])) { 1897 return key; 1898 } 1899 } 1900} 1901 1902function findIndex(array, predicate) { 1903 for (var key = 0; key < array.length; key++) { 1904 if (predicate(array[key])) { 1905 return key; 1906 } 1907 } 1908} 1909 1910var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; 1911var parseOrdinalNumberPattern = /\d+/i; 1912var matchEraPatterns = { 1913 narrow: /^(b|a)/i, 1914 abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, 1915 wide: /^(before christ|before common era|anno domini|common era)/i 1916}; 1917var parseEraPatterns = { 1918 any: [/^b/i, /^(a|c)/i] 1919}; 1920var matchQuarterPatterns = { 1921 narrow: /^[1234]/i, 1922 abbreviated: /^q[1234]/i, 1923 wide: /^[1234](th|st|nd|rd)? quarter/i 1924}; 1925var parseQuarterPatterns = { 1926 any: [/1/i, /2/i, /3/i, /4/i] 1927}; 1928var matchMonthPatterns = { 1929 narrow: /^[jfmasond]/i, 1930 abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, 1931 wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i 1932}; 1933var parseMonthPatterns = { 1934 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], 1935 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] 1936}; 1937var matchDayPatterns = { 1938 narrow: /^[smtwf]/i, 1939 short: /^(su|mo|tu|we|th|fr|sa)/i, 1940 abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, 1941 wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i 1942}; 1943var parseDayPatterns = { 1944 narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], 1945 any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i] 1946}; 1947var matchDayPeriodPatterns = { 1948 narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, 1949 any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i 1950}; 1951var parseDayPeriodPatterns = { 1952 any: { 1953 am: /^a/i, 1954 pm: /^p/i, 1955 midnight: /^mi/i, 1956 noon: /^no/i, 1957 morning: /morning/i, 1958 afternoon: /afternoon/i, 1959 evening: /evening/i, 1960 night: /night/i 1961 } 1962}; 1963var match = { 1964 ordinalNumber: buildMatchPatternFn({ 1965 matchPattern: matchOrdinalNumberPattern, 1966 parsePattern: parseOrdinalNumberPattern, 1967 valueCallback: function (value) { 1968 return parseInt(value, 10); 1969 } 1970 }), 1971 era: buildMatchFn({ 1972 matchPatterns: matchEraPatterns, 1973 defaultMatchWidth: 'wide', 1974 parsePatterns: parseEraPatterns, 1975 defaultParseWidth: 'any' 1976 }), 1977 quarter: buildMatchFn({ 1978 matchPatterns: matchQuarterPatterns, 1979 defaultMatchWidth: 'wide', 1980 parsePatterns: parseQuarterPatterns, 1981 defaultParseWidth: 'any', 1982 valueCallback: function (index) { 1983 return index + 1; 1984 } 1985 }), 1986 month: buildMatchFn({ 1987 matchPatterns: matchMonthPatterns, 1988 defaultMatchWidth: 'wide', 1989 parsePatterns: parseMonthPatterns, 1990 defaultParseWidth: 'any' 1991 }), 1992 day: buildMatchFn({ 1993 matchPatterns: matchDayPatterns, 1994 defaultMatchWidth: 'wide', 1995 parsePatterns: parseDayPatterns, 1996 defaultParseWidth: 'any' 1997 }), 1998 dayPeriod: buildMatchFn({ 1999 matchPatterns: matchDayPeriodPatterns, 2000 defaultMatchWidth: 'any', 2001 parsePatterns: parseDayPeriodPatterns, 2002 defaultParseWidth: 'any' 2003 }) 2004}; 2005var match$1 = match; 2006 2007/** 2008 * @type {Locale} 2009 * @category Locales 2010 * @summary English locale (United States). 2011 * @language English 2012 * @iso-639-2 eng 2013 * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp} 2014 * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss} 2015 */ 2016 2017var locale = { 2018 code: 'en-US', 2019 formatDistance: formatDistance, 2020 formatLong: formatLong$1, 2021 formatRelative: formatRelative, 2022 localize: localize$1, 2023 match: match$1, 2024 options: { 2025 weekStartsOn: 0 2026 /* Sunday */ 2027 , 2028 firstWeekContainsDate: 1 2029 } 2030}; 2031var defaultLocale = locale; 2032 2033/** 2034 * @name subMilliseconds 2035 * @category Millisecond Helpers 2036 * @summary Subtract the specified number of milliseconds from the given date. 2037 * 2038 * @description 2039 * Subtract the specified number of milliseconds from the given date. 2040 * 2041 * ### v2.0.0 breaking changes: 2042 * 2043 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 2044 * 2045 * @param {Date|Number} date - the date to be changed 2046 * @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`. 2047 * @returns {Date} the new date with the milliseconds subtracted 2048 * @throws {TypeError} 2 arguments required 2049 * 2050 * @example 2051 * // Subtract 750 milliseconds from 10 July 2014 12:45:30.000: 2052 * const result = subMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750) 2053 * //=> Thu Jul 10 2014 12:45:29.250 2054 */ 2055 2056function subMilliseconds(dirtyDate, dirtyAmount) { 2057 requiredArgs(2, arguments); 2058 var amount = toInteger(dirtyAmount); 2059 return addMilliseconds(dirtyDate, -amount); 2060} 2061 2062function addLeadingZeros(number, targetLength) { 2063 var sign = number < 0 ? '-' : ''; 2064 var output = Math.abs(number).toString(); 2065 2066 while (output.length < targetLength) { 2067 output = '0' + output; 2068 } 2069 2070 return sign + output; 2071} 2072 2073/* 2074 * | | Unit | | Unit | 2075 * |-----|--------------------------------|-----|--------------------------------| 2076 * | a | AM, PM | A* | | 2077 * | d | Day of month | D | | 2078 * | h | Hour [1-12] | H | Hour [0-23] | 2079 * | m | Minute | M | Month | 2080 * | s | Second | S | Fraction of second | 2081 * | y | Year (abs) | Y | | 2082 * 2083 * Letters marked by * are not implemented but reserved by Unicode standard. 2084 */ 2085 2086var formatters$2 = { 2087 // Year 2088 y: function (date, token) { 2089 // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens 2090 // | Year | y | yy | yyy | yyyy | yyyyy | 2091 // |----------|-------|----|-------|-------|-------| 2092 // | AD 1 | 1 | 01 | 001 | 0001 | 00001 | 2093 // | AD 12 | 12 | 12 | 012 | 0012 | 00012 | 2094 // | AD 123 | 123 | 23 | 123 | 0123 | 00123 | 2095 // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 | 2096 // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 | 2097 var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript) 2098 2099 var year = signedYear > 0 ? signedYear : 1 - signedYear; 2100 return addLeadingZeros(token === 'yy' ? year % 100 : year, token.length); 2101 }, 2102 // Month 2103 M: function (date, token) { 2104 var month = date.getUTCMonth(); 2105 return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2); 2106 }, 2107 // Day of the month 2108 d: function (date, token) { 2109 return addLeadingZeros(date.getUTCDate(), token.length); 2110 }, 2111 // AM or PM 2112 a: function (date, token) { 2113 var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am'; 2114 2115 switch (token) { 2116 case 'a': 2117 case 'aa': 2118 return dayPeriodEnumValue.toUpperCase(); 2119 2120 case 'aaa': 2121 return dayPeriodEnumValue; 2122 2123 case 'aaaaa': 2124 return dayPeriodEnumValue[0]; 2125 2126 case 'aaaa': 2127 default: 2128 return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.'; 2129 } 2130 }, 2131 // Hour [1-12] 2132 h: function (date, token) { 2133 return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length); 2134 }, 2135 // Hour [0-23] 2136 H: function (date, token) { 2137 return addLeadingZeros(date.getUTCHours(), token.length); 2138 }, 2139 // Minute 2140 m: function (date, token) { 2141 return addLeadingZeros(date.getUTCMinutes(), token.length); 2142 }, 2143 // Second 2144 s: function (date, token) { 2145 return addLeadingZeros(date.getUTCSeconds(), token.length); 2146 }, 2147 // Fraction of second 2148 S: function (date, token) { 2149 var numberOfDigits = token.length; 2150 var milliseconds = date.getUTCMilliseconds(); 2151 var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3)); 2152 return addLeadingZeros(fractionalSeconds, token.length); 2153 } 2154}; 2155var formatters$3 = formatters$2; 2156 2157var MILLISECONDS_IN_DAY = 86400000; // This function will be a part of public API when UTC function will be implemented. 2158// See issue: https://github.com/date-fns/date-fns/issues/376 2159 2160function getUTCDayOfYear(dirtyDate) { 2161 requiredArgs(1, arguments); 2162 var date = toDate(dirtyDate); 2163 var timestamp = date.getTime(); 2164 date.setUTCMonth(0, 1); 2165 date.setUTCHours(0, 0, 0, 0); 2166 var startOfYearTimestamp = date.getTime(); 2167 var difference = timestamp - startOfYearTimestamp; 2168 return Math.floor(difference / MILLISECONDS_IN_DAY) + 1; 2169} 2170 2171// See issue: https://github.com/date-fns/date-fns/issues/376 2172 2173function startOfUTCISOWeek(dirtyDate) { 2174 requiredArgs(1, arguments); 2175 var weekStartsOn = 1; 2176 var date = toDate(dirtyDate); 2177 var day = date.getUTCDay(); 2178 var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; 2179 date.setUTCDate(date.getUTCDate() - diff); 2180 date.setUTCHours(0, 0, 0, 0); 2181 return date; 2182} 2183 2184// See issue: https://github.com/date-fns/date-fns/issues/376 2185 2186function getUTCISOWeekYear(dirtyDate) { 2187 requiredArgs(1, arguments); 2188 var date = toDate(dirtyDate); 2189 var year = date.getUTCFullYear(); 2190 var fourthOfJanuaryOfNextYear = new Date(0); 2191 fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4); 2192 fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0); 2193 var startOfNextYear = startOfUTCISOWeek(fourthOfJanuaryOfNextYear); 2194 var fourthOfJanuaryOfThisYear = new Date(0); 2195 fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4); 2196 fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0); 2197 var startOfThisYear = startOfUTCISOWeek(fourthOfJanuaryOfThisYear); 2198 2199 if (date.getTime() >= startOfNextYear.getTime()) { 2200 return year + 1; 2201 } else if (date.getTime() >= startOfThisYear.getTime()) { 2202 return year; 2203 } else { 2204 return year - 1; 2205 } 2206} 2207 2208// See issue: https://github.com/date-fns/date-fns/issues/376 2209 2210function startOfUTCISOWeekYear(dirtyDate) { 2211 requiredArgs(1, arguments); 2212 var year = getUTCISOWeekYear(dirtyDate); 2213 var fourthOfJanuary = new Date(0); 2214 fourthOfJanuary.setUTCFullYear(year, 0, 4); 2215 fourthOfJanuary.setUTCHours(0, 0, 0, 0); 2216 var date = startOfUTCISOWeek(fourthOfJanuary); 2217 return date; 2218} 2219 2220var MILLISECONDS_IN_WEEK$1 = 604800000; // This function will be a part of public API when UTC function will be implemented. 2221// See issue: https://github.com/date-fns/date-fns/issues/376 2222 2223function getUTCISOWeek(dirtyDate) { 2224 requiredArgs(1, arguments); 2225 var date = toDate(dirtyDate); 2226 var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime(); // Round the number of days to the nearest integer 2227 // because the number of milliseconds in a week is not constant 2228 // (e.g. it's different in the week of the daylight saving time clock shift) 2229 2230 return Math.round(diff / MILLISECONDS_IN_WEEK$1) + 1; 2231} 2232 2233// See issue: https://github.com/date-fns/date-fns/issues/376 2234 2235function startOfUTCWeek(dirtyDate, dirtyOptions) { 2236 requiredArgs(1, arguments); 2237 var options = dirtyOptions || {}; 2238 var locale = options.locale; 2239 var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; 2240 var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); 2241 var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN 2242 2243 if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { 2244 throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); 2245 } 2246 2247 var date = toDate(dirtyDate); 2248 var day = date.getUTCDay(); 2249 var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; 2250 date.setUTCDate(date.getUTCDate() - diff); 2251 date.setUTCHours(0, 0, 0, 0); 2252 return date; 2253} 2254 2255// See issue: https://github.com/date-fns/date-fns/issues/376 2256 2257function getUTCWeekYear(dirtyDate, dirtyOptions) { 2258 requiredArgs(1, arguments); 2259 var date = toDate(dirtyDate, dirtyOptions); 2260 var year = date.getUTCFullYear(); 2261 var options = dirtyOptions || {}; 2262 var locale = options.locale; 2263 var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate; 2264 var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate); 2265 var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN 2266 2267 if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) { 2268 throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively'); 2269 } 2270 2271 var firstWeekOfNextYear = new Date(0); 2272 firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate); 2273 firstWeekOfNextYear.setUTCHours(0, 0, 0, 0); 2274 var startOfNextYear = startOfUTCWeek(firstWeekOfNextYear, dirtyOptions); 2275 var firstWeekOfThisYear = new Date(0); 2276 firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate); 2277 firstWeekOfThisYear.setUTCHours(0, 0, 0, 0); 2278 var startOfThisYear = startOfUTCWeek(firstWeekOfThisYear, dirtyOptions); 2279 2280 if (date.getTime() >= startOfNextYear.getTime()) { 2281 return year + 1; 2282 } else if (date.getTime() >= startOfThisYear.getTime()) { 2283 return year; 2284 } else { 2285 return year - 1; 2286 } 2287} 2288 2289// See issue: https://github.com/date-fns/date-fns/issues/376 2290 2291function startOfUTCWeekYear(dirtyDate, dirtyOptions) { 2292 requiredArgs(1, arguments); 2293 var options = dirtyOptions || {}; 2294 var locale = options.locale; 2295 var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate; 2296 var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate); 2297 var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate); 2298 var year = getUTCWeekYear(dirtyDate, dirtyOptions); 2299 var firstWeek = new Date(0); 2300 firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate); 2301 firstWeek.setUTCHours(0, 0, 0, 0); 2302 var date = startOfUTCWeek(firstWeek, dirtyOptions); 2303 return date; 2304} 2305 2306var MILLISECONDS_IN_WEEK = 604800000; // This function will be a part of public API when UTC function will be implemented. 2307// See issue: https://github.com/date-fns/date-fns/issues/376 2308 2309function getUTCWeek(dirtyDate, options) { 2310 requiredArgs(1, arguments); 2311 var date = toDate(dirtyDate); 2312 var diff = startOfUTCWeek(date, options).getTime() - startOfUTCWeekYear(date, options).getTime(); // Round the number of days to the nearest integer 2313 // because the number of milliseconds in a week is not constant 2314 // (e.g. it's different in the week of the daylight saving time clock shift) 2315 2316 return Math.round(diff / MILLISECONDS_IN_WEEK) + 1; 2317} 2318 2319var dayPeriodEnum = { 2320 am: 'am', 2321 pm: 'pm', 2322 midnight: 'midnight', 2323 noon: 'noon', 2324 morning: 'morning', 2325 afternoon: 'afternoon', 2326 evening: 'evening', 2327 night: 'night' 2328 /* 2329 * | | Unit | | Unit | 2330 * |-----|--------------------------------|-----|--------------------------------| 2331 * | a | AM, PM | A* | Milliseconds in day | 2332 * | b | AM, PM, noon, midnight | B | Flexible day period | 2333 * | c | Stand-alone local day of week | C* | Localized hour w/ day period | 2334 * | d | Day of month | D | Day of year | 2335 * | e | Local day of week | E | Day of week | 2336 * | f | | F* | Day of week in month | 2337 * | g* | Modified Julian day | G | Era | 2338 * | h | Hour [1-12] | H | Hour [0-23] | 2339 * | i! | ISO day of week | I! | ISO week of year | 2340 * | j* | Localized hour w/ day period | J* | Localized hour w/o day period | 2341 * | k | Hour [1-24] | K | Hour [0-11] | 2342 * | l* | (deprecated) | L | Stand-alone month | 2343 * | m | Minute | M | Month | 2344 * | n | | N | | 2345 * | o! | Ordinal number modifier | O | Timezone (GMT) | 2346 * | p! | Long localized time | P! | Long localized date | 2347 * | q | Stand-alone quarter | Q | Quarter | 2348 * | r* | Related Gregorian year | R! | ISO week-numbering year | 2349 * | s | Second | S | Fraction of second | 2350 * | t! | Seconds timestamp | T! | Milliseconds timestamp | 2351 * | u | Extended year | U* | Cyclic year | 2352 * | v* | Timezone (generic non-locat.) | V* | Timezone (location) | 2353 * | w | Local week of year | W* | Week of month | 2354 * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) | 2355 * | y | Year (abs) | Y | Local week-numbering year | 2356 * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) | 2357 * 2358 * Letters marked by * are not implemented but reserved by Unicode standard. 2359 * 2360 * Letters marked by ! are non-standard, but implemented by date-fns: 2361 * - `o` modifies the previous token to turn it into an ordinal (see `format` docs) 2362 * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days, 2363 * i.e. 7 for Sunday, 1 for Monday, etc. 2364 * - `I` is ISO week of year, as opposed to `w` which is local week of year. 2365 * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year. 2366 * `R` is supposed to be used in conjunction with `I` and `i` 2367 * for universal ISO week-numbering date, whereas 2368 * `Y` is supposed to be used in conjunction with `w` and `e` 2369 * for week-numbering date specific to the locale. 2370 * - `P` is long localized date format 2371 * - `p` is long localized time format 2372 */ 2373 2374}; 2375var formatters = { 2376 // Era 2377 G: function (date, token, localize) { 2378 var era = date.getUTCFullYear() > 0 ? 1 : 0; 2379 2380 switch (token) { 2381 // AD, BC 2382 case 'G': 2383 case 'GG': 2384 case 'GGG': 2385 return localize.era(era, { 2386 width: 'abbreviated' 2387 }); 2388 // A, B 2389 2390 case 'GGGGG': 2391 return localize.era(era, { 2392 width: 'narrow' 2393 }); 2394 // Anno Domini, Before Christ 2395 2396 case 'GGGG': 2397 default: 2398 return localize.era(era, { 2399 width: 'wide' 2400 }); 2401 } 2402 }, 2403 // Year 2404 y: function (date, token, localize) { 2405 // Ordinal number 2406 if (token === 'yo') { 2407 var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript) 2408 2409 var year = signedYear > 0 ? signedYear : 1 - signedYear; 2410 return localize.ordinalNumber(year, { 2411 unit: 'year' 2412 }); 2413 } 2414 2415 return formatters$3.y(date, token); 2416 }, 2417 // Local week-numbering year 2418 Y: function (date, token, localize, options) { 2419 var signedWeekYear = getUTCWeekYear(date, options); // Returns 1 for 1 BC (which is year 0 in JavaScript) 2420 2421 var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear; // Two digit year 2422 2423 if (token === 'YY') { 2424 var twoDigitYear = weekYear % 100; 2425 return addLeadingZeros(twoDigitYear, 2); 2426 } // Ordinal number 2427 2428 2429 if (token === 'Yo') { 2430 return localize.ordinalNumber(weekYear, { 2431 unit: 'year' 2432 }); 2433 } // Padding 2434 2435 2436 return addLeadingZeros(weekYear, token.length); 2437 }, 2438 // ISO week-numbering year 2439 R: function (date, token) { 2440 var isoWeekYear = getUTCISOWeekYear(date); // Padding 2441 2442 return addLeadingZeros(isoWeekYear, token.length); 2443 }, 2444 // Extended year. This is a single number designating the year of this calendar system. 2445 // The main difference between `y` and `u` localizers are B.C. years: 2446 // | Year | `y` | `u` | 2447 // |------|-----|-----| 2448 // | AC 1 | 1 | 1 | 2449 // | BC 1 | 1 | 0 | 2450 // | BC 2 | 2 | -1 | 2451 // Also `yy` always returns the last two digits of a year, 2452 // while `uu` pads single digit years to 2 characters and returns other years unchanged. 2453 u: function (date, token) { 2454 var year = date.getUTCFullYear(); 2455 return addLeadingZeros(year, token.length); 2456 }, 2457 // Quarter 2458 Q: function (date, token, localize) { 2459 var quarter = Math.ceil((date.getUTCMonth() + 1) / 3); 2460 2461 switch (token) { 2462 // 1, 2, 3, 4 2463 case 'Q': 2464 return String(quarter); 2465 // 01, 02, 03, 04 2466 2467 case 'QQ': 2468 return addLeadingZeros(quarter, 2); 2469 // 1st, 2nd, 3rd, 4th 2470 2471 case 'Qo': 2472 return localize.ordinalNumber(quarter, { 2473 unit: 'quarter' 2474 }); 2475 // Q1, Q2, Q3, Q4 2476 2477 case 'QQQ': 2478 return localize.quarter(quarter, { 2479 width: 'abbreviated', 2480 context: 'formatting' 2481 }); 2482 // 1, 2, 3, 4 (narrow quarter; could be not numerical) 2483 2484 case 'QQQQQ': 2485 return localize.quarter(quarter, { 2486 width: 'narrow', 2487 context: 'formatting' 2488 }); 2489 // 1st quarter, 2nd quarter, ... 2490 2491 case 'QQQQ': 2492 default: 2493 return localize.quarter(quarter, { 2494 width: 'wide', 2495 context: 'formatting' 2496 }); 2497 } 2498 }, 2499 // Stand-alone quarter 2500 q: function (date, token, localize) { 2501 var quarter = Math.ceil((date.getUTCMonth() + 1) / 3); 2502 2503 switch (token) { 2504 // 1, 2, 3, 4 2505 case 'q': 2506 return String(quarter); 2507 // 01, 02, 03, 04 2508 2509 case 'qq': 2510 return addLeadingZeros(quarter, 2); 2511 // 1st, 2nd, 3rd, 4th 2512 2513 case 'qo': 2514 return localize.ordinalNumber(quarter, { 2515 unit: 'quarter' 2516 }); 2517 // Q1, Q2, Q3, Q4 2518 2519 case 'qqq': 2520 return localize.quarter(quarter, { 2521 width: 'abbreviated', 2522 context: 'standalone' 2523 }); 2524 // 1, 2, 3, 4 (narrow quarter; could be not numerical) 2525 2526 case 'qqqqq': 2527 return localize.quarter(quarter, { 2528 width: 'narrow', 2529 context: 'standalone' 2530 }); 2531 // 1st quarter, 2nd quarter, ... 2532 2533 case 'qqqq': 2534 default: 2535 return localize.quarter(quarter, { 2536 width: 'wide', 2537 context: 'standalone' 2538 }); 2539 } 2540 }, 2541 // Month 2542 M: function (date, token, localize) { 2543 var month = date.getUTCMonth(); 2544 2545 switch (token) { 2546 case 'M': 2547 case 'MM': 2548 return formatters$3.M(date, token); 2549 // 1st, 2nd, ..., 12th 2550 2551 case 'Mo': 2552 return localize.ordinalNumber(month + 1, { 2553 unit: 'month' 2554 }); 2555 // Jan, Feb, ..., Dec 2556 2557 case 'MMM': 2558 return localize.month(month, { 2559 width: 'abbreviated', 2560 context: 'formatting' 2561 }); 2562 // J, F, ..., D 2563 2564 case 'MMMMM': 2565 return localize.month(month, { 2566 width: 'narrow', 2567 context: 'formatting' 2568 }); 2569 // January, February, ..., December 2570 2571 case 'MMMM': 2572 default: 2573 return localize.month(month, { 2574 width: 'wide', 2575 context: 'formatting' 2576 }); 2577 } 2578 }, 2579 // Stand-alone month 2580 L: function (date, token, localize) { 2581 var month = date.getUTCMonth(); 2582 2583 switch (token) { 2584 // 1, 2, ..., 12 2585 case 'L': 2586 return String(month + 1); 2587 // 01, 02, ..., 12 2588 2589 case 'LL': 2590 return addLeadingZeros(month + 1, 2); 2591 // 1st, 2nd, ..., 12th 2592 2593 case 'Lo': 2594 return localize.ordinalNumber(month + 1, { 2595 unit: 'month' 2596 }); 2597 // Jan, Feb, ..., Dec 2598 2599 case 'LLL': 2600 return localize.month(month, { 2601 width: 'abbreviated', 2602 context: 'standalone' 2603 }); 2604 // J, F, ..., D 2605 2606 case 'LLLLL': 2607 return localize.month(month, { 2608 width: 'narrow', 2609 context: 'standalone' 2610 }); 2611 // January, February, ..., December 2612 2613 case 'LLLL': 2614 default: 2615 return localize.month(month, { 2616 width: 'wide', 2617 context: 'standalone' 2618 }); 2619 } 2620 }, 2621 // Local week of year 2622 w: function (date, token, localize, options) { 2623 var week = getUTCWeek(date, options); 2624 2625 if (token === 'wo') { 2626 return localize.ordinalNumber(week, { 2627 unit: 'week' 2628 }); 2629 } 2630 2631 return addLeadingZeros(week, token.length); 2632 }, 2633 // ISO week of year 2634 I: function (date, token, localize) { 2635 var isoWeek = getUTCISOWeek(date); 2636 2637 if (token === 'Io') { 2638 return localize.ordinalNumber(isoWeek, { 2639 unit: 'week' 2640 }); 2641 } 2642 2643 return addLeadingZeros(isoWeek, token.length); 2644 }, 2645 // Day of the month 2646 d: function (date, token, localize) { 2647 if (token === 'do') { 2648 return localize.ordinalNumber(date.getUTCDate(), { 2649 unit: 'date' 2650 }); 2651 } 2652 2653 return formatters$3.d(date, token); 2654 }, 2655 // Day of year 2656 D: function (date, token, localize) { 2657 var dayOfYear = getUTCDayOfYear(date); 2658 2659 if (token === 'Do') { 2660 return localize.ordinalNumber(dayOfYear, { 2661 unit: 'dayOfYear' 2662 }); 2663 } 2664 2665 return addLeadingZeros(dayOfYear, token.length); 2666 }, 2667 // Day of week 2668 E: function (date, token, localize) { 2669 var dayOfWeek = date.getUTCDay(); 2670 2671 switch (token) { 2672 // Tue 2673 case 'E': 2674 case 'EE': 2675 case 'EEE': 2676 return localize.day(dayOfWeek, { 2677 width: 'abbreviated', 2678 context: 'formatting' 2679 }); 2680 // T 2681 2682 case 'EEEEE': 2683 return localize.day(dayOfWeek, { 2684 width: 'narrow', 2685 context: 'formatting' 2686 }); 2687 // Tu 2688 2689 case 'EEEEEE': 2690 return localize.day(dayOfWeek, { 2691 width: 'short', 2692 context: 'formatting' 2693 }); 2694 // Tuesday 2695 2696 case 'EEEE': 2697 default: 2698 return localize.day(dayOfWeek, { 2699 width: 'wide', 2700 context: 'formatting' 2701 }); 2702 } 2703 }, 2704 // Local day of week 2705 e: function (date, token, localize, options) { 2706 var dayOfWeek = date.getUTCDay(); 2707 var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7; 2708 2709 switch (token) { 2710 // Numerical value (Nth day of week with current locale or weekStartsOn) 2711 case 'e': 2712 return String(localDayOfWeek); 2713 // Padded numerical value 2714 2715 case 'ee': 2716 return addLeadingZeros(localDayOfWeek, 2); 2717 // 1st, 2nd, ..., 7th 2718 2719 case 'eo': 2720 return localize.ordinalNumber(localDayOfWeek, { 2721 unit: 'day' 2722 }); 2723 2724 case 'eee': 2725 return localize.day(dayOfWeek, { 2726 width: 'abbreviated', 2727 context: 'formatting' 2728 }); 2729 // T 2730 2731 case 'eeeee': 2732 return localize.day(dayOfWeek, { 2733 width: 'narrow', 2734 context: 'formatting' 2735 }); 2736 // Tu 2737 2738 case 'eeeeee': 2739 return localize.day(dayOfWeek, { 2740 width: 'short', 2741 context: 'formatting' 2742 }); 2743 // Tuesday 2744 2745 case 'eeee': 2746 default: 2747 return localize.day(dayOfWeek, { 2748 width: 'wide', 2749 context: 'formatting' 2750 }); 2751 } 2752 }, 2753 // Stand-alone local day of week 2754 c: function (date, token, localize, options) { 2755 var dayOfWeek = date.getUTCDay(); 2756 var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7; 2757 2758 switch (token) { 2759 // Numerical value (same as in `e`) 2760 case 'c': 2761 return String(localDayOfWeek); 2762 // Padded numerical value 2763 2764 case 'cc': 2765 return addLeadingZeros(localDayOfWeek, token.length); 2766 // 1st, 2nd, ..., 7th 2767 2768 case 'co': 2769 return localize.ordinalNumber(localDayOfWeek, { 2770 unit: 'day' 2771 }); 2772 2773 case 'ccc': 2774 return localize.day(dayOfWeek, { 2775 width: 'abbreviated', 2776 context: 'standalone' 2777 }); 2778 // T 2779 2780 case 'ccccc': 2781 return localize.day(dayOfWeek, { 2782 width: 'narrow', 2783 context: 'standalone' 2784 }); 2785 // Tu 2786 2787 case 'cccccc': 2788 return localize.day(dayOfWeek, { 2789 width: 'short', 2790 context: 'standalone' 2791 }); 2792 // Tuesday 2793 2794 case 'cccc': 2795 default: 2796 return localize.day(dayOfWeek, { 2797 width: 'wide', 2798 context: 'standalone' 2799 }); 2800 } 2801 }, 2802 // ISO day of week 2803 i: function (date, token, localize) { 2804 var dayOfWeek = date.getUTCDay(); 2805 var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek; 2806 2807 switch (token) { 2808 // 2 2809 case 'i': 2810 return String(isoDayOfWeek); 2811 // 02 2812 2813 case 'ii': 2814 return addLeadingZeros(isoDayOfWeek, token.length); 2815 // 2nd 2816 2817 case 'io': 2818 return localize.ordinalNumber(isoDayOfWeek, { 2819 unit: 'day' 2820 }); 2821 // Tue 2822 2823 case 'iii': 2824 return localize.day(dayOfWeek, { 2825 width: 'abbreviated', 2826 context: 'formatting' 2827 }); 2828 // T 2829 2830 case 'iiiii': 2831 return localize.day(dayOfWeek, { 2832 width: 'narrow', 2833 context: 'formatting' 2834 }); 2835 // Tu 2836 2837 case 'iiiiii': 2838 return localize.day(dayOfWeek, { 2839 width: 'short', 2840 context: 'formatting' 2841 }); 2842 // Tuesday 2843 2844 case 'iiii': 2845 default: 2846 return localize.day(dayOfWeek, { 2847 width: 'wide', 2848 context: 'formatting' 2849 }); 2850 } 2851 }, 2852 // AM or PM 2853 a: function (date, token, localize) { 2854 var hours = date.getUTCHours(); 2855 var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am'; 2856 2857 switch (token) { 2858 case 'a': 2859 case 'aa': 2860 return localize.dayPeriod(dayPeriodEnumValue, { 2861 width: 'abbreviated', 2862 context: 'formatting' 2863 }); 2864 2865 case 'aaa': 2866 return localize.dayPeriod(dayPeriodEnumValue, { 2867 width: 'abbreviated', 2868 context: 'formatting' 2869 }).toLowerCase(); 2870 2871 case 'aaaaa': 2872 return localize.dayPeriod(dayPeriodEnumValue, { 2873 width: 'narrow', 2874 context: 'formatting' 2875 }); 2876 2877 case 'aaaa': 2878 default: 2879 return localize.dayPeriod(dayPeriodEnumValue, { 2880 width: 'wide', 2881 context: 'formatting' 2882 }); 2883 } 2884 }, 2885 // AM, PM, midnight, noon 2886 b: function (date, token, localize) { 2887 var hours = date.getUTCHours(); 2888 var dayPeriodEnumValue; 2889 2890 if (hours === 12) { 2891 dayPeriodEnumValue = dayPeriodEnum.noon; 2892 } else if (hours === 0) { 2893 dayPeriodEnumValue = dayPeriodEnum.midnight; 2894 } else { 2895 dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am'; 2896 } 2897 2898 switch (token) { 2899 case 'b': 2900 case 'bb': 2901 return localize.dayPeriod(dayPeriodEnumValue, { 2902 width: 'abbreviated', 2903 context: 'formatting' 2904 }); 2905 2906 case 'bbb': 2907 return localize.dayPeriod(dayPeriodEnumValue, { 2908 width: 'abbreviated', 2909 context: 'formatting' 2910 }).toLowerCase(); 2911 2912 case 'bbbbb': 2913 return localize.dayPeriod(dayPeriodEnumValue, { 2914 width: 'narrow', 2915 context: 'formatting' 2916 }); 2917 2918 case 'bbbb': 2919 default: 2920 return localize.dayPeriod(dayPeriodEnumValue, { 2921 width: 'wide', 2922 context: 'formatting' 2923 }); 2924 } 2925 }, 2926 // in the morning, in the afternoon, in the evening, at night 2927 B: function (date, token, localize) { 2928 var hours = date.getUTCHours(); 2929 var dayPeriodEnumValue; 2930 2931 if (hours >= 17) { 2932 dayPeriodEnumValue = dayPeriodEnum.evening; 2933 } else if (hours >= 12) { 2934 dayPeriodEnumValue = dayPeriodEnum.afternoon; 2935 } else if (hours >= 4) { 2936 dayPeriodEnumValue = dayPeriodEnum.morning; 2937 } else { 2938 dayPeriodEnumValue = dayPeriodEnum.night; 2939 } 2940 2941 switch (token) { 2942 case 'B': 2943 case 'BB': 2944 case 'BBB': 2945 return localize.dayPeriod(dayPeriodEnumValue, { 2946 width: 'abbreviated', 2947 context: 'formatting' 2948 }); 2949 2950 case 'BBBBB': 2951 return localize.dayPeriod(dayPeriodEnumValue, { 2952 width: 'narrow', 2953 context: 'formatting' 2954 }); 2955 2956 case 'BBBB': 2957 default: 2958 return localize.dayPeriod(dayPeriodEnumValue, { 2959 width: 'wide', 2960 context: 'formatting' 2961 }); 2962 } 2963 }, 2964 // Hour [1-12] 2965 h: function (date, token, localize) { 2966 if (token === 'ho') { 2967 var hours = date.getUTCHours() % 12; 2968 if (hours === 0) hours = 12; 2969 return localize.ordinalNumber(hours, { 2970 unit: 'hour' 2971 }); 2972 } 2973 2974 return formatters$3.h(date, token); 2975 }, 2976 // Hour [0-23] 2977 H: function (date, token, localize) { 2978 if (token === 'Ho') { 2979 return localize.ordinalNumber(date.getUTCHours(), { 2980 unit: 'hour' 2981 }); 2982 } 2983 2984 return formatters$3.H(date, token); 2985 }, 2986 // Hour [0-11] 2987 K: function (date, token, localize) { 2988 var hours = date.getUTCHours() % 12; 2989 2990 if (token === 'Ko') { 2991 return localize.ordinalNumber(hours, { 2992 unit: 'hour' 2993 }); 2994 } 2995 2996 return addLeadingZeros(hours, token.length); 2997 }, 2998 // Hour [1-24] 2999 k: function (date, token, localize) { 3000 var hours = date.getUTCHours(); 3001 if (hours === 0) hours = 24; 3002 3003 if (token === 'ko') { 3004 return localize.ordinalNumber(hours, { 3005 unit: 'hour' 3006 }); 3007 } 3008 3009 return addLeadingZeros(hours, token.length); 3010 }, 3011 // Minute 3012 m: function (date, token, localize) { 3013 if (token === 'mo') { 3014 return localize.ordinalNumber(date.getUTCMinutes(), { 3015 unit: 'minute' 3016 }); 3017 } 3018 3019 return formatters$3.m(date, token); 3020 }, 3021 // Second 3022 s: function (date, token, localize) { 3023 if (token === 'so') { 3024 return localize.ordinalNumber(date.getUTCSeconds(), { 3025 unit: 'second' 3026 }); 3027 } 3028 3029 return formatters$3.s(date, token); 3030 }, 3031 // Fraction of second 3032 S: function (date, token) { 3033 return formatters$3.S(date, token); 3034 }, 3035 // Timezone (ISO-8601. If offset is 0, output is always `'Z'`) 3036 X: function (date, token, _localize, options) { 3037 var originalDate = options._originalDate || date; 3038 var timezoneOffset = originalDate.getTimezoneOffset(); 3039 3040 if (timezoneOffset === 0) { 3041 return 'Z'; 3042 } 3043 3044 switch (token) { 3045 // Hours and optional minutes 3046 case 'X': 3047 return formatTimezoneWithOptionalMinutes(timezoneOffset); 3048 // Hours, minutes and optional seconds without `:` delimiter 3049 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets 3050 // so this token always has the same output as `XX` 3051 3052 case 'XXXX': 3053 case 'XX': 3054 // Hours and minutes without `:` delimiter 3055 return formatTimezone(timezoneOffset); 3056 // Hours, minutes and optional seconds with `:` delimiter 3057 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets 3058 // so this token always has the same output as `XXX` 3059 3060 case 'XXXXX': 3061 case 'XXX': // Hours and minutes with `:` delimiter 3062 3063 default: 3064 return formatTimezone(timezoneOffset, ':'); 3065 } 3066 }, 3067 // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent) 3068 x: function (date, token, _localize, options) { 3069 var originalDate = options._originalDate || date; 3070 var timezoneOffset = originalDate.getTimezoneOffset(); 3071 3072 switch (token) { 3073 // Hours and optional minutes 3074 case 'x': 3075 return formatTimezoneWithOptionalMinutes(timezoneOffset); 3076 // Hours, minutes and optional seconds without `:` delimiter 3077 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets 3078 // so this token always has the same output as `xx` 3079 3080 case 'xxxx': 3081 case 'xx': 3082 // Hours and minutes without `:` delimiter 3083 return formatTimezone(timezoneOffset); 3084 // Hours, minutes and optional seconds with `:` delimiter 3085 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets 3086 // so this token always has the same output as `xxx` 3087 3088 case 'xxxxx': 3089 case 'xxx': // Hours and minutes with `:` delimiter 3090 3091 default: 3092 return formatTimezone(timezoneOffset, ':'); 3093 } 3094 }, 3095 // Timezone (GMT) 3096 O: function (date, token, _localize, options) { 3097 var originalDate = options._originalDate || date; 3098 var timezoneOffset = originalDate.getTimezoneOffset(); 3099 3100 switch (token) { 3101 // Short 3102 case 'O': 3103 case 'OO': 3104 case 'OOO': 3105 return 'GMT' + formatTimezoneShort(timezoneOffset, ':'); 3106 // Long 3107 3108 case 'OOOO': 3109 default: 3110 return 'GMT' + formatTimezone(timezoneOffset, ':'); 3111 } 3112 }, 3113 // Timezone (specific non-location) 3114 z: function (date, token, _localize, options) { 3115 var originalDate = options._originalDate || date; 3116 var timezoneOffset = originalDate.getTimezoneOffset(); 3117 3118 switch (token) { 3119 // Short 3120 case 'z': 3121 case 'zz': 3122 case 'zzz': 3123 return 'GMT' + formatTimezoneShort(timezoneOffset, ':'); 3124 // Long 3125 3126 case 'zzzz': 3127 default: 3128 return 'GMT' + formatTimezone(timezoneOffset, ':'); 3129 } 3130 }, 3131 // Seconds timestamp 3132 t: function (date, token, _localize, options) { 3133 var originalDate = options._originalDate || date; 3134 var timestamp = Math.floor(originalDate.getTime() / 1000); 3135 return addLeadingZeros(timestamp, token.length); 3136 }, 3137 // Milliseconds timestamp 3138 T: function (date, token, _localize, options) { 3139 var originalDate = options._originalDate || date; 3140 var timestamp = originalDate.getTime(); 3141 return addLeadingZeros(timestamp, token.length); 3142 } 3143}; 3144 3145function formatTimezoneShort(offset, dirtyDelimiter) { 3146 var sign = offset > 0 ? '-' : '+'; 3147 var absOffset = Math.abs(offset); 3148 var hours = Math.floor(absOffset / 60); 3149 var minutes = absOffset % 60; 3150 3151 if (minutes === 0) { 3152 return sign + String(hours); 3153 } 3154 3155 var delimiter = dirtyDelimiter || ''; 3156 return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2); 3157} 3158 3159function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) { 3160 if (offset % 60 === 0) { 3161 var sign = offset > 0 ? '-' : '+'; 3162 return sign + addLeadingZeros(Math.abs(offset) / 60, 2); 3163 } 3164 3165 return formatTimezone(offset, dirtyDelimiter); 3166} 3167 3168function formatTimezone(offset, dirtyDelimiter) { 3169 var delimiter = dirtyDelimiter || ''; 3170 var sign = offset > 0 ? '-' : '+'; 3171 var absOffset = Math.abs(offset); 3172 var hours = addLeadingZeros(Math.floor(absOffset / 60), 2); 3173 var minutes = addLeadingZeros(absOffset % 60, 2); 3174 return sign + hours + delimiter + minutes; 3175} 3176 3177var formatters$1 = formatters; 3178 3179function dateLongFormatter(pattern, formatLong) { 3180 switch (pattern) { 3181 case 'P': 3182 return formatLong.date({ 3183 width: 'short' 3184 }); 3185 3186 case 'PP': 3187 return formatLong.date({ 3188 width: 'medium' 3189 }); 3190 3191 case 'PPP': 3192 return formatLong.date({ 3193 width: 'long' 3194 }); 3195 3196 case 'PPPP': 3197 default: 3198 return formatLong.date({ 3199 width: 'full' 3200 }); 3201 } 3202} 3203 3204function timeLongFormatter(pattern, formatLong) { 3205 switch (pattern) { 3206 case 'p': 3207 return formatLong.time({ 3208 width: 'short' 3209 }); 3210 3211 case 'pp': 3212 return formatLong.time({ 3213 width: 'medium' 3214 }); 3215 3216 case 'ppp': 3217 return formatLong.time({ 3218 width: 'long' 3219 }); 3220 3221 case 'pppp': 3222 default: 3223 return formatLong.time({ 3224 width: 'full' 3225 }); 3226 } 3227} 3228 3229function dateTimeLongFormatter(pattern, formatLong) { 3230 var matchResult = pattern.match(/(P+)(p+)?/); 3231 var datePattern = matchResult[1]; 3232 var timePattern = matchResult[2]; 3233 3234 if (!timePattern) { 3235 return dateLongFormatter(pattern, formatLong); 3236 } 3237 3238 var dateTimeFormat; 3239 3240 switch (datePattern) { 3241 case 'P': 3242 dateTimeFormat = formatLong.dateTime({ 3243 width: 'short' 3244 }); 3245 break; 3246 3247 case 'PP': 3248 dateTimeFormat = formatLong.dateTime({ 3249 width: 'medium' 3250 }); 3251 break; 3252 3253 case 'PPP': 3254 dateTimeFormat = formatLong.dateTime({ 3255 width: 'long' 3256 }); 3257 break; 3258 3259 case 'PPPP': 3260 default: 3261 dateTimeFormat = formatLong.dateTime({ 3262 width: 'full' 3263 }); 3264 break; 3265 } 3266 3267 return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong)); 3268} 3269 3270var longFormatters = { 3271 p: timeLongFormatter, 3272 P: dateTimeLongFormatter 3273}; 3274var longFormatters$1 = longFormatters; 3275 3276var protectedDayOfYearTokens = ['D', 'DD']; 3277var protectedWeekYearTokens = ['YY', 'YYYY']; 3278function isProtectedDayOfYearToken(token) { 3279 return protectedDayOfYearTokens.indexOf(token) !== -1; 3280} 3281function isProtectedWeekYearToken(token) { 3282 return protectedWeekYearTokens.indexOf(token) !== -1; 3283} 3284function throwProtectedError(token, format, input) { 3285 if (token === 'YYYY') { 3286 throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://git.io/fxCyr")); 3287 } else if (token === 'YY') { 3288 throw new RangeError("Use `yy` instead of `YY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://git.io/fxCyr")); 3289 } else if (token === 'D') { 3290 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")); 3291 } else if (token === 'DD') { 3292 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")); 3293 } 3294} 3295 3296// - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token 3297// (one of the certain letters followed by `o`) 3298// - (\w)\1* matches any sequences of the same letter 3299// - '' matches two quote characters in a row 3300// - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('), 3301// except a single quote symbol, which ends the sequence. 3302// Two quote characters do not end the sequence. 3303// If there is no matching single quote 3304// then the sequence will continue until the end of the string. 3305// - . matches any single character unmatched by previous parts of the RegExps 3306 3307var formattingTokensRegExp$1 = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g; // This RegExp catches symbols escaped by quotes, and also 3308// sequences of symbols P, p, and the combinations like `PPPPPPPppppp` 3309 3310var longFormattingTokensRegExp$1 = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g; 3311var escapedStringRegExp$1 = /^'([^]*?)'?$/; 3312var doubleQuoteRegExp$1 = /''/g; 3313var unescapedLatinCharacterRegExp$1 = /[a-zA-Z]/; 3314/** 3315 * @name format 3316 * @category Common Helpers 3317 * @summary Format the date. 3318 * 3319 * @description 3320 * Return the formatted date string in the given format. The result may vary by locale. 3321 * 3322 * > â ï¸ Please note that the `format` tokens differ from Moment.js and other libraries. 3323 * > See: https://git.io/fxCyr 3324 * 3325 * The characters wrapped between two single quotes characters (') are escaped. 3326 * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. 3327 * (see the last example) 3328 * 3329 * Format of the string is based on Unicode Technical Standard #35: 3330 * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table 3331 * with a few additions (see note 7 below the table). 3332 * 3333 * Accepted patterns: 3334 * | Unit | Pattern | Result examples | Notes | 3335 * |---------------------------------|---------|-----------------------------------|-------| 3336 * | Era | G..GGG | AD, BC | | 3337 * | | GGGG | Anno Domini, Before Christ | 2 | 3338 * | | GGGGG | A, B | | 3339 * | Calendar year | y | 44, 1, 1900, 2017 | 5 | 3340 * | | yo | 44th, 1st, 0th, 17th | 5,7 | 3341 * | | yy | 44, 01, 00, 17 | 5 | 3342 * | | yyy | 044, 001, 1900, 2017 | 5 | 3343 * | | yyyy | 0044, 0001, 1900, 2017 | 5 | 3344 * | | yyyyy | ... | 3,5 | 3345 * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 | 3346 * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 | 3347 * | | YY | 44, 01, 00, 17 | 5,8 | 3348 * | | YYY | 044, 001, 1900, 2017 | 5 | 3349 * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 | 3350 * | | YYYYY | ... | 3,5 | 3351 * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 | 3352 * | | RR | -43, 00, 01, 1900, 2017 | 5,7 | 3353 * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 | 3354 * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 | 3355 * | | RRRRR | ... | 3,5,7 | 3356 * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 | 3357 * | | uu | -43, 01, 1900, 2017 | 5 | 3358 * | | uuu | -043, 001, 1900, 2017 | 5 | 3359 * | | uuuu | -0043, 0001, 1900, 2017 | 5 | 3360 * | | uuuuu | ... | 3,5 | 3361 * | Quarter (formatting) | Q | 1, 2, 3, 4 | | 3362 * | | Qo | 1st, 2nd, 3rd, 4th | 7 | 3363 * | | QQ | 01, 02, 03, 04 | | 3364 * | | QQQ | Q1, Q2, Q3, Q4 | | 3365 * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 | 3366 * | | QQQQQ | 1, 2, 3, 4 | 4 | 3367 * | Quarter (stand-alone) | q | 1, 2, 3, 4 | | 3368 * | | qo | 1st, 2nd, 3rd, 4th | 7 | 3369 * | | qq | 01, 02, 03, 04 | | 3370 * | | qqq | Q1, Q2, Q3, Q4 | | 3371 * | | qqqq | 1st quarter, 2nd quarter, ... | 2 | 3372 * | | qqqqq | 1, 2, 3, 4 | 4 | 3373 * | Month (formatting) | M | 1, 2, ..., 12 | | 3374 * | | Mo | 1st, 2nd, ..., 12th | 7 | 3375 * | | MM | 01, 02, ..., 12 | | 3376 * | | MMM | Jan, Feb, ..., Dec | | 3377 * | | MMMM | January, February, ..., December | 2 | 3378 * | | MMMMM | J, F, ..., D | | 3379 * | Month (stand-alone) | L | 1, 2, ..., 12 | | 3380 * | | Lo | 1st, 2nd, ..., 12th | 7 | 3381 * | | LL | 01, 02, ..., 12 | | 3382 * | | LLL | Jan, Feb, ..., Dec | | 3383 * | | LLLL | January, February, ..., December | 2 | 3384 * | | LLLLL | J, F, ..., D | | 3385 * | Local week of year | w | 1, 2, ..., 53 | | 3386 * | | wo | 1st, 2nd, ..., 53th | 7 | 3387 * | | ww | 01, 02, ..., 53 | | 3388 * | ISO week of year | I | 1, 2, ..., 53 | 7 | 3389 * | | Io | 1st, 2nd, ..., 53th | 7 | 3390 * | | II | 01, 02, ..., 53 | 7 | 3391 * | Day of month | d | 1, 2, ..., 31 | | 3392 * | | do | 1st, 2nd, ..., 31st | 7 | 3393 * | | dd | 01, 02, ..., 31 | | 3394 * | Day of year | D | 1, 2, ..., 365, 366 | 9 | 3395 * | | Do | 1st, 2nd, ..., 365th, 366th | 7 | 3396 * | | DD | 01, 02, ..., 365, 366 | 9 | 3397 * | | DDD | 001, 002, ..., 365, 366 | | 3398 * | | DDDD | ... | 3 | 3399 * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | | 3400 * | | EEEE | Monday, Tuesday, ..., Sunday | 2 | 3401 * | | EEEEE | M, T, W, T, F, S, S | | 3402 * | | EEEEEE | Mo, Tu, We, Th, Fr, Su, Sa | | 3403 * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 | 3404 * | | io | 1st, 2nd, ..., 7th | 7 | 3405 * | | ii | 01, 02, ..., 07 | 7 | 3406 * | | iii | Mon, Tue, Wed, ..., Sun | 7 | 3407 * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 | 3408 * | | iiiii | M, T, W, T, F, S, S | 7 | 3409 * | | iiiiii | Mo, Tu, We, Th, Fr, Su, Sa | 7 | 3410 * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | | 3411 * | | eo | 2nd, 3rd, ..., 1st | 7 | 3412 * | | ee | 02, 03, ..., 01 | | 3413 * | | eee | Mon, Tue, Wed, ..., Sun | | 3414 * | | eeee | Monday, Tuesday, ..., Sunday | 2 | 3415 * | | eeeee | M, T, W, T, F, S, S | | 3416 * | | eeeeee | Mo, Tu, We, Th, Fr, Su, Sa | | 3417 * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | | 3418 * | | co | 2nd, 3rd, ..., 1st | 7 | 3419 * | | cc | 02, 03, ..., 01 | | 3420 * | | ccc | Mon, Tue, Wed, ..., Sun | | 3421 * | | cccc | Monday, Tuesday, ..., Sunday | 2 | 3422 * | | ccccc | M, T, W, T, F, S, S | | 3423 * | | cccccc | Mo, Tu, We, Th, Fr, Su, Sa | | 3424 * | AM, PM | a..aa | AM, PM | | 3425 * | | aaa | am, pm | | 3426 * | | aaaa | a.m., p.m. | 2 | 3427 * | | aaaaa | a, p | | 3428 * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | | 3429 * | | bbb | am, pm, noon, midnight | | 3430 * | | bbbb | a.m., p.m., noon, midnight | 2 | 3431 * | | bbbbb | a, p, n, mi | | 3432 * | Flexible day period | B..BBB | at night, in the morning, ... | | 3433 * | | BBBB | at night, in the morning, ... | 2 | 3434 * | | BBBBB | at night, in the morning, ... | | 3435 * | Hour [1-12] | h | 1, 2, ..., 11, 12 | | 3436 * | | ho | 1st, 2nd, ..., 11th, 12th | 7 | 3437 * | | hh | 01, 02, ..., 11, 12 | | 3438 * | Hour [0-23] | H | 0, 1, 2, ..., 23 | | 3439 * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 | 3440 * | | HH | 00, 01, 02, ..., 23 | | 3441 * | Hour [0-11] | K | 1, 2, ..., 11, 0 | | 3442 * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 | 3443 * | | KK | 01, 02, ..., 11, 00 | | 3444 * | Hour [1-24] | k | 24, 1, 2, ..., 23 | | 3445 * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 | 3446 * | | kk | 24, 01, 02, ..., 23 | | 3447 * | Minute | m | 0, 1, ..., 59 | | 3448 * | | mo | 0th, 1st, ..., 59th | 7 | 3449 * | | mm | 00, 01, ..., 59 | | 3450 * | Second | s | 0, 1, ..., 59 | | 3451 * | | so | 0th, 1st, ..., 59th | 7 | 3452 * | | ss | 00, 01, ..., 59 | | 3453 * | Fraction of second | S | 0, 1, ..., 9 | | 3454 * | | SS | 00, 01, ..., 99 | | 3455 * | | SSS | 000, 0001, ..., 999 | | 3456 * | | SSSS | ... | 3 | 3457 * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | | 3458 * | | XX | -0800, +0530, Z | | 3459 * | | XXX | -08:00, +05:30, Z | | 3460 * | | XXXX | -0800, +0530, Z, +123456 | 2 | 3461 * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | | 3462 * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | | 3463 * | | xx | -0800, +0530, +0000 | | 3464 * | | xxx | -08:00, +05:30, +00:00 | 2 | 3465 * | | xxxx | -0800, +0530, +0000, +123456 | | 3466 * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | | 3467 * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | | 3468 * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 | 3469 * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 | 3470 * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 | 3471 * | Seconds timestamp | t | 512969520 | 7 | 3472 * | | tt | ... | 3,7 | 3473 * | Milliseconds timestamp | T | 512969520900 | 7 | 3474 * | | TT | ... | 3,7 | 3475 * | Long localized date | P | 04/29/1453 | 7 | 3476 * | | PP | Apr 29, 1453 | 7 | 3477 * | | PPP | April 29th, 1453 | 7 | 3478 * | | PPPP | Friday, April 29th, 1453 | 2,7 | 3479 * | Long localized time | p | 12:00 AM | 7 | 3480 * | | pp | 12:00:00 AM | 7 | 3481 * | | ppp | 12:00:00 AM GMT+2 | 7 | 3482 * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 | 3483 * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 | 3484 * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 | 3485 * | | PPPppp | April 29th, 1453 at ... | 7 | 3486 * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 | 3487 * Notes: 3488 * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale 3489 * are the same as "stand-alone" units, but are different in some languages. 3490 * "Formatting" units are declined according to the rules of the language 3491 * in the context of a date. "Stand-alone" units are always nominative singular: 3492 * 3493 * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'` 3494 * 3495 * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'` 3496 * 3497 * 2. Any sequence of the identical letters is a pattern, unless it is escaped by 3498 * the single quote characters (see below). 3499 * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`) 3500 * the output will be the same as default pattern for this unit, usually 3501 * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units 3502 * are marked with "2" in the last column of the table. 3503 * 3504 * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'` 3505 * 3506 * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'` 3507 * 3508 * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'` 3509 * 3510 * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'` 3511 * 3512 * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'` 3513 * 3514 * 3. Some patterns could be unlimited length (such as `yyyyyyyy`). 3515 * The output will be padded with zeros to match the length of the pattern. 3516 * 3517 * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'` 3518 * 3519 * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales. 3520 * These tokens represent the shortest form of the quarter. 3521 * 3522 * 5. The main difference between `y` and `u` patterns are B.C. years: 3523 * 3524 * | Year | `y` | `u` | 3525 * |------|-----|-----| 3526 * | AC 1 | 1 | 1 | 3527 * | BC 1 | 1 | 0 | 3528 * | BC 2 | 2 | -1 | 3529 * 3530 * Also `yy` always returns the last two digits of a year, 3531 * while `uu` pads single digit years to 2 characters and returns other years unchanged: 3532 * 3533 * | Year | `yy` | `uu` | 3534 * |------|------|------| 3535 * | 1 | 01 | 01 | 3536 * | 14 | 14 | 14 | 3537 * | 376 | 76 | 376 | 3538 * | 1453 | 53 | 1453 | 3539 * 3540 * The same difference is true for local and ISO week-numbering years (`Y` and `R`), 3541 * except local week-numbering years are dependent on `options.weekStartsOn` 3542 * and `options.firstWeekContainsDate` (compare [getISOWeekYear]{@link https://date-fns.org/docs/getISOWeekYear} 3543 * and [getWeekYear]{@link https://date-fns.org/docs/getWeekYear}). 3544 * 3545 * 6. Specific non-location timezones are currently unavailable in `date-fns`, 3546 * so right now these tokens fall back to GMT timezones. 3547 * 3548 * 7. These patterns are not in the Unicode Technical Standard #35: 3549 * - `i`: ISO day of week 3550 * - `I`: ISO week of year 3551 * - `R`: ISO week-numbering year 3552 * - `t`: seconds timestamp 3553 * - `T`: milliseconds timestamp 3554 * - `o`: ordinal number modifier 3555 * - `P`: long localized date 3556 * - `p`: long localized time 3557 * 3558 * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years. 3559 * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://git.io/fxCyr 3560 * 3561 * 9. `D` and `DD` tokens represent days of the year but they are ofthen confused with days of the month. 3562 * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://git.io/fxCyr 3563 * 3564 * ### v2.0.0 breaking changes: 3565 * 3566 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 3567 * 3568 * - The second argument is now required for the sake of explicitness. 3569 * 3570 * ```javascript 3571 * // Before v2.0.0 3572 * format(new Date(2016, 0, 1)) 3573 * 3574 * // v2.0.0 onward 3575 * format(new Date(2016, 0, 1), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx") 3576 * ``` 3577 * 3578 * - New format string API for `format` function 3579 * which is based on [Unicode Technical Standard #35](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). 3580 * See [this post](https://blog.date-fns.org/post/unicode-tokens-in-date-fns-v2-sreatyki91jg) for more details. 3581 * 3582 * - Characters are now escaped using single quote symbols (`'`) instead of square brackets. 3583 * 3584 * @param {Date|Number} date - the original date 3585 * @param {String} format - the string of tokens 3586 * @param {Object} [options] - an object with options. 3587 * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} 3588 * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday) 3589 * @param {Number} [options.firstWeekContainsDate=1] - the day of January, which is 3590 * @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`; 3591 * see: https://git.io/fxCyr 3592 * @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`; 3593 * see: https://git.io/fxCyr 3594 * @returns {String} the formatted date string 3595 * @throws {TypeError} 2 arguments required 3596 * @throws {RangeError} `date` must not be Invalid Date 3597 * @throws {RangeError} `options.locale` must contain `localize` property 3598 * @throws {RangeError} `options.locale` must contain `formatLong` property 3599 * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6 3600 * @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7 3601 * @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://git.io/fxCyr 3602 * @throws {RangeError} use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://git.io/fxCyr 3603 * @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 3604 * @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 3605 * @throws {RangeError} format string contains an unescaped latin alphabet character 3606 * 3607 * @example 3608 * // Represent 11 February 2014 in middle-endian format: 3609 * var result = format(new Date(2014, 1, 11), 'MM/dd/yyyy') 3610 * //=> '02/11/2014' 3611 * 3612 * @example 3613 * // Represent 2 July 2014 in Esperanto: 3614 * import { eoLocale } from 'date-fns/locale/eo' 3615 * var result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", { 3616 * locale: eoLocale 3617 * }) 3618 * //=> '2-a de julio 2014' 3619 * 3620 * @example 3621 * // Escape string by single quote characters: 3622 * var result = format(new Date(2014, 6, 2, 15), "h 'o''clock'") 3623 * //=> "3 o'clock" 3624 */ 3625 3626function format(dirtyDate, dirtyFormatStr, dirtyOptions) { 3627 requiredArgs(2, arguments); 3628 var formatStr = String(dirtyFormatStr); 3629 var options = dirtyOptions || {}; 3630 var locale = options.locale || defaultLocale; 3631 var localeFirstWeekContainsDate = locale.options && locale.options.firstWeekContainsDate; 3632 var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate); 3633 var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN 3634 3635 if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) { 3636 throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively'); 3637 } 3638 3639 var localeWeekStartsOn = locale.options && locale.options.weekStartsOn; 3640 var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); 3641 var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN 3642 3643 if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { 3644 throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); 3645 } 3646 3647 if (!locale.localize) { 3648 throw new RangeError('locale must contain localize property'); 3649 } 3650 3651 if (!locale.formatLong) { 3652 throw new RangeError('locale must contain formatLong property'); 3653 } 3654 3655 var originalDate = toDate(dirtyDate); 3656 3657 if (!isValid(originalDate)) { 3658 throw new RangeError('Invalid time value'); 3659 } // Convert the date in system timezone to the same date in UTC+00:00 timezone. 3660 // This ensures that when UTC functions will be implemented, locales will be compatible with them. 3661 // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376 3662 3663 3664 var timezoneOffset = getTimezoneOffsetInMilliseconds(originalDate); 3665 var utcDate = subMilliseconds(originalDate, timezoneOffset); 3666 var formatterOptions = { 3667 firstWeekContainsDate: firstWeekContainsDate, 3668 weekStartsOn: weekStartsOn, 3669 locale: locale, 3670 _originalDate: originalDate 3671 }; 3672 var result = formatStr.match(longFormattingTokensRegExp$1).map(function (substring) { 3673 var firstCharacter = substring[0]; 3674 3675 if (firstCharacter === 'p' || firstCharacter === 'P') { 3676 var longFormatter = longFormatters$1[firstCharacter]; 3677 return longFormatter(substring, locale.formatLong, formatterOptions); 3678 } 3679 3680 return substring; 3681 }).join('').match(formattingTokensRegExp$1).map(function (substring) { 3682 // Replace two single quote characters with one single quote character 3683 if (substring === "''") { 3684 return "'"; 3685 } 3686 3687 var firstCharacter = substring[0]; 3688 3689 if (firstCharacter === "'") { 3690 return cleanEscapedString$1(substring); 3691 } 3692 3693 var formatter = formatters$1[firstCharacter]; 3694 3695 if (formatter) { 3696 if (!options.useAdditionalWeekYearTokens && isProtectedWeekYearToken(substring)) { 3697 throwProtectedError(substring, dirtyFormatStr, dirtyDate); 3698 } 3699 3700 if (!options.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(substring)) { 3701 throwProtectedError(substring, dirtyFormatStr, dirtyDate); 3702 } 3703 3704 return formatter(utcDate, substring, locale.localize, formatterOptions); 3705 } 3706 3707 if (firstCharacter.match(unescapedLatinCharacterRegExp$1)) { 3708 throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`'); 3709 } 3710 3711 return substring; 3712 }).join(''); 3713 return result; 3714} 3715 3716function cleanEscapedString$1(input) { 3717 return input.match(escapedStringRegExp$1)[1].replace(doubleQuoteRegExp$1, "'"); 3718} 3719 3720function assign(target, dirtyObject) { 3721 if (target == null) { 3722 throw new TypeError('assign requires that input parameter not be null or undefined'); 3723 } 3724 3725 dirtyObject = dirtyObject || {}; 3726 3727 for (var property in dirtyObject) { 3728 if (dirtyObject.hasOwnProperty(property)) { 3729 target[property] = dirtyObject[property]; 3730 } 3731 } 3732 3733 return target; 3734} 3735 3736// See issue: https://github.com/date-fns/date-fns/issues/376 3737 3738function setUTCDay(dirtyDate, dirtyDay, dirtyOptions) { 3739 requiredArgs(2, arguments); 3740 var options = dirtyOptions || {}; 3741 var locale = options.locale; 3742 var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; 3743 var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); 3744 var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN 3745 3746 if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { 3747 throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); 3748 } 3749 3750 var date = toDate(dirtyDate); 3751 var day = toInteger(dirtyDay); 3752 var currentDay = date.getUTCDay(); 3753 var remainder = day % 7; 3754 var dayIndex = (remainder + 7) % 7; 3755 var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay; 3756 date.setUTCDate(date.getUTCDate() + diff); 3757 return date; 3758} 3759 3760// See issue: https://github.com/date-fns/date-fns/issues/376 3761 3762function setUTCISODay(dirtyDate, dirtyDay) { 3763 requiredArgs(2, arguments); 3764 var day = toInteger(dirtyDay); 3765 3766 if (day % 7 === 0) { 3767 day = day - 7; 3768 } 3769 3770 var weekStartsOn = 1; 3771 var date = toDate(dirtyDate); 3772 var currentDay = date.getUTCDay(); 3773 var remainder = day % 7; 3774 var dayIndex = (remainder + 7) % 7; 3775 var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay; 3776 date.setUTCDate(date.getUTCDate() + diff); 3777 return date; 3778} 3779 3780// See issue: https://github.com/date-fns/date-fns/issues/376 3781 3782function setUTCISOWeek(dirtyDate, dirtyISOWeek) { 3783 requiredArgs(2, arguments); 3784 var date = toDate(dirtyDate); 3785 var isoWeek = toInteger(dirtyISOWeek); 3786 var diff = getUTCISOWeek(date) - isoWeek; 3787 date.setUTCDate(date.getUTCDate() - diff * 7); 3788 return date; 3789} 3790 3791// See issue: https://github.com/date-fns/date-fns/issues/376 3792 3793function setUTCWeek(dirtyDate, dirtyWeek, options) { 3794 requiredArgs(2, arguments); 3795 var date = toDate(dirtyDate); 3796 var week = toInteger(dirtyWeek); 3797 var diff = getUTCWeek(date, options) - week; 3798 date.setUTCDate(date.getUTCDate() - diff * 7); 3799 return date; 3800} 3801 3802var MILLISECONDS_IN_HOUR$1 = 3600000; 3803var MILLISECONDS_IN_MINUTE$1 = 60000; 3804var MILLISECONDS_IN_SECOND = 1000; 3805var numericPatterns = { 3806 month: /^(1[0-2]|0?\d)/, 3807 // 0 to 12 3808 date: /^(3[0-1]|[0-2]?\d)/, 3809 // 0 to 31 3810 dayOfYear: /^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/, 3811 // 0 to 366 3812 week: /^(5[0-3]|[0-4]?\d)/, 3813 // 0 to 53 3814 hour23h: /^(2[0-3]|[0-1]?\d)/, 3815 // 0 to 23 3816 hour24h: /^(2[0-4]|[0-1]?\d)/, 3817 // 0 to 24 3818 hour11h: /^(1[0-1]|0?\d)/, 3819 // 0 to 11 3820 hour12h: /^(1[0-2]|0?\d)/, 3821 // 0 to 12 3822 minute: /^[0-5]?\d/, 3823 // 0 to 59 3824 second: /^[0-5]?\d/, 3825 // 0 to 59 3826 singleDigit: /^\d/, 3827 // 0 to 9 3828 twoDigits: /^\d{1,2}/, 3829 // 0 to 99 3830 threeDigits: /^\d{1,3}/, 3831 // 0 to 999 3832 fourDigits: /^\d{1,4}/, 3833 // 0 to 9999 3834 anyDigitsSigned: /^-?\d+/, 3835 singleDigitSigned: /^-?\d/, 3836 // 0 to 9, -0 to -9 3837 twoDigitsSigned: /^-?\d{1,2}/, 3838 // 0 to 99, -0 to -99 3839 threeDigitsSigned: /^-?\d{1,3}/, 3840 // 0 to 999, -0 to -999 3841 fourDigitsSigned: /^-?\d{1,4}/ // 0 to 9999, -0 to -9999 3842 3843}; 3844var timezonePatterns = { 3845 basicOptionalMinutes: /^([+-])(\d{2})(\d{2})?|Z/, 3846 basic: /^([+-])(\d{2})(\d{2})|Z/, 3847 basicOptionalSeconds: /^([+-])(\d{2})(\d{2})((\d{2}))?|Z/, 3848 extended: /^([+-])(\d{2}):(\d{2})|Z/, 3849 extendedOptionalSeconds: /^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/ 3850}; 3851 3852function parseNumericPattern(pattern, string, valueCallback) { 3853 var matchResult = string.match(pattern); 3854 3855 if (!matchResult) { 3856 return null; 3857 } 3858 3859 var value = parseInt(matchResult[0], 10); 3860 return { 3861 value: valueCallback ? valueCallback(value) : value, 3862 rest: string.slice(matchResult[0].length) 3863 }; 3864} 3865 3866function parseTimezonePattern(pattern, string) { 3867 var matchResult = string.match(pattern); 3868 3869 if (!matchResult) { 3870 return null; 3871 } // Input is 'Z' 3872 3873 3874 if (matchResult[0] === 'Z') { 3875 return { 3876 value: 0, 3877 rest: string.slice(1) 3878 }; 3879 } 3880 3881 var sign = matchResult[1] === '+' ? 1 : -1; 3882 var hours = matchResult[2] ? parseInt(matchResult[2], 10) : 0; 3883 var minutes = matchResult[3] ? parseInt(matchResult[3], 10) : 0; 3884 var seconds = matchResult[5] ? parseInt(matchResult[5], 10) : 0; 3885 return { 3886 value: sign * (hours * MILLISECONDS_IN_HOUR$1 + minutes * MILLISECONDS_IN_MINUTE$1 + seconds * MILLISECONDS_IN_SECOND), 3887 rest: string.slice(matchResult[0].length) 3888 }; 3889} 3890 3891function parseAnyDigitsSigned(string, valueCallback) { 3892 return parseNumericPattern(numericPatterns.anyDigitsSigned, string, valueCallback); 3893} 3894 3895function parseNDigits(n, string, valueCallback) { 3896 switch (n) { 3897 case 1: 3898 return parseNumericPattern(numericPatterns.singleDigit, string, valueCallback); 3899 3900 case 2: 3901 return parseNumericPattern(numericPatterns.twoDigits, string, valueCallback); 3902 3903 case 3: 3904 return parseNumericPattern(numericPatterns.threeDigits, string, valueCallback); 3905 3906 case 4: 3907 return parseNumericPattern(numericPatterns.fourDigits, string, valueCallback); 3908 3909 default: 3910 return parseNumericPattern(new RegExp('^\\d{1,' + n + '}'), string, valueCallback); 3911 } 3912} 3913 3914function parseNDigitsSigned(n, string, valueCallback) { 3915 switch (n) { 3916 case 1: 3917 return parseNumericPattern(numericPatterns.singleDigitSigned, string, valueCallback); 3918 3919 case 2: 3920 return parseNumericPattern(numericPatterns.twoDigitsSigned, string, valueCallback); 3921 3922 case 3: 3923 return parseNumericPattern(numericPatterns.threeDigitsSigned, string, valueCallback); 3924 3925 case 4: 3926 return parseNumericPattern(numericPatterns.fourDigitsSigned, string, valueCallback); 3927 3928 default: 3929 return parseNumericPattern(new RegExp('^-?\\d{1,' + n + '}'), string, valueCallback); 3930 } 3931} 3932 3933function dayPeriodEnumToHours(enumValue) { 3934 switch (enumValue) { 3935 case 'morning': 3936 return 4; 3937 3938 case 'evening': 3939 return 17; 3940 3941 case 'pm': 3942 case 'noon': 3943 case 'afternoon': 3944 return 12; 3945 3946 case 'am': 3947 case 'midnight': 3948 case 'night': 3949 default: 3950 return 0; 3951 } 3952} 3953 3954function normalizeTwoDigitYear(twoDigitYear, currentYear) { 3955 var isCommonEra = currentYear > 0; // Absolute number of the current year: 3956 // 1 -> 1 AC 3957 // 0 -> 1 BC 3958 // -1 -> 2 BC 3959 3960 var absCurrentYear = isCommonEra ? currentYear : 1 - currentYear; 3961 var result; 3962 3963 if (absCurrentYear <= 50) { 3964 result = twoDigitYear || 100; 3965 } else { 3966 var rangeEnd = absCurrentYear + 50; 3967 var rangeEndCentury = Math.floor(rangeEnd / 100) * 100; 3968 var isPreviousCentury = twoDigitYear >= rangeEnd % 100; 3969 result = twoDigitYear + rangeEndCentury - (isPreviousCentury ? 100 : 0); 3970 } 3971 3972 return isCommonEra ? result : 1 - result; 3973} 3974 3975var DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 3976var DAYS_IN_MONTH_LEAP_YEAR = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // User for validation 3977 3978function isLeapYearIndex$1(year) { 3979 return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0; 3980} 3981/* 3982 * | | Unit | | Unit | 3983 * |-----|--------------------------------|-----|--------------------------------| 3984 * | a | AM, PM | A* | Milliseconds in day | 3985 * | b | AM, PM, noon, midnight | B | Flexible day period | 3986 * | c | Stand-alone local day of week | C* | Localized hour w/ day period | 3987 * | d | Day of month | D | Day of year | 3988 * | e | Local day of week | E | Day of week | 3989 * | f | | F* | Day of week in month | 3990 * | g* | Modified Julian day | G | Era | 3991 * | h | Hour [1-12] | H | Hour [0-23] | 3992 * | i! | ISO day of week | I! | ISO week of year | 3993 * | j* | Localized hour w/ day period | J* | Localized hour w/o day period | 3994 * | k | Hour [1-24] | K | Hour [0-11] | 3995 * | l* | (deprecated) | L | Stand-alone month | 3996 * | m | Minute | M | Month | 3997 * | n | | N | | 3998 * | o! | Ordinal number modifier | O* | Timezone (GMT) | 3999 * | p | | P | | 4000 * | q | Stand-alone quarter | Q | Quarter | 4001 * | r* | Related Gregorian year | R! | ISO week-numbering year | 4002 * | s | Second | S | Fraction of second | 4003 * | t! | Seconds timestamp | T! | Milliseconds timestamp | 4004 * | u | Extended year | U* | Cyclic year | 4005 * | v* | Timezone (generic non-locat.) | V* | Timezone (location) | 4006 * | w | Local week of year | W* | Week of month | 4007 * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) | 4008 * | y | Year (abs) | Y | Local week-numbering year | 4009 * | z* | Timezone (specific non-locat.) | Z* | Timezone (aliases) | 4010 * 4011 * Letters marked by * are not implemented but reserved by Unicode standard. 4012 * 4013 * Letters marked by ! are non-standard, but implemented by date-fns: 4014 * - `o` modifies the previous token to turn it into an ordinal (see `parse` docs) 4015 * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days, 4016 * i.e. 7 for Sunday, 1 for Monday, etc. 4017 * - `I` is ISO week of year, as opposed to `w` which is local week of year. 4018 * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year. 4019 * `R` is supposed to be used in conjunction with `I` and `i` 4020 * for universal ISO week-numbering date, whereas 4021 * `Y` is supposed to be used in conjunction with `w` and `e` 4022 * for week-numbering date specific to the locale. 4023 */ 4024 4025 4026var parsers = { 4027 // Era 4028 G: { 4029 priority: 140, 4030 parse: function (string, token, match, _options) { 4031 switch (token) { 4032 // AD, BC 4033 case 'G': 4034 case 'GG': 4035 case 'GGG': 4036 return match.era(string, { 4037 width: 'abbreviated' 4038 }) || match.era(string, { 4039 width: 'narrow' 4040 }); 4041 // A, B 4042 4043 case 'GGGGG': 4044 return match.era(string, { 4045 width: 'narrow' 4046 }); 4047 // Anno Domini, Before Christ 4048 4049 case 'GGGG': 4050 default: 4051 return match.era(string, { 4052 width: 'wide' 4053 }) || match.era(string, { 4054 width: 'abbreviated' 4055 }) || match.era(string, { 4056 width: 'narrow' 4057 }); 4058 } 4059 }, 4060 set: function (date, flags, value, _options) { 4061 flags.era = value; 4062 date.setUTCFullYear(value, 0, 1); 4063 date.setUTCHours(0, 0, 0, 0); 4064 return date; 4065 }, 4066 incompatibleTokens: ['R', 'u', 't', 'T'] 4067 }, 4068 // Year 4069 y: { 4070 // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns 4071 // | Year | y | yy | yyy | yyyy | yyyyy | 4072 // |----------|-------|----|-------|-------|-------| 4073 // | AD 1 | 1 | 01 | 001 | 0001 | 00001 | 4074 // | AD 12 | 12 | 12 | 012 | 0012 | 00012 | 4075 // | AD 123 | 123 | 23 | 123 | 0123 | 00123 | 4076 // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 | 4077 // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 | 4078 priority: 130, 4079 parse: function (string, token, match, _options) { 4080 var valueCallback = function (year) { 4081 return { 4082 year: year, 4083 isTwoDigitYear: token === 'yy' 4084 }; 4085 }; 4086 4087 switch (token) { 4088 case 'y': 4089 return parseNDigits(4, string, valueCallback); 4090 4091 case 'yo': 4092 return match.ordinalNumber(string, { 4093 unit: 'year', 4094 valueCallback: valueCallback 4095 }); 4096 4097 default: 4098 return parseNDigits(token.length, string, valueCallback); 4099 } 4100 }, 4101 validate: function (_date, value, _options) { 4102 return value.isTwoDigitYear || value.year > 0; 4103 }, 4104 set: function (date, flags, value, _options) { 4105 var currentYear = date.getUTCFullYear(); 4106 4107 if (value.isTwoDigitYear) { 4108 var normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear); 4109 date.setUTCFullYear(normalizedTwoDigitYear, 0, 1); 4110 date.setUTCHours(0, 0, 0, 0); 4111 return date; 4112 } 4113 4114 var year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year; 4115 date.setUTCFullYear(year, 0, 1); 4116 date.setUTCHours(0, 0, 0, 0); 4117 return date; 4118 }, 4119 incompatibleTokens: ['Y', 'R', 'u', 'w', 'I', 'i', 'e', 'c', 't', 'T'] 4120 }, 4121 // Local week-numbering year 4122 Y: { 4123 priority: 130, 4124 parse: function (string, token, match, _options) { 4125 var valueCallback = function (year) { 4126 return { 4127 year: year, 4128 isTwoDigitYear: token === 'YY' 4129 }; 4130 }; 4131 4132 switch (token) { 4133 case 'Y': 4134 return parseNDigits(4, string, valueCallback); 4135 4136 case 'Yo': 4137 return match.ordinalNumber(string, { 4138 unit: 'year', 4139 valueCallback: valueCallback 4140 }); 4141 4142 default: 4143 return parseNDigits(token.length, string, valueCallback); 4144 } 4145 }, 4146 validate: function (_date, value, _options) { 4147 return value.isTwoDigitYear || value.year > 0; 4148 }, 4149 set: function (date, flags, value, options) { 4150 var currentYear = getUTCWeekYear(date, options); 4151 4152 if (value.isTwoDigitYear) { 4153 var normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear); 4154 date.setUTCFullYear(normalizedTwoDigitYear, 0, options.firstWeekContainsDate); 4155 date.setUTCHours(0, 0, 0, 0); 4156 return startOfUTCWeek(date, options); 4157 } 4158 4159 var year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year; 4160 date.setUTCFullYear(year, 0, options.firstWeekContainsDate); 4161 date.setUTCHours(0, 0, 0, 0); 4162 return startOfUTCWeek(date, options); 4163 }, 4164 incompatibleTokens: ['y', 'R', 'u', 'Q', 'q', 'M', 'L', 'I', 'd', 'D', 'i', 't', 'T'] 4165 }, 4166 // ISO week-numbering year 4167 R: { 4168 priority: 130, 4169 parse: function (string, token, _match, _options) { 4170 if (token === 'R') { 4171 return parseNDigitsSigned(4, string); 4172 } 4173 4174 return parseNDigitsSigned(token.length, string); 4175 }, 4176 set: function (_date, _flags, value, _options) { 4177 var firstWeekOfYear = new Date(0); 4178 firstWeekOfYear.setUTCFullYear(value, 0, 4); 4179 firstWeekOfYear.setUTCHours(0, 0, 0, 0); 4180 return startOfUTCISOWeek(firstWeekOfYear); 4181 }, 4182 incompatibleTokens: ['G', 'y', 'Y', 'u', 'Q', 'q', 'M', 'L', 'w', 'd', 'D', 'e', 'c', 't', 'T'] 4183 }, 4184 // Extended year 4185 u: { 4186 priority: 130, 4187 parse: function (string, token, _match, _options) { 4188 if (token === 'u') { 4189 return parseNDigitsSigned(4, string); 4190 } 4191 4192 return parseNDigitsSigned(token.length, string); 4193 }, 4194 set: function (date, _flags, value, _options) { 4195 date.setUTCFullYear(value, 0, 1); 4196 date.setUTCHours(0, 0, 0, 0); 4197 return date; 4198 }, 4199 incompatibleTokens: ['G', 'y', 'Y', 'R', 'w', 'I', 'i', 'e', 'c', 't', 'T'] 4200 }, 4201 // Quarter 4202 Q: { 4203 priority: 120, 4204 parse: function (string, token, match, _options) { 4205 switch (token) { 4206 // 1, 2, 3, 4 4207 case 'Q': 4208 case 'QQ': 4209 // 01, 02, 03, 04 4210 return parseNDigits(token.length, string); 4211 // 1st, 2nd, 3rd, 4th 4212 4213 case 'Qo': 4214 return match.ordinalNumber(string, { 4215 unit: 'quarter' 4216 }); 4217 // Q1, Q2, Q3, Q4 4218 4219 case 'QQQ': 4220 return match.quarter(string, { 4221 width: 'abbreviated', 4222 context: 'formatting' 4223 }) || match.quarter(string, { 4224 width: 'narrow', 4225 context: 'formatting' 4226 }); 4227 // 1, 2, 3, 4 (narrow quarter; could be not numerical) 4228 4229 case 'QQQQQ': 4230 return match.quarter(string, { 4231 width: 'narrow', 4232 context: 'formatting' 4233 }); 4234 // 1st quarter, 2nd quarter, ... 4235 4236 case 'QQQQ': 4237 default: 4238 return match.quarter(string, { 4239 width: 'wide', 4240 context: 'formatting' 4241 }) || match.quarter(string, { 4242 width: 'abbreviated', 4243 context: 'formatting' 4244 }) || match.quarter(string, { 4245 width: 'narrow', 4246 context: 'formatting' 4247 }); 4248 } 4249 }, 4250 validate: function (_date, value, _options) { 4251 return value >= 1 && value <= 4; 4252 }, 4253 set: function (date, _flags, value, _options) { 4254 date.setUTCMonth((value - 1) * 3, 1); 4255 date.setUTCHours(0, 0, 0, 0); 4256 return date; 4257 }, 4258 incompatibleTokens: ['Y', 'R', 'q', 'M', 'L', 'w', 'I', 'd', 'D', 'i', 'e', 'c', 't', 'T'] 4259 }, 4260 // Stand-alone quarter 4261 q: { 4262 priority: 120, 4263 parse: function (string, token, match, _options) { 4264 switch (token) { 4265 // 1, 2, 3, 4 4266 case 'q': 4267 case 'qq': 4268 // 01, 02, 03, 04 4269 return parseNDigits(token.length, string); 4270 // 1st, 2nd, 3rd, 4th 4271 4272 case 'qo': 4273 return match.ordinalNumber(string, { 4274 unit: 'quarter' 4275 }); 4276 // Q1, Q2, Q3, Q4 4277 4278 case 'qqq': 4279 return match.quarter(string, { 4280 width: 'abbreviated', 4281 context: 'standalone' 4282 }) || match.quarter(string, { 4283 width: 'narrow', 4284 context: 'standalone' 4285 }); 4286 // 1, 2, 3, 4 (narrow quarter; could be not numerical) 4287 4288 case 'qqqqq': 4289 return match.quarter(string, { 4290 width: 'narrow', 4291 context: 'standalone' 4292 }); 4293 // 1st quarter, 2nd quarter, ... 4294 4295 case 'qqqq': 4296 default: 4297 return match.quarter(string, { 4298 width: 'wide', 4299 context: 'standalone' 4300 }) || match.quarter(string, { 4301 width: 'abbreviated', 4302 context: 'standalone' 4303 }) || match.quarter(string, { 4304 width: 'narrow', 4305 context: 'standalone' 4306 }); 4307 } 4308 }, 4309 validate: function (_date, value, _options) { 4310 return value >= 1 && value <= 4; 4311 }, 4312 set: function (date, _flags, value, _options) { 4313 date.setUTCMonth((value - 1) * 3, 1); 4314 date.setUTCHours(0, 0, 0, 0); 4315 return date; 4316 }, 4317 incompatibleTokens: ['Y', 'R', 'Q', 'M', 'L', 'w', 'I', 'd', 'D', 'i', 'e', 'c', 't', 'T'] 4318 }, 4319 // Month 4320 M: { 4321 priority: 110, 4322 parse: function (string, token, match, _options) { 4323 var valueCallback = function (value) { 4324 return value - 1; 4325 }; 4326 4327 switch (token) { 4328 // 1, 2, ..., 12 4329 case 'M': 4330 return parseNumericPattern(numericPatterns.month, string, valueCallback); 4331 // 01, 02, ..., 12 4332 4333 case 'MM': 4334 return parseNDigits(2, string, valueCallback); 4335 // 1st, 2nd, ..., 12th 4336 4337 case 'Mo': 4338 return match.ordinalNumber(string, { 4339 unit: 'month', 4340 valueCallback: valueCallback 4341 }); 4342 // Jan, Feb, ..., Dec 4343 4344 case 'MMM': 4345 return match.month(string, { 4346 width: 'abbreviated', 4347 context: 'formatting' 4348 }) || match.month(string, { 4349 width: 'narrow', 4350 context: 'formatting' 4351 }); 4352 // J, F, ..., D 4353 4354 case 'MMMMM': 4355 return match.month(string, { 4356 width: 'narrow', 4357 context: 'formatting' 4358 }); 4359 // January, February, ..., December 4360 4361 case 'MMMM': 4362 default: 4363 return match.month(string, { 4364 width: 'wide', 4365 context: 'formatting' 4366 }) || match.month(string, { 4367 width: 'abbreviated', 4368 context: 'formatting' 4369 }) || match.month(string, { 4370 width: 'narrow', 4371 context: 'formatting' 4372 }); 4373 } 4374 }, 4375 validate: function (_date, value, _options) { 4376 return value >= 0 && value <= 11; 4377 }, 4378 set: function (date, _flags, value, _options) { 4379 date.setUTCMonth(value, 1); 4380 date.setUTCHours(0, 0, 0, 0); 4381 return date; 4382 }, 4383 incompatibleTokens: ['Y', 'R', 'q', 'Q', 'L', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T'] 4384 }, 4385 // Stand-alone month 4386 L: { 4387 priority: 110, 4388 parse: function (string, token, match, _options) { 4389 var valueCallback = function (value) { 4390 return value - 1; 4391 }; 4392 4393 switch (token) { 4394 // 1, 2, ..., 12 4395 case 'L': 4396 return parseNumericPattern(numericPatterns.month, string, valueCallback); 4397 // 01, 02, ..., 12 4398 4399 case 'LL': 4400 return parseNDigits(2, string, valueCallback); 4401 // 1st, 2nd, ..., 12th 4402 4403 case 'Lo': 4404 return match.ordinalNumber(string, { 4405 unit: 'month', 4406 valueCallback: valueCallback 4407 }); 4408 // Jan, Feb, ..., Dec 4409 4410 case 'LLL': 4411 return match.month(string, { 4412 width: 'abbreviated', 4413 context: 'standalone' 4414 }) || match.month(string, { 4415 width: 'narrow', 4416 context: 'standalone' 4417 }); 4418 // J, F, ..., D 4419 4420 case 'LLLLL': 4421 return match.month(string, { 4422 width: 'narrow', 4423 context: 'standalone' 4424 }); 4425 // January, February, ..., December 4426 4427 case 'LLLL': 4428 default: 4429 return match.month(string, { 4430 width: 'wide', 4431 context: 'standalone' 4432 }) || match.month(string, { 4433 width: 'abbreviated', 4434 context: 'standalone' 4435 }) || match.month(string, { 4436 width: 'narrow', 4437 context: 'standalone' 4438 }); 4439 } 4440 }, 4441 validate: function (_date, value, _options) { 4442 return value >= 0 && value <= 11; 4443 }, 4444 set: function (date, _flags, value, _options) { 4445 date.setUTCMonth(value, 1); 4446 date.setUTCHours(0, 0, 0, 0); 4447 return date; 4448 }, 4449 incompatibleTokens: ['Y', 'R', 'q', 'Q', 'M', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T'] 4450 }, 4451 // Local week of year 4452 w: { 4453 priority: 100, 4454 parse: function (string, token, match, _options) { 4455 switch (token) { 4456 case 'w': 4457 return parseNumericPattern(numericPatterns.week, string); 4458 4459 case 'wo': 4460 return match.ordinalNumber(string, { 4461 unit: 'week' 4462 }); 4463 4464 default: 4465 return parseNDigits(token.length, string); 4466 } 4467 }, 4468 validate: function (_date, value, _options) { 4469 return value >= 1 && value <= 53; 4470 }, 4471 set: function (date, _flags, value, options) { 4472 return startOfUTCWeek(setUTCWeek(date, value, options), options); 4473 }, 4474 incompatibleTokens: ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'i', 't', 'T'] 4475 }, 4476 // ISO week of year 4477 I: { 4478 priority: 100, 4479 parse: function (string, token, match, _options) { 4480 switch (token) { 4481 case 'I': 4482 return parseNumericPattern(numericPatterns.week, string); 4483 4484 case 'Io': 4485 return match.ordinalNumber(string, { 4486 unit: 'week' 4487 }); 4488 4489 default: 4490 return parseNDigits(token.length, string); 4491 } 4492 }, 4493 validate: function (_date, value, _options) { 4494 return value >= 1 && value <= 53; 4495 }, 4496 set: function (date, _flags, value, options) { 4497 return startOfUTCISOWeek(setUTCISOWeek(date, value, options), options); 4498 }, 4499 incompatibleTokens: ['y', 'Y', 'u', 'q', 'Q', 'M', 'L', 'w', 'd', 'D', 'e', 'c', 't', 'T'] 4500 }, 4501 // Day of the month 4502 d: { 4503 priority: 90, 4504 subPriority: 1, 4505 parse: function (string, token, match, _options) { 4506 switch (token) { 4507 case 'd': 4508 return parseNumericPattern(numericPatterns.date, string); 4509 4510 case 'do': 4511 return match.ordinalNumber(string, { 4512 unit: 'date' 4513 }); 4514 4515 default: 4516 return parseNDigits(token.length, string); 4517 } 4518 }, 4519 validate: function (date, value, _options) { 4520 var year = date.getUTCFullYear(); 4521 var isLeapYear = isLeapYearIndex$1(year); 4522 var month = date.getUTCMonth(); 4523 4524 if (isLeapYear) { 4525 return value >= 1 && value <= DAYS_IN_MONTH_LEAP_YEAR[month]; 4526 } else { 4527 return value >= 1 && value <= DAYS_IN_MONTH[month]; 4528 } 4529 }, 4530 set: function (date, _flags, value, _options) { 4531 date.setUTCDate(value); 4532 date.setUTCHours(0, 0, 0, 0); 4533 return date; 4534 }, 4535 incompatibleTokens: ['Y', 'R', 'q', 'Q', 'w', 'I', 'D', 'i', 'e', 'c', 't', 'T'] 4536 }, 4537 // Day of year 4538 D: { 4539 priority: 90, 4540 subPriority: 1, 4541 parse: function (string, token, match, _options) { 4542 switch (token) { 4543 case 'D': 4544 case 'DD': 4545 return parseNumericPattern(numericPatterns.dayOfYear, string); 4546 4547 case 'Do': 4548 return match.ordinalNumber(string, { 4549 unit: 'date' 4550 }); 4551 4552 default: 4553 return parseNDigits(token.length, string); 4554 } 4555 }, 4556 validate: function (date, value, _options) { 4557 var year = date.getUTCFullYear(); 4558 var isLeapYear = isLeapYearIndex$1(year); 4559 4560 if (isLeapYear) { 4561 return value >= 1 && value <= 366; 4562 } else { 4563 return value >= 1 && value <= 365; 4564 } 4565 }, 4566 set: function (date, _flags, value, _options) { 4567 date.setUTCMonth(0, value); 4568 date.setUTCHours(0, 0, 0, 0); 4569 return date; 4570 }, 4571 incompatibleTokens: ['Y', 'R', 'q', 'Q', 'M', 'L', 'w', 'I', 'd', 'E', 'i', 'e', 'c', 't', 'T'] 4572 }, 4573 // Day of week 4574 E: { 4575 priority: 90, 4576 parse: function (string, token, match, _options) { 4577 switch (token) { 4578 // Tue 4579 case 'E': 4580 case 'EE': 4581 case 'EEE': 4582 return match.day(string, { 4583 width: 'abbreviated', 4584 context: 'formatting' 4585 }) || match.day(string, { 4586 width: 'short', 4587 context: 'formatting' 4588 }) || match.day(string, { 4589 width: 'narrow', 4590 context: 'formatting' 4591 }); 4592 // T 4593 4594 case 'EEEEE': 4595 return match.day(string, { 4596 width: 'narrow', 4597 context: 'formatting' 4598 }); 4599 // Tu 4600 4601 case 'EEEEEE': 4602 return match.day(string, { 4603 width: 'short', 4604 context: 'formatting' 4605 }) || match.day(string, { 4606 width: 'narrow', 4607 context: 'formatting' 4608 }); 4609 // Tuesday 4610 4611 case 'EEEE': 4612 default: 4613 return match.day(string, { 4614 width: 'wide', 4615 context: 'formatting' 4616 }) || match.day(string, { 4617 width: 'abbreviated', 4618 context: 'formatting' 4619 }) || match.day(string, { 4620 width: 'short', 4621 context: 'formatting' 4622 }) || match.day(string, { 4623 width: 'narrow', 4624 context: 'formatting' 4625 }); 4626 } 4627 }, 4628 validate: function (_date, value, _options) { 4629 return value >= 0 && value <= 6; 4630 }, 4631 set: function (date, _flags, value, options) { 4632 date = setUTCDay(date, value, options); 4633 date.setUTCHours(0, 0, 0, 0); 4634 return date; 4635 }, 4636 incompatibleTokens: ['D', 'i', 'e', 'c', 't', 'T'] 4637 }, 4638 // Local day of week 4639 e: { 4640 priority: 90, 4641 parse: function (string, token, match, options) { 4642 var valueCallback = function (value) { 4643 var wholeWeekDays = Math.floor((value - 1) / 7) * 7; 4644 return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays; 4645 }; 4646 4647 switch (token) { 4648 // 3 4649 case 'e': 4650 case 'ee': 4651 // 03 4652 return parseNDigits(token.length, string, valueCallback); 4653 // 3rd 4654 4655 case 'eo': 4656 return match.ordinalNumber(string, { 4657 unit: 'day', 4658 valueCallback: valueCallback 4659 }); 4660 // Tue 4661 4662 case 'eee': 4663 return match.day(string, { 4664 width: 'abbreviated', 4665 context: 'formatting' 4666 }) || match.day(string, { 4667 width: 'short', 4668 context: 'formatting' 4669 }) || match.day(string, { 4670 width: 'narrow', 4671 context: 'formatting' 4672 }); 4673 // T 4674 4675 case 'eeeee': 4676 return match.day(string, { 4677 width: 'narrow', 4678 context: 'formatting' 4679 }); 4680 // Tu 4681 4682 case 'eeeeee': 4683 return match.day(string, { 4684 width: 'short', 4685 context: 'formatting' 4686 }) || match.day(string, { 4687 width: 'narrow', 4688 context: 'formatting' 4689 }); 4690 // Tuesday 4691 4692 case 'eeee': 4693 default: 4694 return match.day(string, { 4695 width: 'wide', 4696 context: 'formatting' 4697 }) || match.day(string, { 4698 width: 'abbreviated', 4699 context: 'formatting' 4700 }) || match.day(string, { 4701 width: 'short', 4702 context: 'formatting' 4703 }) || match.day(string, { 4704 width: 'narrow', 4705 context: 'formatting' 4706 }); 4707 } 4708 }, 4709 validate: function (_date, value, _options) { 4710 return value >= 0 && value <= 6; 4711 }, 4712 set: function (date, _flags, value, options) { 4713 date = setUTCDay(date, value, options); 4714 date.setUTCHours(0, 0, 0, 0); 4715 return date; 4716 }, 4717 incompatibleTokens: ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'c', 't', 'T'] 4718 }, 4719 // Stand-alone local day of week 4720 c: { 4721 priority: 90, 4722 parse: function (string, token, match, options) { 4723 var valueCallback = function (value) { 4724 var wholeWeekDays = Math.floor((value - 1) / 7) * 7; 4725 return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays; 4726 }; 4727 4728 switch (token) { 4729 // 3 4730 case 'c': 4731 case 'cc': 4732 // 03 4733 return parseNDigits(token.length, string, valueCallback); 4734 // 3rd 4735 4736 case 'co': 4737 return match.ordinalNumber(string, { 4738 unit: 'day', 4739 valueCallback: valueCallback 4740 }); 4741 // Tue 4742 4743 case 'ccc': 4744 return match.day(string, { 4745 width: 'abbreviated', 4746 context: 'standalone' 4747 }) || match.day(string, { 4748 width: 'short', 4749 context: 'standalone' 4750 }) || match.day(string, { 4751 width: 'narrow', 4752 context: 'standalone' 4753 }); 4754 // T 4755 4756 case 'ccccc': 4757 return match.day(string, { 4758 width: 'narrow', 4759 context: 'standalone' 4760 }); 4761 // Tu 4762 4763 case 'cccccc': 4764 return match.day(string, { 4765 width: 'short', 4766 context: 'standalone' 4767 }) || match.day(string, { 4768 width: 'narrow', 4769 context: 'standalone' 4770 }); 4771 // Tuesday 4772 4773 case 'cccc': 4774 default: 4775 return match.day(string, { 4776 width: 'wide', 4777 context: 'standalone' 4778 }) || match.day(string, { 4779 width: 'abbreviated', 4780 context: 'standalone' 4781 }) || match.day(string, { 4782 width: 'short', 4783 context: 'standalone' 4784 }) || match.day(string, { 4785 width: 'narrow', 4786 context: 'standalone' 4787 }); 4788 } 4789 }, 4790 validate: function (_date, value, _options) { 4791 return value >= 0 && value <= 6; 4792 }, 4793 set: function (date, _flags, value, options) { 4794 date = setUTCDay(date, value, options); 4795 date.setUTCHours(0, 0, 0, 0); 4796 return date; 4797 }, 4798 incompatibleTokens: ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'e', 't', 'T'] 4799 }, 4800 // ISO day of week 4801 i: { 4802 priority: 90, 4803 parse: function (string, token, match, _options) { 4804 var valueCallback = function (value) { 4805 if (value === 0) { 4806 return 7; 4807 } 4808 4809 return value; 4810 }; 4811 4812 switch (token) { 4813 // 2 4814 case 'i': 4815 case 'ii': 4816 // 02 4817 return parseNDigits(token.length, string); 4818 // 2nd 4819 4820 case 'io': 4821 return match.ordinalNumber(string, { 4822 unit: 'day' 4823 }); 4824 // Tue 4825 4826 case 'iii': 4827 return match.day(string, { 4828 width: 'abbreviated', 4829 context: 'formatting', 4830 valueCallback: valueCallback 4831 }) || match.day(string, { 4832 width: 'short', 4833 context: 'formatting', 4834 valueCallback: valueCallback 4835 }) || match.day(string, { 4836 width: 'narrow', 4837 context: 'formatting', 4838 valueCallback: valueCallback 4839 }); 4840 // T 4841 4842 case 'iiiii': 4843 return match.day(string, { 4844 width: 'narrow', 4845 context: 'formatting', 4846 valueCallback: valueCallback 4847 }); 4848 // Tu 4849 4850 case 'iiiiii': 4851 return match.day(string, { 4852 width: 'short', 4853 context: 'formatting', 4854 valueCallback: valueCallback 4855 }) || match.day(string, { 4856 width: 'narrow', 4857 context: 'formatting', 4858 valueCallback: valueCallback 4859 }); 4860 // Tuesday 4861 4862 case 'iiii': 4863 default: 4864 return match.day(string, { 4865 width: 'wide', 4866 context: 'formatting', 4867 valueCallback: valueCallback 4868 }) || match.day(string, { 4869 width: 'abbreviated', 4870 context: 'formatting', 4871 valueCallback: valueCallback 4872 }) || match.day(string, { 4873 width: 'short', 4874 context: 'formatting', 4875 valueCallback: valueCallback 4876 }) || match.day(string, { 4877 width: 'narrow', 4878 context: 'formatting', 4879 valueCallback: valueCallback 4880 }); 4881 } 4882 }, 4883 validate: function (_date, value, _options) { 4884 return value >= 1 && value <= 7; 4885 }, 4886 set: function (date, _flags, value, options) { 4887 date = setUTCISODay(date, value, options); 4888 date.setUTCHours(0, 0, 0, 0); 4889 return date; 4890 }, 4891 incompatibleTokens: ['y', 'Y', 'u', 'q', 'Q', 'M', 'L', 'w', 'd', 'D', 'E', 'e', 'c', 't', 'T'] 4892 }, 4893 // AM or PM 4894 a: { 4895 priority: 80, 4896 parse: function (string, token, match, _options) { 4897 switch (token) { 4898 case 'a': 4899 case 'aa': 4900 case 'aaa': 4901 return match.dayPeriod(string, { 4902 width: 'abbreviated', 4903 context: 'formatting' 4904 }) || match.dayPeriod(string, { 4905 width: 'narrow', 4906 context: 'formatting' 4907 }); 4908 4909 case 'aaaaa': 4910 return match.dayPeriod(string, { 4911 width: 'narrow', 4912 context: 'formatting' 4913 }); 4914 4915 case 'aaaa': 4916 default: 4917 return match.dayPeriod(string, { 4918 width: 'wide', 4919 context: 'formatting' 4920 }) || match.dayPeriod(string, { 4921 width: 'abbreviated', 4922 context: 'formatting' 4923 }) || match.dayPeriod(string, { 4924 width: 'narrow', 4925 context: 'formatting' 4926 }); 4927 } 4928 }, 4929 set: function (date, _flags, value, _options) { 4930 date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0); 4931 return date; 4932 }, 4933 incompatibleTokens: ['b', 'B', 'H', 'K', 'k', 't', 'T'] 4934 }, 4935 // AM, PM, midnight 4936 b: { 4937 priority: 80, 4938 parse: function (string, token, match, _options) { 4939 switch (token) { 4940 case 'b': 4941 case 'bb': 4942 case 'bbb': 4943 return match.dayPeriod(string, { 4944 width: 'abbreviated', 4945 context: 'formatting' 4946 }) || match.dayPeriod(string, { 4947 width: 'narrow', 4948 context: 'formatting' 4949 }); 4950 4951 case 'bbbbb': 4952 return match.dayPeriod(string, { 4953 width: 'narrow', 4954 context: 'formatting' 4955 }); 4956 4957 case 'bbbb': 4958 default: 4959 return match.dayPeriod(string, { 4960 width: 'wide', 4961 context: 'formatting' 4962 }) || match.dayPeriod(string, { 4963 width: 'abbreviated', 4964 context: 'formatting' 4965 }) || match.dayPeriod(string, { 4966 width: 'narrow', 4967 context: 'formatting' 4968 }); 4969 } 4970 }, 4971 set: function (date, _flags, value, _options) { 4972 date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0); 4973 return date; 4974 }, 4975 incompatibleTokens: ['a', 'B', 'H', 'K', 'k', 't', 'T'] 4976 }, 4977 // in the morning, in the afternoon, in the evening, at night 4978 B: { 4979 priority: 80, 4980 parse: function (string, token, match, _options) { 4981 switch (token) { 4982 case 'B': 4983 case 'BB': 4984 case 'BBB': 4985 return match.dayPeriod(string, { 4986 width: 'abbreviated', 4987 context: 'formatting' 4988 }) || match.dayPeriod(string, { 4989 width: 'narrow', 4990 context: 'formatting' 4991 }); 4992 4993 case 'BBBBB': 4994 return match.dayPeriod(string, { 4995 width: 'narrow', 4996 context: 'formatting' 4997 }); 4998 4999 case 'BBBB': 5000 default: 5001 return match.dayPeriod(string, { 5002 width: 'wide', 5003 context: 'formatting' 5004 }) || match.dayPeriod(string, { 5005 width: 'abbreviated', 5006 context: 'formatting' 5007 }) || match.dayPeriod(string, { 5008 width: 'narrow', 5009 context: 'formatting' 5010 }); 5011 } 5012 }, 5013 set: function (date, _flags, value, _options) { 5014 date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0); 5015 return date; 5016 }, 5017 incompatibleTokens: ['a', 'b', 't', 'T'] 5018 }, 5019 // Hour [1-12] 5020 h: { 5021 priority: 70, 5022 parse: function (string, token, match, _options) { 5023 switch (token) { 5024 case 'h': 5025 return parseNumericPattern(numericPatterns.hour12h, string); 5026 5027 case 'ho': 5028 return match.ordinalNumber(string, { 5029 unit: 'hour' 5030 }); 5031 5032 default: 5033 return parseNDigits(token.length, string); 5034 } 5035 }, 5036 validate: function (_date, value, _options) { 5037 return value >= 1 && value <= 12; 5038 }, 5039 set: function (date, _flags, value, _options) { 5040 var isPM = date.getUTCHours() >= 12; 5041 5042 if (isPM && value < 12) { 5043 date.setUTCHours(value + 12, 0, 0, 0); 5044 } else if (!isPM && value === 12) { 5045 date.setUTCHours(0, 0, 0, 0); 5046 } else { 5047 date.setUTCHours(value, 0, 0, 0); 5048 } 5049 5050 return date; 5051 }, 5052 incompatibleTokens: ['H', 'K', 'k', 't', 'T'] 5053 }, 5054 // Hour [0-23] 5055 H: { 5056 priority: 70, 5057 parse: function (string, token, match, _options) { 5058 switch (token) { 5059 case 'H': 5060 return parseNumericPattern(numericPatterns.hour23h, string); 5061 5062 case 'Ho': 5063 return match.ordinalNumber(string, { 5064 unit: 'hour' 5065 }); 5066 5067 default: 5068 return parseNDigits(token.length, string); 5069 } 5070 }, 5071 validate: function (_date, value, _options) { 5072 return value >= 0 && value <= 23; 5073 }, 5074 set: function (date, _flags, value, _options) { 5075 date.setUTCHours(value, 0, 0, 0); 5076 return date; 5077 }, 5078 incompatibleTokens: ['a', 'b', 'h', 'K', 'k', 't', 'T'] 5079 }, 5080 // Hour [0-11] 5081 K: { 5082 priority: 70, 5083 parse: function (string, token, match, _options) { 5084 switch (token) { 5085 case 'K': 5086 return parseNumericPattern(numericPatterns.hour11h, string); 5087 5088 case 'Ko': 5089 return match.ordinalNumber(string, { 5090 unit: 'hour' 5091 }); 5092 5093 default: 5094 return parseNDigits(token.length, string); 5095 } 5096 }, 5097 validate: function (_date, value, _options) { 5098 return value >= 0 && value <= 11; 5099 }, 5100 set: function (date, _flags, value, _options) { 5101 var isPM = date.getUTCHours() >= 12; 5102 5103 if (isPM && value < 12) { 5104 date.setUTCHours(value + 12, 0, 0, 0); 5105 } else { 5106 date.setUTCHours(value, 0, 0, 0); 5107 } 5108 5109 return date; 5110 }, 5111 incompatibleTokens: ['a', 'b', 'h', 'H', 'k', 't', 'T'] 5112 }, 5113 // Hour [1-24] 5114 k: { 5115 priority: 70, 5116 parse: function (string, token, match, _options) { 5117 switch (token) { 5118 case 'k': 5119 return parseNumericPattern(numericPatterns.hour24h, string); 5120 5121 case 'ko': 5122 return match.ordinalNumber(string, { 5123 unit: 'hour' 5124 }); 5125 5126 default: 5127 return parseNDigits(token.length, string); 5128 } 5129 }, 5130 validate: function (_date, value, _options) { 5131 return value >= 1 && value <= 24; 5132 }, 5133 set: function (date, _flags, value, _options) { 5134 var hours = value <= 24 ? value % 24 : value; 5135 date.setUTCHours(hours, 0, 0, 0); 5136 return date; 5137 }, 5138 incompatibleTokens: ['a', 'b', 'h', 'H', 'K', 't', 'T'] 5139 }, 5140 // Minute 5141 m: { 5142 priority: 60, 5143 parse: function (string, token, match, _options) { 5144 switch (token) { 5145 case 'm': 5146 return parseNumericPattern(numericPatterns.minute, string); 5147 5148 case 'mo': 5149 return match.ordinalNumber(string, { 5150 unit: 'minute' 5151 }); 5152 5153 default: 5154 return parseNDigits(token.length, string); 5155 } 5156 }, 5157 validate: function (_date, value, _options) { 5158 return value >= 0 && value <= 59; 5159 }, 5160 set: function (date, _flags, value, _options) { 5161 date.setUTCMinutes(value, 0, 0); 5162 return date; 5163 }, 5164 incompatibleTokens: ['t', 'T'] 5165 }, 5166 // Second 5167 s: { 5168 priority: 50, 5169 parse: function (string, token, match, _options) { 5170 switch (token) { 5171 case 's': 5172 return parseNumericPattern(numericPatterns.second, string); 5173 5174 case 'so': 5175 return match.ordinalNumber(string, { 5176 unit: 'second' 5177 }); 5178 5179 default: 5180 return parseNDigits(token.length, string); 5181 } 5182 }, 5183 validate: function (_date, value, _options) { 5184 return value >= 0 && value <= 59; 5185 }, 5186 set: function (date, _flags, value, _options) { 5187 date.setUTCSeconds(value, 0); 5188 return date; 5189 }, 5190 incompatibleTokens: ['t', 'T'] 5191 }, 5192 // Fraction of second 5193 S: { 5194 priority: 30, 5195 parse: function (string, token, _match, _options) { 5196 var valueCallback = function (value) { 5197 return Math.floor(value * Math.pow(10, -token.length + 3)); 5198 }; 5199 5200 return parseNDigits(token.length, string, valueCallback); 5201 }, 5202 set: function (date, _flags, value, _options) { 5203 date.setUTCMilliseconds(value); 5204 return date; 5205 }, 5206 incompatibleTokens: ['t', 'T'] 5207 }, 5208 // Timezone (ISO-8601. +00:00 is `'Z'`) 5209 X: { 5210 priority: 10, 5211 parse: function (string, token, _match, _options) { 5212 switch (token) { 5213 case 'X': 5214 return parseTimezonePattern(timezonePatterns.basicOptionalMinutes, string); 5215 5216 case 'XX': 5217 return parseTimezonePattern(timezonePatterns.basic, string); 5218 5219 case 'XXXX': 5220 return parseTimezonePattern(timezonePatterns.basicOptionalSeconds, string); 5221 5222 case 'XXXXX': 5223 return parseTimezonePattern(timezonePatterns.extendedOptionalSeconds, string); 5224 5225 case 'XXX': 5226 default: 5227 return parseTimezonePattern(timezonePatterns.extended, string); 5228 } 5229 }, 5230 set: function (date, flags, value, _options) { 5231 if (flags.timestampIsSet) { 5232 return date; 5233 } 5234 5235 return new Date(date.getTime() - value); 5236 }, 5237 incompatibleTokens: ['t', 'T', 'x'] 5238 }, 5239 // Timezone (ISO-8601) 5240 x: { 5241 priority: 10, 5242 parse: function (string, token, _match, _options) { 5243 switch (token) { 5244 case 'x': 5245 return parseTimezonePattern(timezonePatterns.basicOptionalMinutes, string); 5246 5247 case 'xx': 5248 return parseTimezonePattern(timezonePatterns.basic, string); 5249 5250 case 'xxxx': 5251 return parseTimezonePattern(timezonePatterns.basicOptionalSeconds, string); 5252 5253 case 'xxxxx': 5254 return parseTimezonePattern(timezonePatterns.extendedOptionalSeconds, string); 5255 5256 case 'xxx': 5257 default: 5258 return parseTimezonePattern(timezonePatterns.extended, string); 5259 } 5260 }, 5261 set: function (date, flags, value, _options) { 5262 if (flags.timestampIsSet) { 5263 return date; 5264 } 5265 5266 return new Date(date.getTime() - value); 5267 }, 5268 incompatibleTokens: ['t', 'T', 'X'] 5269 }, 5270 // Seconds timestamp 5271 t: { 5272 priority: 40, 5273 parse: function (string, _token, _match, _options) { 5274 return parseAnyDigitsSigned(string); 5275 }, 5276 set: function (_date, _flags, value, _options) { 5277 return [new Date(value * 1000), { 5278 timestampIsSet: true 5279 }]; 5280 }, 5281 incompatibleTokens: '*' 5282 }, 5283 // Milliseconds timestamp 5284 T: { 5285 priority: 20, 5286 parse: function (string, _token, _match, _options) { 5287 return parseAnyDigitsSigned(string); 5288 }, 5289 set: function (_date, _flags, value, _options) { 5290 return [new Date(value), { 5291 timestampIsSet: true 5292 }]; 5293 }, 5294 incompatibleTokens: '*' 5295 } 5296}; 5297var parsers$1 = parsers; 5298 5299var TIMEZONE_UNIT_PRIORITY = 10; // This RegExp consists of three parts separated by `|`: 5300// - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token 5301// (one of the certain letters followed by `o`) 5302// - (\w)\1* matches any sequences of the same letter 5303// - '' matches two quote characters in a row 5304// - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('), 5305// except a single quote symbol, which ends the sequence. 5306// Two quote characters do not end the sequence. 5307// If there is no matching single quote 5308// then the sequence will continue until the end of the string. 5309// - . matches any single character unmatched by previous parts of the RegExps 5310 5311var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g; // This RegExp catches symbols escaped by quotes, and also 5312// sequences of symbols P, p, and the combinations like `PPPPPPPppppp` 5313 5314var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g; 5315var escapedStringRegExp = /^'([^]*?)'?$/; 5316var doubleQuoteRegExp = /''/g; 5317var notWhitespaceRegExp = /\S/; 5318var unescapedLatinCharacterRegExp = /[a-zA-Z]/; 5319/** 5320 * @name parse 5321 * @category Common Helpers 5322 * @summary Parse the date. 5323 * 5324 * @description 5325 * Return the date parsed from string using the given format string. 5326 * 5327 * > â ï¸ Please note that the `format` tokens differ from Moment.js and other libraries. 5328 * > See: https://git.io/fxCyr 5329 * 5330 * The characters in the format string wrapped between two single quotes characters (') are escaped. 5331 * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. 5332 * 5333 * Format of the format string is based on Unicode Technical Standard #35: 5334 * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table 5335 * with a few additions (see note 5 below the table). 5336 * 5337 * Not all tokens are compatible. Combinations that don't make sense or could lead to bugs are prohibited 5338 * and will throw `RangeError`. For example usage of 24-hour format token with AM/PM token will throw an exception: 5339 * 5340 * ```javascript 5341 * parse('23 AM', 'HH a', new Date()) 5342 * //=> RangeError: The format string mustn't contain `HH` and `a` at the same time 5343 * ``` 5344 * 5345 * See the compatibility table: https://docs.google.com/spreadsheets/d/e/2PACX-1vQOPU3xUhplll6dyoMmVUXHKl_8CRDs6_ueLmex3SoqwhuolkuN3O05l4rqx5h1dKX8eb46Ul-CCSrq/pubhtml?gid=0&single=true 5346 * 5347 * Accepted format string patterns: 5348 * | Unit |Prior| Pattern | Result examples | Notes | 5349 * |---------------------------------|-----|---------|-----------------------------------|-------| 5350 * | Era | 140 | G..GGG | AD, BC | | 5351 * | | | GGGG | Anno Domini, Before Christ | 2 | 5352 * | | | GGGGG | A, B | | 5353 * | Calendar year | 130 | y | 44, 1, 1900, 2017, 9999 | 4 | 5354 * | | | yo | 44th, 1st, 1900th, 9999999th | 4,5 | 5355 * | | | yy | 44, 01, 00, 17 | 4 | 5356 * | | | yyy | 044, 001, 123, 999 | 4 | 5357 * | | | yyyy | 0044, 0001, 1900, 2017 | 4 | 5358 * | | | yyyyy | ... | 2,4 | 5359 * | Local week-numbering year | 130 | Y | 44, 1, 1900, 2017, 9000 | 4 | 5360 * | | | Yo | 44th, 1st, 1900th, 9999999th | 4,5 | 5361 * | | | YY | 44, 01, 00, 17 | 4,6 | 5362 * | | | YYY | 044, 001, 123, 999 | 4 | 5363 * | | | YYYY | 0044, 0001, 1900, 2017 | 4,6 | 5364 * | | | YYYYY | ... | 2,4 | 5365 * | ISO week-numbering year | 130 | R | -43, 1, 1900, 2017, 9999, -9999 | 4,5 | 5366 * | | | RR | -43, 01, 00, 17 | 4,5 | 5367 * | | | RRR | -043, 001, 123, 999, -999 | 4,5 | 5368 * | | | RRRR | -0043, 0001, 2017, 9999, -9999 | 4,5 | 5369 * | | | RRRRR | ... | 2,4,5 | 5370 * | Extended year | 130 | u | -43, 1, 1900, 2017, 9999, -999 | 4 | 5371 * | | | uu | -43, 01, 99, -99 | 4 | 5372 * | | | uuu | -043, 001, 123, 999, -999 | 4 | 5373 * | | | uuuu | -0043, 0001, 2017, 9999, -9999 | 4 | 5374 * | | | uuuuu | ... | 2,4 | 5375 * | Quarter (formatting) | 120 | Q | 1, 2, 3, 4 | | 5376 * | | | Qo | 1st, 2nd, 3rd, 4th | 5 | 5377 * | | | QQ | 01, 02, 03, 04 | | 5378 * | | | QQQ | Q1, Q2, Q3, Q4 | | 5379 * | | | QQQQ | 1st quarter, 2nd quarter, ... | 2 | 5380 * | | | QQQQQ | 1, 2, 3, 4 | 4 | 5381 * | Quarter (stand-alone) | 120 | q | 1, 2, 3, 4 | | 5382 * | | | qo | 1st, 2nd, 3rd, 4th | 5 | 5383 * | | | qq | 01, 02, 03, 04 | | 5384 * | | | qqq | Q1, Q2, Q3, Q4 | | 5385 * | | | qqqq | 1st quarter, 2nd quarter, ... | 2 | 5386 * | | | qqqqq | 1, 2, 3, 4 | 3 | 5387 * | Month (formatting) | 110 | M | 1, 2, ..., 12 | | 5388 * | | | Mo | 1st, 2nd, ..., 12th | 5 | 5389 * | | | MM | 01, 02, ..., 12 | | 5390 * | | | MMM | Jan, Feb, ..., Dec | | 5391 * | | | MMMM | January, February, ..., December | 2 | 5392 * | | | MMMMM | J, F, ..., D | | 5393 * | Month (stand-alone) | 110 | L | 1, 2, ..., 12 | | 5394 * | | | Lo | 1st, 2nd, ..., 12th | 5 | 5395 * | | | LL | 01, 02, ..., 12 | | 5396 * | | | LLL | Jan, Feb, ..., Dec | | 5397 * | | | LLLL | January, February, ..., December | 2 | 5398 * | | | LLLLL | J, F, ..., D | | 5399 * | Local week of year | 100 | w | 1, 2, ..., 53 | | 5400 * | | | wo | 1st, 2nd, ..., 53th | 5 | 5401 * | | | ww | 01, 02, ..., 53 | | 5402 * | ISO week of year | 100 | I | 1, 2, ..., 53 | 5 | 5403 * | | | Io | 1st, 2nd, ..., 53th | 5 | 5404 * | | | II | 01, 02, ..., 53 | 5 | 5405 * | Day of month | 90 | d | 1, 2, ..., 31 | | 5406 * | | | do | 1st, 2nd, ..., 31st | 5 | 5407 * | | | dd | 01, 02, ..., 31 | | 5408 * | Day of year | 90 | D | 1, 2, ..., 365, 366 | 7 | 5409 * | | | Do | 1st, 2nd, ..., 365th, 366th | 5 | 5410 * | | | DD | 01, 02, ..., 365, 366 | 7 | 5411 * | | | DDD | 001, 002, ..., 365, 366 | | 5412 * | | | DDDD | ... | 2 | 5413 * | Day of week (formatting) | 90 | E..EEE | Mon, Tue, Wed, ..., Sun | | 5414 * | | | EEEE | Monday, Tuesday, ..., Sunday | 2 | 5415 * | | | EEEEE | M, T, W, T, F, S, S | | 5416 * | | | EEEEEE | Mo, Tu, We, Th, Fr, Su, Sa | | 5417 * | ISO day of week (formatting) | 90 | i | 1, 2, 3, ..., 7 | 5 | 5418 * | | | io | 1st, 2nd, ..., 7th | 5 | 5419 * | | | ii | 01, 02, ..., 07 | 5 | 5420 * | | | iii | Mon, Tue, Wed, ..., Sun | 5 | 5421 * | | | iiii | Monday, Tuesday, ..., Sunday | 2,5 | 5422 * | | | iiiii | M, T, W, T, F, S, S | 5 | 5423 * | | | iiiiii | Mo, Tu, We, Th, Fr, Su, Sa | 5 | 5424 * | Local day of week (formatting) | 90 | e | 2, 3, 4, ..., 1 | | 5425 * | | | eo | 2nd, 3rd, ..., 1st | 5 | 5426 * | | | ee | 02, 03, ..., 01 | | 5427 * | | | eee | Mon, Tue, Wed, ..., Sun | | 5428 * | | | eeee | Monday, Tuesday, ..., Sunday | 2 | 5429 * | | | eeeee | M, T, W, T, F, S, S | | 5430 * | | | eeeeee | Mo, Tu, We, Th, Fr, Su, Sa | | 5431 * | Local day of week (stand-alone) | 90 | c | 2, 3, 4, ..., 1 | | 5432 * | | | co | 2nd, 3rd, ..., 1st | 5 | 5433 * | | | cc | 02, 03, ..., 01 | | 5434 * | | | ccc | Mon, Tue, Wed, ..., Sun | | 5435 * | | | cccc | Monday, Tuesday, ..., Sunday | 2 | 5436 * | | | ccccc | M, T, W, T, F, S, S | | 5437 * | | | cccccc | Mo, Tu, We, Th, Fr, Su, Sa | | 5438 * | AM, PM | 80 | a..aaa | AM, PM | | 5439 * | | | aaaa | a.m., p.m. | 2 | 5440 * | | | aaaaa | a, p | | 5441 * | AM, PM, noon, midnight | 80 | b..bbb | AM, PM, noon, midnight | | 5442 * | | | bbbb | a.m., p.m., noon, midnight | 2 | 5443 * | | | bbbbb | a, p, n, mi | | 5444 * | Flexible day period | 80 | B..BBB | at night, in the morning, ... | | 5445 * | | | BBBB | at night, in the morning, ... | 2 | 5446 * | | | BBBBB | at night, in the morning, ... | | 5447 * | Hour [1-12] | 70 | h | 1, 2, ..., 11, 12 | | 5448 * | | | ho | 1st, 2nd, ..., 11th, 12th | 5 | 5449 * | | | hh | 01, 02, ..., 11, 12 | | 5450 * | Hour [0-23] | 70 | H | 0, 1, 2, ..., 23 | | 5451 * | | | Ho | 0th, 1st, 2nd, ..., 23rd | 5 | 5452 * | | | HH | 00, 01, 02, ..., 23 | | 5453 * | Hour [0-11] | 70 | K | 1, 2, ..., 11, 0 | | 5454 * | | | Ko | 1st, 2nd, ..., 11th, 0th | 5 | 5455 * | | | KK | 01, 02, ..., 11, 00 | | 5456 * | Hour [1-24] | 70 | k | 24, 1, 2, ..., 23 | | 5457 * | | | ko | 24th, 1st, 2nd, ..., 23rd | 5 | 5458 * | | | kk | 24, 01, 02, ..., 23 | | 5459 * | Minute | 60 | m | 0, 1, ..., 59 | | 5460 * | | | mo | 0th, 1st, ..., 59th | 5 | 5461 * | | | mm | 00, 01, ..., 59 | | 5462 * | Second | 50 | s | 0, 1, ..., 59 | | 5463 * | | | so | 0th, 1st, ..., 59th | 5 | 5464 * | | | ss | 00, 01, ..., 59 | | 5465 * | Seconds timestamp | 40 | t | 512969520 | | 5466 * | | | tt | ... | 2 | 5467 * | Fraction of second | 30 | S | 0, 1, ..., 9 | | 5468 * | | | SS | 00, 01, ..., 99 | | 5469 * | | | SSS | 000, 0001, ..., 999 | | 5470 * | | | SSSS | ... | 2 | 5471 * | Milliseconds timestamp | 20 | T | 512969520900 | | 5472 * | | | TT | ... | 2 | 5473 * | Timezone (ISO-8601 w/ Z) | 10 | X | -08, +0530, Z | | 5474 * | | | XX | -0800, +0530, Z | | 5475 * | | | XXX | -08:00, +05:30, Z | | 5476 * | | | XXXX | -0800, +0530, Z, +123456 | 2 | 5477 * | | | XXXXX | -08:00, +05:30, Z, +12:34:56 | | 5478 * | Timezone (ISO-8601 w/o Z) | 10 | x | -08, +0530, +00 | | 5479 * | | | xx | -0800, +0530, +0000 | | 5480 * | | | xxx | -08:00, +05:30, +00:00 | 2 | 5481 * | | | xxxx | -0800, +0530, +0000, +123456 | | 5482 * | | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | | 5483 * | Long localized date | NA | P | 05/29/1453 | 5,8 | 5484 * | | | PP | May 29, 1453 | | 5485 * | | | PPP | May 29th, 1453 | | 5486 * | | | PPPP | Sunday, May 29th, 1453 | 2,5,8 | 5487 * | Long localized time | NA | p | 12:00 AM | 5,8 | 5488 * | | | pp | 12:00:00 AM | | 5489 * | Combination of date and time | NA | Pp | 05/29/1453, 12:00 AM | | 5490 * | | | PPpp | May 29, 1453, 12:00:00 AM | | 5491 * | | | PPPpp | May 29th, 1453 at ... | | 5492 * | | | PPPPpp | Sunday, May 29th, 1453 at ... | 2,5,8 | 5493 * Notes: 5494 * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale 5495 * are the same as "stand-alone" units, but are different in some languages. 5496 * "Formatting" units are declined according to the rules of the language 5497 * in the context of a date. "Stand-alone" units are always nominative singular. 5498 * In `format` function, they will produce different result: 5499 * 5500 * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'` 5501 * 5502 * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'` 5503 * 5504 * `parse` will try to match both formatting and stand-alone units interchangably. 5505 * 5506 * 2. Any sequence of the identical letters is a pattern, unless it is escaped by 5507 * the single quote characters (see below). 5508 * If the sequence is longer than listed in table: 5509 * - for numerical units (`yyyyyyyy`) `parse` will try to match a number 5510 * as wide as the sequence 5511 * - for text units (`MMMMMMMM`) `parse` will try to match the widest variation of the unit. 5512 * These variations are marked with "2" in the last column of the table. 5513 * 5514 * 3. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales. 5515 * These tokens represent the shortest form of the quarter. 5516 * 5517 * 4. The main difference between `y` and `u` patterns are B.C. years: 5518 * 5519 * | Year | `y` | `u` | 5520 * |------|-----|-----| 5521 * | AC 1 | 1 | 1 | 5522 * | BC 1 | 1 | 0 | 5523 * | BC 2 | 2 | -1 | 5524 * 5525 * Also `yy` will try to guess the century of two digit year by proximity with `referenceDate`: 5526 * 5527 * `parse('50', 'yy', new Date(2018, 0, 1)) //=> Sat Jan 01 2050 00:00:00` 5528 * 5529 * `parse('75', 'yy', new Date(2018, 0, 1)) //=> Wed Jan 01 1975 00:00:00` 5530 * 5531 * while `uu` will just assign the year as is: 5532 * 5533 * `parse('50', 'uu', new Date(2018, 0, 1)) //=> Sat Jan 01 0050 00:00:00` 5534 * 5535 * `parse('75', 'uu', new Date(2018, 0, 1)) //=> Tue Jan 01 0075 00:00:00` 5536 * 5537 * The same difference is true for local and ISO week-numbering years (`Y` and `R`), 5538 * except local week-numbering years are dependent on `options.weekStartsOn` 5539 * and `options.firstWeekContainsDate` (compare [setISOWeekYear]{@link https://date-fns.org/docs/setISOWeekYear} 5540 * and [setWeekYear]{@link https://date-fns.org/docs/setWeekYear}). 5541 * 5542 * 5. These patterns are not in the Unicode Technical Standard #35: 5543 * - `i`: ISO day of week 5544 * - `I`: ISO week of year 5545 * - `R`: ISO week-numbering year 5546 * - `o`: ordinal number modifier 5547 * - `P`: long localized date 5548 * - `p`: long localized time 5549 * 5550 * 6. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years. 5551 * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://git.io/fxCyr 5552 * 5553 * 7. `D` and `DD` tokens represent days of the year but they are ofthen confused with days of the month. 5554 * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://git.io/fxCyr 5555 * 5556 * 8. `P+` tokens do not have a defined priority since they are merely aliases to other tokens based 5557 * on the given locale. 5558 * 5559 * using `en-US` locale: `P` => `MM/dd/yyyy` 5560 * using `en-US` locale: `p` => `hh:mm a` 5561 * using `pt-BR` locale: `P` => `dd/MM/yyyy` 5562 * using `pt-BR` locale: `p` => `HH:mm` 5563 * 5564 * Values will be assigned to the date in the descending order of its unit's priority. 5565 * Units of an equal priority overwrite each other in the order of appearance. 5566 * 5567 * If no values of higher priority are parsed (e.g. when parsing string 'January 1st' without a year), 5568 * the values will be taken from 3rd argument `referenceDate` which works as a context of parsing. 5569 * 5570 * `referenceDate` must be passed for correct work of the function. 5571 * If you're not sure which `referenceDate` to supply, create a new instance of Date: 5572 * `parse('02/11/2014', 'MM/dd/yyyy', new Date())` 5573 * In this case parsing will be done in the context of the current date. 5574 * If `referenceDate` is `Invalid Date` or a value not convertible to valid `Date`, 5575 * then `Invalid Date` will be returned. 5576 * 5577 * The result may vary by locale. 5578 * 5579 * If `formatString` matches with `dateString` but does not provides tokens, `referenceDate` will be returned. 5580 * 5581 * If parsing failed, `Invalid Date` will be returned. 5582 * Invalid Date is a Date, whose time value is NaN. 5583 * Time value of Date: http://es5.github.io/#x15.9.1.1 5584 * 5585 * ### v2.0.0 breaking changes: 5586 * 5587 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 5588 * 5589 * - Old `parse` was renamed to `toDate`. 5590 * Now `parse` is a new function which parses a string using a provided format. 5591 * 5592 * ```javascript 5593 * // Before v2.0.0 5594 * parse('2016-01-01') 5595 * 5596 * // v2.0.0 onward (toDate no longer accepts a string) 5597 * toDate(1392098430000) // Unix to timestamp 5598 * toDate(new Date(2014, 1, 11, 11, 30, 30)) // Cloning the date 5599 * parse('2016-01-01', 'yyyy-MM-dd', new Date()) 5600 * ``` 5601 * 5602 * @param {String} dateString - the string to parse 5603 * @param {String} formatString - the string of tokens 5604 * @param {Date|Number} referenceDate - defines values missing from the parsed dateString 5605 * @param {Object} [options] - an object with options. 5606 * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} 5607 * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday) 5608 * @param {1|2|3|4|5|6|7} [options.firstWeekContainsDate=1] - the day of January, which is always in the first week of the year 5609 * @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`; 5610 * see: https://git.io/fxCyr 5611 * @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`; 5612 * see: https://git.io/fxCyr 5613 * @returns {Date} the parsed date 5614 * @throws {TypeError} 3 arguments required 5615 * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6 5616 * @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7 5617 * @throws {RangeError} `options.locale` must contain `match` property 5618 * @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://git.io/fxCyr 5619 * @throws {RangeError} use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://git.io/fxCyr 5620 * @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 5621 * @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 5622 * @throws {RangeError} format string contains an unescaped latin alphabet character 5623 * 5624 * @example 5625 * // Parse 11 February 2014 from middle-endian format: 5626 * var result = parse('02/11/2014', 'MM/dd/yyyy', new Date()) 5627 * //=> Tue Feb 11 2014 00:00:00 5628 * 5629 * @example 5630 * // Parse 28th of February in Esperanto locale in the context of 2010 year: 5631 * import eo from 'date-fns/locale/eo' 5632 * var result = parse('28-a de februaro', "do 'de' MMMM", new Date(2010, 0, 1), { 5633 * locale: eo 5634 * }) 5635 * //=> Sun Feb 28 2010 00:00:00 5636 */ 5637 5638function parse(dirtyDateString, dirtyFormatString, dirtyReferenceDate, dirtyOptions) { 5639 requiredArgs(3, arguments); 5640 var dateString = String(dirtyDateString); 5641 var formatString = String(dirtyFormatString); 5642 var options = dirtyOptions || {}; 5643 var locale = options.locale || defaultLocale; 5644 5645 if (!locale.match) { 5646 throw new RangeError('locale must contain match property'); 5647 } 5648 5649 var localeFirstWeekContainsDate = locale.options && locale.options.firstWeekContainsDate; 5650 var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate); 5651 var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN 5652 5653 if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) { 5654 throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively'); 5655 } 5656 5657 var localeWeekStartsOn = locale.options && locale.options.weekStartsOn; 5658 var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); 5659 var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN 5660 5661 if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { 5662 throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); 5663 } 5664 5665 if (formatString === '') { 5666 if (dateString === '') { 5667 return toDate(dirtyReferenceDate); 5668 } else { 5669 return new Date(NaN); 5670 } 5671 } 5672 5673 var subFnOptions = { 5674 firstWeekContainsDate: firstWeekContainsDate, 5675 weekStartsOn: weekStartsOn, 5676 locale: locale // If timezone isn't specified, it will be set to the system timezone 5677 5678 }; 5679 var setters = [{ 5680 priority: TIMEZONE_UNIT_PRIORITY, 5681 subPriority: -1, 5682 set: dateToSystemTimezone, 5683 index: 0 5684 }]; 5685 var i; 5686 var tokens = formatString.match(longFormattingTokensRegExp).map(function (substring) { 5687 var firstCharacter = substring[0]; 5688 5689 if (firstCharacter === 'p' || firstCharacter === 'P') { 5690 var longFormatter = longFormatters$1[firstCharacter]; 5691 return longFormatter(substring, locale.formatLong, subFnOptions); 5692 } 5693 5694 return substring; 5695 }).join('').match(formattingTokensRegExp); 5696 var usedTokens = []; 5697 5698 for (i = 0; i < tokens.length; i++) { 5699 var token = tokens[i]; 5700 5701 if (!options.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token)) { 5702 throwProtectedError(token, formatString, dirtyDateString); 5703 } 5704 5705 if (!options.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) { 5706 throwProtectedError(token, formatString, dirtyDateString); 5707 } 5708 5709 var firstCharacter = token[0]; 5710 var parser = parsers$1[firstCharacter]; 5711 5712 if (parser) { 5713 var incompatibleTokens = parser.incompatibleTokens; 5714 5715 if (Array.isArray(incompatibleTokens)) { 5716 var incompatibleToken = void 0; 5717 5718 for (var _i = 0; _i < usedTokens.length; _i++) { 5719 var usedToken = usedTokens[_i].token; 5720 5721 if (incompatibleTokens.indexOf(usedToken) !== -1 || usedToken === firstCharacter) { 5722 incompatibleToken = usedTokens[_i]; 5723 break; 5724 } 5725 } 5726 5727 if (incompatibleToken) { 5728 throw new RangeError("The format string mustn't contain `".concat(incompatibleToken.fullToken, "` and `").concat(token, "` at the same time")); 5729 } 5730 } else if (parser.incompatibleTokens === '*' && usedTokens.length) { 5731 throw new RangeError("The format string mustn't contain `".concat(token, "` and any other token at the same time")); 5732 } 5733 5734 usedTokens.push({ 5735 token: firstCharacter, 5736 fullToken: token 5737 }); 5738 var parseResult = parser.parse(dateString, token, locale.match, subFnOptions); 5739 5740 if (!parseResult) { 5741 return new Date(NaN); 5742 } 5743 5744 setters.push({ 5745 priority: parser.priority, 5746 subPriority: parser.subPriority || 0, 5747 set: parser.set, 5748 validate: parser.validate, 5749 value: parseResult.value, 5750 index: setters.length 5751 }); 5752 dateString = parseResult.rest; 5753 } else { 5754 if (firstCharacter.match(unescapedLatinCharacterRegExp)) { 5755 throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`'); 5756 } // Replace two single quote characters with one single quote character 5757 5758 5759 if (token === "''") { 5760 token = "'"; 5761 } else if (firstCharacter === "'") { 5762 token = cleanEscapedString(token); 5763 } // Cut token from string, or, if string doesn't match the token, return Invalid Date 5764 5765 5766 if (dateString.indexOf(token) === 0) { 5767 dateString = dateString.slice(token.length); 5768 } else { 5769 return new Date(NaN); 5770 } 5771 } 5772 } // Check if the remaining input contains something other than whitespace 5773 5774 5775 if (dateString.length > 0 && notWhitespaceRegExp.test(dateString)) { 5776 return new Date(NaN); 5777 } 5778 5779 var uniquePrioritySetters = setters.map(function (setter) { 5780 return setter.priority; 5781 }).sort(function (a, b) { 5782 return b - a; 5783 }).filter(function (priority, index, array) { 5784 return array.indexOf(priority) === index; 5785 }).map(function (priority) { 5786 return setters.filter(function (setter) { 5787 return setter.priority === priority; 5788 }).sort(function (a, b) { 5789 return b.subPriority - a.subPriority; 5790 }); 5791 }).map(function (setterArray) { 5792 return setterArray[0]; 5793 }); 5794 var date = toDate(dirtyReferenceDate); 5795 5796 if (isNaN(date)) { 5797 return new Date(NaN); 5798 } // Convert the date in system timezone to the same date in UTC+00:00 timezone. 5799 // This ensures that when UTC functions will be implemented, locales will be compatible with them. 5800 // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/37 5801 5802 5803 var utcDate = subMilliseconds(date, getTimezoneOffsetInMilliseconds(date)); 5804 var flags = {}; 5805 5806 for (i = 0; i < uniquePrioritySetters.length; i++) { 5807 var setter = uniquePrioritySetters[i]; 5808 5809 if (setter.validate && !setter.validate(utcDate, setter.value, subFnOptions)) { 5810 return new Date(NaN); 5811 } 5812 5813 var result = setter.set(utcDate, flags, setter.value, subFnOptions); // Result is tuple (date, flags) 5814 5815 if (result[0]) { 5816 utcDate = result[0]; 5817 assign(flags, result[1]); // Result is date 5818 } else { 5819 utcDate = result; 5820 } 5821 } 5822 5823 return utcDate; 5824} 5825 5826function dateToSystemTimezone(date, flags) { 5827 if (flags.timestampIsSet) { 5828 return date; 5829 } 5830 5831 var convertedDate = new Date(0); 5832 convertedDate.setFullYear(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()); 5833 convertedDate.setHours(date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()); 5834 return convertedDate; 5835} 5836 5837function cleanEscapedString(input) { 5838 return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'"); 5839} 5840 5841/** 5842 * @name startOfHour 5843 * @category Hour Helpers 5844 * @summary Return the start of an hour for the given date. 5845 * 5846 * @description 5847 * Return the start of an hour for the given date. 5848 * The result will be in the local timezone. 5849 * 5850 * ### v2.0.0 breaking changes: 5851 * 5852 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 5853 * 5854 * @param {Date|Number} date - the original date 5855 * @returns {Date} the start of an hour 5856 * @throws {TypeError} 1 argument required 5857 * 5858 * @example 5859 * // The start of an hour for 2 September 2014 11:55:00: 5860 * const result = startOfHour(new Date(2014, 8, 2, 11, 55)) 5861 * //=> Tue Sep 02 2014 11:00:00 5862 */ 5863 5864function startOfHour(dirtyDate) { 5865 requiredArgs(1, arguments); 5866 var date = toDate(dirtyDate); 5867 date.setMinutes(0, 0, 0); 5868 return date; 5869} 5870 5871/** 5872 * @name startOfMinute 5873 * @category Minute Helpers 5874 * @summary Return the start of a minute for the given date. 5875 * 5876 * @description 5877 * Return the start of a minute for the given date. 5878 * The result will be in the local timezone. 5879 * 5880 * ### v2.0.0 breaking changes: 5881 * 5882 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 5883 * 5884 * @param {Date|Number} date - the original date 5885 * @returns {Date} the start of a minute 5886 * @throws {TypeError} 1 argument required 5887 * 5888 * @example 5889 * // The start of a minute for 1 December 2014 22:15:45.400: 5890 * const result = startOfMinute(new Date(2014, 11, 1, 22, 15, 45, 400)) 5891 * //=> Mon Dec 01 2014 22:15:00 5892 */ 5893 5894function startOfMinute(dirtyDate) { 5895 requiredArgs(1, arguments); 5896 var date = toDate(dirtyDate); 5897 date.setSeconds(0, 0); 5898 return date; 5899} 5900 5901/** 5902 * @name startOfSecond 5903 * @category Second Helpers 5904 * @summary Return the start of a second for the given date. 5905 * 5906 * @description 5907 * Return the start of a second for the given date. 5908 * The result will be in the local timezone. 5909 * 5910 * ### v2.0.0 breaking changes: 5911 * 5912 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 5913 * 5914 * @param {Date|Number} date - the original date 5915 * @returns {Date} the start of a second 5916 * @throws {TypeError} 1 argument required 5917 * 5918 * @example 5919 * // The start of a second for 1 December 2014 22:15:45.400: 5920 * const result = startOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400)) 5921 * //=> Mon Dec 01 2014 22:15:45.000 5922 */ 5923 5924function startOfSecond(dirtyDate) { 5925 requiredArgs(1, arguments); 5926 var date = toDate(dirtyDate); 5927 date.setMilliseconds(0); 5928 return date; 5929} 5930 5931var MILLISECONDS_IN_HOUR = 3600000; 5932var MILLISECONDS_IN_MINUTE = 60000; 5933var DEFAULT_ADDITIONAL_DIGITS = 2; 5934var patterns = { 5935 dateTimeDelimiter: /[T ]/, 5936 timeZoneDelimiter: /[Z ]/i, 5937 timezone: /([Z+-].*)$/ 5938}; 5939var dateRegex = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/; 5940var timeRegex = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/; 5941var timezoneRegex = /^([+-])(\d{2})(?::?(\d{2}))?$/; 5942/** 5943 * @name parseISO 5944 * @category Common Helpers 5945 * @summary Parse ISO string 5946 * 5947 * @description 5948 * Parse the given string in ISO 8601 format and return an instance of Date. 5949 * 5950 * Function accepts complete ISO 8601 formats as well as partial implementations. 5951 * ISO 8601: http://en.wikipedia.org/wiki/ISO_8601 5952 * 5953 * If the argument isn't a string, the function cannot parse the string or 5954 * the values are invalid, it returns Invalid Date. 5955 * 5956 * ### v2.0.0 breaking changes: 5957 * 5958 * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 5959 * 5960 * - The previous `parse` implementation was renamed to `parseISO`. 5961 * 5962 * ```javascript 5963 * // Before v2.0.0 5964 * parse('2016-01-01') 5965 * 5966 * // v2.0.0 onward 5967 * parseISO('2016-01-01') 5968 * ``` 5969 * 5970 * - `parseISO` now validates separate date and time values in ISO-8601 strings 5971 * and returns `Invalid Date` if the date is invalid. 5972 * 5973 * ```javascript 5974 * parseISO('2018-13-32') 5975 * //=> Invalid Date 5976 * ``` 5977 * 5978 * - `parseISO` now doesn't fall back to `new Date` constructor 5979 * if it fails to parse a string argument. Instead, it returns `Invalid Date`. 5980 * 5981 * @param {String} argument - the value to convert 5982 * @param {Object} [options] - an object with options. 5983 * @param {0|1|2} [options.additionalDigits=2] - the additional number of digits in the extended year format 5984 * @returns {Date} the parsed date in the local time zone 5985 * @throws {TypeError} 1 argument required 5986 * @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2 5987 * 5988 * @example 5989 * // Convert string '2014-02-11T11:30:30' to date: 5990 * var result = parseISO('2014-02-11T11:30:30') 5991 * //=> Tue Feb 11 2014 11:30:30 5992 * 5993 * @example 5994 * // Convert string '+02014101' to date, 5995 * // if the additional number of digits in the extended year format is 1: 5996 * var result = parseISO('+02014101', { additionalDigits: 1 }) 5997 * //=> Fri Apr 11 2014 00:00:00 5998 */ 5999 6000function parseISO(argument, dirtyOptions) { 6001 requiredArgs(1, arguments); 6002 var options = dirtyOptions || {}; 6003 var additionalDigits = options.additionalDigits == null ? DEFAULT_ADDITIONAL_DIGITS : toInteger(options.additionalDigits); 6004 6005 if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) { 6006 throw new RangeError('additionalDigits must be 0, 1 or 2'); 6007 } 6008 6009 if (!(typeof argument === 'string' || Object.prototype.toString.call(argument) === '[object String]')) { 6010 return new Date(NaN); 6011 } 6012 6013 var dateStrings = splitDateString(argument); 6014 var date; 6015 6016 if (dateStrings.date) { 6017 var parseYearResult = parseYear(dateStrings.date, additionalDigits); 6018 date = parseDate(parseYearResult.restDateString, parseYearResult.year); 6019 } 6020 6021 if (isNaN(date) || !date) { 6022 return new Date(NaN); 6023 } 6024 6025 var timestamp = date.getTime(); 6026 var time = 0; 6027 var offset; 6028 6029 if (dateStrings.time) { 6030 time = parseTime(dateStrings.time); 6031 6032 if (isNaN(time) || time === null) { 6033 return new Date(NaN); 6034 } 6035 } 6036 6037 if (dateStrings.timezone) { 6038 offset = parseTimezone(dateStrings.timezone); 6039 6040 if (isNaN(offset)) { 6041 return new Date(NaN); 6042 } 6043 } else { 6044 var dirtyDate = new Date(timestamp + time); // js parsed string assuming it's in UTC timezone 6045 // but we need it to be parsed in our timezone 6046 // so we use utc values to build date in our timezone. 6047 // Year values from 0 to 99 map to the years 1900 to 1999 6048 // so set year explicitly with setFullYear. 6049 6050 var result = new Date(0); 6051 result.setFullYear(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate()); 6052 result.setHours(dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds()); 6053 return result; 6054 } 6055 6056 return new Date(timestamp + time + offset); 6057} 6058 6059function splitDateString(dateString) { 6060 var dateStrings = {}; 6061 var array = dateString.split(patterns.dateTimeDelimiter); 6062 var timeString; // The regex match should only return at maximum two array elements. 6063 // [date], [time], or [date, time]. 6064 6065 if (array.length > 2) { 6066 return dateStrings; 6067 } 6068 6069 if (/:/.test(array[0])) { 6070 dateStrings.date = null; 6071 timeString = array[0]; 6072 } else { 6073 dateStrings.date = array[0]; 6074 timeString = array[1]; 6075 6076 if (patterns.timeZoneDelimiter.test(dateStrings.date)) { 6077 dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0]; 6078 timeString = dateString.substr(dateStrings.date.length, dateString.length); 6079 } 6080 } 6081 6082 if (timeString) { 6083 var token = patterns.timezone.exec(timeString); 6084 6085 if (token) { 6086 dateStrings.time = timeString.replace(token[1], ''); 6087 dateStrings.timezone = token[1]; 6088 } else { 6089 dateStrings.time = timeString; 6090 } 6091 } 6092 6093 return dateStrings; 6094} 6095 6096function parseYear(dateString, additionalDigits) { 6097 var regex = new RegExp('^(?:(\\d{4}|[+-]\\d{' + (4 + additionalDigits) + '})|(\\d{2}|[+-]\\d{' + (2 + additionalDigits) + '})$)'); 6098 var captures = dateString.match(regex); // Invalid ISO-formatted year 6099 6100 if (!captures) return { 6101 year: null 6102 }; 6103 var year = captures[1] && parseInt(captures[1]); 6104 var century = captures[2] && parseInt(captures[2]); 6105 return { 6106 year: century == null ? year : century * 100, 6107 restDateString: dateString.slice((captures[1] || captures[2]).length) 6108 }; 6109} 6110 6111function parseDate(dateString, year) { 6112 // Invalid ISO-formatted year 6113 if (year === null) return null; 6114 var captures = dateString.match(dateRegex); // Invalid ISO-formatted string 6115 6116 if (!captures) return null; 6117 var isWeekDate = !!captures[4]; 6118 var dayOfYear = parseDateUnit(captures[1]); 6119 var month = parseDateUnit(captures[2]) - 1; 6120 var day = parseDateUnit(captures[3]); 6121 var week = parseDateUnit(captures[4]); 6122 var dayOfWeek = parseDateUnit(captures[5]) - 1; 6123 6124 if (isWeekDate) { 6125 if (!validateWeekDate(year, week, dayOfWeek)) { 6126 return new Date(NaN); 6127 } 6128 6129 return dayOfISOWeekYear(year, week, dayOfWeek); 6130 } else { 6131 var date = new Date(0); 6132 6133 if (!validateDate(year, month, day) || !validateDayOfYearDate(year, dayOfYear)) { 6134 return new Date(NaN); 6135 } 6136 6137 date.setUTCFullYear(year, month, Math.max(dayOfYear, day)); 6138 return date; 6139 } 6140} 6141 6142function parseDateUnit(value) { 6143 return value ? parseInt(value) : 1; 6144} 6145 6146function parseTime(timeString) { 6147 var captures = timeString.match(timeRegex); 6148 if (!captures) return null; // Invalid ISO-formatted time 6149 6150 var hours = parseTimeUnit(captures[1]); 6151 var minutes = parseTimeUnit(captures[2]); 6152 var seconds = parseTimeUnit(captures[3]); 6153 6154 if (!validateTime(hours, minutes, seconds)) { 6155 return NaN; 6156 } 6157 6158 return hours * MILLISECONDS_IN_HOUR + minutes * MILLISECONDS_IN_MINUTE + seconds * 1000; 6159} 6160 6161function parseTimeUnit(value) { 6162 return value && parseFloat(value.replace(',', '.')) || 0; 6163} 6164 6165function parseTimezone(timezoneString) { 6166 if (timezoneString === 'Z') return 0; 6167 var captures = timezoneString.match(timezoneRegex); 6168 if (!captures) return 0; 6169 var sign = captures[1] === '+' ? -1 : 1; 6170 var hours = parseInt(captures[2]); 6171 var minutes = captures[3] && parseInt(captures[3]) || 0; 6172 6173 if (!validateTimezone(hours, minutes)) { 6174 return NaN; 6175 } 6176 6177 return sign * (hours * MILLISECONDS_IN_HOUR + minutes * MILLISECONDS_IN_MINUTE); 6178} 6179 6180function dayOfISOWeekYear(isoWeekYear, week, day) { 6181 var date = new Date(0); 6182 date.setUTCFullYear(isoWeekYear, 0, 4); 6183 var fourthOfJanuaryDay = date.getUTCDay() || 7; 6184 var diff = (week - 1) * 7 + day + 1 - fourthOfJanuaryDay; 6185 date.setUTCDate(date.getUTCDate() + diff); 6186 return date; 6187} // Validation functions 6188// February is null to handle the leap year (using ||) 6189 6190 6191var daysInMonths = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 6192 6193function isLeapYearIndex(year) { 6194 return year % 400 === 0 || year % 4 === 0 && year % 100; 6195} 6196 6197function validateDate(year, month, date) { 6198 return month >= 0 && month <= 11 && date >= 1 && date <= (daysInMonths[month] || (isLeapYearIndex(year) ? 29 : 28)); 6199} 6200 6201function validateDayOfYearDate(year, dayOfYear) { 6202 return dayOfYear >= 1 && dayOfYear <= (isLeapYearIndex(year) ? 366 : 365); 6203} 6204 6205function validateWeekDate(_year, week, day) { 6206 return week >= 1 && week <= 53 && day >= 0 && day <= 6; 6207} 6208 6209function validateTime(hours, minutes, seconds) { 6210 if (hours === 24) { 6211 return minutes === 0 && seconds === 0; 6212 } 6213 6214 return seconds >= 0 && seconds < 60 && minutes >= 0 && minutes < 60 && hours >= 0 && hours < 25; 6215} 6216 6217function validateTimezone(_hours, minutes) { 6218 return minutes >= 0 && minutes <= 59; 6219} 6220 6221const FORMATS = { 6222 datetime: 'MMM d, yyyy, h:mm:ss aaaa', 6223 millisecond: 'h:mm:ss.SSS aaaa', 6224 second: 'h:mm:ss aaaa', 6225 minute: 'h:mm aaaa', 6226 hour: 'ha', 6227 day: 'MMM d', 6228 week: 'PP', 6229 month: 'MMM yyyy', 6230 quarter: 'qqq - yyyy', 6231 year: 'yyyy' 6232}; 6233 6234chart_js._adapters._date.override({ 6235 _id: 'date-fns', // DEBUG 6236 6237 formats: function() { 6238 return FORMATS; 6239 }, 6240 6241 parse: function(value, fmt) { 6242 if (value === null || typeof value === 'undefined') { 6243 return null; 6244 } 6245 const type = typeof value; 6246 if (type === 'number' || value instanceof Date) { 6247 value = toDate(value); 6248 } else if (type === 'string') { 6249 if (typeof fmt === 'string') { 6250 value = parse(value, fmt, new Date(), this.options); 6251 } else { 6252 value = parseISO(value, this.options); 6253 } 6254 } 6255 return isValid(value) ? value.getTime() : null; 6256 }, 6257 6258 format: function(time, fmt) { 6259 return format(time, fmt, this.options); 6260 }, 6261 6262 add: function(time, amount, unit) { 6263 switch (unit) { 6264 case 'millisecond': return addMilliseconds(time, amount); 6265 case 'second': return addSeconds(time, amount); 6266 case 'minute': return addMinutes(time, amount); 6267 case 'hour': return addHours(time, amount); 6268 case 'day': return addDays(time, amount); 6269 case 'week': return addWeeks(time, amount); 6270 case 'month': return addMonths(time, amount); 6271 case 'quarter': return addQuarters(time, amount); 6272 case 'year': return addYears(time, amount); 6273 default: return time; 6274 } 6275 }, 6276 6277 diff: function(max, min, unit) { 6278 switch (unit) { 6279 case 'millisecond': return differenceInMilliseconds(max, min); 6280 case 'second': return differenceInSeconds(max, min); 6281 case 'minute': return differenceInMinutes(max, min); 6282 case 'hour': return differenceInHours(max, min); 6283 case 'day': return differenceInDays(max, min); 6284 case 'week': return differenceInWeeks(max, min); 6285 case 'month': return differenceInMonths(max, min); 6286 case 'quarter': return differenceInQuarters(max, min); 6287 case 'year': return differenceInYears(max, min); 6288 default: return 0; 6289 } 6290 }, 6291 6292 startOf: function(time, unit, weekday) { 6293 switch (unit) { 6294 case 'second': return startOfSecond(time); 6295 case 'minute': return startOfMinute(time); 6296 case 'hour': return startOfHour(time); 6297 case 'day': return startOfDay(time); 6298 case 'week': return startOfWeek(time); 6299 case 'isoWeek': return startOfWeek(time, {weekStartsOn: +weekday}); 6300 case 'month': return startOfMonth(time); 6301 case 'quarter': return startOfQuarter(time); 6302 case 'year': return startOfYear(time); 6303 default: return time; 6304 } 6305 }, 6306 6307 endOf: function(time, unit) { 6308 switch (unit) { 6309 case 'second': return endOfSecond(time); 6310 case 'minute': return endOfMinute(time); 6311 case 'hour': return endOfHour(time); 6312 case 'day': return endOfDay(time); 6313 case 'week': return endOfWeek(time); 6314 case 'month': return endOfMonth(time); 6315 case 'quarter': return endOfQuarter(time); 6316 case 'year': return endOfYear(time); 6317 default: return time; 6318 } 6319 } 6320}); 6321 6322}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.