@arc-ui/components 11.16.0 → 11.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/dist/Calendar/Calendar.cjs.js +21 -0
  2. package/dist/Calendar/Calendar.esm.js +13 -0
  3. package/dist/Calendar/package.json +7 -0
  4. package/dist/Checkbox/Checkbox.cjs.js +3 -2
  5. package/dist/Checkbox/Checkbox.esm.js +3 -2
  6. package/dist/DatePicker/DatePicker.cjs.js +565 -0
  7. package/dist/DatePicker/DatePicker.esm.js +552 -0
  8. package/dist/DatePicker/package.json +7 -0
  9. package/dist/FormControl/FormControl.cjs.js +2 -1
  10. package/dist/FormControl/FormControl.esm.js +2 -1
  11. package/dist/InformationCard/InformationCard.cjs.js +10 -9
  12. package/dist/InformationCard/InformationCard.esm.js +8 -7
  13. package/dist/MediaCard/MediaCard.cjs.js +56 -0
  14. package/dist/MediaCard/MediaCard.esm.js +48 -0
  15. package/dist/MediaCard/package.json +7 -0
  16. package/dist/Modal/Modal.cjs.js +13 -286
  17. package/dist/Modal/Modal.esm.js +6 -279
  18. package/dist/RadioGroup/RadioGroup.cjs.js +3 -2
  19. package/dist/RadioGroup/RadioGroup.esm.js +3 -2
  20. package/dist/Select/Select.cjs.js +31 -2705
  21. package/dist/Select/Select.esm.js +13 -2668
  22. package/dist/SiteFooter/SiteFooter.cjs.js +2 -2
  23. package/dist/SiteFooter/SiteFooter.esm.js +3 -3
  24. package/dist/SiteHeader/SiteHeader.cjs.js +2 -2
  25. package/dist/SiteHeader/SiteHeader.esm.js +2 -2
  26. package/dist/SiteHeaderV2/SiteHeaderV2.cjs.js +23 -0
  27. package/dist/SiteHeaderV2/SiteHeaderV2.esm.js +15 -0
  28. package/dist/SiteHeaderV2/package.json +7 -0
  29. package/dist/Switch/Switch.cjs.js +4 -3
  30. package/dist/Switch/Switch.esm.js +4 -3
  31. package/dist/Tabs/Tabs.cjs.js +5 -5
  32. package/dist/Tabs/Tabs.esm.js +5 -5
  33. package/dist/TextArea/TextArea.cjs.js +20 -20
  34. package/dist/TextArea/TextArea.esm.js +20 -20
  35. package/dist/TextInput/TextInput.cjs.js +3 -2
  36. package/dist/TextInput/TextInput.esm.js +3 -2
  37. package/dist/Toast/Toast.cjs.js +6 -7
  38. package/dist/Toast/Toast.esm.js +6 -7
  39. package/dist/TypographyCard/TypographyCard.cjs.js +13 -70
  40. package/dist/TypographyCard/TypographyCard.esm.js +14 -71
  41. package/dist/_shared/cjs/Calendar-18e255f8.js +4106 -0
  42. package/dist/_shared/cjs/CardFooter-43c32239.js +80 -0
  43. package/dist/_shared/cjs/CardLabel-768abf20.js +54 -0
  44. package/dist/_shared/cjs/{Checkbox-904ad028.js → Checkbox-4d4b432f.js} +1 -1
  45. package/dist/_shared/cjs/{index-3d69ea00.js → Combination-9974f2e2.js} +662 -145
  46. package/dist/_shared/cjs/{FormControl-166e0957.js → FormControl-b26ad353.js} +8 -5
  47. package/dist/_shared/cjs/{RadioGroup-1eddf86f.js → RadioGroup-23c964ae.js} +1 -1
  48. package/dist/_shared/cjs/{SiteFooter-97c27b29.js → SiteFooter-65b6360c.js} +2 -2
  49. package/dist/_shared/cjs/{SiteHeader.rehydrator-af3dddef.js → SiteHeader.rehydrator-df053a52.js} +8 -8
  50. package/dist/_shared/cjs/SiteHeaderV2-8ce6d4fc.js +610 -0
  51. package/dist/_shared/cjs/{Tabs-cc77dabb.js → Tabs-34db6bc1.js} +4 -4
  52. package/dist/_shared/cjs/{TextInput-fd9c756f.js → TextInput-d0370fa8.js} +19 -6
  53. package/dist/_shared/cjs/{Toast-91e96744.js → Toast-392b1d60.js} +292 -34
  54. package/dist/_shared/cjs/{index-84e6a68f.js → index-6eb396a3.js} +1 -1
  55. package/dist/_shared/cjs/{index-6542b467.js → index-74004a9c.js} +1 -1
  56. package/dist/_shared/cjs/index-77ab5c6a.js +2180 -0
  57. package/dist/_shared/cjs/{index-d31f2b65.js → index-9f99d686.js} +1 -1
  58. package/dist/_shared/cjs/{index-1641d0b4.js → index-a31e64a9.js} +1 -1
  59. package/dist/_shared/cjs/{index-49c72a87.js → index-d38f1bd0.js} +1 -1
  60. package/dist/_shared/esm/Calendar-4033fa48.js +4093 -0
  61. package/dist/_shared/esm/CardFooter-dd8d4000.js +74 -0
  62. package/dist/_shared/esm/CardLabel-d6d71407.js +46 -0
  63. package/dist/_shared/esm/{Checkbox-8a5bb9a1.js → Checkbox-720b074d.js} +1 -1
  64. package/dist/_shared/esm/{index-3e2bc99d.js → Combination-e9f7e64e.js} +643 -132
  65. package/dist/_shared/esm/{FormControl-9d4ddfec.js → FormControl-f0b8fe91.js} +8 -5
  66. package/dist/_shared/esm/{RadioGroup-238db88d.js → RadioGroup-37fdb06b.js} +1 -1
  67. package/dist/_shared/esm/{SiteFooter-94316b8b.js → SiteFooter-38ee1536.js} +1 -1
  68. package/dist/_shared/esm/{SiteHeader.rehydrator-1b507253.js → SiteHeader.rehydrator-32bdcd88.js} +2 -2
  69. package/dist/_shared/esm/SiteHeaderV2-f8377627.js +604 -0
  70. package/dist/_shared/esm/{Tabs-8719d952.js → Tabs-df9965dd.js} +4 -4
  71. package/dist/_shared/esm/{TextInput-c1e2a1dd.js → TextInput-abbab56b.js} +19 -6
  72. package/dist/_shared/esm/{Toast-7cb1e544.js → Toast-5d66e13f.js} +264 -7
  73. package/dist/_shared/esm/{index-39019a9b.js → index-044da8d0.js} +1 -1
  74. package/dist/_shared/esm/{index-6b7b075c.js → index-25a5b393.js} +1 -1
  75. package/dist/_shared/esm/{index-246b4f18.js → index-2cfab9f2.js} +1 -1
  76. package/dist/_shared/esm/{index-12f3a407.js → index-7b531fa7.js} +68 -68
  77. package/dist/_shared/esm/index-b84a20c6.js +2155 -0
  78. package/dist/_shared/esm/{index-db47e95a.js → index-ca72c9d5.js} +1 -1
  79. package/dist/_shared/esm/{index-936b5179.js → index-efa9be1a.js} +1 -1
  80. package/dist/_shared/esm/{index.es-c552c0ea.js → use-media-query-4c807227.js} +9 -9
  81. package/dist/index.es.js +1135 -791
  82. package/dist/index.es.js.map +1 -1
  83. package/dist/index.js +1136 -791
  84. package/dist/index.js.map +1 -1
  85. package/dist/styles.css +4 -4
  86. package/dist/types/components/Calendar/Calendar.d.ts +49 -0
  87. package/dist/types/components/Calendar/Calendar.provider.d.ts +21 -0
  88. package/dist/types/components/Calendar/components/CalendarDateSelect/CalendarDateSelect.d.ts +15 -0
  89. package/dist/types/components/Calendar/components/CalendarDateSelect/index.d.ts +1 -0
  90. package/dist/types/components/Calendar/components/CalendarDayGrid/CalendarDayGrid.d.ts +6 -0
  91. package/dist/types/components/Calendar/components/CalendarDayGrid/index.d.ts +1 -0
  92. package/dist/types/components/Calendar/components/CalendarDayNumber/CalendarDayNumber.d.ts +8 -0
  93. package/dist/types/components/Calendar/components/CalendarDayNumber/index.d.ts +1 -0
  94. package/dist/types/components/Calendar/components/CalendarDoubleMonthView/CalendarDoubleMonthView.d.ts +9 -0
  95. package/dist/types/components/Calendar/components/CalendarDoubleMonthView/index.d.ts +1 -0
  96. package/dist/types/components/Calendar/components/CalendarFooter/CalendarFooter.d.ts +6 -0
  97. package/dist/types/components/Calendar/components/CalendarFooter/index.d.ts +1 -0
  98. package/dist/types/components/Calendar/components/CalendarMonthView/CalendarMonthView.d.ts +9 -0
  99. package/dist/types/components/Calendar/components/CalendarMonthView/index.d.ts +1 -0
  100. package/dist/types/components/Calendar/components/CalendarMonthYearView/CalendarMonthYearView.d.ts +11 -0
  101. package/dist/types/components/Calendar/components/CalendarMonthYearView/index.d.ts +1 -0
  102. package/dist/types/components/Calendar/components/CalendarNavButton/CalendarNavButton.d.ts +10 -0
  103. package/dist/types/components/Calendar/components/CalendarNavButton/index.d.ts +1 -0
  104. package/dist/types/components/Calendar/components/CalendarWrapper/CalendarWrapper.d.ts +5 -0
  105. package/dist/types/components/Calendar/components/CalendarWrapper/index.d.ts +1 -0
  106. package/dist/types/components/Calendar/components/index.d.ts +6 -0
  107. package/dist/types/components/Calendar/constants/day-names.d.ts +5 -0
  108. package/dist/types/components/Calendar/constants/index.d.ts +1 -0
  109. package/dist/types/components/Calendar/helpers/contains-date.d.ts +1 -0
  110. package/dist/types/components/Calendar/helpers/contains-date.test.d.ts +1 -0
  111. package/dist/types/components/Calendar/helpers/date-without-time.d.ts +1 -0
  112. package/dist/types/components/Calendar/helpers/date-without-time.test.d.ts +1 -0
  113. package/dist/types/components/Calendar/helpers/get-calendar-type.d.ts +2 -0
  114. package/dist/types/components/Calendar/helpers/get-calendar-type.test.d.ts +1 -0
  115. package/dist/types/components/Calendar/helpers/get-dates-in-month.d.ts +1 -0
  116. package/dist/types/components/Calendar/helpers/get-dates-in-month.test.d.ts +1 -0
  117. package/dist/types/components/Calendar/helpers/get-double-month-display-range.d.ts +1 -0
  118. package/dist/types/components/Calendar/helpers/get-double-month-display-range.test.d.ts +1 -0
  119. package/dist/types/components/Calendar/helpers/get-focus-date.d.ts +5 -0
  120. package/dist/types/components/Calendar/helpers/get-focus-date.test.d.ts +1 -0
  121. package/dist/types/components/Calendar/helpers/get-highlighted-range.d.ts +6 -0
  122. package/dist/types/components/Calendar/helpers/get-highlighted-range.test.d.ts +1 -0
  123. package/dist/types/components/Calendar/helpers/get-keydown-date.d.ts +6 -0
  124. package/dist/types/components/Calendar/helpers/get-keydown-date.test.d.ts +1 -0
  125. package/dist/types/components/Calendar/helpers/index.d.ts +13 -0
  126. package/dist/types/components/Calendar/helpers/is-day.d.ts +2 -0
  127. package/dist/types/components/Calendar/helpers/is-day.test.d.ts +1 -0
  128. package/dist/types/components/Calendar/helpers/is-disabled-date.d.ts +1 -0
  129. package/dist/types/components/Calendar/helpers/is-disabled-date.test.d.ts +1 -0
  130. package/dist/types/components/Calendar/helpers/is-month-after-max-date.d.ts +1 -0
  131. package/dist/types/components/Calendar/helpers/is-month-after-max-date.test.d.ts +1 -0
  132. package/dist/types/components/Calendar/helpers/is-month-before-min-date.d.ts +1 -0
  133. package/dist/types/components/Calendar/helpers/is-month-before-min-date.test.d.ts +1 -0
  134. package/dist/types/components/Calendar/helpers/process-selected-range.d.ts +9 -0
  135. package/dist/types/components/Calendar/helpers/process-selected-range.test.d.ts +1 -0
  136. package/dist/types/components/Calendar/index.d.ts +2 -0
  137. package/dist/types/components/Calendar/state/handlers/calendar-keydown-handler.d.ts +3 -0
  138. package/dist/types/components/Calendar/state/handlers/day-grid-leave-handler.d.ts +3 -0
  139. package/dist/types/components/Calendar/state/handlers/day-number-select-handler.d.ts +3 -0
  140. package/dist/types/components/Calendar/state/handlers/default-handler.d.ts +2 -0
  141. package/dist/types/components/Calendar/state/handlers/dropdown-change-month-handler.d.ts +3 -0
  142. package/dist/types/components/Calendar/state/handlers/dropdown-change-year-handler.d.ts +3 -0
  143. package/dist/types/components/Calendar/state/handlers/highlight-range-handler.d.ts +3 -0
  144. package/dist/types/components/Calendar/state/handlers/index.d.ts +12 -0
  145. package/dist/types/components/Calendar/state/handlers/range-select-handler.d.ts +3 -0
  146. package/dist/types/components/Calendar/state/handlers/show-next-double-month-handler.d.ts +3 -0
  147. package/dist/types/components/Calendar/state/handlers/show-next-month-handler.d.ts +3 -0
  148. package/dist/types/components/Calendar/state/handlers/show-previous-double-month-handler.d.ts +3 -0
  149. package/dist/types/components/Calendar/state/handlers/show-previous-month-handler.d.ts +3 -0
  150. package/dist/types/components/Calendar/state/index.d.ts +2 -0
  151. package/dist/types/components/Calendar/state/reducer.d.ts +3 -0
  152. package/dist/types/components/Calendar/state/reducer.test.d.ts +1 -0
  153. package/dist/types/components/Calendar/state/types/actions.d.ts +81 -0
  154. package/dist/types/components/Calendar/state/types/state-handler.d.ts +3 -0
  155. package/dist/types/components/Calendar/state/types/state.d.ts +5 -0
  156. package/dist/types/components/Calendar/types/calendar-type.d.ts +1 -0
  157. package/dist/types/components/Calendar/types/date-select-value.d.ts +2 -0
  158. package/dist/types/components/Calendar/types/index.d.ts +6 -0
  159. package/dist/types/components/Calendar/types/key-names.d.ts +13 -0
  160. package/dist/types/components/Calendar/types/range-selection.d.ts +10 -0
  161. package/dist/types/components/Calendar/types/selection-type.d.ts +1 -0
  162. package/dist/types/components/Calendar/types/week-days.d.ts +18 -0
  163. package/dist/types/components/DatePicker/DatePicker.d.ts +17 -0
  164. package/dist/types/components/DatePicker/constants/date-format.d.ts +1 -0
  165. package/dist/types/components/DatePicker/constants/index.d.ts +1 -0
  166. package/dist/types/components/DatePicker/helpers/convert-date-string-to-date.d.ts +1 -0
  167. package/dist/types/components/DatePicker/helpers/convert-date-string-to-date.test.d.ts +1 -0
  168. package/dist/types/components/DatePicker/helpers/convert-range-string-to-dates.d.ts +1 -0
  169. package/dist/types/components/DatePicker/helpers/convert-range-string-to-dates.test.d.ts +1 -0
  170. package/dist/types/components/DatePicker/helpers/format-date.d.ts +1 -0
  171. package/dist/types/components/DatePicker/helpers/format-date.test.d.ts +1 -0
  172. package/dist/types/components/DatePicker/helpers/index.d.ts +8 -0
  173. package/dist/types/components/DatePicker/helpers/is-date-valid.d.ts +1 -0
  174. package/dist/types/components/DatePicker/helpers/is-date-valid.test.d.ts +1 -0
  175. package/dist/types/components/DatePicker/helpers/is-disabled-date.d.ts +1 -0
  176. package/dist/types/components/DatePicker/helpers/is-disabled-date.test.d.ts +1 -0
  177. package/dist/types/components/DatePicker/helpers/is-range-valid.d.ts +1 -0
  178. package/dist/types/components/DatePicker/helpers/is-range-valid.test.d.ts +1 -0
  179. package/dist/types/components/DatePicker/helpers/parse-date-string.d.ts +5 -0
  180. package/dist/types/components/DatePicker/helpers/parse-date-string.test.d.ts +1 -0
  181. package/dist/types/components/DatePicker/helpers/parse-range-string.d.ts +14 -0
  182. package/dist/types/components/DatePicker/helpers/parse-range-string.test.d.ts +1 -0
  183. package/dist/types/components/DatePicker/index.d.ts +6 -0
  184. package/dist/types/components/FormControl/FormControl.d.ts +4 -0
  185. package/dist/types/components/RadioGroup/RadioGroup.d.ts +1 -1
  186. package/dist/types/components/SiteHeaderV2/SiteHeaderV2.d.ts +77 -0
  187. package/dist/types/components/SiteHeaderV2/components/BackButton/BackButton.d.ts +5 -0
  188. package/dist/types/components/SiteHeaderV2/components/BackButton/index.d.ts +1 -0
  189. package/dist/types/components/SiteHeaderV2/components/Column/Column.d.ts +8 -0
  190. package/dist/types/components/SiteHeaderV2/components/Column/index.d.ts +1 -0
  191. package/dist/types/components/SiteHeaderV2/components/HorizontalPanel/HorizontalPanel.d.ts +13 -0
  192. package/dist/types/components/SiteHeaderV2/components/HorizontalPanel/index.d.ts +1 -0
  193. package/dist/types/components/SiteHeaderV2/components/Item/Item.d.ts +20 -0
  194. package/dist/types/components/SiteHeaderV2/components/Item/index.d.ts +1 -0
  195. package/dist/types/components/SiteHeaderV2/components/ItemGroup/ItemGroup.d.ts +27 -0
  196. package/dist/types/components/SiteHeaderV2/components/ItemGroup/index.d.ts +1 -0
  197. package/dist/types/components/SiteHeaderV2/components/MenuButton/MenuButton.d.ts +6 -0
  198. package/dist/types/components/SiteHeaderV2/components/MenuButton/index.d.ts +1 -0
  199. package/dist/types/components/SiteHeaderV2/components/NavItem/NavItem.d.ts +40 -0
  200. package/dist/types/components/SiteHeaderV2/components/NavItem/NavItemWithSubNav.d.ts +55 -0
  201. package/dist/types/components/SiteHeaderV2/components/NavItem/index.d.ts +2 -0
  202. package/dist/types/components/SiteHeaderV2/components/NodeItem/NodeItem.d.ts +8 -0
  203. package/dist/types/components/SiteHeaderV2/components/Panel/Panel.d.ts +26 -0
  204. package/dist/types/components/SiteHeaderV2/components/Panel/index.d.ts +1 -0
  205. package/dist/types/components/SiteHeaderV2/components/SubNavItem/SubNavItem.d.ts +45 -0
  206. package/dist/types/components/SiteHeaderV2/components/SubNavItem/index.d.ts +1 -0
  207. package/dist/types/components/SiteHeaderV2/components/VerticalDivider/VerticalDivider.d.ts +1 -0
  208. package/dist/types/components/SiteHeaderV2/components/VerticalDivider/index.d.ts +1 -0
  209. package/dist/types/components/SiteHeaderV2/index.d.ts +1 -0
  210. package/dist/types/components/TextArea/TextArea.d.ts +4 -0
  211. package/dist/types/components/TextInput/TextInput.d.ts +22 -3
  212. package/dist/types/components/index.d.ts +1 -0
  213. package/dist/types/private-components/CardFooter/CardFooter.d.ts +11 -0
  214. package/dist/types/private-components/CardFooter/index.d.ts +1 -0
  215. package/dist/types/private-components/CardHeading/CardHeading.d.ts +19 -0
  216. package/dist/types/private-components/CardHeading/index.d.ts +1 -0
  217. package/dist/types/private-components/CardLabel/CardLabel.d.ts +10 -0
  218. package/dist/types/private-components/CardLabel/index.d.ts +1 -0
  219. package/dist/types/private-components/index.d.ts +4 -0
  220. package/dist/types/styles.d.ts +6 -0
  221. package/package.json +4 -2
  222. package/dist/_shared/cjs/BtIconArrowRight.esm-8e8ac316.js +0 -30
  223. package/dist/_shared/cjs/index-4ecad2dd.js +0 -273
  224. package/dist/_shared/esm/BtIconArrowRight.esm-267916a4.js +0 -24
  225. package/dist/_shared/esm/index-d0307140.js +0 -264
  226. package/dist/types/internal-components/index.d.ts +0 -1
  227. package/dist/_shared/cjs/{index-56a040f4.js → index-dd1d18ea.js} +66 -66
  228. package/dist/_shared/cjs/{index.es-26dd8c5d.js → use-media-query-e61881d8.js} +8 -8
  229. /package/dist/types/{internal-components → private-components}/ConditionalWrapper/ConditionalWrapper.d.ts +0 -0
  230. /package/dist/types/{internal-components → private-components}/ConditionalWrapper/index.d.ts +0 -0
@@ -0,0 +1,4106 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var useMediaQuery = require('./use-media-query-e61881d8.js');
5
+ var filterDataAttrs = require('./filter-data-attrs-1c9a530c.js');
6
+ var index = require('./index-9947ac13.js');
7
+ var Text = require('./Text-606ca3a2.js');
8
+ var VisuallyHidden = require('./VisuallyHidden-e2c8b291.js');
9
+ var Surface = require('./Surface-038db6e1.js');
10
+ var Heading = require('./Heading-27cba320.js');
11
+ var BtIconChevronLeftMid_esm = require('./BtIconChevronLeftMid.esm-0aaa6770.js');
12
+ var BtIconChevronRightMid_esm = require('./BtIconChevronRightMid.esm-d01ebbd4.js');
13
+ var Icon = require('./Icon-a9801f05.js');
14
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
+
19
+ function toInteger(dirtyNumber) {
20
+ if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
21
+ return NaN;
22
+ }
23
+ var number = Number(dirtyNumber);
24
+ if (isNaN(number)) {
25
+ return number;
26
+ }
27
+ return number < 0 ? Math.ceil(number) : Math.floor(number);
28
+ }
29
+
30
+ function _typeof(o) {
31
+ "@babel/helpers - typeof";
32
+
33
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
34
+ return typeof o;
35
+ } : function (o) {
36
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
37
+ }, _typeof(o);
38
+ }
39
+
40
+ function requiredArgs(required, args) {
41
+ if (args.length < required) {
42
+ throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
43
+ }
44
+ }
45
+
46
+ /**
47
+ * @name toDate
48
+ * @category Common Helpers
49
+ * @summary Convert the given argument to an instance of Date.
50
+ *
51
+ * @description
52
+ * Convert the given argument to an instance of Date.
53
+ *
54
+ * If the argument is an instance of Date, the function returns its clone.
55
+ *
56
+ * If the argument is a number, it is treated as a timestamp.
57
+ *
58
+ * If the argument is none of the above, the function returns Invalid Date.
59
+ *
60
+ * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
61
+ *
62
+ * @param {Date|Number} argument - the value to convert
63
+ * @returns {Date} the parsed date in the local time zone
64
+ * @throws {TypeError} 1 argument required
65
+ *
66
+ * @example
67
+ * // Clone the date:
68
+ * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
69
+ * //=> Tue Feb 11 2014 11:30:30
70
+ *
71
+ * @example
72
+ * // Convert the timestamp to date:
73
+ * const result = toDate(1392098430000)
74
+ * //=> Tue Feb 11 2014 11:30:30
75
+ */
76
+ function toDate(argument) {
77
+ requiredArgs(1, arguments);
78
+ var argStr = Object.prototype.toString.call(argument);
79
+
80
+ // Clone the date
81
+ if (argument instanceof Date || _typeof(argument) === 'object' && argStr === '[object Date]') {
82
+ // Prevent the date to lose the milliseconds when passed to new Date() in IE10
83
+ return new Date(argument.getTime());
84
+ } else if (typeof argument === 'number' || argStr === '[object Number]') {
85
+ return new Date(argument);
86
+ } else {
87
+ if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {
88
+ // eslint-disable-next-line no-console
89
+ console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments");
90
+ // eslint-disable-next-line no-console
91
+ console.warn(new Error().stack);
92
+ }
93
+ return new Date(NaN);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * @name addMonths
99
+ * @category Month Helpers
100
+ * @summary Add the specified number of months to the given date.
101
+ *
102
+ * @description
103
+ * Add the specified number of months to the given date.
104
+ *
105
+ * @param {Date|Number} date - the date to be changed
106
+ * @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`.
107
+ * @returns {Date} the new date with the months added
108
+ * @throws {TypeError} 2 arguments required
109
+ *
110
+ * @example
111
+ * // Add 5 months to 1 September 2014:
112
+ * const result = addMonths(new Date(2014, 8, 1), 5)
113
+ * //=> Sun Feb 01 2015 00:00:00
114
+ */
115
+ function addMonths(dirtyDate, dirtyAmount) {
116
+ requiredArgs(2, arguments);
117
+ var date = toDate(dirtyDate);
118
+ var amount = toInteger(dirtyAmount);
119
+ if (isNaN(amount)) {
120
+ return new Date(NaN);
121
+ }
122
+ if (!amount) {
123
+ // If 0 months, no-op to avoid changing times in the hour before end of DST
124
+ return date;
125
+ }
126
+ var dayOfMonth = date.getDate();
127
+
128
+ // The JS Date object supports date math by accepting out-of-bounds values for
129
+ // month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and
130
+ // new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we
131
+ // want except that dates will wrap around the end of a month, meaning that
132
+ // new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So
133
+ // we'll default to the end of the desired month by adding 1 to the desired
134
+ // month and using a date of 0 to back up one day to the end of the desired
135
+ // month.
136
+ var endOfDesiredMonth = new Date(date.getTime());
137
+ endOfDesiredMonth.setMonth(date.getMonth() + amount + 1, 0);
138
+ var daysInMonth = endOfDesiredMonth.getDate();
139
+ if (dayOfMonth >= daysInMonth) {
140
+ // If we're already at the end of the month, then this is the correct date
141
+ // and we're done.
142
+ return endOfDesiredMonth;
143
+ } else {
144
+ // Otherwise, we now know that setting the original day-of-month value won't
145
+ // cause an overflow, so set the desired day-of-month. Note that we can't
146
+ // just set the date of `endOfDesiredMonth` because that object may have had
147
+ // its time changed in the unusual case where where a DST transition was on
148
+ // the last day of the month and its local time was in the hour skipped or
149
+ // repeated next to a DST transition. So we use `date` instead which is
150
+ // guaranteed to still have the original time.
151
+ date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth);
152
+ return date;
153
+ }
154
+ }
155
+
156
+ /**
157
+ * @name subMonths
158
+ * @category Month Helpers
159
+ * @summary Subtract the specified number of months from the given date.
160
+ *
161
+ * @description
162
+ * Subtract the specified number of months from the given date.
163
+ *
164
+ * @param {Date|Number} date - the date to be changed
165
+ * @param {Number} amount - the amount of months to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
166
+ * @returns {Date} the new date with the months subtracted
167
+ * @throws {TypeError} 2 arguments required
168
+ *
169
+ * @example
170
+ * // Subtract 5 months from 1 February 2015:
171
+ * const result = subMonths(new Date(2015, 1, 1), 5)
172
+ * //=> Mon Sep 01 2014 00:00:00
173
+ */
174
+ function subMonths(dirtyDate, dirtyAmount) {
175
+ requiredArgs(2, arguments);
176
+ var amount = toInteger(dirtyAmount);
177
+ return addMonths(dirtyDate, -amount);
178
+ }
179
+
180
+ /**
181
+ * @name startOfMonth
182
+ * @category Month Helpers
183
+ * @summary Return the start of a month for the given date.
184
+ *
185
+ * @description
186
+ * Return the start of a month for the given date.
187
+ * The result will be in the local timezone.
188
+ *
189
+ * @param {Date|Number} date - the original date
190
+ * @returns {Date} the start of a month
191
+ * @throws {TypeError} 1 argument required
192
+ *
193
+ * @example
194
+ * // The start of a month for 2 September 2014 11:55:00:
195
+ * const result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0))
196
+ * //=> Mon Sep 01 2014 00:00:00
197
+ */
198
+ function startOfMonth(dirtyDate) {
199
+ requiredArgs(1, arguments);
200
+ var date = toDate(dirtyDate);
201
+ date.setDate(1);
202
+ date.setHours(0, 0, 0, 0);
203
+ return date;
204
+ }
205
+
206
+ var containsDate = function (dates, compareDate) {
207
+ return dates.map(function (date) { return date.getTime(); }).includes(compareDate.getTime());
208
+ };
209
+
210
+ /**
211
+ * @name getMonth
212
+ * @category Month Helpers
213
+ * @summary Get the month of the given date.
214
+ *
215
+ * @description
216
+ * Get the month of the given date.
217
+ *
218
+ * @param {Date|Number} date - the given date
219
+ * @returns {Number} the month
220
+ * @throws {TypeError} 1 argument required
221
+ *
222
+ * @example
223
+ * // Which month is 29 February 2012?
224
+ * const result = getMonth(new Date(2012, 1, 29))
225
+ * //=> 1
226
+ */
227
+ function getMonth(dirtyDate) {
228
+ requiredArgs(1, arguments);
229
+ var date = toDate(dirtyDate);
230
+ var month = date.getMonth();
231
+ return month;
232
+ }
233
+
234
+ /**
235
+ * @name getYear
236
+ * @category Year Helpers
237
+ * @summary Get the year of the given date.
238
+ *
239
+ * @description
240
+ * Get the year of the given date.
241
+ *
242
+ * @param {Date|Number} date - the given date
243
+ * @returns {Number} the year
244
+ * @throws {TypeError} 1 argument required
245
+ *
246
+ * @example
247
+ * // Which year is 2 July 2014?
248
+ * const result = getYear(new Date(2014, 6, 2))
249
+ * //=> 2014
250
+ */
251
+ function getYear(dirtyDate) {
252
+ requiredArgs(1, arguments);
253
+ return toDate(dirtyDate).getFullYear();
254
+ }
255
+
256
+ /**
257
+ * @name getDaysInMonth
258
+ * @category Month Helpers
259
+ * @summary Get the number of days in a month of the given date.
260
+ *
261
+ * @description
262
+ * Get the number of days in a month of the given date.
263
+ *
264
+ * @param {Date|Number} date - the given date
265
+ * @returns {Number} the number of days in a month
266
+ * @throws {TypeError} 1 argument required
267
+ *
268
+ * @example
269
+ * // How many days are in February 2000?
270
+ * const result = getDaysInMonth(new Date(2000, 1))
271
+ * //=> 29
272
+ */
273
+ function getDaysInMonth(dirtyDate) {
274
+ requiredArgs(1, arguments);
275
+ var date = toDate(dirtyDate);
276
+ var year = date.getFullYear();
277
+ var monthIndex = date.getMonth();
278
+ var lastDayOfMonth = new Date(0);
279
+ lastDayOfMonth.setFullYear(year, monthIndex + 1, 0);
280
+ lastDayOfMonth.setHours(0, 0, 0, 0);
281
+ return lastDayOfMonth.getDate();
282
+ }
283
+
284
+ /**
285
+ * @name setMonth
286
+ * @category Month Helpers
287
+ * @summary Set the month to the given date.
288
+ *
289
+ * @description
290
+ * Set the month to the given date.
291
+ *
292
+ * @param {Date|Number} date - the date to be changed
293
+ * @param {Number} month - the month of the new date
294
+ * @returns {Date} the new date with the month set
295
+ * @throws {TypeError} 2 arguments required
296
+ *
297
+ * @example
298
+ * // Set February to 1 September 2014:
299
+ * const result = setMonth(new Date(2014, 8, 1), 1)
300
+ * //=> Sat Feb 01 2014 00:00:00
301
+ */
302
+ function setMonth(dirtyDate, dirtyMonth) {
303
+ requiredArgs(2, arguments);
304
+ var date = toDate(dirtyDate);
305
+ var month = toInteger(dirtyMonth);
306
+ var year = date.getFullYear();
307
+ var day = date.getDate();
308
+ var dateWithDesiredMonth = new Date(0);
309
+ dateWithDesiredMonth.setFullYear(year, month, 15);
310
+ dateWithDesiredMonth.setHours(0, 0, 0, 0);
311
+ var daysInMonth = getDaysInMonth(dateWithDesiredMonth);
312
+ // Set the last day of the new month
313
+ // if the original date was the last day of the longer month
314
+ date.setMonth(month, Math.min(day, daysInMonth));
315
+ return date;
316
+ }
317
+
318
+ /**
319
+ * @name set
320
+ * @category Common Helpers
321
+ * @summary Set date values to a given date.
322
+ *
323
+ * @description
324
+ * Set date values to a given date.
325
+ *
326
+ * Sets time values to date from object `values`.
327
+ * A value is not set if it is undefined or null or doesn't exist in `values`.
328
+ *
329
+ * Note about bundle size: `set` does not internally use `setX` functions from date-fns but instead opts
330
+ * to use native `Date#setX` methods. If you use this function, you may not want to include the
331
+ * other `setX` functions that date-fns provides if you are concerned about the bundle size.
332
+ *
333
+ * @param {Date|Number} date - the date to be changed
334
+ * @param {Object} values - an object with options
335
+ * @param {Number} [values.year] - the number of years to be set
336
+ * @param {Number} [values.month] - the number of months to be set
337
+ * @param {Number} [values.date] - the number of days to be set
338
+ * @param {Number} [values.hours] - the number of hours to be set
339
+ * @param {Number} [values.minutes] - the number of minutes to be set
340
+ * @param {Number} [values.seconds] - the number of seconds to be set
341
+ * @param {Number} [values.milliseconds] - the number of milliseconds to be set
342
+ * @returns {Date} the new date with options set
343
+ * @throws {TypeError} 2 arguments required
344
+ * @throws {RangeError} `values` must be an object
345
+ *
346
+ * @example
347
+ * // Transform 1 September 2014 into 20 October 2015 in a single line:
348
+ * const result = set(new Date(2014, 8, 20), { year: 2015, month: 9, date: 20 })
349
+ * //=> Tue Oct 20 2015 00:00:00
350
+ *
351
+ * @example
352
+ * // Set 12 PM to 1 September 2014 01:23:45 to 1 September 2014 12:00:00:
353
+ * const result = set(new Date(2014, 8, 1, 1, 23, 45), { hours: 12 })
354
+ * //=> Mon Sep 01 2014 12:23:45
355
+ */
356
+ function set(dirtyDate, values) {
357
+ requiredArgs(2, arguments);
358
+ if (_typeof(values) !== 'object' || values === null) {
359
+ throw new RangeError('values parameter must be an object');
360
+ }
361
+ var date = toDate(dirtyDate);
362
+
363
+ // Check if date is Invalid Date because Date.prototype.setFullYear ignores the value of Invalid Date
364
+ if (isNaN(date.getTime())) {
365
+ return new Date(NaN);
366
+ }
367
+ if (values.year != null) {
368
+ date.setFullYear(values.year);
369
+ }
370
+ if (values.month != null) {
371
+ date = setMonth(date, values.month);
372
+ }
373
+ if (values.date != null) {
374
+ date.setDate(toInteger(values.date));
375
+ }
376
+ if (values.hours != null) {
377
+ date.setHours(toInteger(values.hours));
378
+ }
379
+ if (values.minutes != null) {
380
+ date.setMinutes(toInteger(values.minutes));
381
+ }
382
+ if (values.seconds != null) {
383
+ date.setSeconds(toInteger(values.seconds));
384
+ }
385
+ if (values.milliseconds != null) {
386
+ date.setMilliseconds(toInteger(values.milliseconds));
387
+ }
388
+ return date;
389
+ }
390
+
391
+ var dateWithoutTime = function (date) {
392
+ return set(new Date(date), {
393
+ hours: 0,
394
+ minutes: 0,
395
+ milliseconds: 0,
396
+ seconds: 0
397
+ });
398
+ };
399
+
400
+ var getDatesInMonth = function (date) {
401
+ var dateYear = getYear(date);
402
+ var dateMonth = getMonth(date);
403
+ return Array.from({ length: getDaysInMonth(date) }, function (_, i) {
404
+ return dateWithoutTime(new Date(dateYear, dateMonth, i + 1));
405
+ });
406
+ };
407
+
408
+ /**
409
+ * @name getDay
410
+ * @category Weekday Helpers
411
+ * @summary Get the day of the week of the given date.
412
+ *
413
+ * @description
414
+ * Get the day of the week of the given date.
415
+ *
416
+ * @param {Date|Number} date - the given date
417
+ * @returns {0|1|2|3|4|5|6} the day of week, 0 represents Sunday
418
+ * @throws {TypeError} 1 argument required
419
+ *
420
+ * @example
421
+ * // Which day of the week is 29 February 2012?
422
+ * const result = getDay(new Date(2012, 1, 29))
423
+ * //=> 3
424
+ */
425
+ function getDay(dirtyDate) {
426
+ requiredArgs(1, arguments);
427
+ var date = toDate(dirtyDate);
428
+ var day = date.getDay();
429
+ return day;
430
+ }
431
+
432
+ var WeekDaysAbbr;
433
+ (function (WeekDaysAbbr) {
434
+ WeekDaysAbbr["MON"] = "Mon";
435
+ WeekDaysAbbr["TUE"] = "Tue";
436
+ WeekDaysAbbr["WED"] = "Wed";
437
+ WeekDaysAbbr["THUR"] = "Thur";
438
+ WeekDaysAbbr["FRI"] = "Fri";
439
+ WeekDaysAbbr["SAT"] = "Sat";
440
+ WeekDaysAbbr["SUN"] = "Sun";
441
+ })(WeekDaysAbbr || (WeekDaysAbbr = {}));
442
+ var WeekDays;
443
+ (function (WeekDays) {
444
+ WeekDays["MONDAY"] = "Monday";
445
+ WeekDays["TUESDAY"] = "Tuesday";
446
+ WeekDays["WEDNESDAY"] = "Wednesday";
447
+ WeekDays["THURSDAY"] = "Thursday";
448
+ WeekDays["FRIDAY"] = "Friday";
449
+ WeekDays["SATURDAY"] = "Saturday";
450
+ WeekDays["SUNDAY"] = "Sunday";
451
+ })(WeekDays || (WeekDays = {}));
452
+
453
+ var isDay = function (date, day) {
454
+ var _a;
455
+ var dayMap = (_a = {},
456
+ _a[WeekDays.MONDAY] = 1,
457
+ _a[WeekDays.TUESDAY] = 2,
458
+ _a[WeekDays.WEDNESDAY] = 3,
459
+ _a[WeekDays.THURSDAY] = 4,
460
+ _a[WeekDays.FRIDAY] = 5,
461
+ _a[WeekDays.SATURDAY] = 6,
462
+ _a[WeekDays.SUNDAY] = 0,
463
+ _a);
464
+ return getDay(date) === dayMap[day];
465
+ };
466
+
467
+ /**
468
+ * @name isBefore
469
+ * @category Common Helpers
470
+ * @summary Is the first date before the second one?
471
+ *
472
+ * @description
473
+ * Is the first date before the second one?
474
+ *
475
+ * @param {Date|Number} date - the date that should be before the other one to return true
476
+ * @param {Date|Number} dateToCompare - the date to compare with
477
+ * @returns {Boolean} the first date is before the second date
478
+ * @throws {TypeError} 2 arguments required
479
+ *
480
+ * @example
481
+ * // Is 10 July 1989 before 11 February 1987?
482
+ * const result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))
483
+ * //=> false
484
+ */
485
+ function isBefore(dirtyDate, dirtyDateToCompare) {
486
+ requiredArgs(2, arguments);
487
+ var date = toDate(dirtyDate);
488
+ var dateToCompare = toDate(dirtyDateToCompare);
489
+ return date.getTime() < dateToCompare.getTime();
490
+ }
491
+
492
+ /**
493
+ * @name isAfter
494
+ * @category Common Helpers
495
+ * @summary Is the first date after the second one?
496
+ *
497
+ * @description
498
+ * Is the first date after the second one?
499
+ *
500
+ * @param {Date|Number} date - the date that should be after the other one to return true
501
+ * @param {Date|Number} dateToCompare - the date to compare with
502
+ * @returns {Boolean} the first date is after the second date
503
+ * @throws {TypeError} 2 arguments required
504
+ *
505
+ * @example
506
+ * // Is 10 July 1989 after 11 February 1987?
507
+ * const result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
508
+ * //=> true
509
+ */
510
+ function isAfter(dirtyDate, dirtyDateToCompare) {
511
+ requiredArgs(2, arguments);
512
+ var date = toDate(dirtyDate);
513
+ var dateToCompare = toDate(dirtyDateToCompare);
514
+ return date.getTime() > dateToCompare.getTime();
515
+ }
516
+
517
+ var isDisabledDate = function (date, disabledDates, minDate, maxDate) {
518
+ return ((minDate && isBefore(date, minDate)) ||
519
+ (maxDate && isAfter(date, maxDate)) ||
520
+ (disabledDates && containsDate(disabledDates, date)));
521
+ };
522
+
523
+ var isMonthBeforeMinDate = function (month, minDate) {
524
+ return getDatesInMonth(month).every(function (date) {
525
+ return isBefore(date, minDate);
526
+ });
527
+ };
528
+
529
+ var isMonthAfterMaxDate = function (date, maxDate) {
530
+ return getDatesInMonth(date).every(function (date) {
531
+ return isAfter(date, maxDate);
532
+ });
533
+ };
534
+
535
+ /**
536
+ * @name compareAsc
537
+ * @category Common Helpers
538
+ * @summary Compare the two dates and return -1, 0 or 1.
539
+ *
540
+ * @description
541
+ * Compare the two dates and return 1 if the first date is after the second,
542
+ * -1 if the first date is before the second or 0 if dates are equal.
543
+ *
544
+ * @param {Date|Number} dateLeft - the first date to compare
545
+ * @param {Date|Number} dateRight - the second date to compare
546
+ * @returns {Number} the result of the comparison
547
+ * @throws {TypeError} 2 arguments required
548
+ *
549
+ * @example
550
+ * // Compare 11 February 1987 and 10 July 1989:
551
+ * const result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10))
552
+ * //=> -1
553
+ *
554
+ * @example
555
+ * // Sort the array of dates:
556
+ * const result = [
557
+ * new Date(1995, 6, 2),
558
+ * new Date(1987, 1, 11),
559
+ * new Date(1989, 6, 10)
560
+ * ].sort(compareAsc)
561
+ * //=> [
562
+ * // Wed Feb 11 1987 00:00:00,
563
+ * // Mon Jul 10 1989 00:00:00,
564
+ * // Sun Jul 02 1995 00:00:00
565
+ * // ]
566
+ */
567
+ function compareAsc(dirtyDateLeft, dirtyDateRight) {
568
+ requiredArgs(2, arguments);
569
+ var dateLeft = toDate(dirtyDateLeft);
570
+ var dateRight = toDate(dirtyDateRight);
571
+ var diff = dateLeft.getTime() - dateRight.getTime();
572
+ if (diff < 0) {
573
+ return -1;
574
+ } else if (diff > 0) {
575
+ return 1;
576
+ // Return 0 if diff is 0; return NaN if diff is NaN
577
+ } else {
578
+ return diff;
579
+ }
580
+ }
581
+
582
+ /**
583
+ * @name eachDayOfInterval
584
+ * @category Interval Helpers
585
+ * @summary Return the array of dates within the specified time interval.
586
+ *
587
+ * @description
588
+ * Return the array of dates within the specified time interval.
589
+ *
590
+ * @param {Interval} interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval}
591
+ * @param {Object} [options] - an object with options.
592
+ * @param {Number} [options.step=1] - the step to increment by. The value should be more than 1.
593
+ * @returns {Date[]} the array with starts of days from the day of the interval start to the day of the interval end
594
+ * @throws {TypeError} 1 argument required
595
+ * @throws {RangeError} `options.step` must be a number greater than 1
596
+ * @throws {RangeError} The start of an interval cannot be after its end
597
+ * @throws {RangeError} Date in interval cannot be `Invalid Date`
598
+ *
599
+ * @example
600
+ * // Each day between 6 October 2014 and 10 October 2014:
601
+ * const result = eachDayOfInterval({
602
+ * start: new Date(2014, 9, 6),
603
+ * end: new Date(2014, 9, 10)
604
+ * })
605
+ * //=> [
606
+ * // Mon Oct 06 2014 00:00:00,
607
+ * // Tue Oct 07 2014 00:00:00,
608
+ * // Wed Oct 08 2014 00:00:00,
609
+ * // Thu Oct 09 2014 00:00:00,
610
+ * // Fri Oct 10 2014 00:00:00
611
+ * // ]
612
+ */
613
+ function eachDayOfInterval(dirtyInterval, options) {
614
+ var _options$step;
615
+ requiredArgs(1, arguments);
616
+ var interval = dirtyInterval || {};
617
+ var startDate = toDate(interval.start);
618
+ var endDate = toDate(interval.end);
619
+ var endTime = endDate.getTime();
620
+
621
+ // Throw an exception if start date is after end date or if any date is `Invalid Date`
622
+ if (!(startDate.getTime() <= endTime)) {
623
+ throw new RangeError('Invalid interval');
624
+ }
625
+ var dates = [];
626
+ var currentDate = startDate;
627
+ currentDate.setHours(0, 0, 0, 0);
628
+ var step = Number((_options$step = options === null || options === void 0 ? void 0 : options.step) !== null && _options$step !== void 0 ? _options$step : 1);
629
+ if (step < 1 || isNaN(step)) throw new RangeError('`options.step` must be a number greater than 1');
630
+ while (currentDate.getTime() <= endTime) {
631
+ dates.push(toDate(currentDate));
632
+ currentDate.setDate(currentDate.getDate() + step);
633
+ currentDate.setHours(0, 0, 0, 0);
634
+ }
635
+ return dates;
636
+ }
637
+
638
+ var processSelectedRange = function (_a) {
639
+ var range = _a.range, value = _a.value, disabledDates = _a.disabledDates;
640
+ var exisitingRange = range.filter(function (date) { return Boolean(date); });
641
+ var newRange = filterDataAttrs.__spreadArray(filterDataAttrs.__spreadArray([], (exisitingRange.length === 2 ? [] : exisitingRange), true), [
642
+ value,
643
+ ], false).sort(compareAsc);
644
+ var isSelectionComplete = newRange.length === 2;
645
+ var allDaysInRange = isSelectionComplete
646
+ ? eachDayOfInterval({
647
+ start: newRange[0],
648
+ end: newRange[1]
649
+ })
650
+ : [];
651
+ var rangeOnChangeValue = {
652
+ dates: allDaysInRange.map(function (date) { return ({
653
+ value: date,
654
+ disabled: disabledDates ? containsDate(disabledDates, date) : false
655
+ }); }),
656
+ selectedDate: value,
657
+ start: newRange[0],
658
+ end: newRange[1],
659
+ isSelectionComplete: isSelectionComplete
660
+ };
661
+ return {
662
+ rangeValue: newRange,
663
+ rangeOnChangeValue: rangeOnChangeValue
664
+ };
665
+ };
666
+
667
+ var getCalendarType = function (type, isDesktop) {
668
+ if (type === "double" && !isDesktop) {
669
+ return "month";
670
+ }
671
+ if (type === "double" && isDesktop) {
672
+ return "double";
673
+ }
674
+ return type;
675
+ };
676
+
677
+ var getDoubleMonthDisplayRange = function (date) {
678
+ var firstMonth = getMonth(date) % 2 !== 0 ? subMonths(date, 1) : date;
679
+ var secondMonth = addMonths(firstMonth, 1);
680
+ return [firstMonth, secondMonth];
681
+ };
682
+
683
+ var getFocusDate = function (_a) {
684
+ var minDate = _a.minDate, maxDate = _a.maxDate, date = _a.date;
685
+ var isFocusDateBeforeMinDate = minDate && isBefore(date, minDate);
686
+ var isFocusDateAfterMaxDate = maxDate && isAfter(date, maxDate);
687
+ if (isFocusDateBeforeMinDate) {
688
+ return minDate;
689
+ }
690
+ if (isFocusDateAfterMaxDate) {
691
+ return maxDate;
692
+ }
693
+ return date;
694
+ };
695
+
696
+ var getHighlightRange = function (_a) {
697
+ var date = _a.date, minDate = _a.minDate, maxDate = _a.maxDate, range = _a.range;
698
+ var existingRange = range.filter(function (date) { return Boolean(date); });
699
+ if (existingRange.filter(function (date) { return Boolean(date); }).length === 1) {
700
+ var isDateBeforeMinDate = minDate && isBefore(date, minDate);
701
+ var isDateAfterMaxDate = maxDate && isAfter(date, maxDate);
702
+ if (isDateBeforeMinDate) {
703
+ return [minDate, existingRange[0]].sort(compareAsc);
704
+ }
705
+ if (isDateAfterMaxDate) {
706
+ return [maxDate, existingRange[0]].sort(compareAsc);
707
+ }
708
+ return [date, existingRange[0]].sort(compareAsc);
709
+ }
710
+ return existingRange;
711
+ };
712
+
713
+ /**
714
+ * @name addDays
715
+ * @category Day Helpers
716
+ * @summary Add the specified number of days to the given date.
717
+ *
718
+ * @description
719
+ * Add the specified number of days to the given date.
720
+ *
721
+ * @param {Date|Number} date - the date to be changed
722
+ * @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`.
723
+ * @returns {Date} - the new date with the days added
724
+ * @throws {TypeError} - 2 arguments required
725
+ *
726
+ * @example
727
+ * // Add 10 days to 1 September 2014:
728
+ * const result = addDays(new Date(2014, 8, 1), 10)
729
+ * //=> Thu Sep 11 2014 00:00:00
730
+ */
731
+ function addDays(dirtyDate, dirtyAmount) {
732
+ requiredArgs(2, arguments);
733
+ var date = toDate(dirtyDate);
734
+ var amount = toInteger(dirtyAmount);
735
+ if (isNaN(amount)) {
736
+ return new Date(NaN);
737
+ }
738
+ if (!amount) {
739
+ // If 0 days, no-op to avoid changing times in the hour before end of DST
740
+ return date;
741
+ }
742
+ date.setDate(date.getDate() + amount);
743
+ return date;
744
+ }
745
+
746
+ /**
747
+ * @name addWeeks
748
+ * @category Week Helpers
749
+ * @summary Add the specified number of weeks to the given date.
750
+ *
751
+ * @description
752
+ * Add the specified number of week to the given date.
753
+ *
754
+ * @param {Date|Number} date - the date to be changed
755
+ * @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`.
756
+ * @returns {Date} the new date with the weeks added
757
+ * @throws {TypeError} 2 arguments required
758
+ *
759
+ * @example
760
+ * // Add 4 weeks to 1 September 2014:
761
+ * const result = addWeeks(new Date(2014, 8, 1), 4)
762
+ * //=> Mon Sep 29 2014 00:00:00
763
+ */
764
+ function addWeeks(dirtyDate, dirtyAmount) {
765
+ requiredArgs(2, arguments);
766
+ var amount = toInteger(dirtyAmount);
767
+ var days = amount * 7;
768
+ return addDays(dirtyDate, days);
769
+ }
770
+
771
+ /**
772
+ * @name subDays
773
+ * @category Day Helpers
774
+ * @summary Subtract the specified number of days from the given date.
775
+ *
776
+ * @description
777
+ * Subtract the specified number of days from the given date.
778
+ *
779
+ * @param {Date|Number} date - the date to be changed
780
+ * @param {Number} amount - the amount of days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
781
+ * @returns {Date} the new date with the days subtracted
782
+ * @throws {TypeError} 2 arguments required
783
+ *
784
+ * @example
785
+ * // Subtract 10 days from 1 September 2014:
786
+ * const result = subDays(new Date(2014, 8, 1), 10)
787
+ * //=> Fri Aug 22 2014 00:00:00
788
+ */
789
+ function subDays(dirtyDate, dirtyAmount) {
790
+ requiredArgs(2, arguments);
791
+ var amount = toInteger(dirtyAmount);
792
+ return addDays(dirtyDate, -amount);
793
+ }
794
+
795
+ var defaultOptions = {};
796
+ function getDefaultOptions() {
797
+ return defaultOptions;
798
+ }
799
+
800
+ /**
801
+ * @name startOfWeek
802
+ * @category Week Helpers
803
+ * @summary Return the start of a week for the given date.
804
+ *
805
+ * @description
806
+ * Return the start of a week for the given date.
807
+ * The result will be in the local timezone.
808
+ *
809
+ * @param {Date|Number} date - the original date
810
+ * @param {Object} [options] - an object with options.
811
+ * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
812
+ * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
813
+ * @returns {Date} the start of a week
814
+ * @throws {TypeError} 1 argument required
815
+ * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
816
+ *
817
+ * @example
818
+ * // The start of a week for 2 September 2014 11:55:00:
819
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
820
+ * //=> Sun Aug 31 2014 00:00:00
821
+ *
822
+ * @example
823
+ * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
824
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
825
+ * //=> Mon Sep 01 2014 00:00:00
826
+ */
827
+ function startOfWeek(dirtyDate, options) {
828
+ var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
829
+ requiredArgs(1, arguments);
830
+ var defaultOptions = getDefaultOptions();
831
+ var weekStartsOn = toInteger((_ref = (_ref2 = (_ref3 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.weekStartsOn) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.weekStartsOn) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.weekStartsOn) !== null && _ref !== void 0 ? _ref : 0);
832
+
833
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
834
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
835
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
836
+ }
837
+ var date = toDate(dirtyDate);
838
+ var day = date.getDay();
839
+ var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
840
+ date.setDate(date.getDate() - diff);
841
+ date.setHours(0, 0, 0, 0);
842
+ return date;
843
+ }
844
+
845
+ /**
846
+ * @name endOfWeek
847
+ * @category Week Helpers
848
+ * @summary Return the end of a week for the given date.
849
+ *
850
+ * @description
851
+ * Return the end of a week for the given date.
852
+ * The result will be in the local timezone.
853
+ *
854
+ * @param {Date|Number} date - the original date
855
+ * @param {Object} [options] - an object with options.
856
+ * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
857
+ * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
858
+ * @returns {Date} the end of a week
859
+ * @throws {TypeError} 1 argument required
860
+ * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
861
+ *
862
+ * @example
863
+ * // The end of a week for 2 September 2014 11:55:00:
864
+ * const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0))
865
+ * //=> Sat Sep 06 2014 23:59:59.999
866
+ *
867
+ * @example
868
+ * // If the week starts on Monday, the end of the week for 2 September 2014 11:55:00:
869
+ * const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
870
+ * //=> Sun Sep 07 2014 23:59:59.999
871
+ */
872
+ function endOfWeek(dirtyDate, options) {
873
+ var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
874
+ requiredArgs(1, arguments);
875
+ var defaultOptions = getDefaultOptions();
876
+ var weekStartsOn = toInteger((_ref = (_ref2 = (_ref3 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.weekStartsOn) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.weekStartsOn) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.weekStartsOn) !== null && _ref !== void 0 ? _ref : 0);
877
+
878
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
879
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
880
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
881
+ }
882
+ var date = toDate(dirtyDate);
883
+ var day = date.getDay();
884
+ var diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn);
885
+ date.setDate(date.getDate() + diff);
886
+ date.setHours(23, 59, 59, 999);
887
+ return date;
888
+ }
889
+
890
+ /**
891
+ * @name subWeeks
892
+ * @category Week Helpers
893
+ * @summary Subtract the specified number of weeks from the given date.
894
+ *
895
+ * @description
896
+ * Subtract the specified number of weeks from the given date.
897
+ *
898
+ * @param {Date|Number} date - the date to be changed
899
+ * @param {Number} amount - the amount of weeks to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
900
+ * @returns {Date} the new date with the weeks subtracted
901
+ * @throws {TypeError} 2 arguments required
902
+ *
903
+ * @example
904
+ * // Subtract 4 weeks from 1 September 2014:
905
+ * const result = subWeeks(new Date(2014, 8, 1), 4)
906
+ * //=> Mon Aug 04 2014 00:00:00
907
+ */
908
+ function subWeeks(dirtyDate, dirtyAmount) {
909
+ requiredArgs(2, arguments);
910
+ var amount = toInteger(dirtyAmount);
911
+ return addWeeks(dirtyDate, -amount);
912
+ }
913
+
914
+ /**
915
+ * @name addYears
916
+ * @category Year Helpers
917
+ * @summary Add the specified number of years to the given date.
918
+ *
919
+ * @description
920
+ * Add the specified number of years to the given date.
921
+ *
922
+ * @param {Date|Number} date - the date to be changed
923
+ * @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`.
924
+ * @returns {Date} the new date with the years added
925
+ * @throws {TypeError} 2 arguments required
926
+ *
927
+ * @example
928
+ * // Add 5 years to 1 September 2014:
929
+ * const result = addYears(new Date(2014, 8, 1), 5)
930
+ * //=> Sun Sep 01 2019 00:00:00
931
+ */
932
+ function addYears(dirtyDate, dirtyAmount) {
933
+ requiredArgs(2, arguments);
934
+ var amount = toInteger(dirtyAmount);
935
+ return addMonths(dirtyDate, amount * 12);
936
+ }
937
+
938
+ /**
939
+ * @name subYears
940
+ * @category Year Helpers
941
+ * @summary Subtract the specified number of years from the given date.
942
+ *
943
+ * @description
944
+ * Subtract the specified number of years from the given date.
945
+ *
946
+ * @param {Date|Number} date - the date to be changed
947
+ * @param {Number} amount - the amount of years to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
948
+ * @returns {Date} the new date with the years subtracted
949
+ * @throws {TypeError} 2 arguments required
950
+ *
951
+ * @example
952
+ * // Subtract 5 years from 1 September 2014:
953
+ * const result = subYears(new Date(2014, 8, 1), 5)
954
+ * //=> Tue Sep 01 2009 00:00:00
955
+ */
956
+ function subYears(dirtyDate, dirtyAmount) {
957
+ requiredArgs(2, arguments);
958
+ var amount = toInteger(dirtyAmount);
959
+ return addYears(dirtyDate, -amount);
960
+ }
961
+
962
+ var KeyNames;
963
+ (function (KeyNames) {
964
+ KeyNames["ArrowUp"] = "ArrowUp";
965
+ KeyNames["ArrowDown"] = "ArrowDown";
966
+ KeyNames["ArrowLeft"] = "ArrowLeft";
967
+ KeyNames["ArrowRight"] = "ArrowRight";
968
+ KeyNames["Home"] = "Home";
969
+ KeyNames["End"] = "End";
970
+ KeyNames["PageUp"] = "PageUp";
971
+ KeyNames["PageDown"] = "PageDown";
972
+ KeyNames["Tab"] = "Tab";
973
+ KeyNames["Enter"] = "Enter";
974
+ KeyNames["Space"] = " ";
975
+ })(KeyNames || (KeyNames = {}));
976
+
977
+ var getKeyDownDate = function (_a) {
978
+ var key = _a.key, shiftKey = _a.shiftKey, focusDate = _a.focusDate;
979
+ switch (key) {
980
+ case KeyNames.ArrowDown:
981
+ return addWeeks(focusDate, 1);
982
+ case KeyNames.ArrowLeft:
983
+ return subDays(focusDate, 1);
984
+ case KeyNames.ArrowRight:
985
+ return addDays(focusDate, 1);
986
+ case KeyNames.ArrowUp:
987
+ return subWeeks(focusDate, 1);
988
+ case KeyNames.Home:
989
+ return dateWithoutTime(startOfWeek(focusDate, { weekStartsOn: 1 }));
990
+ case KeyNames.End:
991
+ return dateWithoutTime(endOfWeek(focusDate, { weekStartsOn: 1 }));
992
+ case KeyNames.PageUp:
993
+ return shiftKey ? subYears(focusDate, 1) : subMonths(focusDate, 1);
994
+ case KeyNames.PageDown:
995
+ return shiftKey ? addYears(focusDate, 1) : addMonths(focusDate, 1);
996
+ default:
997
+ return focusDate;
998
+ }
999
+ };
1000
+
1001
+ /**
1002
+ * @name endOfDay
1003
+ * @category Day Helpers
1004
+ * @summary Return the end of a day for the given date.
1005
+ *
1006
+ * @description
1007
+ * Return the end of a day for the given date.
1008
+ * The result will be in the local timezone.
1009
+ *
1010
+ * @param {Date|Number} date - the original date
1011
+ * @returns {Date} the end of a day
1012
+ * @throws {TypeError} 1 argument required
1013
+ *
1014
+ * @example
1015
+ * // The end of a day for 2 September 2014 11:55:00:
1016
+ * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0))
1017
+ * //=> Tue Sep 02 2014 23:59:59.999
1018
+ */
1019
+ function endOfDay(dirtyDate) {
1020
+ requiredArgs(1, arguments);
1021
+ var date = toDate(dirtyDate);
1022
+ date.setHours(23, 59, 59, 999);
1023
+ return date;
1024
+ }
1025
+
1026
+ /**
1027
+ * @name endOfMonth
1028
+ * @category Month Helpers
1029
+ * @summary Return the end of a month for the given date.
1030
+ *
1031
+ * @description
1032
+ * Return the end of a month for the given date.
1033
+ * The result will be in the local timezone.
1034
+ *
1035
+ * @param {Date|Number} date - the original date
1036
+ * @returns {Date} the end of a month
1037
+ * @throws {TypeError} 1 argument required
1038
+ *
1039
+ * @example
1040
+ * // The end of a month for 2 September 2014 11:55:00:
1041
+ * const result = endOfMonth(new Date(2014, 8, 2, 11, 55, 0))
1042
+ * //=> Tue Sep 30 2014 23:59:59.999
1043
+ */
1044
+ function endOfMonth(dirtyDate) {
1045
+ requiredArgs(1, arguments);
1046
+ var date = toDate(dirtyDate);
1047
+ var month = date.getMonth();
1048
+ date.setFullYear(date.getFullYear(), month + 1, 0);
1049
+ date.setHours(23, 59, 59, 999);
1050
+ return date;
1051
+ }
1052
+
1053
+ /**
1054
+ * @name isLastDayOfMonth
1055
+ * @category Month Helpers
1056
+ * @summary Is the given date the last day of a month?
1057
+ *
1058
+ * @description
1059
+ * Is the given date the last day of a month?
1060
+ *
1061
+ * @param {Date|Number} date - the date to check
1062
+ * @returns {Boolean} the date is the last day of a month
1063
+ * @throws {TypeError} 1 argument required
1064
+ *
1065
+ * @example
1066
+ * // Is 28 February 2014 the last day of a month?
1067
+ * const result = isLastDayOfMonth(new Date(2014, 1, 28))
1068
+ * //=> true
1069
+ */
1070
+ function isLastDayOfMonth(dirtyDate) {
1071
+ requiredArgs(1, arguments);
1072
+ var date = toDate(dirtyDate);
1073
+ return endOfDay(date).getTime() === endOfMonth(date).getTime();
1074
+ }
1075
+
1076
+ /**
1077
+ * @name isFirstDayOfMonth
1078
+ * @category Month Helpers
1079
+ * @summary Is the given date the first day of a month?
1080
+ *
1081
+ * @description
1082
+ * Is the given date the first day of a month?
1083
+ *
1084
+ * @param {Date|Number} date - the date to check
1085
+ * @returns {Boolean} the date is the first day of a month
1086
+ * @throws {TypeError} 1 argument required
1087
+ *
1088
+ * @example
1089
+ * // Is 1 September 2014 the first day of a month?
1090
+ * const result = isFirstDayOfMonth(new Date(2014, 8, 1))
1091
+ * //=> true
1092
+ */
1093
+ function isFirstDayOfMonth(dirtyDate) {
1094
+ requiredArgs(1, arguments);
1095
+ return toDate(dirtyDate).getDate() === 1;
1096
+ }
1097
+
1098
+ /**
1099
+ * @name getDate
1100
+ * @category Day Helpers
1101
+ * @summary Get the day of the month of the given date.
1102
+ *
1103
+ * @description
1104
+ * Get the day of the month of the given date.
1105
+ *
1106
+ * @param {Date|Number} date - the given date
1107
+ * @returns {Number} the day of month
1108
+ * @throws {TypeError} 1 argument required
1109
+ *
1110
+ * @example
1111
+ * // Which day of the month is 29 February 2012?
1112
+ * const result = getDate(new Date(2012, 1, 29))
1113
+ * //=> 29
1114
+ */
1115
+ function getDate(dirtyDate) {
1116
+ requiredArgs(1, arguments);
1117
+ var date = toDate(dirtyDate);
1118
+ var dayOfMonth = date.getDate();
1119
+ return dayOfMonth;
1120
+ }
1121
+
1122
+ /**
1123
+ * @name isEqual
1124
+ * @category Common Helpers
1125
+ * @summary Are the given dates equal?
1126
+ *
1127
+ * @description
1128
+ * Are the given dates equal?
1129
+ *
1130
+ * @param {Date|Number} dateLeft - the first date to compare
1131
+ * @param {Date|Number} dateRight - the second date to compare
1132
+ * @returns {Boolean} the dates are equal
1133
+ * @throws {TypeError} 2 arguments required
1134
+ *
1135
+ * @example
1136
+ * // Are 2 July 2014 06:30:45.000 and 2 July 2014 06:30:45.500 equal?
1137
+ * const result = isEqual(
1138
+ * new Date(2014, 6, 2, 6, 30, 45, 0),
1139
+ * new Date(2014, 6, 2, 6, 30, 45, 500)
1140
+ * )
1141
+ * //=> false
1142
+ */
1143
+ function isEqual(dirtyLeftDate, dirtyRightDate) {
1144
+ requiredArgs(2, arguments);
1145
+ var dateLeft = toDate(dirtyLeftDate);
1146
+ var dateRight = toDate(dirtyRightDate);
1147
+ return dateLeft.getTime() === dateRight.getTime();
1148
+ }
1149
+
1150
+ /**
1151
+ * @name isDate
1152
+ * @category Common Helpers
1153
+ * @summary Is the given value a date?
1154
+ *
1155
+ * @description
1156
+ * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
1157
+ *
1158
+ * @param {*} value - the value to check
1159
+ * @returns {boolean} true if the given value is a date
1160
+ * @throws {TypeError} 1 arguments required
1161
+ *
1162
+ * @example
1163
+ * // For a valid date:
1164
+ * const result = isDate(new Date())
1165
+ * //=> true
1166
+ *
1167
+ * @example
1168
+ * // For an invalid date:
1169
+ * const result = isDate(new Date(NaN))
1170
+ * //=> true
1171
+ *
1172
+ * @example
1173
+ * // For some value:
1174
+ * const result = isDate('2014-02-31')
1175
+ * //=> false
1176
+ *
1177
+ * @example
1178
+ * // For an object:
1179
+ * const result = isDate({})
1180
+ * //=> false
1181
+ */
1182
+ function isDate(value) {
1183
+ requiredArgs(1, arguments);
1184
+ return value instanceof Date || _typeof(value) === 'object' && Object.prototype.toString.call(value) === '[object Date]';
1185
+ }
1186
+
1187
+ /**
1188
+ * @name isValid
1189
+ * @category Common Helpers
1190
+ * @summary Is the given date valid?
1191
+ *
1192
+ * @description
1193
+ * Returns false if argument is Invalid Date and true otherwise.
1194
+ * Argument is converted to Date using `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
1195
+ * Invalid Date is a Date, whose time value is NaN.
1196
+ *
1197
+ * Time value of Date: http://es5.github.io/#x15.9.1.1
1198
+ *
1199
+ * @param {*} date - the date to check
1200
+ * @returns {Boolean} the date is valid
1201
+ * @throws {TypeError} 1 argument required
1202
+ *
1203
+ * @example
1204
+ * // For the valid date:
1205
+ * const result = isValid(new Date(2014, 1, 31))
1206
+ * //=> true
1207
+ *
1208
+ * @example
1209
+ * // For the value, convertable into a date:
1210
+ * const result = isValid(1393804800000)
1211
+ * //=> true
1212
+ *
1213
+ * @example
1214
+ * // For the invalid date:
1215
+ * const result = isValid(new Date(''))
1216
+ * //=> false
1217
+ */
1218
+ function isValid(dirtyDate) {
1219
+ requiredArgs(1, arguments);
1220
+ if (!isDate(dirtyDate) && typeof dirtyDate !== 'number') {
1221
+ return false;
1222
+ }
1223
+ var date = toDate(dirtyDate);
1224
+ return !isNaN(Number(date));
1225
+ }
1226
+
1227
+ /**
1228
+ * @name addMilliseconds
1229
+ * @category Millisecond Helpers
1230
+ * @summary Add the specified number of milliseconds to the given date.
1231
+ *
1232
+ * @description
1233
+ * Add the specified number of milliseconds to the given date.
1234
+ *
1235
+ * @param {Date|Number} date - the date to be changed
1236
+ * @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`.
1237
+ * @returns {Date} the new date with the milliseconds added
1238
+ * @throws {TypeError} 2 arguments required
1239
+ *
1240
+ * @example
1241
+ * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
1242
+ * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
1243
+ * //=> Thu Jul 10 2014 12:45:30.750
1244
+ */
1245
+ function addMilliseconds(dirtyDate, dirtyAmount) {
1246
+ requiredArgs(2, arguments);
1247
+ var timestamp = toDate(dirtyDate).getTime();
1248
+ var amount = toInteger(dirtyAmount);
1249
+ return new Date(timestamp + amount);
1250
+ }
1251
+
1252
+ /**
1253
+ * @name subMilliseconds
1254
+ * @category Millisecond Helpers
1255
+ * @summary Subtract the specified number of milliseconds from the given date.
1256
+ *
1257
+ * @description
1258
+ * Subtract the specified number of milliseconds from the given date.
1259
+ *
1260
+ * @param {Date|Number} date - the date to be changed
1261
+ * @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`.
1262
+ * @returns {Date} the new date with the milliseconds subtracted
1263
+ * @throws {TypeError} 2 arguments required
1264
+ *
1265
+ * @example
1266
+ * // Subtract 750 milliseconds from 10 July 2014 12:45:30.000:
1267
+ * const result = subMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
1268
+ * //=> Thu Jul 10 2014 12:45:29.250
1269
+ */
1270
+ function subMilliseconds(dirtyDate, dirtyAmount) {
1271
+ requiredArgs(2, arguments);
1272
+ var amount = toInteger(dirtyAmount);
1273
+ return addMilliseconds(dirtyDate, -amount);
1274
+ }
1275
+
1276
+ var MILLISECONDS_IN_DAY = 86400000;
1277
+ function getUTCDayOfYear(dirtyDate) {
1278
+ requiredArgs(1, arguments);
1279
+ var date = toDate(dirtyDate);
1280
+ var timestamp = date.getTime();
1281
+ date.setUTCMonth(0, 1);
1282
+ date.setUTCHours(0, 0, 0, 0);
1283
+ var startOfYearTimestamp = date.getTime();
1284
+ var difference = timestamp - startOfYearTimestamp;
1285
+ return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
1286
+ }
1287
+
1288
+ function startOfUTCISOWeek(dirtyDate) {
1289
+ requiredArgs(1, arguments);
1290
+ var weekStartsOn = 1;
1291
+ var date = toDate(dirtyDate);
1292
+ var day = date.getUTCDay();
1293
+ var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
1294
+ date.setUTCDate(date.getUTCDate() - diff);
1295
+ date.setUTCHours(0, 0, 0, 0);
1296
+ return date;
1297
+ }
1298
+
1299
+ function getUTCISOWeekYear(dirtyDate) {
1300
+ requiredArgs(1, arguments);
1301
+ var date = toDate(dirtyDate);
1302
+ var year = date.getUTCFullYear();
1303
+ var fourthOfJanuaryOfNextYear = new Date(0);
1304
+ fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
1305
+ fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
1306
+ var startOfNextYear = startOfUTCISOWeek(fourthOfJanuaryOfNextYear);
1307
+ var fourthOfJanuaryOfThisYear = new Date(0);
1308
+ fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
1309
+ fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
1310
+ var startOfThisYear = startOfUTCISOWeek(fourthOfJanuaryOfThisYear);
1311
+ if (date.getTime() >= startOfNextYear.getTime()) {
1312
+ return year + 1;
1313
+ } else if (date.getTime() >= startOfThisYear.getTime()) {
1314
+ return year;
1315
+ } else {
1316
+ return year - 1;
1317
+ }
1318
+ }
1319
+
1320
+ function startOfUTCISOWeekYear(dirtyDate) {
1321
+ requiredArgs(1, arguments);
1322
+ var year = getUTCISOWeekYear(dirtyDate);
1323
+ var fourthOfJanuary = new Date(0);
1324
+ fourthOfJanuary.setUTCFullYear(year, 0, 4);
1325
+ fourthOfJanuary.setUTCHours(0, 0, 0, 0);
1326
+ var date = startOfUTCISOWeek(fourthOfJanuary);
1327
+ return date;
1328
+ }
1329
+
1330
+ var MILLISECONDS_IN_WEEK$1 = 604800000;
1331
+ function getUTCISOWeek(dirtyDate) {
1332
+ requiredArgs(1, arguments);
1333
+ var date = toDate(dirtyDate);
1334
+ var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime();
1335
+
1336
+ // Round the number of days to the nearest integer
1337
+ // because the number of milliseconds in a week is not constant
1338
+ // (e.g. it's different in the week of the daylight saving time clock shift)
1339
+ return Math.round(diff / MILLISECONDS_IN_WEEK$1) + 1;
1340
+ }
1341
+
1342
+ function startOfUTCWeek(dirtyDate, options) {
1343
+ var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
1344
+ requiredArgs(1, arguments);
1345
+ var defaultOptions = getDefaultOptions();
1346
+ var weekStartsOn = toInteger((_ref = (_ref2 = (_ref3 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.weekStartsOn) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.weekStartsOn) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.weekStartsOn) !== null && _ref !== void 0 ? _ref : 0);
1347
+
1348
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
1349
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
1350
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
1351
+ }
1352
+ var date = toDate(dirtyDate);
1353
+ var day = date.getUTCDay();
1354
+ var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
1355
+ date.setUTCDate(date.getUTCDate() - diff);
1356
+ date.setUTCHours(0, 0, 0, 0);
1357
+ return date;
1358
+ }
1359
+
1360
+ function getUTCWeekYear(dirtyDate, options) {
1361
+ var _ref, _ref2, _ref3, _options$firstWeekCon, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
1362
+ requiredArgs(1, arguments);
1363
+ var date = toDate(dirtyDate);
1364
+ var year = date.getUTCFullYear();
1365
+ var defaultOptions = getDefaultOptions();
1366
+ var firstWeekContainsDate = toInteger((_ref = (_ref2 = (_ref3 = (_options$firstWeekCon = options === null || options === void 0 ? void 0 : options.firstWeekContainsDate) !== null && _options$firstWeekCon !== void 0 ? _options$firstWeekCon : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.firstWeekContainsDate) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.firstWeekContainsDate) !== null && _ref !== void 0 ? _ref : 1);
1367
+
1368
+ // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
1369
+ if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
1370
+ throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
1371
+ }
1372
+ var firstWeekOfNextYear = new Date(0);
1373
+ firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate);
1374
+ firstWeekOfNextYear.setUTCHours(0, 0, 0, 0);
1375
+ var startOfNextYear = startOfUTCWeek(firstWeekOfNextYear, options);
1376
+ var firstWeekOfThisYear = new Date(0);
1377
+ firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
1378
+ firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
1379
+ var startOfThisYear = startOfUTCWeek(firstWeekOfThisYear, options);
1380
+ if (date.getTime() >= startOfNextYear.getTime()) {
1381
+ return year + 1;
1382
+ } else if (date.getTime() >= startOfThisYear.getTime()) {
1383
+ return year;
1384
+ } else {
1385
+ return year - 1;
1386
+ }
1387
+ }
1388
+
1389
+ function startOfUTCWeekYear(dirtyDate, options) {
1390
+ var _ref, _ref2, _ref3, _options$firstWeekCon, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
1391
+ requiredArgs(1, arguments);
1392
+ var defaultOptions = getDefaultOptions();
1393
+ var firstWeekContainsDate = toInteger((_ref = (_ref2 = (_ref3 = (_options$firstWeekCon = options === null || options === void 0 ? void 0 : options.firstWeekContainsDate) !== null && _options$firstWeekCon !== void 0 ? _options$firstWeekCon : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.firstWeekContainsDate) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.firstWeekContainsDate) !== null && _ref !== void 0 ? _ref : 1);
1394
+ var year = getUTCWeekYear(dirtyDate, options);
1395
+ var firstWeek = new Date(0);
1396
+ firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
1397
+ firstWeek.setUTCHours(0, 0, 0, 0);
1398
+ var date = startOfUTCWeek(firstWeek, options);
1399
+ return date;
1400
+ }
1401
+
1402
+ var MILLISECONDS_IN_WEEK = 604800000;
1403
+ function getUTCWeek(dirtyDate, options) {
1404
+ requiredArgs(1, arguments);
1405
+ var date = toDate(dirtyDate);
1406
+ var diff = startOfUTCWeek(date, options).getTime() - startOfUTCWeekYear(date, options).getTime();
1407
+
1408
+ // Round the number of days to the nearest integer
1409
+ // because the number of milliseconds in a week is not constant
1410
+ // (e.g. it's different in the week of the daylight saving time clock shift)
1411
+ return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
1412
+ }
1413
+
1414
+ function addLeadingZeros(number, targetLength) {
1415
+ var sign = number < 0 ? '-' : '';
1416
+ var output = Math.abs(number).toString();
1417
+ while (output.length < targetLength) {
1418
+ output = '0' + output;
1419
+ }
1420
+ return sign + output;
1421
+ }
1422
+
1423
+ /*
1424
+ * | | Unit | | Unit |
1425
+ * |-----|--------------------------------|-----|--------------------------------|
1426
+ * | a | AM, PM | A* | |
1427
+ * | d | Day of month | D | |
1428
+ * | h | Hour [1-12] | H | Hour [0-23] |
1429
+ * | m | Minute | M | Month |
1430
+ * | s | Second | S | Fraction of second |
1431
+ * | y | Year (abs) | Y | |
1432
+ *
1433
+ * Letters marked by * are not implemented but reserved by Unicode standard.
1434
+ */
1435
+ var formatters$2 = {
1436
+ // Year
1437
+ y: function y(date, token) {
1438
+ // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
1439
+ // | Year | y | yy | yyy | yyyy | yyyyy |
1440
+ // |----------|-------|----|-------|-------|-------|
1441
+ // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
1442
+ // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
1443
+ // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
1444
+ // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
1445
+ // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
1446
+
1447
+ var signedYear = date.getUTCFullYear();
1448
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
1449
+ var year = signedYear > 0 ? signedYear : 1 - signedYear;
1450
+ return addLeadingZeros(token === 'yy' ? year % 100 : year, token.length);
1451
+ },
1452
+ // Month
1453
+ M: function M(date, token) {
1454
+ var month = date.getUTCMonth();
1455
+ return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2);
1456
+ },
1457
+ // Day of the month
1458
+ d: function d(date, token) {
1459
+ return addLeadingZeros(date.getUTCDate(), token.length);
1460
+ },
1461
+ // AM or PM
1462
+ a: function a(date, token) {
1463
+ var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
1464
+ switch (token) {
1465
+ case 'a':
1466
+ case 'aa':
1467
+ return dayPeriodEnumValue.toUpperCase();
1468
+ case 'aaa':
1469
+ return dayPeriodEnumValue;
1470
+ case 'aaaaa':
1471
+ return dayPeriodEnumValue[0];
1472
+ case 'aaaa':
1473
+ default:
1474
+ return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
1475
+ }
1476
+ },
1477
+ // Hour [1-12]
1478
+ h: function h(date, token) {
1479
+ return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length);
1480
+ },
1481
+ // Hour [0-23]
1482
+ H: function H(date, token) {
1483
+ return addLeadingZeros(date.getUTCHours(), token.length);
1484
+ },
1485
+ // Minute
1486
+ m: function m(date, token) {
1487
+ return addLeadingZeros(date.getUTCMinutes(), token.length);
1488
+ },
1489
+ // Second
1490
+ s: function s(date, token) {
1491
+ return addLeadingZeros(date.getUTCSeconds(), token.length);
1492
+ },
1493
+ // Fraction of second
1494
+ S: function S(date, token) {
1495
+ var numberOfDigits = token.length;
1496
+ var milliseconds = date.getUTCMilliseconds();
1497
+ var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
1498
+ return addLeadingZeros(fractionalSeconds, token.length);
1499
+ }
1500
+ };
1501
+ var formatters$3 = formatters$2;
1502
+
1503
+ var dayPeriodEnum = {
1504
+ am: 'am',
1505
+ pm: 'pm',
1506
+ midnight: 'midnight',
1507
+ noon: 'noon',
1508
+ morning: 'morning',
1509
+ afternoon: 'afternoon',
1510
+ evening: 'evening',
1511
+ night: 'night'
1512
+ };
1513
+ /*
1514
+ * | | Unit | | Unit |
1515
+ * |-----|--------------------------------|-----|--------------------------------|
1516
+ * | a | AM, PM | A* | Milliseconds in day |
1517
+ * | b | AM, PM, noon, midnight | B | Flexible day period |
1518
+ * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
1519
+ * | d | Day of month | D | Day of year |
1520
+ * | e | Local day of week | E | Day of week |
1521
+ * | f | | F* | Day of week in month |
1522
+ * | g* | Modified Julian day | G | Era |
1523
+ * | h | Hour [1-12] | H | Hour [0-23] |
1524
+ * | i! | ISO day of week | I! | ISO week of year |
1525
+ * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
1526
+ * | k | Hour [1-24] | K | Hour [0-11] |
1527
+ * | l* | (deprecated) | L | Stand-alone month |
1528
+ * | m | Minute | M | Month |
1529
+ * | n | | N | |
1530
+ * | o! | Ordinal number modifier | O | Timezone (GMT) |
1531
+ * | p! | Long localized time | P! | Long localized date |
1532
+ * | q | Stand-alone quarter | Q | Quarter |
1533
+ * | r* | Related Gregorian year | R! | ISO week-numbering year |
1534
+ * | s | Second | S | Fraction of second |
1535
+ * | t! | Seconds timestamp | T! | Milliseconds timestamp |
1536
+ * | u | Extended year | U* | Cyclic year |
1537
+ * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
1538
+ * | w | Local week of year | W* | Week of month |
1539
+ * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
1540
+ * | y | Year (abs) | Y | Local week-numbering year |
1541
+ * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
1542
+ *
1543
+ * Letters marked by * are not implemented but reserved by Unicode standard.
1544
+ *
1545
+ * Letters marked by ! are non-standard, but implemented by date-fns:
1546
+ * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
1547
+ * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
1548
+ * i.e. 7 for Sunday, 1 for Monday, etc.
1549
+ * - `I` is ISO week of year, as opposed to `w` which is local week of year.
1550
+ * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
1551
+ * `R` is supposed to be used in conjunction with `I` and `i`
1552
+ * for universal ISO week-numbering date, whereas
1553
+ * `Y` is supposed to be used in conjunction with `w` and `e`
1554
+ * for week-numbering date specific to the locale.
1555
+ * - `P` is long localized date format
1556
+ * - `p` is long localized time format
1557
+ */
1558
+
1559
+ var formatters = {
1560
+ // Era
1561
+ G: function G(date, token, localize) {
1562
+ var era = date.getUTCFullYear() > 0 ? 1 : 0;
1563
+ switch (token) {
1564
+ // AD, BC
1565
+ case 'G':
1566
+ case 'GG':
1567
+ case 'GGG':
1568
+ return localize.era(era, {
1569
+ width: 'abbreviated'
1570
+ });
1571
+ // A, B
1572
+ case 'GGGGG':
1573
+ return localize.era(era, {
1574
+ width: 'narrow'
1575
+ });
1576
+ // Anno Domini, Before Christ
1577
+ case 'GGGG':
1578
+ default:
1579
+ return localize.era(era, {
1580
+ width: 'wide'
1581
+ });
1582
+ }
1583
+ },
1584
+ // Year
1585
+ y: function y(date, token, localize) {
1586
+ // Ordinal number
1587
+ if (token === 'yo') {
1588
+ var signedYear = date.getUTCFullYear();
1589
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
1590
+ var year = signedYear > 0 ? signedYear : 1 - signedYear;
1591
+ return localize.ordinalNumber(year, {
1592
+ unit: 'year'
1593
+ });
1594
+ }
1595
+ return formatters$3.y(date, token);
1596
+ },
1597
+ // Local week-numbering year
1598
+ Y: function Y(date, token, localize, options) {
1599
+ var signedWeekYear = getUTCWeekYear(date, options);
1600
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
1601
+ var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
1602
+
1603
+ // Two digit year
1604
+ if (token === 'YY') {
1605
+ var twoDigitYear = weekYear % 100;
1606
+ return addLeadingZeros(twoDigitYear, 2);
1607
+ }
1608
+
1609
+ // Ordinal number
1610
+ if (token === 'Yo') {
1611
+ return localize.ordinalNumber(weekYear, {
1612
+ unit: 'year'
1613
+ });
1614
+ }
1615
+
1616
+ // Padding
1617
+ return addLeadingZeros(weekYear, token.length);
1618
+ },
1619
+ // ISO week-numbering year
1620
+ R: function R(date, token) {
1621
+ var isoWeekYear = getUTCISOWeekYear(date);
1622
+
1623
+ // Padding
1624
+ return addLeadingZeros(isoWeekYear, token.length);
1625
+ },
1626
+ // Extended year. This is a single number designating the year of this calendar system.
1627
+ // The main difference between `y` and `u` localizers are B.C. years:
1628
+ // | Year | `y` | `u` |
1629
+ // |------|-----|-----|
1630
+ // | AC 1 | 1 | 1 |
1631
+ // | BC 1 | 1 | 0 |
1632
+ // | BC 2 | 2 | -1 |
1633
+ // Also `yy` always returns the last two digits of a year,
1634
+ // while `uu` pads single digit years to 2 characters and returns other years unchanged.
1635
+ u: function u(date, token) {
1636
+ var year = date.getUTCFullYear();
1637
+ return addLeadingZeros(year, token.length);
1638
+ },
1639
+ // Quarter
1640
+ Q: function Q(date, token, localize) {
1641
+ var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
1642
+ switch (token) {
1643
+ // 1, 2, 3, 4
1644
+ case 'Q':
1645
+ return String(quarter);
1646
+ // 01, 02, 03, 04
1647
+ case 'QQ':
1648
+ return addLeadingZeros(quarter, 2);
1649
+ // 1st, 2nd, 3rd, 4th
1650
+ case 'Qo':
1651
+ return localize.ordinalNumber(quarter, {
1652
+ unit: 'quarter'
1653
+ });
1654
+ // Q1, Q2, Q3, Q4
1655
+ case 'QQQ':
1656
+ return localize.quarter(quarter, {
1657
+ width: 'abbreviated',
1658
+ context: 'formatting'
1659
+ });
1660
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
1661
+ case 'QQQQQ':
1662
+ return localize.quarter(quarter, {
1663
+ width: 'narrow',
1664
+ context: 'formatting'
1665
+ });
1666
+ // 1st quarter, 2nd quarter, ...
1667
+ case 'QQQQ':
1668
+ default:
1669
+ return localize.quarter(quarter, {
1670
+ width: 'wide',
1671
+ context: 'formatting'
1672
+ });
1673
+ }
1674
+ },
1675
+ // Stand-alone quarter
1676
+ q: function q(date, token, localize) {
1677
+ var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
1678
+ switch (token) {
1679
+ // 1, 2, 3, 4
1680
+ case 'q':
1681
+ return String(quarter);
1682
+ // 01, 02, 03, 04
1683
+ case 'qq':
1684
+ return addLeadingZeros(quarter, 2);
1685
+ // 1st, 2nd, 3rd, 4th
1686
+ case 'qo':
1687
+ return localize.ordinalNumber(quarter, {
1688
+ unit: 'quarter'
1689
+ });
1690
+ // Q1, Q2, Q3, Q4
1691
+ case 'qqq':
1692
+ return localize.quarter(quarter, {
1693
+ width: 'abbreviated',
1694
+ context: 'standalone'
1695
+ });
1696
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
1697
+ case 'qqqqq':
1698
+ return localize.quarter(quarter, {
1699
+ width: 'narrow',
1700
+ context: 'standalone'
1701
+ });
1702
+ // 1st quarter, 2nd quarter, ...
1703
+ case 'qqqq':
1704
+ default:
1705
+ return localize.quarter(quarter, {
1706
+ width: 'wide',
1707
+ context: 'standalone'
1708
+ });
1709
+ }
1710
+ },
1711
+ // Month
1712
+ M: function M(date, token, localize) {
1713
+ var month = date.getUTCMonth();
1714
+ switch (token) {
1715
+ case 'M':
1716
+ case 'MM':
1717
+ return formatters$3.M(date, token);
1718
+ // 1st, 2nd, ..., 12th
1719
+ case 'Mo':
1720
+ return localize.ordinalNumber(month + 1, {
1721
+ unit: 'month'
1722
+ });
1723
+ // Jan, Feb, ..., Dec
1724
+ case 'MMM':
1725
+ return localize.month(month, {
1726
+ width: 'abbreviated',
1727
+ context: 'formatting'
1728
+ });
1729
+ // J, F, ..., D
1730
+ case 'MMMMM':
1731
+ return localize.month(month, {
1732
+ width: 'narrow',
1733
+ context: 'formatting'
1734
+ });
1735
+ // January, February, ..., December
1736
+ case 'MMMM':
1737
+ default:
1738
+ return localize.month(month, {
1739
+ width: 'wide',
1740
+ context: 'formatting'
1741
+ });
1742
+ }
1743
+ },
1744
+ // Stand-alone month
1745
+ L: function L(date, token, localize) {
1746
+ var month = date.getUTCMonth();
1747
+ switch (token) {
1748
+ // 1, 2, ..., 12
1749
+ case 'L':
1750
+ return String(month + 1);
1751
+ // 01, 02, ..., 12
1752
+ case 'LL':
1753
+ return addLeadingZeros(month + 1, 2);
1754
+ // 1st, 2nd, ..., 12th
1755
+ case 'Lo':
1756
+ return localize.ordinalNumber(month + 1, {
1757
+ unit: 'month'
1758
+ });
1759
+ // Jan, Feb, ..., Dec
1760
+ case 'LLL':
1761
+ return localize.month(month, {
1762
+ width: 'abbreviated',
1763
+ context: 'standalone'
1764
+ });
1765
+ // J, F, ..., D
1766
+ case 'LLLLL':
1767
+ return localize.month(month, {
1768
+ width: 'narrow',
1769
+ context: 'standalone'
1770
+ });
1771
+ // January, February, ..., December
1772
+ case 'LLLL':
1773
+ default:
1774
+ return localize.month(month, {
1775
+ width: 'wide',
1776
+ context: 'standalone'
1777
+ });
1778
+ }
1779
+ },
1780
+ // Local week of year
1781
+ w: function w(date, token, localize, options) {
1782
+ var week = getUTCWeek(date, options);
1783
+ if (token === 'wo') {
1784
+ return localize.ordinalNumber(week, {
1785
+ unit: 'week'
1786
+ });
1787
+ }
1788
+ return addLeadingZeros(week, token.length);
1789
+ },
1790
+ // ISO week of year
1791
+ I: function I(date, token, localize) {
1792
+ var isoWeek = getUTCISOWeek(date);
1793
+ if (token === 'Io') {
1794
+ return localize.ordinalNumber(isoWeek, {
1795
+ unit: 'week'
1796
+ });
1797
+ }
1798
+ return addLeadingZeros(isoWeek, token.length);
1799
+ },
1800
+ // Day of the month
1801
+ d: function d(date, token, localize) {
1802
+ if (token === 'do') {
1803
+ return localize.ordinalNumber(date.getUTCDate(), {
1804
+ unit: 'date'
1805
+ });
1806
+ }
1807
+ return formatters$3.d(date, token);
1808
+ },
1809
+ // Day of year
1810
+ D: function D(date, token, localize) {
1811
+ var dayOfYear = getUTCDayOfYear(date);
1812
+ if (token === 'Do') {
1813
+ return localize.ordinalNumber(dayOfYear, {
1814
+ unit: 'dayOfYear'
1815
+ });
1816
+ }
1817
+ return addLeadingZeros(dayOfYear, token.length);
1818
+ },
1819
+ // Day of week
1820
+ E: function E(date, token, localize) {
1821
+ var dayOfWeek = date.getUTCDay();
1822
+ switch (token) {
1823
+ // Tue
1824
+ case 'E':
1825
+ case 'EE':
1826
+ case 'EEE':
1827
+ return localize.day(dayOfWeek, {
1828
+ width: 'abbreviated',
1829
+ context: 'formatting'
1830
+ });
1831
+ // T
1832
+ case 'EEEEE':
1833
+ return localize.day(dayOfWeek, {
1834
+ width: 'narrow',
1835
+ context: 'formatting'
1836
+ });
1837
+ // Tu
1838
+ case 'EEEEEE':
1839
+ return localize.day(dayOfWeek, {
1840
+ width: 'short',
1841
+ context: 'formatting'
1842
+ });
1843
+ // Tuesday
1844
+ case 'EEEE':
1845
+ default:
1846
+ return localize.day(dayOfWeek, {
1847
+ width: 'wide',
1848
+ context: 'formatting'
1849
+ });
1850
+ }
1851
+ },
1852
+ // Local day of week
1853
+ e: function e(date, token, localize, options) {
1854
+ var dayOfWeek = date.getUTCDay();
1855
+ var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1856
+ switch (token) {
1857
+ // Numerical value (Nth day of week with current locale or weekStartsOn)
1858
+ case 'e':
1859
+ return String(localDayOfWeek);
1860
+ // Padded numerical value
1861
+ case 'ee':
1862
+ return addLeadingZeros(localDayOfWeek, 2);
1863
+ // 1st, 2nd, ..., 7th
1864
+ case 'eo':
1865
+ return localize.ordinalNumber(localDayOfWeek, {
1866
+ unit: 'day'
1867
+ });
1868
+ case 'eee':
1869
+ return localize.day(dayOfWeek, {
1870
+ width: 'abbreviated',
1871
+ context: 'formatting'
1872
+ });
1873
+ // T
1874
+ case 'eeeee':
1875
+ return localize.day(dayOfWeek, {
1876
+ width: 'narrow',
1877
+ context: 'formatting'
1878
+ });
1879
+ // Tu
1880
+ case 'eeeeee':
1881
+ return localize.day(dayOfWeek, {
1882
+ width: 'short',
1883
+ context: 'formatting'
1884
+ });
1885
+ // Tuesday
1886
+ case 'eeee':
1887
+ default:
1888
+ return localize.day(dayOfWeek, {
1889
+ width: 'wide',
1890
+ context: 'formatting'
1891
+ });
1892
+ }
1893
+ },
1894
+ // Stand-alone local day of week
1895
+ c: function c(date, token, localize, options) {
1896
+ var dayOfWeek = date.getUTCDay();
1897
+ var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1898
+ switch (token) {
1899
+ // Numerical value (same as in `e`)
1900
+ case 'c':
1901
+ return String(localDayOfWeek);
1902
+ // Padded numerical value
1903
+ case 'cc':
1904
+ return addLeadingZeros(localDayOfWeek, token.length);
1905
+ // 1st, 2nd, ..., 7th
1906
+ case 'co':
1907
+ return localize.ordinalNumber(localDayOfWeek, {
1908
+ unit: 'day'
1909
+ });
1910
+ case 'ccc':
1911
+ return localize.day(dayOfWeek, {
1912
+ width: 'abbreviated',
1913
+ context: 'standalone'
1914
+ });
1915
+ // T
1916
+ case 'ccccc':
1917
+ return localize.day(dayOfWeek, {
1918
+ width: 'narrow',
1919
+ context: 'standalone'
1920
+ });
1921
+ // Tu
1922
+ case 'cccccc':
1923
+ return localize.day(dayOfWeek, {
1924
+ width: 'short',
1925
+ context: 'standalone'
1926
+ });
1927
+ // Tuesday
1928
+ case 'cccc':
1929
+ default:
1930
+ return localize.day(dayOfWeek, {
1931
+ width: 'wide',
1932
+ context: 'standalone'
1933
+ });
1934
+ }
1935
+ },
1936
+ // ISO day of week
1937
+ i: function i(date, token, localize) {
1938
+ var dayOfWeek = date.getUTCDay();
1939
+ var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
1940
+ switch (token) {
1941
+ // 2
1942
+ case 'i':
1943
+ return String(isoDayOfWeek);
1944
+ // 02
1945
+ case 'ii':
1946
+ return addLeadingZeros(isoDayOfWeek, token.length);
1947
+ // 2nd
1948
+ case 'io':
1949
+ return localize.ordinalNumber(isoDayOfWeek, {
1950
+ unit: 'day'
1951
+ });
1952
+ // Tue
1953
+ case 'iii':
1954
+ return localize.day(dayOfWeek, {
1955
+ width: 'abbreviated',
1956
+ context: 'formatting'
1957
+ });
1958
+ // T
1959
+ case 'iiiii':
1960
+ return localize.day(dayOfWeek, {
1961
+ width: 'narrow',
1962
+ context: 'formatting'
1963
+ });
1964
+ // Tu
1965
+ case 'iiiiii':
1966
+ return localize.day(dayOfWeek, {
1967
+ width: 'short',
1968
+ context: 'formatting'
1969
+ });
1970
+ // Tuesday
1971
+ case 'iiii':
1972
+ default:
1973
+ return localize.day(dayOfWeek, {
1974
+ width: 'wide',
1975
+ context: 'formatting'
1976
+ });
1977
+ }
1978
+ },
1979
+ // AM or PM
1980
+ a: function a(date, token, localize) {
1981
+ var hours = date.getUTCHours();
1982
+ var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1983
+ switch (token) {
1984
+ case 'a':
1985
+ case 'aa':
1986
+ return localize.dayPeriod(dayPeriodEnumValue, {
1987
+ width: 'abbreviated',
1988
+ context: 'formatting'
1989
+ });
1990
+ case 'aaa':
1991
+ return localize.dayPeriod(dayPeriodEnumValue, {
1992
+ width: 'abbreviated',
1993
+ context: 'formatting'
1994
+ }).toLowerCase();
1995
+ case 'aaaaa':
1996
+ return localize.dayPeriod(dayPeriodEnumValue, {
1997
+ width: 'narrow',
1998
+ context: 'formatting'
1999
+ });
2000
+ case 'aaaa':
2001
+ default:
2002
+ return localize.dayPeriod(dayPeriodEnumValue, {
2003
+ width: 'wide',
2004
+ context: 'formatting'
2005
+ });
2006
+ }
2007
+ },
2008
+ // AM, PM, midnight, noon
2009
+ b: function b(date, token, localize) {
2010
+ var hours = date.getUTCHours();
2011
+ var dayPeriodEnumValue;
2012
+ if (hours === 12) {
2013
+ dayPeriodEnumValue = dayPeriodEnum.noon;
2014
+ } else if (hours === 0) {
2015
+ dayPeriodEnumValue = dayPeriodEnum.midnight;
2016
+ } else {
2017
+ dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
2018
+ }
2019
+ switch (token) {
2020
+ case 'b':
2021
+ case 'bb':
2022
+ return localize.dayPeriod(dayPeriodEnumValue, {
2023
+ width: 'abbreviated',
2024
+ context: 'formatting'
2025
+ });
2026
+ case 'bbb':
2027
+ return localize.dayPeriod(dayPeriodEnumValue, {
2028
+ width: 'abbreviated',
2029
+ context: 'formatting'
2030
+ }).toLowerCase();
2031
+ case 'bbbbb':
2032
+ return localize.dayPeriod(dayPeriodEnumValue, {
2033
+ width: 'narrow',
2034
+ context: 'formatting'
2035
+ });
2036
+ case 'bbbb':
2037
+ default:
2038
+ return localize.dayPeriod(dayPeriodEnumValue, {
2039
+ width: 'wide',
2040
+ context: 'formatting'
2041
+ });
2042
+ }
2043
+ },
2044
+ // in the morning, in the afternoon, in the evening, at night
2045
+ B: function B(date, token, localize) {
2046
+ var hours = date.getUTCHours();
2047
+ var dayPeriodEnumValue;
2048
+ if (hours >= 17) {
2049
+ dayPeriodEnumValue = dayPeriodEnum.evening;
2050
+ } else if (hours >= 12) {
2051
+ dayPeriodEnumValue = dayPeriodEnum.afternoon;
2052
+ } else if (hours >= 4) {
2053
+ dayPeriodEnumValue = dayPeriodEnum.morning;
2054
+ } else {
2055
+ dayPeriodEnumValue = dayPeriodEnum.night;
2056
+ }
2057
+ switch (token) {
2058
+ case 'B':
2059
+ case 'BB':
2060
+ case 'BBB':
2061
+ return localize.dayPeriod(dayPeriodEnumValue, {
2062
+ width: 'abbreviated',
2063
+ context: 'formatting'
2064
+ });
2065
+ case 'BBBBB':
2066
+ return localize.dayPeriod(dayPeriodEnumValue, {
2067
+ width: 'narrow',
2068
+ context: 'formatting'
2069
+ });
2070
+ case 'BBBB':
2071
+ default:
2072
+ return localize.dayPeriod(dayPeriodEnumValue, {
2073
+ width: 'wide',
2074
+ context: 'formatting'
2075
+ });
2076
+ }
2077
+ },
2078
+ // Hour [1-12]
2079
+ h: function h(date, token, localize) {
2080
+ if (token === 'ho') {
2081
+ var hours = date.getUTCHours() % 12;
2082
+ if (hours === 0) hours = 12;
2083
+ return localize.ordinalNumber(hours, {
2084
+ unit: 'hour'
2085
+ });
2086
+ }
2087
+ return formatters$3.h(date, token);
2088
+ },
2089
+ // Hour [0-23]
2090
+ H: function H(date, token, localize) {
2091
+ if (token === 'Ho') {
2092
+ return localize.ordinalNumber(date.getUTCHours(), {
2093
+ unit: 'hour'
2094
+ });
2095
+ }
2096
+ return formatters$3.H(date, token);
2097
+ },
2098
+ // Hour [0-11]
2099
+ K: function K(date, token, localize) {
2100
+ var hours = date.getUTCHours() % 12;
2101
+ if (token === 'Ko') {
2102
+ return localize.ordinalNumber(hours, {
2103
+ unit: 'hour'
2104
+ });
2105
+ }
2106
+ return addLeadingZeros(hours, token.length);
2107
+ },
2108
+ // Hour [1-24]
2109
+ k: function k(date, token, localize) {
2110
+ var hours = date.getUTCHours();
2111
+ if (hours === 0) hours = 24;
2112
+ if (token === 'ko') {
2113
+ return localize.ordinalNumber(hours, {
2114
+ unit: 'hour'
2115
+ });
2116
+ }
2117
+ return addLeadingZeros(hours, token.length);
2118
+ },
2119
+ // Minute
2120
+ m: function m(date, token, localize) {
2121
+ if (token === 'mo') {
2122
+ return localize.ordinalNumber(date.getUTCMinutes(), {
2123
+ unit: 'minute'
2124
+ });
2125
+ }
2126
+ return formatters$3.m(date, token);
2127
+ },
2128
+ // Second
2129
+ s: function s(date, token, localize) {
2130
+ if (token === 'so') {
2131
+ return localize.ordinalNumber(date.getUTCSeconds(), {
2132
+ unit: 'second'
2133
+ });
2134
+ }
2135
+ return formatters$3.s(date, token);
2136
+ },
2137
+ // Fraction of second
2138
+ S: function S(date, token) {
2139
+ return formatters$3.S(date, token);
2140
+ },
2141
+ // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
2142
+ X: function X(date, token, _localize, options) {
2143
+ var originalDate = options._originalDate || date;
2144
+ var timezoneOffset = originalDate.getTimezoneOffset();
2145
+ if (timezoneOffset === 0) {
2146
+ return 'Z';
2147
+ }
2148
+ switch (token) {
2149
+ // Hours and optional minutes
2150
+ case 'X':
2151
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
2152
+
2153
+ // Hours, minutes and optional seconds without `:` delimiter
2154
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2155
+ // so this token always has the same output as `XX`
2156
+ case 'XXXX':
2157
+ case 'XX':
2158
+ // Hours and minutes without `:` delimiter
2159
+ return formatTimezone(timezoneOffset);
2160
+
2161
+ // Hours, minutes and optional seconds with `:` delimiter
2162
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2163
+ // so this token always has the same output as `XXX`
2164
+ case 'XXXXX':
2165
+ case 'XXX': // Hours and minutes with `:` delimiter
2166
+ default:
2167
+ return formatTimezone(timezoneOffset, ':');
2168
+ }
2169
+ },
2170
+ // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
2171
+ x: function x(date, token, _localize, options) {
2172
+ var originalDate = options._originalDate || date;
2173
+ var timezoneOffset = originalDate.getTimezoneOffset();
2174
+ switch (token) {
2175
+ // Hours and optional minutes
2176
+ case 'x':
2177
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
2178
+
2179
+ // Hours, minutes and optional seconds without `:` delimiter
2180
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2181
+ // so this token always has the same output as `xx`
2182
+ case 'xxxx':
2183
+ case 'xx':
2184
+ // Hours and minutes without `:` delimiter
2185
+ return formatTimezone(timezoneOffset);
2186
+
2187
+ // Hours, minutes and optional seconds with `:` delimiter
2188
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2189
+ // so this token always has the same output as `xxx`
2190
+ case 'xxxxx':
2191
+ case 'xxx': // Hours and minutes with `:` delimiter
2192
+ default:
2193
+ return formatTimezone(timezoneOffset, ':');
2194
+ }
2195
+ },
2196
+ // Timezone (GMT)
2197
+ O: function O(date, token, _localize, options) {
2198
+ var originalDate = options._originalDate || date;
2199
+ var timezoneOffset = originalDate.getTimezoneOffset();
2200
+ switch (token) {
2201
+ // Short
2202
+ case 'O':
2203
+ case 'OO':
2204
+ case 'OOO':
2205
+ return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
2206
+ // Long
2207
+ case 'OOOO':
2208
+ default:
2209
+ return 'GMT' + formatTimezone(timezoneOffset, ':');
2210
+ }
2211
+ },
2212
+ // Timezone (specific non-location)
2213
+ z: function z(date, token, _localize, options) {
2214
+ var originalDate = options._originalDate || date;
2215
+ var timezoneOffset = originalDate.getTimezoneOffset();
2216
+ switch (token) {
2217
+ // Short
2218
+ case 'z':
2219
+ case 'zz':
2220
+ case 'zzz':
2221
+ return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
2222
+ // Long
2223
+ case 'zzzz':
2224
+ default:
2225
+ return 'GMT' + formatTimezone(timezoneOffset, ':');
2226
+ }
2227
+ },
2228
+ // Seconds timestamp
2229
+ t: function t(date, token, _localize, options) {
2230
+ var originalDate = options._originalDate || date;
2231
+ var timestamp = Math.floor(originalDate.getTime() / 1000);
2232
+ return addLeadingZeros(timestamp, token.length);
2233
+ },
2234
+ // Milliseconds timestamp
2235
+ T: function T(date, token, _localize, options) {
2236
+ var originalDate = options._originalDate || date;
2237
+ var timestamp = originalDate.getTime();
2238
+ return addLeadingZeros(timestamp, token.length);
2239
+ }
2240
+ };
2241
+ function formatTimezoneShort(offset, dirtyDelimiter) {
2242
+ var sign = offset > 0 ? '-' : '+';
2243
+ var absOffset = Math.abs(offset);
2244
+ var hours = Math.floor(absOffset / 60);
2245
+ var minutes = absOffset % 60;
2246
+ if (minutes === 0) {
2247
+ return sign + String(hours);
2248
+ }
2249
+ var delimiter = dirtyDelimiter || '';
2250
+ return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
2251
+ }
2252
+ function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
2253
+ if (offset % 60 === 0) {
2254
+ var sign = offset > 0 ? '-' : '+';
2255
+ return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
2256
+ }
2257
+ return formatTimezone(offset, dirtyDelimiter);
2258
+ }
2259
+ function formatTimezone(offset, dirtyDelimiter) {
2260
+ var delimiter = dirtyDelimiter || '';
2261
+ var sign = offset > 0 ? '-' : '+';
2262
+ var absOffset = Math.abs(offset);
2263
+ var hours = addLeadingZeros(Math.floor(absOffset / 60), 2);
2264
+ var minutes = addLeadingZeros(absOffset % 60, 2);
2265
+ return sign + hours + delimiter + minutes;
2266
+ }
2267
+ var formatters$1 = formatters;
2268
+
2269
+ var dateLongFormatter = function dateLongFormatter(pattern, formatLong) {
2270
+ switch (pattern) {
2271
+ case 'P':
2272
+ return formatLong.date({
2273
+ width: 'short'
2274
+ });
2275
+ case 'PP':
2276
+ return formatLong.date({
2277
+ width: 'medium'
2278
+ });
2279
+ case 'PPP':
2280
+ return formatLong.date({
2281
+ width: 'long'
2282
+ });
2283
+ case 'PPPP':
2284
+ default:
2285
+ return formatLong.date({
2286
+ width: 'full'
2287
+ });
2288
+ }
2289
+ };
2290
+ var timeLongFormatter = function timeLongFormatter(pattern, formatLong) {
2291
+ switch (pattern) {
2292
+ case 'p':
2293
+ return formatLong.time({
2294
+ width: 'short'
2295
+ });
2296
+ case 'pp':
2297
+ return formatLong.time({
2298
+ width: 'medium'
2299
+ });
2300
+ case 'ppp':
2301
+ return formatLong.time({
2302
+ width: 'long'
2303
+ });
2304
+ case 'pppp':
2305
+ default:
2306
+ return formatLong.time({
2307
+ width: 'full'
2308
+ });
2309
+ }
2310
+ };
2311
+ var dateTimeLongFormatter = function dateTimeLongFormatter(pattern, formatLong) {
2312
+ var matchResult = pattern.match(/(P+)(p+)?/) || [];
2313
+ var datePattern = matchResult[1];
2314
+ var timePattern = matchResult[2];
2315
+ if (!timePattern) {
2316
+ return dateLongFormatter(pattern, formatLong);
2317
+ }
2318
+ var dateTimeFormat;
2319
+ switch (datePattern) {
2320
+ case 'P':
2321
+ dateTimeFormat = formatLong.dateTime({
2322
+ width: 'short'
2323
+ });
2324
+ break;
2325
+ case 'PP':
2326
+ dateTimeFormat = formatLong.dateTime({
2327
+ width: 'medium'
2328
+ });
2329
+ break;
2330
+ case 'PPP':
2331
+ dateTimeFormat = formatLong.dateTime({
2332
+ width: 'long'
2333
+ });
2334
+ break;
2335
+ case 'PPPP':
2336
+ default:
2337
+ dateTimeFormat = formatLong.dateTime({
2338
+ width: 'full'
2339
+ });
2340
+ break;
2341
+ }
2342
+ return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
2343
+ };
2344
+ var longFormatters = {
2345
+ p: timeLongFormatter,
2346
+ P: dateTimeLongFormatter
2347
+ };
2348
+ var longFormatters$1 = longFormatters;
2349
+
2350
+ /**
2351
+ * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
2352
+ * They usually appear for dates that denote time before the timezones were introduced
2353
+ * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
2354
+ * and GMT+01:00:00 after that date)
2355
+ *
2356
+ * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
2357
+ * which would lead to incorrect calculations.
2358
+ *
2359
+ * This function returns the timezone offset in milliseconds that takes seconds in account.
2360
+ */
2361
+ function getTimezoneOffsetInMilliseconds(date) {
2362
+ var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
2363
+ utcDate.setUTCFullYear(date.getFullYear());
2364
+ return date.getTime() - utcDate.getTime();
2365
+ }
2366
+
2367
+ var protectedDayOfYearTokens = ['D', 'DD'];
2368
+ var protectedWeekYearTokens = ['YY', 'YYYY'];
2369
+ function isProtectedDayOfYearToken(token) {
2370
+ return protectedDayOfYearTokens.indexOf(token) !== -1;
2371
+ }
2372
+ function isProtectedWeekYearToken(token) {
2373
+ return protectedWeekYearTokens.indexOf(token) !== -1;
2374
+ }
2375
+ function throwProtectedError(token, format, input) {
2376
+ if (token === 'YYYY') {
2377
+ throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
2378
+ } else if (token === 'YY') {
2379
+ throw new RangeError("Use `yy` instead of `YY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
2380
+ } else if (token === 'D') {
2381
+ throw new RangeError("Use `d` instead of `D` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
2382
+ } else if (token === 'DD') {
2383
+ throw new RangeError("Use `dd` instead of `DD` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
2384
+ }
2385
+ }
2386
+
2387
+ var formatDistanceLocale = {
2388
+ lessThanXSeconds: {
2389
+ one: 'less than a second',
2390
+ other: 'less than {{count}} seconds'
2391
+ },
2392
+ xSeconds: {
2393
+ one: '1 second',
2394
+ other: '{{count}} seconds'
2395
+ },
2396
+ halfAMinute: 'half a minute',
2397
+ lessThanXMinutes: {
2398
+ one: 'less than a minute',
2399
+ other: 'less than {{count}} minutes'
2400
+ },
2401
+ xMinutes: {
2402
+ one: '1 minute',
2403
+ other: '{{count}} minutes'
2404
+ },
2405
+ aboutXHours: {
2406
+ one: 'about 1 hour',
2407
+ other: 'about {{count}} hours'
2408
+ },
2409
+ xHours: {
2410
+ one: '1 hour',
2411
+ other: '{{count}} hours'
2412
+ },
2413
+ xDays: {
2414
+ one: '1 day',
2415
+ other: '{{count}} days'
2416
+ },
2417
+ aboutXWeeks: {
2418
+ one: 'about 1 week',
2419
+ other: 'about {{count}} weeks'
2420
+ },
2421
+ xWeeks: {
2422
+ one: '1 week',
2423
+ other: '{{count}} weeks'
2424
+ },
2425
+ aboutXMonths: {
2426
+ one: 'about 1 month',
2427
+ other: 'about {{count}} months'
2428
+ },
2429
+ xMonths: {
2430
+ one: '1 month',
2431
+ other: '{{count}} months'
2432
+ },
2433
+ aboutXYears: {
2434
+ one: 'about 1 year',
2435
+ other: 'about {{count}} years'
2436
+ },
2437
+ xYears: {
2438
+ one: '1 year',
2439
+ other: '{{count}} years'
2440
+ },
2441
+ overXYears: {
2442
+ one: 'over 1 year',
2443
+ other: 'over {{count}} years'
2444
+ },
2445
+ almostXYears: {
2446
+ one: 'almost 1 year',
2447
+ other: 'almost {{count}} years'
2448
+ }
2449
+ };
2450
+ var formatDistance = function formatDistance(token, count, options) {
2451
+ var result;
2452
+ var tokenValue = formatDistanceLocale[token];
2453
+ if (typeof tokenValue === 'string') {
2454
+ result = tokenValue;
2455
+ } else if (count === 1) {
2456
+ result = tokenValue.one;
2457
+ } else {
2458
+ result = tokenValue.other.replace('{{count}}', count.toString());
2459
+ }
2460
+ if (options !== null && options !== void 0 && options.addSuffix) {
2461
+ if (options.comparison && options.comparison > 0) {
2462
+ return 'in ' + result;
2463
+ } else {
2464
+ return result + ' ago';
2465
+ }
2466
+ }
2467
+ return result;
2468
+ };
2469
+ var formatDistance$1 = formatDistance;
2470
+
2471
+ function buildFormatLongFn(args) {
2472
+ return function () {
2473
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2474
+ // TODO: Remove String()
2475
+ var width = options.width ? String(options.width) : args.defaultWidth;
2476
+ var format = args.formats[width] || args.formats[args.defaultWidth];
2477
+ return format;
2478
+ };
2479
+ }
2480
+
2481
+ var dateFormats = {
2482
+ full: 'EEEE, MMMM do, y',
2483
+ long: 'MMMM do, y',
2484
+ medium: 'MMM d, y',
2485
+ short: 'MM/dd/yyyy'
2486
+ };
2487
+ var timeFormats = {
2488
+ full: 'h:mm:ss a zzzz',
2489
+ long: 'h:mm:ss a z',
2490
+ medium: 'h:mm:ss a',
2491
+ short: 'h:mm a'
2492
+ };
2493
+ var dateTimeFormats = {
2494
+ full: "{{date}} 'at' {{time}}",
2495
+ long: "{{date}} 'at' {{time}}",
2496
+ medium: '{{date}}, {{time}}',
2497
+ short: '{{date}}, {{time}}'
2498
+ };
2499
+ var formatLong = {
2500
+ date: buildFormatLongFn({
2501
+ formats: dateFormats,
2502
+ defaultWidth: 'full'
2503
+ }),
2504
+ time: buildFormatLongFn({
2505
+ formats: timeFormats,
2506
+ defaultWidth: 'full'
2507
+ }),
2508
+ dateTime: buildFormatLongFn({
2509
+ formats: dateTimeFormats,
2510
+ defaultWidth: 'full'
2511
+ })
2512
+ };
2513
+ var formatLong$1 = formatLong;
2514
+
2515
+ var formatRelativeLocale = {
2516
+ lastWeek: "'last' eeee 'at' p",
2517
+ yesterday: "'yesterday at' p",
2518
+ today: "'today at' p",
2519
+ tomorrow: "'tomorrow at' p",
2520
+ nextWeek: "eeee 'at' p",
2521
+ other: 'P'
2522
+ };
2523
+ var formatRelative = function formatRelative(token, _date, _baseDate, _options) {
2524
+ return formatRelativeLocale[token];
2525
+ };
2526
+ var formatRelative$1 = formatRelative;
2527
+
2528
+ function buildLocalizeFn(args) {
2529
+ return function (dirtyIndex, options) {
2530
+ var context = options !== null && options !== void 0 && options.context ? String(options.context) : 'standalone';
2531
+ var valuesArray;
2532
+ if (context === 'formatting' && args.formattingValues) {
2533
+ var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
2534
+ var width = options !== null && options !== void 0 && options.width ? String(options.width) : defaultWidth;
2535
+ valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
2536
+ } else {
2537
+ var _defaultWidth = args.defaultWidth;
2538
+ var _width = options !== null && options !== void 0 && options.width ? String(options.width) : args.defaultWidth;
2539
+ valuesArray = args.values[_width] || args.values[_defaultWidth];
2540
+ }
2541
+ var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex;
2542
+ // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
2543
+ return valuesArray[index];
2544
+ };
2545
+ }
2546
+
2547
+ var eraValues = {
2548
+ narrow: ['B', 'A'],
2549
+ abbreviated: ['BC', 'AD'],
2550
+ wide: ['Before Christ', 'Anno Domini']
2551
+ };
2552
+ var quarterValues = {
2553
+ narrow: ['1', '2', '3', '4'],
2554
+ abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
2555
+ wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter']
2556
+ };
2557
+
2558
+ // Note: in English, the names of days of the week and months are capitalized.
2559
+ // If you are making a new locale based on this one, check if the same is true for the language you're working on.
2560
+ // Generally, formatted dates should look like they are in the middle of a sentence,
2561
+ // e.g. in Spanish language the weekdays and months should be in the lowercase.
2562
+ var monthValues = {
2563
+ narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
2564
+ abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
2565
+ wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
2566
+ };
2567
+ var dayValues = {
2568
+ narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
2569
+ short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
2570
+ abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
2571
+ wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
2572
+ };
2573
+ var dayPeriodValues = {
2574
+ narrow: {
2575
+ am: 'a',
2576
+ pm: 'p',
2577
+ midnight: 'mi',
2578
+ noon: 'n',
2579
+ morning: 'morning',
2580
+ afternoon: 'afternoon',
2581
+ evening: 'evening',
2582
+ night: 'night'
2583
+ },
2584
+ abbreviated: {
2585
+ am: 'AM',
2586
+ pm: 'PM',
2587
+ midnight: 'midnight',
2588
+ noon: 'noon',
2589
+ morning: 'morning',
2590
+ afternoon: 'afternoon',
2591
+ evening: 'evening',
2592
+ night: 'night'
2593
+ },
2594
+ wide: {
2595
+ am: 'a.m.',
2596
+ pm: 'p.m.',
2597
+ midnight: 'midnight',
2598
+ noon: 'noon',
2599
+ morning: 'morning',
2600
+ afternoon: 'afternoon',
2601
+ evening: 'evening',
2602
+ night: 'night'
2603
+ }
2604
+ };
2605
+ var formattingDayPeriodValues = {
2606
+ narrow: {
2607
+ am: 'a',
2608
+ pm: 'p',
2609
+ midnight: 'mi',
2610
+ noon: 'n',
2611
+ morning: 'in the morning',
2612
+ afternoon: 'in the afternoon',
2613
+ evening: 'in the evening',
2614
+ night: 'at night'
2615
+ },
2616
+ abbreviated: {
2617
+ am: 'AM',
2618
+ pm: 'PM',
2619
+ midnight: 'midnight',
2620
+ noon: 'noon',
2621
+ morning: 'in the morning',
2622
+ afternoon: 'in the afternoon',
2623
+ evening: 'in the evening',
2624
+ night: 'at night'
2625
+ },
2626
+ wide: {
2627
+ am: 'a.m.',
2628
+ pm: 'p.m.',
2629
+ midnight: 'midnight',
2630
+ noon: 'noon',
2631
+ morning: 'in the morning',
2632
+ afternoon: 'in the afternoon',
2633
+ evening: 'in the evening',
2634
+ night: 'at night'
2635
+ }
2636
+ };
2637
+ var ordinalNumber = function ordinalNumber(dirtyNumber, _options) {
2638
+ var number = Number(dirtyNumber);
2639
+
2640
+ // If ordinal numbers depend on context, for example,
2641
+ // if they are different for different grammatical genders,
2642
+ // use `options.unit`.
2643
+ //
2644
+ // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
2645
+ // 'day', 'hour', 'minute', 'second'.
2646
+
2647
+ var rem100 = number % 100;
2648
+ if (rem100 > 20 || rem100 < 10) {
2649
+ switch (rem100 % 10) {
2650
+ case 1:
2651
+ return number + 'st';
2652
+ case 2:
2653
+ return number + 'nd';
2654
+ case 3:
2655
+ return number + 'rd';
2656
+ }
2657
+ }
2658
+ return number + 'th';
2659
+ };
2660
+ var localize = {
2661
+ ordinalNumber: ordinalNumber,
2662
+ era: buildLocalizeFn({
2663
+ values: eraValues,
2664
+ defaultWidth: 'wide'
2665
+ }),
2666
+ quarter: buildLocalizeFn({
2667
+ values: quarterValues,
2668
+ defaultWidth: 'wide',
2669
+ argumentCallback: function argumentCallback(quarter) {
2670
+ return quarter - 1;
2671
+ }
2672
+ }),
2673
+ month: buildLocalizeFn({
2674
+ values: monthValues,
2675
+ defaultWidth: 'wide'
2676
+ }),
2677
+ day: buildLocalizeFn({
2678
+ values: dayValues,
2679
+ defaultWidth: 'wide'
2680
+ }),
2681
+ dayPeriod: buildLocalizeFn({
2682
+ values: dayPeriodValues,
2683
+ defaultWidth: 'wide',
2684
+ formattingValues: formattingDayPeriodValues,
2685
+ defaultFormattingWidth: 'wide'
2686
+ })
2687
+ };
2688
+ var localize$1 = localize;
2689
+
2690
+ function buildMatchFn(args) {
2691
+ return function (string) {
2692
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2693
+ var width = options.width;
2694
+ var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
2695
+ var matchResult = string.match(matchPattern);
2696
+ if (!matchResult) {
2697
+ return null;
2698
+ }
2699
+ var matchedString = matchResult[0];
2700
+ var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
2701
+ var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) {
2702
+ return pattern.test(matchedString);
2703
+ }) : findKey(parsePatterns, function (pattern) {
2704
+ return pattern.test(matchedString);
2705
+ });
2706
+ var value;
2707
+ value = args.valueCallback ? args.valueCallback(key) : key;
2708
+ value = options.valueCallback ? options.valueCallback(value) : value;
2709
+ var rest = string.slice(matchedString.length);
2710
+ return {
2711
+ value: value,
2712
+ rest: rest
2713
+ };
2714
+ };
2715
+ }
2716
+ function findKey(object, predicate) {
2717
+ for (var key in object) {
2718
+ if (object.hasOwnProperty(key) && predicate(object[key])) {
2719
+ return key;
2720
+ }
2721
+ }
2722
+ return undefined;
2723
+ }
2724
+ function findIndex(array, predicate) {
2725
+ for (var key = 0; key < array.length; key++) {
2726
+ if (predicate(array[key])) {
2727
+ return key;
2728
+ }
2729
+ }
2730
+ return undefined;
2731
+ }
2732
+
2733
+ function buildMatchPatternFn(args) {
2734
+ return function (string) {
2735
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2736
+ var matchResult = string.match(args.matchPattern);
2737
+ if (!matchResult) return null;
2738
+ var matchedString = matchResult[0];
2739
+ var parseResult = string.match(args.parsePattern);
2740
+ if (!parseResult) return null;
2741
+ var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
2742
+ value = options.valueCallback ? options.valueCallback(value) : value;
2743
+ var rest = string.slice(matchedString.length);
2744
+ return {
2745
+ value: value,
2746
+ rest: rest
2747
+ };
2748
+ };
2749
+ }
2750
+
2751
+ var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
2752
+ var parseOrdinalNumberPattern = /\d+/i;
2753
+ var matchEraPatterns = {
2754
+ narrow: /^(b|a)/i,
2755
+ abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
2756
+ wide: /^(before christ|before common era|anno domini|common era)/i
2757
+ };
2758
+ var parseEraPatterns = {
2759
+ any: [/^b/i, /^(a|c)/i]
2760
+ };
2761
+ var matchQuarterPatterns = {
2762
+ narrow: /^[1234]/i,
2763
+ abbreviated: /^q[1234]/i,
2764
+ wide: /^[1234](th|st|nd|rd)? quarter/i
2765
+ };
2766
+ var parseQuarterPatterns = {
2767
+ any: [/1/i, /2/i, /3/i, /4/i]
2768
+ };
2769
+ var matchMonthPatterns = {
2770
+ narrow: /^[jfmasond]/i,
2771
+ abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
2772
+ wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
2773
+ };
2774
+ var parseMonthPatterns = {
2775
+ 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],
2776
+ 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]
2777
+ };
2778
+ var matchDayPatterns = {
2779
+ narrow: /^[smtwf]/i,
2780
+ short: /^(su|mo|tu|we|th|fr|sa)/i,
2781
+ abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
2782
+ wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
2783
+ };
2784
+ var parseDayPatterns = {
2785
+ narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
2786
+ any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
2787
+ };
2788
+ var matchDayPeriodPatterns = {
2789
+ narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
2790
+ any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
2791
+ };
2792
+ var parseDayPeriodPatterns = {
2793
+ any: {
2794
+ am: /^a/i,
2795
+ pm: /^p/i,
2796
+ midnight: /^mi/i,
2797
+ noon: /^no/i,
2798
+ morning: /morning/i,
2799
+ afternoon: /afternoon/i,
2800
+ evening: /evening/i,
2801
+ night: /night/i
2802
+ }
2803
+ };
2804
+ var match = {
2805
+ ordinalNumber: buildMatchPatternFn({
2806
+ matchPattern: matchOrdinalNumberPattern,
2807
+ parsePattern: parseOrdinalNumberPattern,
2808
+ valueCallback: function valueCallback(value) {
2809
+ return parseInt(value, 10);
2810
+ }
2811
+ }),
2812
+ era: buildMatchFn({
2813
+ matchPatterns: matchEraPatterns,
2814
+ defaultMatchWidth: 'wide',
2815
+ parsePatterns: parseEraPatterns,
2816
+ defaultParseWidth: 'any'
2817
+ }),
2818
+ quarter: buildMatchFn({
2819
+ matchPatterns: matchQuarterPatterns,
2820
+ defaultMatchWidth: 'wide',
2821
+ parsePatterns: parseQuarterPatterns,
2822
+ defaultParseWidth: 'any',
2823
+ valueCallback: function valueCallback(index) {
2824
+ return index + 1;
2825
+ }
2826
+ }),
2827
+ month: buildMatchFn({
2828
+ matchPatterns: matchMonthPatterns,
2829
+ defaultMatchWidth: 'wide',
2830
+ parsePatterns: parseMonthPatterns,
2831
+ defaultParseWidth: 'any'
2832
+ }),
2833
+ day: buildMatchFn({
2834
+ matchPatterns: matchDayPatterns,
2835
+ defaultMatchWidth: 'wide',
2836
+ parsePatterns: parseDayPatterns,
2837
+ defaultParseWidth: 'any'
2838
+ }),
2839
+ dayPeriod: buildMatchFn({
2840
+ matchPatterns: matchDayPeriodPatterns,
2841
+ defaultMatchWidth: 'any',
2842
+ parsePatterns: parseDayPeriodPatterns,
2843
+ defaultParseWidth: 'any'
2844
+ })
2845
+ };
2846
+ var match$1 = match;
2847
+
2848
+ /**
2849
+ * @type {Locale}
2850
+ * @category Locales
2851
+ * @summary English locale (United States).
2852
+ * @language English
2853
+ * @iso-639-2 eng
2854
+ * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}
2855
+ * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}
2856
+ */
2857
+ var locale = {
2858
+ code: 'en-US',
2859
+ formatDistance: formatDistance$1,
2860
+ formatLong: formatLong$1,
2861
+ formatRelative: formatRelative$1,
2862
+ localize: localize$1,
2863
+ match: match$1,
2864
+ options: {
2865
+ weekStartsOn: 0 /* Sunday */,
2866
+ firstWeekContainsDate: 1
2867
+ }
2868
+ };
2869
+ var defaultLocale = locale;
2870
+
2871
+ // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
2872
+ // (one of the certain letters followed by `o`)
2873
+ // - (\w)\1* matches any sequences of the same letter
2874
+ // - '' matches two quote characters in a row
2875
+ // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
2876
+ // except a single quote symbol, which ends the sequence.
2877
+ // Two quote characters do not end the sequence.
2878
+ // If there is no matching single quote
2879
+ // then the sequence will continue until the end of the string.
2880
+ // - . matches any single character unmatched by previous parts of the RegExps
2881
+ var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
2882
+
2883
+ // This RegExp catches symbols escaped by quotes, and also
2884
+ // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
2885
+ var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
2886
+ var escapedStringRegExp = /^'([^]*?)'?$/;
2887
+ var doubleQuoteRegExp = /''/g;
2888
+ var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
2889
+
2890
+ /**
2891
+ * @name format
2892
+ * @category Common Helpers
2893
+ * @summary Format the date.
2894
+ *
2895
+ * @description
2896
+ * Return the formatted date string in the given format. The result may vary by locale.
2897
+ *
2898
+ * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
2899
+ * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2900
+ *
2901
+ * The characters wrapped between two single quotes characters (') are escaped.
2902
+ * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
2903
+ * (see the last example)
2904
+ *
2905
+ * Format of the string is based on Unicode Technical Standard #35:
2906
+ * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
2907
+ * with a few additions (see note 7 below the table).
2908
+ *
2909
+ * Accepted patterns:
2910
+ * | Unit | Pattern | Result examples | Notes |
2911
+ * |---------------------------------|---------|-----------------------------------|-------|
2912
+ * | Era | G..GGG | AD, BC | |
2913
+ * | | GGGG | Anno Domini, Before Christ | 2 |
2914
+ * | | GGGGG | A, B | |
2915
+ * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
2916
+ * | | yo | 44th, 1st, 0th, 17th | 5,7 |
2917
+ * | | yy | 44, 01, 00, 17 | 5 |
2918
+ * | | yyy | 044, 001, 1900, 2017 | 5 |
2919
+ * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
2920
+ * | | yyyyy | ... | 3,5 |
2921
+ * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
2922
+ * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
2923
+ * | | YY | 44, 01, 00, 17 | 5,8 |
2924
+ * | | YYY | 044, 001, 1900, 2017 | 5 |
2925
+ * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
2926
+ * | | YYYYY | ... | 3,5 |
2927
+ * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
2928
+ * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
2929
+ * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
2930
+ * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
2931
+ * | | RRRRR | ... | 3,5,7 |
2932
+ * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
2933
+ * | | uu | -43, 01, 1900, 2017 | 5 |
2934
+ * | | uuu | -043, 001, 1900, 2017 | 5 |
2935
+ * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
2936
+ * | | uuuuu | ... | 3,5 |
2937
+ * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
2938
+ * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
2939
+ * | | QQ | 01, 02, 03, 04 | |
2940
+ * | | QQQ | Q1, Q2, Q3, Q4 | |
2941
+ * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
2942
+ * | | QQQQQ | 1, 2, 3, 4 | 4 |
2943
+ * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
2944
+ * | | qo | 1st, 2nd, 3rd, 4th | 7 |
2945
+ * | | qq | 01, 02, 03, 04 | |
2946
+ * | | qqq | Q1, Q2, Q3, Q4 | |
2947
+ * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
2948
+ * | | qqqqq | 1, 2, 3, 4 | 4 |
2949
+ * | Month (formatting) | M | 1, 2, ..., 12 | |
2950
+ * | | Mo | 1st, 2nd, ..., 12th | 7 |
2951
+ * | | MM | 01, 02, ..., 12 | |
2952
+ * | | MMM | Jan, Feb, ..., Dec | |
2953
+ * | | MMMM | January, February, ..., December | 2 |
2954
+ * | | MMMMM | J, F, ..., D | |
2955
+ * | Month (stand-alone) | L | 1, 2, ..., 12 | |
2956
+ * | | Lo | 1st, 2nd, ..., 12th | 7 |
2957
+ * | | LL | 01, 02, ..., 12 | |
2958
+ * | | LLL | Jan, Feb, ..., Dec | |
2959
+ * | | LLLL | January, February, ..., December | 2 |
2960
+ * | | LLLLL | J, F, ..., D | |
2961
+ * | Local week of year | w | 1, 2, ..., 53 | |
2962
+ * | | wo | 1st, 2nd, ..., 53th | 7 |
2963
+ * | | ww | 01, 02, ..., 53 | |
2964
+ * | ISO week of year | I | 1, 2, ..., 53 | 7 |
2965
+ * | | Io | 1st, 2nd, ..., 53th | 7 |
2966
+ * | | II | 01, 02, ..., 53 | 7 |
2967
+ * | Day of month | d | 1, 2, ..., 31 | |
2968
+ * | | do | 1st, 2nd, ..., 31st | 7 |
2969
+ * | | dd | 01, 02, ..., 31 | |
2970
+ * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
2971
+ * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
2972
+ * | | DD | 01, 02, ..., 365, 366 | 9 |
2973
+ * | | DDD | 001, 002, ..., 365, 366 | |
2974
+ * | | DDDD | ... | 3 |
2975
+ * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
2976
+ * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
2977
+ * | | EEEEE | M, T, W, T, F, S, S | |
2978
+ * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
2979
+ * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
2980
+ * | | io | 1st, 2nd, ..., 7th | 7 |
2981
+ * | | ii | 01, 02, ..., 07 | 7 |
2982
+ * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
2983
+ * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
2984
+ * | | iiiii | M, T, W, T, F, S, S | 7 |
2985
+ * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
2986
+ * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
2987
+ * | | eo | 2nd, 3rd, ..., 1st | 7 |
2988
+ * | | ee | 02, 03, ..., 01 | |
2989
+ * | | eee | Mon, Tue, Wed, ..., Sun | |
2990
+ * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
2991
+ * | | eeeee | M, T, W, T, F, S, S | |
2992
+ * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
2993
+ * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
2994
+ * | | co | 2nd, 3rd, ..., 1st | 7 |
2995
+ * | | cc | 02, 03, ..., 01 | |
2996
+ * | | ccc | Mon, Tue, Wed, ..., Sun | |
2997
+ * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
2998
+ * | | ccccc | M, T, W, T, F, S, S | |
2999
+ * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
3000
+ * | AM, PM | a..aa | AM, PM | |
3001
+ * | | aaa | am, pm | |
3002
+ * | | aaaa | a.m., p.m. | 2 |
3003
+ * | | aaaaa | a, p | |
3004
+ * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
3005
+ * | | bbb | am, pm, noon, midnight | |
3006
+ * | | bbbb | a.m., p.m., noon, midnight | 2 |
3007
+ * | | bbbbb | a, p, n, mi | |
3008
+ * | Flexible day period | B..BBB | at night, in the morning, ... | |
3009
+ * | | BBBB | at night, in the morning, ... | 2 |
3010
+ * | | BBBBB | at night, in the morning, ... | |
3011
+ * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
3012
+ * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
3013
+ * | | hh | 01, 02, ..., 11, 12 | |
3014
+ * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
3015
+ * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
3016
+ * | | HH | 00, 01, 02, ..., 23 | |
3017
+ * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
3018
+ * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
3019
+ * | | KK | 01, 02, ..., 11, 00 | |
3020
+ * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
3021
+ * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
3022
+ * | | kk | 24, 01, 02, ..., 23 | |
3023
+ * | Minute | m | 0, 1, ..., 59 | |
3024
+ * | | mo | 0th, 1st, ..., 59th | 7 |
3025
+ * | | mm | 00, 01, ..., 59 | |
3026
+ * | Second | s | 0, 1, ..., 59 | |
3027
+ * | | so | 0th, 1st, ..., 59th | 7 |
3028
+ * | | ss | 00, 01, ..., 59 | |
3029
+ * | Fraction of second | S | 0, 1, ..., 9 | |
3030
+ * | | SS | 00, 01, ..., 99 | |
3031
+ * | | SSS | 000, 001, ..., 999 | |
3032
+ * | | SSSS | ... | 3 |
3033
+ * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
3034
+ * | | XX | -0800, +0530, Z | |
3035
+ * | | XXX | -08:00, +05:30, Z | |
3036
+ * | | XXXX | -0800, +0530, Z, +123456 | 2 |
3037
+ * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
3038
+ * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
3039
+ * | | xx | -0800, +0530, +0000 | |
3040
+ * | | xxx | -08:00, +05:30, +00:00 | 2 |
3041
+ * | | xxxx | -0800, +0530, +0000, +123456 | |
3042
+ * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
3043
+ * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
3044
+ * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
3045
+ * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
3046
+ * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
3047
+ * | Seconds timestamp | t | 512969520 | 7 |
3048
+ * | | tt | ... | 3,7 |
3049
+ * | Milliseconds timestamp | T | 512969520900 | 7 |
3050
+ * | | TT | ... | 3,7 |
3051
+ * | Long localized date | P | 04/29/1453 | 7 |
3052
+ * | | PP | Apr 29, 1453 | 7 |
3053
+ * | | PPP | April 29th, 1453 | 7 |
3054
+ * | | PPPP | Friday, April 29th, 1453 | 2,7 |
3055
+ * | Long localized time | p | 12:00 AM | 7 |
3056
+ * | | pp | 12:00:00 AM | 7 |
3057
+ * | | ppp | 12:00:00 AM GMT+2 | 7 |
3058
+ * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
3059
+ * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
3060
+ * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
3061
+ * | | PPPppp | April 29th, 1453 at ... | 7 |
3062
+ * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
3063
+ * Notes:
3064
+ * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
3065
+ * are the same as "stand-alone" units, but are different in some languages.
3066
+ * "Formatting" units are declined according to the rules of the language
3067
+ * in the context of a date. "Stand-alone" units are always nominative singular:
3068
+ *
3069
+ * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
3070
+ *
3071
+ * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
3072
+ *
3073
+ * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
3074
+ * the single quote characters (see below).
3075
+ * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
3076
+ * the output will be the same as default pattern for this unit, usually
3077
+ * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
3078
+ * are marked with "2" in the last column of the table.
3079
+ *
3080
+ * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
3081
+ *
3082
+ * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
3083
+ *
3084
+ * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
3085
+ *
3086
+ * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
3087
+ *
3088
+ * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
3089
+ *
3090
+ * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
3091
+ * The output will be padded with zeros to match the length of the pattern.
3092
+ *
3093
+ * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
3094
+ *
3095
+ * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
3096
+ * These tokens represent the shortest form of the quarter.
3097
+ *
3098
+ * 5. The main difference between `y` and `u` patterns are B.C. years:
3099
+ *
3100
+ * | Year | `y` | `u` |
3101
+ * |------|-----|-----|
3102
+ * | AC 1 | 1 | 1 |
3103
+ * | BC 1 | 1 | 0 |
3104
+ * | BC 2 | 2 | -1 |
3105
+ *
3106
+ * Also `yy` always returns the last two digits of a year,
3107
+ * while `uu` pads single digit years to 2 characters and returns other years unchanged:
3108
+ *
3109
+ * | Year | `yy` | `uu` |
3110
+ * |------|------|------|
3111
+ * | 1 | 01 | 01 |
3112
+ * | 14 | 14 | 14 |
3113
+ * | 376 | 76 | 376 |
3114
+ * | 1453 | 53 | 1453 |
3115
+ *
3116
+ * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
3117
+ * except local week-numbering years are dependent on `options.weekStartsOn`
3118
+ * and `options.firstWeekContainsDate` (compare [getISOWeekYear]{@link https://date-fns.org/docs/getISOWeekYear}
3119
+ * and [getWeekYear]{@link https://date-fns.org/docs/getWeekYear}).
3120
+ *
3121
+ * 6. Specific non-location timezones are currently unavailable in `date-fns`,
3122
+ * so right now these tokens fall back to GMT timezones.
3123
+ *
3124
+ * 7. These patterns are not in the Unicode Technical Standard #35:
3125
+ * - `i`: ISO day of week
3126
+ * - `I`: ISO week of year
3127
+ * - `R`: ISO week-numbering year
3128
+ * - `t`: seconds timestamp
3129
+ * - `T`: milliseconds timestamp
3130
+ * - `o`: ordinal number modifier
3131
+ * - `P`: long localized date
3132
+ * - `p`: long localized time
3133
+ *
3134
+ * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
3135
+ * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3136
+ *
3137
+ * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
3138
+ * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3139
+ *
3140
+ * @param {Date|Number} date - the original date
3141
+ * @param {String} format - the string of tokens
3142
+ * @param {Object} [options] - an object with options.
3143
+ * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
3144
+ * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
3145
+ * @param {Number} [options.firstWeekContainsDate=1] - the day of January, which is
3146
+ * @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`;
3147
+ * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3148
+ * @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`;
3149
+ * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3150
+ * @returns {String} the formatted date string
3151
+ * @throws {TypeError} 2 arguments required
3152
+ * @throws {RangeError} `date` must not be Invalid Date
3153
+ * @throws {RangeError} `options.locale` must contain `localize` property
3154
+ * @throws {RangeError} `options.locale` must contain `formatLong` property
3155
+ * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
3156
+ * @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7
3157
+ * @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3158
+ * @throws {RangeError} use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3159
+ * @throws {RangeError} use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3160
+ * @throws {RangeError} use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3161
+ * @throws {RangeError} format string contains an unescaped latin alphabet character
3162
+ *
3163
+ * @example
3164
+ * // Represent 11 February 2014 in middle-endian format:
3165
+ * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
3166
+ * //=> '02/11/2014'
3167
+ *
3168
+ * @example
3169
+ * // Represent 2 July 2014 in Esperanto:
3170
+ * import { eoLocale } from 'date-fns/locale/eo'
3171
+ * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
3172
+ * locale: eoLocale
3173
+ * })
3174
+ * //=> '2-a de julio 2014'
3175
+ *
3176
+ * @example
3177
+ * // Escape string by single quote characters:
3178
+ * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
3179
+ * //=> "3 o'clock"
3180
+ */
3181
+
3182
+ function format(dirtyDate, dirtyFormatStr, options) {
3183
+ var _ref, _options$locale, _ref2, _ref3, _ref4, _options$firstWeekCon, _options$locale2, _options$locale2$opti, _defaultOptions$local, _defaultOptions$local2, _ref5, _ref6, _ref7, _options$weekStartsOn, _options$locale3, _options$locale3$opti, _defaultOptions$local3, _defaultOptions$local4;
3184
+ requiredArgs(2, arguments);
3185
+ var formatStr = String(dirtyFormatStr);
3186
+ var defaultOptions = getDefaultOptions();
3187
+ var locale = (_ref = (_options$locale = options === null || options === void 0 ? void 0 : options.locale) !== null && _options$locale !== void 0 ? _options$locale : defaultOptions.locale) !== null && _ref !== void 0 ? _ref : defaultLocale;
3188
+ var firstWeekContainsDate = toInteger((_ref2 = (_ref3 = (_ref4 = (_options$firstWeekCon = options === null || options === void 0 ? void 0 : options.firstWeekContainsDate) !== null && _options$firstWeekCon !== void 0 ? _options$firstWeekCon : options === null || options === void 0 ? void 0 : (_options$locale2 = options.locale) === null || _options$locale2 === void 0 ? void 0 : (_options$locale2$opti = _options$locale2.options) === null || _options$locale2$opti === void 0 ? void 0 : _options$locale2$opti.firstWeekContainsDate) !== null && _ref4 !== void 0 ? _ref4 : defaultOptions.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.firstWeekContainsDate) !== null && _ref2 !== void 0 ? _ref2 : 1);
3189
+
3190
+ // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
3191
+ if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
3192
+ throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
3193
+ }
3194
+ var weekStartsOn = toInteger((_ref5 = (_ref6 = (_ref7 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale3 = options.locale) === null || _options$locale3 === void 0 ? void 0 : (_options$locale3$opti = _options$locale3.options) === null || _options$locale3$opti === void 0 ? void 0 : _options$locale3$opti.weekStartsOn) !== null && _ref7 !== void 0 ? _ref7 : defaultOptions.weekStartsOn) !== null && _ref6 !== void 0 ? _ref6 : (_defaultOptions$local3 = defaultOptions.locale) === null || _defaultOptions$local3 === void 0 ? void 0 : (_defaultOptions$local4 = _defaultOptions$local3.options) === null || _defaultOptions$local4 === void 0 ? void 0 : _defaultOptions$local4.weekStartsOn) !== null && _ref5 !== void 0 ? _ref5 : 0);
3195
+
3196
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
3197
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
3198
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
3199
+ }
3200
+ if (!locale.localize) {
3201
+ throw new RangeError('locale must contain localize property');
3202
+ }
3203
+ if (!locale.formatLong) {
3204
+ throw new RangeError('locale must contain formatLong property');
3205
+ }
3206
+ var originalDate = toDate(dirtyDate);
3207
+ if (!isValid(originalDate)) {
3208
+ throw new RangeError('Invalid time value');
3209
+ }
3210
+
3211
+ // Convert the date in system timezone to the same date in UTC+00:00 timezone.
3212
+ // This ensures that when UTC functions will be implemented, locales will be compatible with them.
3213
+ // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376
3214
+ var timezoneOffset = getTimezoneOffsetInMilliseconds(originalDate);
3215
+ var utcDate = subMilliseconds(originalDate, timezoneOffset);
3216
+ var formatterOptions = {
3217
+ firstWeekContainsDate: firstWeekContainsDate,
3218
+ weekStartsOn: weekStartsOn,
3219
+ locale: locale,
3220
+ _originalDate: originalDate
3221
+ };
3222
+ var result = formatStr.match(longFormattingTokensRegExp).map(function (substring) {
3223
+ var firstCharacter = substring[0];
3224
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
3225
+ var longFormatter = longFormatters$1[firstCharacter];
3226
+ return longFormatter(substring, locale.formatLong);
3227
+ }
3228
+ return substring;
3229
+ }).join('').match(formattingTokensRegExp).map(function (substring) {
3230
+ // Replace two single quote characters with one single quote character
3231
+ if (substring === "''") {
3232
+ return "'";
3233
+ }
3234
+ var firstCharacter = substring[0];
3235
+ if (firstCharacter === "'") {
3236
+ return cleanEscapedString(substring);
3237
+ }
3238
+ var formatter = formatters$1[firstCharacter];
3239
+ if (formatter) {
3240
+ if (!(options !== null && options !== void 0 && options.useAdditionalWeekYearTokens) && isProtectedWeekYearToken(substring)) {
3241
+ throwProtectedError(substring, dirtyFormatStr, String(dirtyDate));
3242
+ }
3243
+ if (!(options !== null && options !== void 0 && options.useAdditionalDayOfYearTokens) && isProtectedDayOfYearToken(substring)) {
3244
+ throwProtectedError(substring, dirtyFormatStr, String(dirtyDate));
3245
+ }
3246
+ return formatter(utcDate, substring, locale.localize, formatterOptions);
3247
+ }
3248
+ if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
3249
+ throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`');
3250
+ }
3251
+ return substring;
3252
+ }).join('');
3253
+ return result;
3254
+ }
3255
+ function cleanEscapedString(input) {
3256
+ var matched = input.match(escapedStringRegExp);
3257
+ if (!matched) {
3258
+ return input;
3259
+ }
3260
+ return matched[1].replace(doubleQuoteRegExp, "'");
3261
+ }
3262
+
3263
+ var ArcCalendarContext = React.createContext(null);
3264
+
3265
+ var CalendarDayNumber = React.forwardRef(function (_a, autoFocusRef) {
3266
+ var date = _a.date, shouldRender = _a.shouldRender, isFocusWithinDayGrid = _a.isFocusWithinDayGrid;
3267
+ var context = React.useContext(ArcCalendarContext);
3268
+ var isFocusDate = context && isEqual(date, context.focusDate);
3269
+ var tableCellRef = React.useCallback(function (el) {
3270
+ if (el && isFocusDate && isFocusWithinDayGrid) {
3271
+ el.focus();
3272
+ }
3273
+ }, [isFocusDate, isFocusWithinDayGrid]);
3274
+ if (!context) {
3275
+ return null;
3276
+ }
3277
+ var handleRefs = function (el) {
3278
+ tableCellRef(el);
3279
+ if (autoFocusRef && typeof autoFocusRef === "function") {
3280
+ autoFocusRef(el);
3281
+ }
3282
+ };
3283
+ var disabledDates = context.disabledDates, selectedDate = context.selectedDate, selectionType = context.selectionType, selectedRange = context.selectedRange, highlightedRange = context.highlightedRange, todayDate = context.todayDate, onDayNumberClick = context.onDayNumberClick, onDayNumberHover = context.onDayNumberHover, minDate = context.minDate, maxDate = context.maxDate;
3284
+ var highlightedRangeStart = highlightedRange[0];
3285
+ var highlightedRangeEnd = highlightedRange[1];
3286
+ var isSelectedDate = selectionType === "single"
3287
+ ? isEqual(date, selectedDate)
3288
+ : selectedRange.length &&
3289
+ containsDate(selectedRange.filter(function (date) { return Boolean(date); }), date);
3290
+ var isTodayDate = isEqual(date, todayDate);
3291
+ var dateIsWithinHighlightedRange = selectionType === "range" &&
3292
+ highlightedRange.length === 2 &&
3293
+ !isAfter(date, highlightedRangeEnd) &&
3294
+ !isBefore(date, highlightedRangeStart);
3295
+ var isRoundedLeft = selectionType === "range" &&
3296
+ (isDay(date, WeekDays.MONDAY) ||
3297
+ isFirstDayOfMonth(date) ||
3298
+ isEqual(date, highlightedRangeStart));
3299
+ var isRoundedRight = selectionType === "range" &&
3300
+ (isDay(date, WeekDays.SUNDAY) ||
3301
+ isLastDayOfMonth(date) ||
3302
+ isEqual(date, highlightedRangeEnd));
3303
+ var conditionalClasses = {
3304
+ "arc-CalendarDayNumber--selected": isSelectedDate,
3305
+ "arc-CalendarDayNumber--todayDate": isTodayDate,
3306
+ "arc-CalendarDayNumber--hightlightedRange": dateIsWithinHighlightedRange,
3307
+ "arc-CalendarDayNumber--hightlightedRangeRoundedLeft": isRoundedLeft,
3308
+ "arc-CalendarDayNumber--hightlightedRangeRoundedRight": isRoundedRight
3309
+ };
3310
+ var isAriaSelected = isSelectedDate ||
3311
+ (dateIsWithinHighlightedRange && selectedRange.length === 2);
3312
+ var tableCellProps = {
3313
+ className: index.classNames("arc-CalendarDayNumber", conditionalClasses),
3314
+ tabIndex: isFocusDate && shouldRender ? 0 : -1,
3315
+ "aria-current": isTodayDate ? "date" : undefined,
3316
+ "aria-selected": isAriaSelected,
3317
+ "aria-disabled": isDisabledDate(date, disabledDates, minDate, maxDate),
3318
+ onClick: onDayNumberClick(date),
3319
+ onMouseEnter: onDayNumberHover(date)
3320
+ };
3321
+ return (React__default["default"].createElement("td", filterDataAttrs.__assign({ ref: handleRefs, "data-date": date.getTime() }, (shouldRender ? tableCellProps : {})), shouldRender && (React__default["default"].createElement(React__default["default"].Fragment, null,
3322
+ React__default["default"].createElement(VisuallyHidden.VisuallyHidden, null, format(date, "MMMM do, yyyy")),
3323
+ React__default["default"].createElement("div", { className: "arc-CalendarDayNumber-buttonOuter" },
3324
+ React__default["default"].createElement("div", { className: "arc-CalendarDayNumber-buttonInner" },
3325
+ React__default["default"].createElement(Text.Text, { size: "s" },
3326
+ React__default["default"].createElement("span", { "aria-hidden": true }, getDate(date)))))))));
3327
+ });
3328
+
3329
+ const BtIconChevronDownMid = (props) =>
3330
+ /*#__PURE__*/ React__default["default"].createElement(
3331
+ "svg",
3332
+ Object.assign(
3333
+ {
3334
+ viewBox: "0 0 32 32",
3335
+ fill: "none",
3336
+ xmlns: "http://www.w3.org/2000/svg",
3337
+ },
3338
+ props,
3339
+ ),
3340
+ /*#__PURE__*/ React__default["default"].createElement("path", {
3341
+ fillRule: "evenodd",
3342
+ clipRule: "evenodd",
3343
+ d: "M16.0001 18.0909L21.7041 12.3935C21.9566 12.1415 22.2987 12 22.6554 12C23.0121 12 23.3543 12.1415 23.6068 12.3935C23.7316 12.5181 23.8306 12.6661 23.8982 12.829C23.9657 12.9919 24.0005 13.1665 24.0005 13.3429C24.0005 13.5192 23.9657 13.6938 23.8982 13.8567C23.8306 14.0196 23.7316 14.1676 23.6068 14.2922L16.9508 20.9402C16.6983 21.1918 16.3565 21.3331 16.0001 21.3331C15.6437 21.3331 15.3018 21.1918 15.0494 20.9402L8.39342 14.2922C8.26861 14.1676 8.16959 14.0196 8.10202 13.8567C8.03446 13.6938 7.99969 13.5192 7.99969 13.3429C7.99969 13.1665 8.03446 12.9919 8.10202 12.829C8.16959 12.6661 8.26861 12.5181 8.39342 12.3935C8.6459 12.1415 8.98804 12 9.34475 12C9.70147 12 10.0436 12.1415 10.2961 12.3935L16.0001 18.0909Z",
3344
+ fill: "currentColor",
3345
+ }),
3346
+ );
3347
+
3348
+ var CalendarDateSelect = function (_a) {
3349
+ var ariaLabel = _a.ariaLabel, onChange = _a.onChange, name = _a.name, value = _a.value, displayValue = _a.displayValue, options = _a.options;
3350
+ return (React__default["default"].createElement("div", { className: "arc-CalendarDateSelect-wrapper" },
3351
+ React__default["default"].createElement("select", { "aria-label": ariaLabel, onChange: onChange, className: "arc-CalendarDateSelect", value: value, name: name }, options.map(function (_a) {
3352
+ var text = _a.text, value = _a.value;
3353
+ return (React__default["default"].createElement("option", { className: "arc-CalendarDateSelect-option", key: "arc-calendar-year-select-".concat(value), value: value }, text));
3354
+ })),
3355
+ React__default["default"].createElement("div", { "aria-hidden": true, className: "arc-CalendarDateSelect-label" },
3356
+ React__default["default"].createElement(Heading.Heading, { size: "s" }, displayValue || value),
3357
+ React__default["default"].createElement("div", { className: "arc-CalendarDateSelect-icon" },
3358
+ React__default["default"].createElement(Icon.Icon, { size: 24, icon: BtIconChevronDownMid })))));
3359
+ };
3360
+
3361
+ /**
3362
+ * @name isSameMonth
3363
+ * @category Month Helpers
3364
+ * @summary Are the given dates in the same month (and year)?
3365
+ *
3366
+ * @description
3367
+ * Are the given dates in the same month (and year)?
3368
+ *
3369
+ * @param {Date|Number} dateLeft - the first date to check
3370
+ * @param {Date|Number} dateRight - the second date to check
3371
+ * @returns {Boolean} the dates are in the same month (and year)
3372
+ * @throws {TypeError} 2 arguments required
3373
+ *
3374
+ * @example
3375
+ * // Are 2 September 2014 and 25 September 2014 in the same month?
3376
+ * const result = isSameMonth(new Date(2014, 8, 2), new Date(2014, 8, 25))
3377
+ * //=> true
3378
+ *
3379
+ * @example
3380
+ * // Are 2 September 2014 and 25 September 2015 in the same month?
3381
+ * const result = isSameMonth(new Date(2014, 8, 2), new Date(2015, 8, 25))
3382
+ * //=> false
3383
+ */
3384
+ function isSameMonth(dirtyDateLeft, dirtyDateRight) {
3385
+ requiredArgs(2, arguments);
3386
+ var dateLeft = toDate(dirtyDateLeft);
3387
+ var dateRight = toDate(dirtyDateRight);
3388
+ return dateLeft.getFullYear() === dateRight.getFullYear() && dateLeft.getMonth() === dateRight.getMonth();
3389
+ }
3390
+
3391
+ /**
3392
+ * @name eachWeekOfInterval
3393
+ * @category Interval Helpers
3394
+ * @summary Return the array of weeks within the specified time interval.
3395
+ *
3396
+ * @description
3397
+ * Return the array of weeks within the specified time interval.
3398
+ *
3399
+ * @param {Interval} interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval}
3400
+ * @param {Object} [options] - an object with options.
3401
+ * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
3402
+ * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
3403
+ * @returns {Date[]} the array with starts of weeks from the week of the interval start to the week of the interval end
3404
+ * @throws {TypeError} 1 argument required
3405
+ * @throws {RangeError} `options.weekStartsOn` must be 0, 1, ..., 6
3406
+ * @throws {RangeError} The start of an interval cannot be after its end
3407
+ * @throws {RangeError} Date in interval cannot be `Invalid Date`
3408
+ *
3409
+ * @example
3410
+ * // Each week within interval 6 October 2014 - 23 November 2014:
3411
+ * const result = eachWeekOfInterval({
3412
+ * start: new Date(2014, 9, 6),
3413
+ * end: new Date(2014, 10, 23)
3414
+ * })
3415
+ * //=> [
3416
+ * // Sun Oct 05 2014 00:00:00,
3417
+ * // Sun Oct 12 2014 00:00:00,
3418
+ * // Sun Oct 19 2014 00:00:00,
3419
+ * // Sun Oct 26 2014 00:00:00,
3420
+ * // Sun Nov 02 2014 00:00:00,
3421
+ * // Sun Nov 09 2014 00:00:00,
3422
+ * // Sun Nov 16 2014 00:00:00,
3423
+ * // Sun Nov 23 2014 00:00:00
3424
+ * // ]
3425
+ */
3426
+ function eachWeekOfInterval(dirtyInterval, options) {
3427
+ requiredArgs(1, arguments);
3428
+ var interval = dirtyInterval || {};
3429
+ var startDate = toDate(interval.start);
3430
+ var endDate = toDate(interval.end);
3431
+ var endTime = endDate.getTime();
3432
+
3433
+ // Throw an exception if start date is after end date or if any date is `Invalid Date`
3434
+ if (!(startDate.getTime() <= endTime)) {
3435
+ throw new RangeError('Invalid interval');
3436
+ }
3437
+ var startDateWeek = startOfWeek(startDate, options);
3438
+ var endDateWeek = startOfWeek(endDate, options);
3439
+
3440
+ // Some timezones switch DST at midnight, making start of day unreliable in these timezones, 3pm is a safe bet
3441
+ startDateWeek.setHours(15);
3442
+ endDateWeek.setHours(15);
3443
+ endTime = endDateWeek.getTime();
3444
+ var weeks = [];
3445
+ var currentWeek = startDateWeek;
3446
+ while (currentWeek.getTime() <= endTime) {
3447
+ currentWeek.setHours(0);
3448
+ weeks.push(toDate(currentWeek));
3449
+ currentWeek = addWeeks(currentWeek, 1);
3450
+ currentWeek.setHours(15);
3451
+ }
3452
+ return weeks;
3453
+ }
3454
+
3455
+ var DAY_NAMES = [
3456
+ {
3457
+ value: WeekDays.MONDAY,
3458
+ displayValue: WeekDaysAbbr.MON
3459
+ },
3460
+ {
3461
+ value: WeekDays.TUESDAY,
3462
+ displayValue: WeekDaysAbbr.TUE
3463
+ },
3464
+ {
3465
+ value: WeekDays.WEDNESDAY,
3466
+ displayValue: WeekDaysAbbr.WED
3467
+ },
3468
+ {
3469
+ value: WeekDays.THURSDAY,
3470
+ displayValue: WeekDaysAbbr.THUR
3471
+ },
3472
+ {
3473
+ value: WeekDays.FRIDAY,
3474
+ displayValue: WeekDaysAbbr.FRI
3475
+ },
3476
+ {
3477
+ value: WeekDays.SATURDAY,
3478
+ displayValue: WeekDaysAbbr.SAT
3479
+ },
3480
+ {
3481
+ value: WeekDays.SUNDAY,
3482
+ displayValue: WeekDaysAbbr.SUN
3483
+ },
3484
+ ];
3485
+
3486
+ /**
3487
+ * @name isWithinInterval
3488
+ * @category Interval Helpers
3489
+ * @summary Is the given date within the interval?
3490
+ *
3491
+ * @description
3492
+ * Is the given date within the interval? (Including start and end.)
3493
+ *
3494
+ * @param {Date|Number} date - the date to check
3495
+ * @param {Interval} interval - the interval to check
3496
+ * @returns {Boolean} the date is within the interval
3497
+ * @throws {TypeError} 2 arguments required
3498
+ * @throws {RangeError} The start of an interval cannot be after its end
3499
+ * @throws {RangeError} Date in interval cannot be `Invalid Date`
3500
+ *
3501
+ * @example
3502
+ * // For the date within the interval:
3503
+ * isWithinInterval(new Date(2014, 0, 3), {
3504
+ * start: new Date(2014, 0, 1),
3505
+ * end: new Date(2014, 0, 7)
3506
+ * })
3507
+ * //=> true
3508
+ *
3509
+ * @example
3510
+ * // For the date outside of the interval:
3511
+ * isWithinInterval(new Date(2014, 0, 10), {
3512
+ * start: new Date(2014, 0, 1),
3513
+ * end: new Date(2014, 0, 7)
3514
+ * })
3515
+ * //=> false
3516
+ *
3517
+ * @example
3518
+ * // For date equal to interval start:
3519
+ * isWithinInterval(date, { start, end: date }) // => true
3520
+ *
3521
+ * @example
3522
+ * // For date equal to interval end:
3523
+ * isWithinInterval(date, { start: date, end }) // => true
3524
+ */
3525
+ function isWithinInterval(dirtyDate, interval) {
3526
+ requiredArgs(2, arguments);
3527
+ var time = toDate(dirtyDate).getTime();
3528
+ var startTime = toDate(interval.start).getTime();
3529
+ var endTime = toDate(interval.end).getTime();
3530
+
3531
+ // Throw an exception if start date is after end date or if any date is `Invalid Date`
3532
+ if (!(startTime <= endTime)) {
3533
+ throw new RangeError('Invalid interval');
3534
+ }
3535
+ return time >= startTime && time <= endTime;
3536
+ }
3537
+
3538
+ /**
3539
+ * @name setYear
3540
+ * @category Year Helpers
3541
+ * @summary Set the year to the given date.
3542
+ *
3543
+ * @description
3544
+ * Set the year to the given date.
3545
+ *
3546
+ * @param {Date|Number} date - the date to be changed
3547
+ * @param {Number} year - the year of the new date
3548
+ * @returns {Date} the new date with the year set
3549
+ * @throws {TypeError} 2 arguments required
3550
+ *
3551
+ * @example
3552
+ * // Set year 2013 to 1 September 2014:
3553
+ * const result = setYear(new Date(2014, 8, 1), 2013)
3554
+ * //=> Sun Sep 01 2013 00:00:00
3555
+ */
3556
+ function setYear(dirtyDate, dirtyYear) {
3557
+ requiredArgs(2, arguments);
3558
+ var date = toDate(dirtyDate);
3559
+ var year = toInteger(dirtyYear);
3560
+
3561
+ // Check if date is Invalid Date because Date.prototype.setFullYear ignores the value of Invalid Date
3562
+ if (isNaN(date.getTime())) {
3563
+ return new Date(NaN);
3564
+ }
3565
+ date.setFullYear(year);
3566
+ return date;
3567
+ }
3568
+
3569
+ var CalendarDayGrid = function (_a) {
3570
+ var displayRange = _a.displayRange;
3571
+ var hasAutoFocused = React.useRef(false);
3572
+ var dayNumberGridRef = React.useRef(null);
3573
+ var context = React.useContext(ArcCalendarContext);
3574
+ var autoFocusRef = React.useCallback(function (el) {
3575
+ if (el &&
3576
+ el.tabIndex === 0 &&
3577
+ (context === null || context === void 0 ? void 0 : context.autoFocusOnMount) &&
3578
+ !hasAutoFocused.current) {
3579
+ el.focus();
3580
+ }
3581
+ if (document.activeElement === el) {
3582
+ hasAutoFocused.current = true;
3583
+ }
3584
+ }, [context === null || context === void 0 ? void 0 : context.autoFocusOnMount]);
3585
+ if (!context) {
3586
+ return null;
3587
+ }
3588
+ var onKeyboardNavigate = context.onKeyboardNavigate, onDayNumberClick = context.onDayNumberClick, onDayGridLeave = context.onDayGridLeave;
3589
+ var isFocusWithinDayGrid = Boolean(dayNumberGridRef &&
3590
+ dayNumberGridRef.current &&
3591
+ dayNumberGridRef.current.contains(document.activeElement));
3592
+ var handleKeyDown = function (e) {
3593
+ var key = e.key;
3594
+ var newDate = e.target.getAttribute("data-date");
3595
+ if (key === KeyNames.Tab) {
3596
+ return;
3597
+ }
3598
+ if (Object.values(KeyNames).includes(key)) {
3599
+ e.preventDefault();
3600
+ }
3601
+ if ([KeyNames.Space, KeyNames.Enter].includes(key) && newDate) {
3602
+ onDayNumberClick(dateWithoutTime(new Date(parseInt(newDate))))();
3603
+ }
3604
+ else {
3605
+ onKeyboardNavigate(e.key, e.shiftKey);
3606
+ }
3607
+ };
3608
+ var getWeeksInMonth = function (month) {
3609
+ return eachWeekOfInterval({ start: startOfMonth(month), end: endOfMonth(month) }, { weekStartsOn: 1 }).map(function (week) { return eachDayOfInterval({ start: week, end: addDays(week, 6) }); });
3610
+ };
3611
+ return (React__default["default"].createElement("div", { ref: dayNumberGridRef, onMouseLeave: onDayGridLeave, className: index.classNames("arc-CalendarDayGrid", {
3612
+ "arc-CalendarDayGrid--dual": displayRange.length > 1
3613
+ }) }, displayRange.map(function (month) { return (React__default["default"].createElement("div", { key: month.getTime(), className: "arc-CalendarDayGrid-month" },
3614
+ React__default["default"].createElement("table", { className: "arc-CalendarDayGrid-table" },
3615
+ React__default["default"].createElement("thead", null,
3616
+ React__default["default"].createElement("tr", null, DAY_NAMES.map(function (dayName) { return (React__default["default"].createElement("th", { key: "".concat(month.getTime(), "-").concat(dayName.displayValue) },
3617
+ React__default["default"].createElement(Text.Text, { key: dayName.displayValue, size: "s" },
3618
+ React__default["default"].createElement("b", { "aria-hidden": true }, dayName.displayValue)),
3619
+ React__default["default"].createElement(VisuallyHidden.VisuallyHidden, null, dayName.value))); }))),
3620
+ React__default["default"].createElement("tbody", { onKeyDown: handleKeyDown }, getWeeksInMonth(month).map(function (week, i) { return (React__default["default"].createElement("tr", { key: "".concat(month.getTime(), "-week-").concat(i) }, week.map(function (day) { return (React__default["default"].createElement(CalendarDayNumber, { ref: autoFocusRef, shouldRender: isSameMonth(month, day), key: day.getTime(), date: day, isFocusWithinDayGrid: isFocusWithinDayGrid })); }))); }))))); })));
3621
+ };
3622
+
3623
+ var CalendarNavButton = function (_a) {
3624
+ var isDisabled = _a.isDisabled, onClick = _a.onClick, direction = _a.direction, ariaLabel = _a.ariaLabel;
3625
+ var icons = {
3626
+ previous: BtIconChevronLeftMid_esm.BtIconChevronLeftMid,
3627
+ next: BtIconChevronRightMid_esm.BtIconChevronRightMid
3628
+ };
3629
+ return (React__default["default"].createElement("button", { "aria-label": ariaLabel, disabled: isDisabled, onClick: onClick, className: index.classNames("arc-CalendarNavButton", {
3630
+ "arc-CalendarNavButton--previous": direction === "previous",
3631
+ "arc-CalendarNavButton--next": direction === "next"
3632
+ }) },
3633
+ React__default["default"].createElement(Icon.Icon, { size: 32, icon: icons[direction] })));
3634
+ };
3635
+
3636
+ var CalendarDoubleMonthView = function (_a) {
3637
+ var isPreviousMonthDisabled = _a.isPreviousMonthDisabled, isNextMonthDisabled = _a.isNextMonthDisabled, onNextMonthClick = _a.onNextMonthClick, onPreviousMonthClick = _a.onPreviousMonthClick;
3638
+ var context = React.useContext(ArcCalendarContext);
3639
+ if (!context) {
3640
+ return null;
3641
+ }
3642
+ var displayDate = context.displayDate;
3643
+ var displayRange = getDoubleMonthDisplayRange(displayDate);
3644
+ var getAriaLabel = function (date) {
3645
+ var months = getDoubleMonthDisplayRange(date);
3646
+ return "show ".concat(format(months[0], "MMMM yyyy"), " to ").concat(format(months[1], "MMMM yyyy"));
3647
+ };
3648
+ return (React__default["default"].createElement(React__default["default"].Fragment, null,
3649
+ React__default["default"].createElement(VisuallyHidden.VisuallyHidden, null,
3650
+ React__default["default"].createElement(Heading.Heading, { level: "2" },
3651
+ React__default["default"].createElement("span", { "aria-live": "polite" },
3652
+ "showing ",
3653
+ format(displayRange[0], "MMMM yyyy"),
3654
+ " to",
3655
+ " ",
3656
+ format(displayRange[1], "MMMM yyyy")))),
3657
+ React__default["default"].createElement("div", { className: "arc-CalendarDoubleMonthView-header" },
3658
+ React__default["default"].createElement("div", { className: "arc-CalendarDoubleMonthView-headerMonth" },
3659
+ React__default["default"].createElement("div", { className: "arc-CalendarDoubleMonthView-headerMonthItem" },
3660
+ React__default["default"].createElement(CalendarNavButton, { ariaLabel: getAriaLabel(subMonths(displayDate, 2)), direction: "previous", isDisabled: isPreviousMonthDisabled, onClick: onPreviousMonthClick })),
3661
+ React__default["default"].createElement("div", { "aria-hidden": true, className: "arc-CalendarDoubleMonthView-headerMonthItem" },
3662
+ React__default["default"].createElement(Heading.Heading, { level: "2", size: "s" }, format(displayRange[0], "MMM yyyy")))),
3663
+ React__default["default"].createElement("div", { className: "arc-CalendarDoubleMonthView-headerMonth" },
3664
+ React__default["default"].createElement("div", { "aria-hidden": true, className: "arc-CalendarDoubleMonthView-headerMonthItem" },
3665
+ React__default["default"].createElement(Heading.Heading, { level: "2", size: "s" }, format(displayRange[1], "MMM yyyy"))),
3666
+ React__default["default"].createElement("div", { className: "arc-CalendarDoubleMonthView-headerMonthItem" },
3667
+ React__default["default"].createElement(CalendarNavButton, { ariaLabel: getAriaLabel(addMonths(displayDate, 2)), direction: "next", isDisabled: isNextMonthDisabled, onClick: onNextMonthClick })))),
3668
+ React__default["default"].createElement(CalendarDayGrid, { displayRange: displayRange })));
3669
+ };
3670
+
3671
+ var CalendarMonthView = function (_a) {
3672
+ var isPreviousMonthDisabled = _a.isPreviousMonthDisabled, isNextMonthDisabled = _a.isNextMonthDisabled, onNextMonthClick = _a.onNextMonthClick, onPreviousMonthClick = _a.onPreviousMonthClick;
3673
+ var context = React.useContext(ArcCalendarContext);
3674
+ if (!context) {
3675
+ return null;
3676
+ }
3677
+ var displayDate = context.displayDate;
3678
+ return (React__default["default"].createElement(React__default["default"].Fragment, null,
3679
+ React__default["default"].createElement("div", { className: "arc-CalendarMonthView-header" },
3680
+ React__default["default"].createElement(CalendarNavButton, { ariaLabel: "Show ".concat(format(subMonths(displayDate, 1), "MMMM yyyy")), direction: "previous", isDisabled: isPreviousMonthDisabled, onClick: onPreviousMonthClick }),
3681
+ React__default["default"].createElement("div", { className: "arc-CalendarMonthView-headingContainer" },
3682
+ React__default["default"].createElement(VisuallyHidden.VisuallyHidden, null,
3683
+ React__default["default"].createElement(Heading.Heading, { level: "2" },
3684
+ React__default["default"].createElement("span", { "aria-live": "polite" },
3685
+ "showing ",
3686
+ format(displayDate, "MMMM yyyy")))),
3687
+ React__default["default"].createElement("div", { "aria-hidden": true },
3688
+ React__default["default"].createElement(Heading.Heading, { size: "s", level: "2" }, format(displayDate, "MMM yyyy")))),
3689
+ React__default["default"].createElement(CalendarNavButton, { direction: "next", ariaLabel: "Show ".concat(format(addMonths(displayDate, 1), "MMMM yyyy")), isDisabled: isNextMonthDisabled, onClick: onNextMonthClick })),
3690
+ React__default["default"].createElement(CalendarDayGrid, { displayRange: [displayDate] })));
3691
+ };
3692
+
3693
+ var CalendarMonthYearView = function (_a) {
3694
+ var isPreviousMonthDisabled = _a.isPreviousMonthDisabled, isNextMonthDisabled = _a.isNextMonthDisabled, onMonthChange = _a.onMonthChange, onYearChange = _a.onYearChange, onNextMonthClick = _a.onNextMonthClick, onPreviousMonthClick = _a.onPreviousMonthClick;
3695
+ var context = React.useContext(ArcCalendarContext);
3696
+ if (!context) {
3697
+ return null;
3698
+ }
3699
+ var displayDate = context.displayDate, minDate = context.minDate, maxDate = context.maxDate;
3700
+ var monthOptions = Array.from({ length: 12 })
3701
+ .map(function (_, i) { return ({
3702
+ value: i,
3703
+ text: format(new Date(2023, i, 1), "MMMM")
3704
+ }); })
3705
+ .filter(function (_a) {
3706
+ var value = _a.value;
3707
+ var currentDateYear = getYear(displayDate);
3708
+ var date = dateWithoutTime(new Date(currentDateYear, value, 1));
3709
+ return ((!minDate || !isMonthBeforeMinDate(date, minDate)) &&
3710
+ (!maxDate || !isMonthAfterMaxDate(date, maxDate)));
3711
+ });
3712
+ var yearOptions = Array.from({ length: 21 }, function (_, i) {
3713
+ var value = getYear(displayDate) - 10 + i;
3714
+ return {
3715
+ value: value,
3716
+ text: value
3717
+ };
3718
+ }).filter(function (_a) {
3719
+ var value = _a.value;
3720
+ return ((minDate ? value >= getYear(minDate) : true) &&
3721
+ (maxDate ? value <= getYear(maxDate) : true));
3722
+ });
3723
+ return (React__default["default"].createElement(React__default["default"].Fragment, null,
3724
+ React__default["default"].createElement("div", { className: "arc-CalendarMonthYearView-header" },
3725
+ React__default["default"].createElement(VisuallyHidden.VisuallyHidden, null,
3726
+ React__default["default"].createElement(Heading.Heading, { level: "2" },
3727
+ React__default["default"].createElement("span", { "aria-live": "polite" },
3728
+ "showing ",
3729
+ format(displayDate, "MMMM yyyy")))),
3730
+ React__default["default"].createElement("div", { className: "arc-CalendarMonthYearView-selectWrapper" },
3731
+ React__default["default"].createElement("div", null,
3732
+ React__default["default"].createElement(CalendarDateSelect, { options: monthOptions, ariaLabel: "month", onChange: function (e) { return onMonthChange(parseInt(e.target.value)); }, name: "arc-CalendarMonthYearView-monthSelect", displayValue: format(displayDate, "MMM"), value: "".concat(getMonth(displayDate)) })),
3733
+ React__default["default"].createElement("div", { className: "arc-CalendarMonthYearView-yearSelectContainer" },
3734
+ React__default["default"].createElement(CalendarDateSelect, { options: yearOptions, ariaLabel: "year", onChange: function (e) { return onYearChange(parseInt(e.target.value)); }, name: "arc-CalendarMonthYearView-yearSelect", value: getYear(displayDate) }))),
3735
+ React__default["default"].createElement("div", { className: "arc-CalendarMonthYearView-navButtonContainer" },
3736
+ React__default["default"].createElement(CalendarNavButton, { direction: "previous", ariaLabel: "Show ".concat(format(subMonths(displayDate, 1), "MMMM yyyy")), isDisabled: isPreviousMonthDisabled, onClick: onPreviousMonthClick }),
3737
+ React__default["default"].createElement(CalendarNavButton, { direction: "next", ariaLabel: "Show ".concat(format(addMonths(displayDate, 1), "MMMM yyyy")), isDisabled: isNextMonthDisabled, onClick: onNextMonthClick }))),
3738
+ React__default["default"].createElement(CalendarDayGrid, { displayRange: [displayDate] })));
3739
+ };
3740
+
3741
+ var showPreviousMonthHandler = function (payload, state) {
3742
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: getFocusDate({
3743
+ date: subMonths(state.focusDate, 1),
3744
+ minDate: payload.minDate
3745
+ }), displayDate: subMonths(state.displayDate, 1) });
3746
+ };
3747
+
3748
+ var showNextMonthHandler = function (payload, state) {
3749
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: getFocusDate({
3750
+ date: addMonths(state.focusDate, 1),
3751
+ maxDate: payload.maxDate
3752
+ }), displayDate: addMonths(state.displayDate, 1) });
3753
+ };
3754
+
3755
+ var showPreviousDoubleMonthHandler = function (payload, state) {
3756
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: getFocusDate({
3757
+ date: subMonths(state.focusDate, 2),
3758
+ minDate: payload.minDate
3759
+ }), displayDate: subMonths(state.displayDate, 2) });
3760
+ };
3761
+
3762
+ var showNextDoubleMonthHandler = function (payload, state) {
3763
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: getFocusDate({
3764
+ date: addMonths(state.focusDate, 2),
3765
+ maxDate: payload.maxDate
3766
+ }), displayDate: addMonths(state.displayDate, 2) });
3767
+ };
3768
+
3769
+ var rangeSelectHandler = function (payload, state) {
3770
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: payload.date, highlightedRange: payload.range });
3771
+ };
3772
+
3773
+ var highlightRangeHandler = function (payload, state) {
3774
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { highlightedRange: getHighlightRange({
3775
+ date: payload.date,
3776
+ range: payload.range,
3777
+ minDate: payload.minDate,
3778
+ maxDate: payload.maxDate
3779
+ }) });
3780
+ };
3781
+
3782
+ var dayNumberSelectHandler = function (payload, state) {
3783
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: payload });
3784
+ };
3785
+
3786
+ var dayGridLeaveHandler = function (payload, state) {
3787
+ if (payload.selectionType === "range" &&
3788
+ payload.range.filter(function (date) { return Boolean(date); }).length === 1) {
3789
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { highlightedRange: [] });
3790
+ }
3791
+ return filterDataAttrs.__assign({}, state);
3792
+ };
3793
+
3794
+ var dropDownChangeYearHandler = function (payload, state) {
3795
+ var year = payload.year, minDate = payload.minDate, maxDate = payload.maxDate;
3796
+ var yearsToAdd = year - getYear(state.displayDate);
3797
+ var newDisplayDate = addYears(state.displayDate, yearsToAdd);
3798
+ var focusDate = getFocusDate({
3799
+ date: addYears(state.focusDate, yearsToAdd),
3800
+ minDate: payload.minDate,
3801
+ maxDate: payload.maxDate
3802
+ });
3803
+ if (minDate && isBefore(newDisplayDate, minDate)) {
3804
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: focusDate, displayDate: minDate });
3805
+ }
3806
+ if (maxDate && isAfter(newDisplayDate, maxDate)) {
3807
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: focusDate, displayDate: maxDate });
3808
+ }
3809
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: focusDate, displayDate: newDisplayDate });
3810
+ };
3811
+
3812
+ var dropDownChangeMonthHandler = function (payload, state) {
3813
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: getFocusDate({
3814
+ date: setMonth(state.focusDate, payload.month),
3815
+ minDate: payload.minDate,
3816
+ maxDate: payload.maxDate
3817
+ }), displayDate: setMonth(state.displayDate, payload.month) });
3818
+ };
3819
+
3820
+ var calendarKeydownHandler = function (payload, state) {
3821
+ var displayDate = state.displayDate, focusDate = state.focusDate, highlightedRange = state.highlightedRange;
3822
+ var minDate = payload.minDate, maxDate = payload.maxDate, calendarType = payload.calendarType, key = payload.key, shiftKey = payload.shiftKey, range = payload.range, selectionType = payload.selectionType;
3823
+ var isNavigatingByYear = shiftKey && [KeyNames.PageUp, KeyNames.PageDown].includes(key);
3824
+ var keyDownDate = getKeyDownDate({
3825
+ focusDate: focusDate,
3826
+ key: key,
3827
+ shiftKey: shiftKey
3828
+ });
3829
+ var newFocusDate = getFocusDate({
3830
+ minDate: minDate,
3831
+ maxDate: maxDate,
3832
+ date: keyDownDate
3833
+ });
3834
+ var newHighlightedRange = selectionType === "range"
3835
+ ? getHighlightRange({
3836
+ date: keyDownDate,
3837
+ range: range,
3838
+ minDate: minDate,
3839
+ maxDate: maxDate
3840
+ })
3841
+ : highlightedRange;
3842
+ var focusDateIsMinOrMax = (maxDate && isEqual(newFocusDate, maxDate)) ||
3843
+ (minDate && isEqual(newFocusDate, minDate));
3844
+ var _a = getDoubleMonthDisplayRange(displayDate), doubleMonthFirstMonth = _a[0], doubleMonthSecondMonth = _a[1];
3845
+ var doubleMonthVisibleRange = {
3846
+ start: startOfMonth(doubleMonthFirstMonth),
3847
+ end: endOfMonth(doubleMonthSecondMonth)
3848
+ };
3849
+ var singleMonthVisibleRange = {
3850
+ start: startOfMonth(displayDate),
3851
+ end: endOfMonth(displayDate)
3852
+ };
3853
+ var isNewFocusDateVisible = isWithinInterval(newFocusDate, calendarType === "double"
3854
+ ? doubleMonthVisibleRange
3855
+ : singleMonthVisibleRange);
3856
+ var commonState = filterDataAttrs.__assign(filterDataAttrs.__assign({}, state), { focusDate: newFocusDate, highlightedRange: newHighlightedRange });
3857
+ if (!isNewFocusDateVisible &&
3858
+ !focusDateIsMinOrMax &&
3859
+ isNavigatingByYear &&
3860
+ calendarType === "double") {
3861
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, commonState), { displayDate: setYear(displayDate, getYear(newFocusDate)) });
3862
+ }
3863
+ if (!isNewFocusDateVisible) {
3864
+ return filterDataAttrs.__assign(filterDataAttrs.__assign({}, commonState), { displayDate: startOfMonth(newFocusDate) });
3865
+ }
3866
+ return commonState;
3867
+ };
3868
+
3869
+ var defaultHandler = function (state) {
3870
+ return filterDataAttrs.__assign({}, state);
3871
+ };
3872
+
3873
+ var reducer = function (state, action) {
3874
+ switch (action.type) {
3875
+ case "DAY_NUMBER_SELECT":
3876
+ return dayNumberSelectHandler(action.payload, state);
3877
+ case "RANGE_SELECT":
3878
+ return rangeSelectHandler(action.payload, state);
3879
+ case "HIGHLIGHT_RANGE":
3880
+ return highlightRangeHandler(action.payload, state);
3881
+ case "DAY_GRID_LEAVE":
3882
+ return dayGridLeaveHandler(action.payload, state);
3883
+ case "SHOW_PREVIOUS_MONTH":
3884
+ return showPreviousMonthHandler(action.payload, state);
3885
+ case "SHOW_NEXT_MONTH":
3886
+ return showNextMonthHandler(action.payload, state);
3887
+ case "SHOW_PREVIOUS_DOUBLE_MONTH":
3888
+ return showPreviousDoubleMonthHandler(action.payload, state);
3889
+ case "SHOW_NEXT_DOUBLE_MONTH":
3890
+ return showNextDoubleMonthHandler(action.payload, state);
3891
+ case "DROPDOWN_CHANGE_YEAR":
3892
+ return dropDownChangeYearHandler(action.payload, state);
3893
+ case "DROPDOWN_CHANGE_MONTH":
3894
+ return dropDownChangeMonthHandler(action.payload, state);
3895
+ case "CALENDAR_KEYDOWN":
3896
+ return calendarKeydownHandler(action.payload, state);
3897
+ default:
3898
+ return defaultHandler(state);
3899
+ }
3900
+ };
3901
+
3902
+ var CalendarFooter = function (_a) {
3903
+ var onCancelClick = _a.onCancelClick;
3904
+ return (React__default["default"].createElement("div", { className: "arc-CalendarFooter" },
3905
+ React__default["default"].createElement("button", { className: "arc-CalendarFooter-button", onClick: onCancelClick }, "Cancel")));
3906
+ };
3907
+
3908
+ var CalendarWrapper = function (_a) {
3909
+ var children = _a.children;
3910
+ return (React__default["default"].createElement("div", { className: "arc-CalendarWrapper" },
3911
+ React__default["default"].createElement(Surface.Surface, { background: "white" },
3912
+ React__default["default"].createElement("div", { className: "arc-CalendarWrapper-inner" }, children))));
3913
+ };
3914
+
3915
+ var Calendar = function (_a) {
3916
+ var _b = _a.type, type = _b === void 0 ? "month" : _b, _c = _a.selectionType, selectionType = _c === void 0 ? "single" : _c, _d = _a.autoFocusOnMount, autoFocusOnMount = _d === void 0 ? false : _d, _e = _a.selectedRange, rawSelectedRange = _e === void 0 ? [] : _e, _f = _a.selectedDate, rawSelectedDate = _f === void 0 ? new Date() : _f, rawDisabledDates = _a.disabledDates, rawMinDate = _a.minDate, rawMaxDate = _a.maxDate, onCancelClick = _a.onCancelClick, onDateSelect = _a.onDateSelect, onRangeSelect = _a.onRangeSelect;
3917
+ var todayDate = dateWithoutTime(new Date());
3918
+ var selectedDate = dateWithoutTime(rawSelectedDate);
3919
+ var selectedRange = rawSelectedRange
3920
+ .filter(function (rangeDate) { return Boolean(rangeDate); })
3921
+ .map(function (rangeDate) { return dateWithoutTime(rangeDate); });
3922
+ var _g = React.useState(false), isClientLoaded = _g[0], setIsClientLoaded = _g[1];
3923
+ var _h = React.useReducer(reducer, {
3924
+ displayDate: selectionType === "single"
3925
+ ? startOfMonth(selectedDate)
3926
+ : startOfMonth(selectedRange[0] || todayDate),
3927
+ focusDate: selectionType === "single"
3928
+ ? selectedDate
3929
+ : selectedRange[0] || todayDate,
3930
+ highlightedRange: selectedRange
3931
+ }), _j = _h[0], displayDate = _j.displayDate, focusDate = _j.focusDate, highlightedRange = _j.highlightedRange, dispatch = _h[1];
3932
+ var isMinWidthArcBreakpointM = useMediaQuery.useMediaQuery("(min-width: ".concat(useMediaQuery.ArcBreakpointM, "px)"));
3933
+ React.useEffect(function () {
3934
+ setIsClientLoaded(true);
3935
+ }, []);
3936
+ var disabledDates = rawDisabledDates === null || rawDisabledDates === void 0 ? void 0 : rawDisabledDates.map(function (date) { return dateWithoutTime(date); });
3937
+ var minDate = rawMinDate && dateWithoutTime(rawMinDate);
3938
+ var maxDate = rawMaxDate && dateWithoutTime(rawMaxDate);
3939
+ var calendarType = getCalendarType(type, isMinWidthArcBreakpointM);
3940
+ var doubleMonthDisplayRange = getDoubleMonthDisplayRange(displayDate);
3941
+ var isPreviousMonthDisabled = minDate
3942
+ ? isMonthBeforeMinDate(subMonths(displayDate, 1), minDate)
3943
+ : false;
3944
+ var isNextMonthDisabled = maxDate
3945
+ ? isMonthAfterMaxDate(addMonths(displayDate, 1), maxDate)
3946
+ : false;
3947
+ var isDoubleMonthPreviousDisabled = minDate
3948
+ ? isMonthBeforeMinDate(subMonths(doubleMonthDisplayRange[0], 1), minDate)
3949
+ : false;
3950
+ var isDoubleMonthNextDisabled = maxDate
3951
+ ? isMonthAfterMaxDate(addMonths(doubleMonthDisplayRange[1], 1), maxDate)
3952
+ : false;
3953
+ var setDateRange = function (value) {
3954
+ var _a = processSelectedRange({
3955
+ value: value,
3956
+ range: selectedRange,
3957
+ disabledDates: disabledDates
3958
+ }), rangeOnChangeValue = _a.rangeOnChangeValue, rangeValue = _a.rangeValue;
3959
+ dispatch({
3960
+ type: "RANGE_SELECT",
3961
+ payload: {
3962
+ date: value,
3963
+ range: rangeValue
3964
+ }
3965
+ });
3966
+ onRangeSelect && onRangeSelect(rangeOnChangeValue);
3967
+ };
3968
+ var setNewDate = function (value) {
3969
+ dispatch({
3970
+ type: "DAY_NUMBER_SELECT",
3971
+ payload: value
3972
+ });
3973
+ onDateSelect && onDateSelect(value);
3974
+ };
3975
+ var onDayNumberHover = function (date) { return function () {
3976
+ selectionType === "range" &&
3977
+ dispatch({
3978
+ type: "HIGHLIGHT_RANGE",
3979
+ payload: {
3980
+ date: date,
3981
+ minDate: minDate,
3982
+ maxDate: maxDate,
3983
+ range: selectedRange
3984
+ }
3985
+ });
3986
+ }; };
3987
+ var handleDateSelection = function (date) {
3988
+ var isDisabled = isDisabledDate(date, disabledDates, minDate, maxDate);
3989
+ if (isDisabled)
3990
+ return;
3991
+ selectionType === "single" ? setNewDate(date) : setDateRange(date);
3992
+ };
3993
+ var onDayNumberClick = function (date) { return function () {
3994
+ handleDateSelection(date);
3995
+ }; };
3996
+ var onCancelButtonClick = function () {
3997
+ onCancelClick && onCancelClick();
3998
+ };
3999
+ var onDayGridLeave = function () {
4000
+ dispatch({
4001
+ type: "DAY_GRID_LEAVE",
4002
+ payload: {
4003
+ selectionType: selectionType,
4004
+ range: selectedRange
4005
+ }
4006
+ });
4007
+ };
4008
+ var onPreviousMonthClick = function () {
4009
+ dispatch({
4010
+ type: "SHOW_PREVIOUS_MONTH",
4011
+ payload: {
4012
+ minDate: minDate
4013
+ }
4014
+ });
4015
+ };
4016
+ var onNextMonthClick = function () {
4017
+ dispatch({
4018
+ type: "SHOW_NEXT_MONTH",
4019
+ payload: {
4020
+ maxDate: maxDate
4021
+ }
4022
+ });
4023
+ };
4024
+ var onDoubleViewPreviousClick = function () {
4025
+ dispatch({
4026
+ type: "SHOW_PREVIOUS_DOUBLE_MONTH",
4027
+ payload: {
4028
+ minDate: minDate
4029
+ }
4030
+ });
4031
+ };
4032
+ var onDoubleViewNextClick = function () {
4033
+ dispatch({
4034
+ type: "SHOW_NEXT_DOUBLE_MONTH",
4035
+ payload: {
4036
+ maxDate: maxDate
4037
+ }
4038
+ });
4039
+ };
4040
+ var onYearChange = function (year) {
4041
+ dispatch({
4042
+ type: "DROPDOWN_CHANGE_YEAR",
4043
+ payload: {
4044
+ year: year,
4045
+ minDate: minDate,
4046
+ maxDate: maxDate
4047
+ }
4048
+ });
4049
+ };
4050
+ var onMonthChange = function (month) {
4051
+ dispatch({
4052
+ type: "DROPDOWN_CHANGE_MONTH",
4053
+ payload: {
4054
+ month: month,
4055
+ minDate: minDate,
4056
+ maxDate: maxDate
4057
+ }
4058
+ });
4059
+ };
4060
+ var onKeyboardNavigate = function (key, shiftKey) {
4061
+ dispatch({
4062
+ type: "CALENDAR_KEYDOWN",
4063
+ payload: {
4064
+ minDate: minDate,
4065
+ maxDate: maxDate,
4066
+ selectionType: selectionType,
4067
+ calendarType: calendarType,
4068
+ key: key,
4069
+ shiftKey: shiftKey,
4070
+ range: selectedRange
4071
+ }
4072
+ });
4073
+ };
4074
+ return (React__default["default"].createElement(ArcCalendarContext.Provider, { value: {
4075
+ minDate: minDate,
4076
+ maxDate: maxDate,
4077
+ focusDate: focusDate,
4078
+ todayDate: todayDate,
4079
+ displayDate: displayDate,
4080
+ onDayGridLeave: onDayGridLeave,
4081
+ disabledDates: disabledDates,
4082
+ selectedDate: selectedDate,
4083
+ selectionType: selectionType,
4084
+ selectedRange: selectedRange,
4085
+ highlightedRange: highlightedRange,
4086
+ onDayNumberClick: onDayNumberClick,
4087
+ onDayNumberHover: onDayNumberHover,
4088
+ onKeyboardNavigate: onKeyboardNavigate,
4089
+ autoFocusOnMount: autoFocusOnMount
4090
+ } },
4091
+ React__default["default"].createElement("div", { style: { display: isClientLoaded ? "block" : "none" } },
4092
+ React__default["default"].createElement(CalendarWrapper, null,
4093
+ calendarType === "year" && (React__default["default"].createElement(CalendarMonthYearView, { isPreviousMonthDisabled: isPreviousMonthDisabled, isNextMonthDisabled: isNextMonthDisabled, onPreviousMonthClick: onPreviousMonthClick, onNextMonthClick: onNextMonthClick, onMonthChange: onMonthChange, onYearChange: onYearChange })),
4094
+ calendarType === "month" && (React__default["default"].createElement(CalendarMonthView, { isPreviousMonthDisabled: isPreviousMonthDisabled, isNextMonthDisabled: isNextMonthDisabled, onPreviousMonthClick: onPreviousMonthClick, onNextMonthClick: onNextMonthClick })),
4095
+ calendarType === "double" && (React__default["default"].createElement(CalendarDoubleMonthView, { isPreviousMonthDisabled: isDoubleMonthPreviousDisabled, isNextMonthDisabled: isDoubleMonthNextDisabled, onPreviousMonthClick: onDoubleViewPreviousClick, onNextMonthClick: onDoubleViewNextClick })),
4096
+ onCancelClick && (React__default["default"].createElement(CalendarFooter, { onCancelClick: onCancelButtonClick }))))));
4097
+ };
4098
+
4099
+ exports.Calendar = Calendar;
4100
+ exports.compareAsc = compareAsc;
4101
+ exports.format = format;
4102
+ exports.isAfter = isAfter;
4103
+ exports.isBefore = isBefore;
4104
+ exports.isValid = isValid;
4105
+ exports.requiredArgs = requiredArgs;
4106
+ exports.toDate = toDate;