ivt 0.4.7 → 0.4.9

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 (214) hide show
  1. package/dist/accordion/index.mjs +15 -15
  2. package/dist/alert/index.mjs +2 -2
  3. package/dist/alert-dialog/index.mjs +17 -17
  4. package/dist/aspect-ratio/index.mjs +1 -1
  5. package/dist/avatar/index.mjs +7 -7
  6. package/dist/badge/index.mjs +3 -3
  7. package/dist/base/index.d.ts +43 -36
  8. package/dist/base/index.mjs +65 -76
  9. package/dist/base/index.mjs.map +1 -1
  10. package/dist/breadcrumb/index.mjs +5 -5
  11. package/dist/button/index.d.ts +1 -1
  12. package/dist/button/index.mjs +3 -3
  13. package/dist/button-group/index.d.ts +4 -0
  14. package/dist/button-group/index.mjs +7 -0
  15. package/dist/button-group/index.mjs.map +1 -0
  16. package/dist/calendar/index.mjs +8 -8
  17. package/dist/card/index.mjs +2 -2
  18. package/dist/carousel/index.mjs +4 -4
  19. package/dist/chart/index.mjs +4 -4
  20. package/dist/checkbox/index.mjs +13 -13
  21. package/dist/chunks/{Container-Bk36x55h.mjs → Container-LlUz2Xf7.mjs} +2 -2
  22. package/dist/chunks/{Container-Bk36x55h.mjs.map → Container-LlUz2Xf7.mjs.map} +1 -1
  23. package/dist/chunks/{_commonjsHelpers-B6NPw-gB.mjs → _commonjsHelpers-CZIfjjiR.mjs} +1 -1
  24. package/dist/chunks/_commonjsHelpers-CZIfjjiR.mjs.map +1 -0
  25. package/dist/chunks/{accordion-DkQil9br.mjs → accordion-BBMhFkK5.mjs} +11 -11
  26. package/dist/chunks/{accordion-DkQil9br.mjs.map → accordion-BBMhFkK5.mjs.map} +1 -1
  27. package/dist/chunks/{badge-DDmxqVIu.mjs → badge-CShT6Er8.mjs} +2 -2
  28. package/dist/chunks/{badge-DDmxqVIu.mjs.map → badge-CShT6Er8.mjs.map} +1 -1
  29. package/dist/chunks/{bundle-mjs-Bj6M7Bh5.mjs → bundle-mjs-CXcNQyyo.mjs} +1 -1
  30. package/dist/chunks/{bundle-mjs-Bj6M7Bh5.mjs.map → bundle-mjs-CXcNQyyo.mjs.map} +1 -1
  31. package/dist/chunks/{button-DUnGULhS.mjs → button-ay7E6KrE.mjs} +5 -3
  32. package/dist/chunks/button-ay7E6KrE.mjs.map +1 -0
  33. package/dist/chunks/{calendar-Cgi4uVPL.mjs → calendar-D98dWxWB.mjs} +23 -8
  34. package/dist/chunks/{calendar-Cgi4uVPL.mjs.map → calendar-D98dWxWB.mjs.map} +1 -1
  35. package/dist/chunks/{check-D7XegcNq.mjs → check-M4AEcM3j.mjs} +2 -2
  36. package/dist/chunks/{check-D7XegcNq.mjs.map → check-M4AEcM3j.mjs.map} +1 -1
  37. package/dist/chunks/{chevron-down-B7w8j1qi.mjs → chevron-down-BgIYlWhk.mjs} +2 -2
  38. package/dist/chunks/{chevron-down-B7w8j1qi.mjs.map → chevron-down-BgIYlWhk.mjs.map} +1 -1
  39. package/dist/chunks/{chevron-left-P-VgJSoP.mjs → chevron-left-wvVA3SWH.mjs} +2 -2
  40. package/dist/chunks/{chevron-left-P-VgJSoP.mjs.map → chevron-left-wvVA3SWH.mjs.map} +1 -1
  41. package/dist/chunks/{chevron-right-D8I8B3al.mjs → chevron-right-aTufSnLl.mjs} +2 -2
  42. package/dist/chunks/{chevron-right-D8I8B3al.mjs.map → chevron-right-aTufSnLl.mjs.map} +1 -1
  43. package/dist/chunks/{chevrons-up-down-BJzgHrFv.mjs → chevrons-up-down-TytmUcIx.mjs} +2 -2
  44. package/dist/chunks/{chevrons-up-down-BJzgHrFv.mjs.map → chevrons-up-down-TytmUcIx.mjs.map} +1 -1
  45. package/dist/chunks/{command-B2Q7vPrV.mjs → command-OnnopJEP.mjs} +8 -8
  46. package/dist/chunks/{command-B2Q7vPrV.mjs.map → command-OnnopJEP.mjs.map} +1 -1
  47. package/dist/chunks/{createLucideIcon-BnuYhciy.mjs → createLucideIcon-DwD3HsEs.mjs} +1 -1
  48. package/dist/chunks/{createLucideIcon-BnuYhciy.mjs.map → createLucideIcon-DwD3HsEs.mjs.map} +1 -1
  49. package/dist/chunks/{dialog-5R8jYrH2.mjs → dialog-D-h9t9_b.mjs} +4 -4
  50. package/dist/chunks/{dialog-5R8jYrH2.mjs.map → dialog-D-h9t9_b.mjs.map} +1 -1
  51. package/dist/chunks/{ellipsis-rAfolw0i.mjs → ellipsis-x68Orkqp.mjs} +2 -2
  52. package/dist/chunks/{ellipsis-rAfolw0i.mjs.map → ellipsis-x68Orkqp.mjs.map} +1 -1
  53. package/dist/chunks/{hover-card-IMC6GmGl.mjs → hover-card-DXAGq71O.mjs} +11 -11
  54. package/dist/chunks/{hover-card-IMC6GmGl.mjs.map → hover-card-DXAGq71O.mjs.map} +1 -1
  55. package/dist/chunks/{index-Cx4XlYKf.mjs → index-B7kZbHfd.mjs} +1 -1
  56. package/dist/chunks/{index-Cx4XlYKf.mjs.map → index-B7kZbHfd.mjs.map} +1 -1
  57. package/dist/chunks/{index-DGB6xduL.mjs → index-BBC4sR1G.mjs} +5 -5
  58. package/dist/chunks/{index-DGB6xduL.mjs.map → index-BBC4sR1G.mjs.map} +1 -1
  59. package/dist/chunks/{index-CUUcgAWS.mjs → index-BBONAxxm.mjs} +1 -1
  60. package/dist/chunks/{index-CUUcgAWS.mjs.map → index-BBONAxxm.mjs.map} +1 -1
  61. package/dist/chunks/{index-xgPrRc3G.mjs → index-BLAYpkjT.mjs} +5 -5
  62. package/dist/chunks/{index-xgPrRc3G.mjs.map → index-BLAYpkjT.mjs.map} +1 -1
  63. package/dist/chunks/{index-AD2ohxjm.mjs → index-BW3aCz7h.mjs} +1 -1
  64. package/dist/chunks/{index-AD2ohxjm.mjs.map → index-BW3aCz7h.mjs.map} +1 -1
  65. package/dist/chunks/{index-Bfqp6L57.mjs → index-BdYD9SA8.mjs} +1 -1
  66. package/dist/chunks/{index-Bfqp6L57.mjs.map → index-BdYD9SA8.mjs.map} +1 -1
  67. package/dist/chunks/{index-Dj2mKKII.mjs → index-Bs4nZmb7.mjs} +2 -2
  68. package/dist/chunks/{index-Dj2mKKII.mjs.map → index-Bs4nZmb7.mjs.map} +1 -1
  69. package/dist/chunks/{index-x0TwBXvJ.mjs → index-BsVg0u5v.mjs} +1 -1
  70. package/dist/chunks/{index-x0TwBXvJ.mjs.map → index-BsVg0u5v.mjs.map} +1 -1
  71. package/dist/chunks/{index-plymPSgY.mjs → index-BtRo1b5t.mjs} +3 -3
  72. package/dist/chunks/{index-plymPSgY.mjs.map → index-BtRo1b5t.mjs.map} +1 -1
  73. package/dist/chunks/{index-CIlaxeML.mjs → index-BxaETqU9.mjs} +3 -3
  74. package/dist/chunks/{index-CIlaxeML.mjs.map → index-BxaETqU9.mjs.map} +1 -1
  75. package/dist/chunks/{index-C-eBEzsd.mjs → index-C45e7-3X.mjs} +11 -11
  76. package/dist/chunks/{index-C-eBEzsd.mjs.map → index-C45e7-3X.mjs.map} +1 -1
  77. package/dist/chunks/{index-Bhy5-l7L.mjs → index-C5cl9B-D.mjs} +2 -2
  78. package/dist/chunks/{index-Bhy5-l7L.mjs.map → index-C5cl9B-D.mjs.map} +1 -1
  79. package/dist/chunks/{index-D02u4jwi.mjs → index-C9twRC0t.mjs} +1 -1
  80. package/dist/chunks/{index-D02u4jwi.mjs.map → index-C9twRC0t.mjs.map} +1 -1
  81. package/dist/chunks/{index-CI7Tnqaf.mjs → index-CLb4rDzh.mjs} +1 -1
  82. package/dist/chunks/{index-CI7Tnqaf.mjs.map → index-CLb4rDzh.mjs.map} +1 -1
  83. package/dist/chunks/{index-KCHKKCqw.mjs → index-CMbJ1I29.mjs} +2 -2
  84. package/dist/chunks/{index-KCHKKCqw.mjs.map → index-CMbJ1I29.mjs.map} +1 -1
  85. package/dist/chunks/{index-gB-FKFqi.mjs → index-CVGBR4nU.mjs} +15 -15
  86. package/dist/chunks/{index-gB-FKFqi.mjs.map → index-CVGBR4nU.mjs.map} +1 -1
  87. package/dist/chunks/{index-BtzrdXXu.mjs → index-D5pght6h.mjs} +1 -1
  88. package/dist/chunks/{index-BtzrdXXu.mjs.map → index-D5pght6h.mjs.map} +1 -1
  89. package/dist/chunks/{index-CiJHmWph.mjs → index-DRdSNmMB.mjs} +2 -2
  90. package/dist/chunks/{index-CiJHmWph.mjs.map → index-DRdSNmMB.mjs.map} +1 -1
  91. package/dist/chunks/{index-CxpHOtv2.mjs → index-DU7dxusa.mjs} +7 -7
  92. package/dist/chunks/{index-CxpHOtv2.mjs.map → index-DU7dxusa.mjs.map} +1 -1
  93. package/dist/chunks/{index-BL6I2O8I.mjs → index-Db1acFFW.mjs} +1 -1
  94. package/dist/chunks/{index-BL6I2O8I.mjs.map → index-Db1acFFW.mjs.map} +1 -1
  95. package/dist/chunks/{index-CsVkG_9K.mjs → index-DfjpL9Sk.mjs} +9 -9
  96. package/dist/chunks/{index-CsVkG_9K.mjs.map → index-DfjpL9Sk.mjs.map} +1 -1
  97. package/dist/chunks/{index-j8BDMqXg.mjs → index-DpqIXFxh.mjs} +9 -9
  98. package/dist/chunks/{index-j8BDMqXg.mjs.map → index-DpqIXFxh.mjs.map} +1 -1
  99. package/dist/chunks/{index-DKuVLbq1.mjs → index-qOZvnMSQ.mjs} +1 -1
  100. package/dist/chunks/{index-DKuVLbq1.mjs.map → index-qOZvnMSQ.mjs.map} +1 -1
  101. package/dist/chunks/{input-TuCGqI_P.mjs → input-CqipwgOY.mjs} +2 -2
  102. package/dist/chunks/{input-TuCGqI_P.mjs.map → input-CqipwgOY.mjs.map} +1 -1
  103. package/dist/chunks/{label-C3diPSrP.mjs → label-Cx4XtbXv.mjs} +3 -3
  104. package/dist/chunks/{label-C3diPSrP.mjs.map → label-Cx4XtbXv.mjs.map} +1 -1
  105. package/dist/chunks/loader-circle-CfhWFS-M.mjs +15 -0
  106. package/dist/chunks/loader-circle-CfhWFS-M.mjs.map +1 -0
  107. package/dist/chunks/{pagination-CFPUC8_E.mjs → pagination-CzDSUdbY.mjs} +6 -6
  108. package/dist/chunks/{pagination-CFPUC8_E.mjs.map → pagination-CzDSUdbY.mjs.map} +1 -1
  109. package/dist/chunks/{popover-BLkBJEBi.mjs → popover-BFcKYAot.mjs} +13 -13
  110. package/dist/chunks/{popover-BLkBJEBi.mjs.map → popover-BFcKYAot.mjs.map} +1 -1
  111. package/dist/chunks/{progress-BCXpEea-.mjs → progress-Cm71BOo_.mjs} +4 -4
  112. package/dist/chunks/{progress-BCXpEea-.mjs.map → progress-Cm71BOo_.mjs.map} +1 -1
  113. package/dist/chunks/pt-BR-on-YW6Ay.mjs +3275 -0
  114. package/dist/chunks/pt-BR-on-YW6Ay.mjs.map +1 -0
  115. package/dist/chunks/{scroll-area-DfDHXrMl.mjs → scroll-area-B9cWImdG.mjs} +11 -11
  116. package/dist/chunks/{scroll-area-DfDHXrMl.mjs.map → scroll-area-B9cWImdG.mjs.map} +1 -1
  117. package/dist/chunks/{select-Dm61g3Di.mjs → select-CQBb4aB3.mjs} +5 -5
  118. package/dist/chunks/{select-Dm61g3Di.mjs.map → select-CQBb4aB3.mjs.map} +1 -1
  119. package/dist/chunks/{separator-D9zU7ztA.mjs → separator-D6zbGj0R.mjs} +3 -3
  120. package/dist/chunks/{separator-D9zU7ztA.mjs.map → separator-D6zbGj0R.mjs.map} +1 -1
  121. package/dist/chunks/{sheet-CG9T6jEm.mjs → sheet-C0AR_o6p.mjs} +4 -4
  122. package/dist/chunks/{sheet-CG9T6jEm.mjs.map → sheet-C0AR_o6p.mjs.map} +1 -1
  123. package/dist/chunks/{skeleton-BBrPlJZ6.mjs → skeleton-Bd9uEq1R.mjs} +2 -2
  124. package/dist/chunks/{skeleton-BBrPlJZ6.mjs.map → skeleton-Bd9uEq1R.mjs.map} +1 -1
  125. package/dist/chunks/{sortable-C5sg2z09.mjs → sortable-CTcnqQX_.mjs} +3 -3
  126. package/dist/chunks/{sortable-C5sg2z09.mjs.map → sortable-CTcnqQX_.mjs.map} +1 -1
  127. package/dist/chunks/{table-D8dawH6l.mjs → table-C829r3Zv.mjs} +2 -2
  128. package/dist/chunks/{table-D8dawH6l.mjs.map → table-C829r3Zv.mjs.map} +1 -1
  129. package/dist/chunks/textarea-CD6y9GNW.mjs +13 -0
  130. package/dist/chunks/textarea-CD6y9GNW.mjs.map +1 -0
  131. package/dist/chunks/{toggle-BNDwy3fI.mjs → toggle-C8fZP79W.mjs} +5 -5
  132. package/dist/chunks/{toggle-BNDwy3fI.mjs.map → toggle-C8fZP79W.mjs.map} +1 -1
  133. package/dist/chunks/{tooltip-SoLw7T22.mjs → tooltip-R49U1IPs.mjs} +13 -13
  134. package/dist/chunks/{tooltip-SoLw7T22.mjs.map → tooltip-R49U1IPs.mjs.map} +1 -1
  135. package/dist/chunks/{trash-2-C_bzpesE.mjs → trash-2-ZC16Df_k.mjs} +2 -2
  136. package/dist/chunks/{trash-2-C_bzpesE.mjs.map → trash-2-ZC16Df_k.mjs.map} +1 -1
  137. package/dist/chunks/{tslib.es6-dgoTq-4a.mjs → tslib.es6-CnQYzBlA.mjs} +1 -1
  138. package/dist/chunks/{tslib.es6-dgoTq-4a.mjs.map → tslib.es6-CnQYzBlA.mjs.map} +1 -1
  139. package/dist/chunks/{utils-DiIQyE9g.mjs → utils-DwA_HfJw.mjs} +2 -2
  140. package/dist/chunks/{utils-DiIQyE9g.mjs.map → utils-DwA_HfJw.mjs.map} +1 -1
  141. package/dist/chunks/{x-BCPCYl4o.mjs → x-BZdVnIMx.mjs} +2 -2
  142. package/dist/chunks/{x-BCPCYl4o.mjs.map → x-BZdVnIMx.mjs.map} +1 -1
  143. package/dist/collapsible/index.mjs +9 -9
  144. package/dist/combobox/index.mjs +26 -26
  145. package/dist/command/index.mjs +20 -20
  146. package/dist/context-menu/index.mjs +23 -23
  147. package/dist/data-table/index.mjs +35 -35
  148. package/dist/date-picker/index.d.ts +20 -21
  149. package/dist/date-picker/index.mjs +40 -39
  150. package/dist/date-picker/index.mjs.map +1 -1
  151. package/dist/dialog/index.mjs +19 -19
  152. package/dist/drawer/index.mjs +16 -16
  153. package/dist/dropdown-menu/index.mjs +23 -23
  154. package/dist/dropzone/index.mjs +25 -26
  155. package/dist/dropzone/index.mjs.map +1 -1
  156. package/dist/empty/index.d.ts +16 -0
  157. package/dist/empty/index.mjs +65 -0
  158. package/dist/empty/index.mjs.map +1 -0
  159. package/dist/field/index.d.ts +30 -0
  160. package/dist/field/index.mjs +140 -0
  161. package/dist/field/index.mjs.map +1 -0
  162. package/dist/form/index.mjs +4 -4
  163. package/dist/hover-card/index.mjs +15 -15
  164. package/dist/icon/index.mjs +1 -1
  165. package/dist/index.css +1 -1
  166. package/dist/input/index.mjs +3 -3
  167. package/dist/input-group/index.d.ts +20 -0
  168. package/dist/input-group/index.mjs +97 -0
  169. package/dist/input-group/index.mjs.map +1 -0
  170. package/dist/input-otp/index.mjs +3 -3
  171. package/dist/item/index.d.ts +28 -0
  172. package/dist/item/index.mjs +125 -0
  173. package/dist/item/index.mjs.map +1 -0
  174. package/dist/ivt.css +1 -1
  175. package/dist/kbd/index.d.ts +7 -0
  176. package/dist/kbd/index.mjs +21 -0
  177. package/dist/kbd/index.mjs.map +1 -0
  178. package/dist/label/index.mjs +4 -4
  179. package/dist/layout/index.mjs +5 -5
  180. package/dist/menubar/index.mjs +23 -23
  181. package/dist/multi-select/index.mjs +30 -30
  182. package/dist/navigation-menu/index.mjs +17 -17
  183. package/dist/pagination/index.mjs +8 -8
  184. package/dist/popover/index.mjs +18 -18
  185. package/dist/progress/index.mjs +5 -5
  186. package/dist/radio-group/index.mjs +17 -17
  187. package/dist/resizable/index.mjs +3 -3
  188. package/dist/scroll-area/index.mjs +12 -12
  189. package/dist/select/index.mjs +6 -6
  190. package/dist/separator/index.mjs +4 -4
  191. package/dist/shared/index.mjs +5 -5
  192. package/dist/sheet/index.mjs +19 -19
  193. package/dist/sidebar/index.mjs +27 -27
  194. package/dist/skeleton/index.mjs +3 -3
  195. package/dist/skeleton-component/index.mjs +4 -4
  196. package/dist/slider/index.mjs +12 -12
  197. package/dist/sortable/index.mjs +4 -4
  198. package/dist/spinner/index.d.ts +5 -0
  199. package/dist/spinner/index.mjs +17 -0
  200. package/dist/spinner/index.mjs.map +1 -0
  201. package/dist/switch/index.mjs +10 -10
  202. package/dist/table/index.mjs +3 -3
  203. package/dist/tabs/index.mjs +13 -13
  204. package/dist/textarea/index.mjs +4 -13
  205. package/dist/textarea/index.mjs.map +1 -1
  206. package/dist/toast/index.mjs +15 -15
  207. package/dist/toggle/index.mjs +7 -7
  208. package/dist/toggle-group/index.mjs +13 -13
  209. package/dist/tooltip/index.mjs +17 -17
  210. package/package.json +30 -3
  211. package/dist/chunks/_commonjsHelpers-B6NPw-gB.mjs.map +0 -1
  212. package/dist/chunks/button-DUnGULhS.mjs.map +0 -1
  213. package/dist/chunks/pt-BR-dv9Ki026.mjs +0 -608
  214. package/dist/chunks/pt-BR-dv9Ki026.mjs.map +0 -1
@@ -0,0 +1,3275 @@
1
+ import { c as createLucideIcon } from './createLucideIcon-DwD3HsEs.mjs';
2
+ import { g as getDefaultOptions$1, t as toDate, c as constructFrom, m as millisecondsInHour, b as millisecondsInMinute, d as millisecondsInSecond, e as getWeekYear, s as startOfWeek, h as startOfISOWeek, i as getWeek, j as getISOWeek, k as addDays, l as getTimezoneOffsetInMilliseconds, n as enUS, o as longFormatters, p as isProtectedWeekYearToken, w as warnOrThrowProtectedError, q as isProtectedDayOfYearToken, r as isValid, u as buildFormatLongFn, v as buildLocalizeFn, x as buildMatchFn, y as buildMatchPatternFn } from './calendar-D98dWxWB.mjs';
3
+
4
+ const __iconNode = [
5
+ [
6
+ "path",
7
+ {
8
+ d: "M8 2v4",
9
+ key: "1cmpym"
10
+ }
11
+ ],
12
+ [
13
+ "path",
14
+ {
15
+ d: "M16 2v4",
16
+ key: "4m81vk"
17
+ }
18
+ ],
19
+ [
20
+ "rect",
21
+ {
22
+ width: "18",
23
+ height: "18",
24
+ x: "3",
25
+ y: "4",
26
+ rx: "2",
27
+ key: "1hopcy"
28
+ }
29
+ ],
30
+ [
31
+ "path",
32
+ {
33
+ d: "M3 10h18",
34
+ key: "8toen8"
35
+ }
36
+ ],
37
+ [
38
+ "path",
39
+ {
40
+ d: "M8 14h.01",
41
+ key: "6423bh"
42
+ }
43
+ ],
44
+ [
45
+ "path",
46
+ {
47
+ d: "M12 14h.01",
48
+ key: "1etili"
49
+ }
50
+ ],
51
+ [
52
+ "path",
53
+ {
54
+ d: "M16 14h.01",
55
+ key: "1gbofw"
56
+ }
57
+ ],
58
+ [
59
+ "path",
60
+ {
61
+ d: "M8 18h.01",
62
+ key: "lrp35t"
63
+ }
64
+ ],
65
+ [
66
+ "path",
67
+ {
68
+ d: "M12 18h.01",
69
+ key: "mhygvu"
70
+ }
71
+ ],
72
+ [
73
+ "path",
74
+ {
75
+ d: "M16 18h.01",
76
+ key: "kzsmim"
77
+ }
78
+ ]
79
+ ];
80
+ const CalendarDays = createLucideIcon("CalendarDays", __iconNode);
81
+
82
+ /**
83
+ * @name getDefaultOptions
84
+ * @category Common Helpers
85
+ * @summary Get default options.
86
+ * @pure false
87
+ *
88
+ * @description
89
+ * Returns an object that contains defaults for
90
+ * `options.locale`, `options.weekStartsOn` and `options.firstWeekContainsDate`
91
+ * arguments for all functions.
92
+ *
93
+ * You can change these with [setDefaultOptions](https://date-fns.org/docs/setDefaultOptions).
94
+ *
95
+ * @returns The default options
96
+ *
97
+ * @example
98
+ * const result = getDefaultOptions()
99
+ * //=> {}
100
+ *
101
+ * @example
102
+ * setDefaultOptions({ weekStarsOn: 1, firstWeekContainsDate: 4 })
103
+ * const result = getDefaultOptions()
104
+ * //=> { weekStarsOn: 1, firstWeekContainsDate: 4 }
105
+ */ function getDefaultOptions() {
106
+ return Object.assign({}, getDefaultOptions$1());
107
+ }
108
+
109
+ /**
110
+ * The {@link getISODay} function options.
111
+ */ /**
112
+ * @name getISODay
113
+ * @category Weekday Helpers
114
+ * @summary Get the day of the ISO week of the given date.
115
+ *
116
+ * @description
117
+ * Get the day of the ISO week of the given date,
118
+ * which is 7 for Sunday, 1 for Monday etc.
119
+ *
120
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
121
+ *
122
+ * @param date - The given date
123
+ * @param options - An object with options
124
+ *
125
+ * @returns The day of ISO week
126
+ *
127
+ * @example
128
+ * // Which day of the ISO week is 26 February 2012?
129
+ * const result = getISODay(new Date(2012, 1, 26))
130
+ * //=> 7
131
+ */ function getISODay(date, options) {
132
+ const day = toDate(date, options?.in).getDay();
133
+ return day === 0 ? 7 : day;
134
+ }
135
+
136
+ /**
137
+ * @name transpose
138
+ * @category Generic Helpers
139
+ * @summary Transpose the date to the given constructor.
140
+ *
141
+ * @description
142
+ * The function transposes the date to the given constructor. It helps you
143
+ * to transpose the date in the system time zone to say `UTCDate` or any other
144
+ * date extension.
145
+ *
146
+ * @typeParam InputDate - The input `Date` type derived from the passed argument.
147
+ * @typeParam ResultDate - The result `Date` type derived from the passed constructor.
148
+ *
149
+ * @param date - The date to use values from
150
+ * @param constructor - The date constructor to use
151
+ *
152
+ * @returns Date transposed to the given constructor
153
+ *
154
+ * @example
155
+ * // Create July 10, 2022 00:00 in locale time zone
156
+ * const date = new Date(2022, 6, 10)
157
+ * //=> 'Sun Jul 10 2022 00:00:00 GMT+0800 (Singapore Standard Time)'
158
+ *
159
+ * @example
160
+ * // Transpose the date to July 10, 2022 00:00 in UTC
161
+ * transpose(date, UTCDate)
162
+ * //=> 'Sun Jul 10 2022 00:00:00 GMT+0000 (Coordinated Universal Time)'
163
+ */ function transpose(date, constructor) {
164
+ const date_ = isConstructor(constructor) ? new constructor(0) : constructFrom(constructor, 0);
165
+ date_.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
166
+ date_.setHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
167
+ return date_;
168
+ }
169
+ function isConstructor(constructor) {
170
+ return typeof constructor === "function" && constructor.prototype?.constructor === constructor;
171
+ }
172
+
173
+ const TIMEZONE_UNIT_PRIORITY = 10;
174
+ class Setter {
175
+ validate(_utcDate, _options) {
176
+ return true;
177
+ }
178
+ constructor(){
179
+ this.subPriority = 0;
180
+ }
181
+ }
182
+ class ValueSetter extends Setter {
183
+ validate(date, options) {
184
+ return this.validateValue(date, this.value, options);
185
+ }
186
+ set(date, flags, options) {
187
+ return this.setValue(date, flags, this.value, options);
188
+ }
189
+ constructor(value, validateValue, setValue, priority, subPriority){
190
+ super();
191
+ this.value = value;
192
+ this.validateValue = validateValue;
193
+ this.setValue = setValue;
194
+ this.priority = priority;
195
+ if (subPriority) {
196
+ this.subPriority = subPriority;
197
+ }
198
+ }
199
+ }
200
+ class DateTimezoneSetter extends Setter {
201
+ set(date, flags) {
202
+ if (flags.timestampIsSet) return date;
203
+ return constructFrom(date, transpose(date, this.context));
204
+ }
205
+ constructor(context, reference){
206
+ super(), this.priority = TIMEZONE_UNIT_PRIORITY, this.subPriority = -1;
207
+ this.context = context || ((date)=>constructFrom(reference, date));
208
+ }
209
+ }
210
+
211
+ class Parser {
212
+ run(dateString, token, match, options) {
213
+ const result = this.parse(dateString, token, match, options);
214
+ if (!result) {
215
+ return null;
216
+ }
217
+ return {
218
+ setter: new ValueSetter(result.value, this.validate, this.set, this.priority, this.subPriority),
219
+ rest: result.rest
220
+ };
221
+ }
222
+ validate(_utcDate, _value, _options) {
223
+ return true;
224
+ }
225
+ }
226
+
227
+ class EraParser extends Parser {
228
+ parse(dateString, token, match) {
229
+ switch(token){
230
+ // AD, BC
231
+ case "G":
232
+ case "GG":
233
+ case "GGG":
234
+ return match.era(dateString, {
235
+ width: "abbreviated"
236
+ }) || match.era(dateString, {
237
+ width: "narrow"
238
+ });
239
+ // A, B
240
+ case "GGGGG":
241
+ return match.era(dateString, {
242
+ width: "narrow"
243
+ });
244
+ // Anno Domini, Before Christ
245
+ case "GGGG":
246
+ default:
247
+ return match.era(dateString, {
248
+ width: "wide"
249
+ }) || match.era(dateString, {
250
+ width: "abbreviated"
251
+ }) || match.era(dateString, {
252
+ width: "narrow"
253
+ });
254
+ }
255
+ }
256
+ set(date, flags, value) {
257
+ flags.era = value;
258
+ date.setFullYear(value, 0, 1);
259
+ date.setHours(0, 0, 0, 0);
260
+ return date;
261
+ }
262
+ constructor(...args){
263
+ super(...args), this.priority = 140, this.incompatibleTokens = [
264
+ "R",
265
+ "u",
266
+ "t",
267
+ "T"
268
+ ];
269
+ }
270
+ }
271
+
272
+ const numericPatterns = {
273
+ month: /^(1[0-2]|0?\d)/,
274
+ date: /^(3[0-1]|[0-2]?\d)/,
275
+ dayOfYear: /^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,
276
+ week: /^(5[0-3]|[0-4]?\d)/,
277
+ hour23h: /^(2[0-3]|[0-1]?\d)/,
278
+ hour24h: /^(2[0-4]|[0-1]?\d)/,
279
+ hour11h: /^(1[0-1]|0?\d)/,
280
+ hour12h: /^(1[0-2]|0?\d)/,
281
+ minute: /^[0-5]?\d/,
282
+ second: /^[0-5]?\d/,
283
+ singleDigit: /^\d/,
284
+ twoDigits: /^\d{1,2}/,
285
+ threeDigits: /^\d{1,3}/,
286
+ fourDigits: /^\d{1,4}/,
287
+ anyDigitsSigned: /^-?\d+/,
288
+ singleDigitSigned: /^-?\d/,
289
+ twoDigitsSigned: /^-?\d{1,2}/,
290
+ threeDigitsSigned: /^-?\d{1,3}/,
291
+ fourDigitsSigned: /^-?\d{1,4}/
292
+ };
293
+ const timezonePatterns = {
294
+ basicOptionalMinutes: /^([+-])(\d{2})(\d{2})?|Z/,
295
+ basic: /^([+-])(\d{2})(\d{2})|Z/,
296
+ basicOptionalSeconds: /^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,
297
+ extended: /^([+-])(\d{2}):(\d{2})|Z/,
298
+ extendedOptionalSeconds: /^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/
299
+ };
300
+
301
+ function mapValue(parseFnResult, mapFn) {
302
+ if (!parseFnResult) {
303
+ return parseFnResult;
304
+ }
305
+ return {
306
+ value: mapFn(parseFnResult.value),
307
+ rest: parseFnResult.rest
308
+ };
309
+ }
310
+ function parseNumericPattern(pattern, dateString) {
311
+ const matchResult = dateString.match(pattern);
312
+ if (!matchResult) {
313
+ return null;
314
+ }
315
+ return {
316
+ value: parseInt(matchResult[0], 10),
317
+ rest: dateString.slice(matchResult[0].length)
318
+ };
319
+ }
320
+ function parseTimezonePattern(pattern, dateString) {
321
+ const matchResult = dateString.match(pattern);
322
+ if (!matchResult) {
323
+ return null;
324
+ }
325
+ // Input is 'Z'
326
+ if (matchResult[0] === "Z") {
327
+ return {
328
+ value: 0,
329
+ rest: dateString.slice(1)
330
+ };
331
+ }
332
+ const sign = matchResult[1] === "+" ? 1 : -1;
333
+ const hours = matchResult[2] ? parseInt(matchResult[2], 10) : 0;
334
+ const minutes = matchResult[3] ? parseInt(matchResult[3], 10) : 0;
335
+ const seconds = matchResult[5] ? parseInt(matchResult[5], 10) : 0;
336
+ return {
337
+ value: sign * (hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * millisecondsInSecond),
338
+ rest: dateString.slice(matchResult[0].length)
339
+ };
340
+ }
341
+ function parseAnyDigitsSigned(dateString) {
342
+ return parseNumericPattern(numericPatterns.anyDigitsSigned, dateString);
343
+ }
344
+ function parseNDigits(n, dateString) {
345
+ switch(n){
346
+ case 1:
347
+ return parseNumericPattern(numericPatterns.singleDigit, dateString);
348
+ case 2:
349
+ return parseNumericPattern(numericPatterns.twoDigits, dateString);
350
+ case 3:
351
+ return parseNumericPattern(numericPatterns.threeDigits, dateString);
352
+ case 4:
353
+ return parseNumericPattern(numericPatterns.fourDigits, dateString);
354
+ default:
355
+ return parseNumericPattern(new RegExp("^\\d{1," + n + "}"), dateString);
356
+ }
357
+ }
358
+ function parseNDigitsSigned(n, dateString) {
359
+ switch(n){
360
+ case 1:
361
+ return parseNumericPattern(numericPatterns.singleDigitSigned, dateString);
362
+ case 2:
363
+ return parseNumericPattern(numericPatterns.twoDigitsSigned, dateString);
364
+ case 3:
365
+ return parseNumericPattern(numericPatterns.threeDigitsSigned, dateString);
366
+ case 4:
367
+ return parseNumericPattern(numericPatterns.fourDigitsSigned, dateString);
368
+ default:
369
+ return parseNumericPattern(new RegExp("^-?\\d{1," + n + "}"), dateString);
370
+ }
371
+ }
372
+ function dayPeriodEnumToHours(dayPeriod) {
373
+ switch(dayPeriod){
374
+ case "morning":
375
+ return 4;
376
+ case "evening":
377
+ return 17;
378
+ case "pm":
379
+ case "noon":
380
+ case "afternoon":
381
+ return 12;
382
+ case "am":
383
+ case "midnight":
384
+ case "night":
385
+ default:
386
+ return 0;
387
+ }
388
+ }
389
+ function normalizeTwoDigitYear(twoDigitYear, currentYear) {
390
+ const isCommonEra = currentYear > 0;
391
+ // Absolute number of the current year:
392
+ // 1 -> 1 AC
393
+ // 0 -> 1 BC
394
+ // -1 -> 2 BC
395
+ const absCurrentYear = isCommonEra ? currentYear : 1 - currentYear;
396
+ let result;
397
+ if (absCurrentYear <= 50) {
398
+ result = twoDigitYear || 100;
399
+ } else {
400
+ const rangeEnd = absCurrentYear + 50;
401
+ const rangeEndCentury = Math.trunc(rangeEnd / 100) * 100;
402
+ const isPreviousCentury = twoDigitYear >= rangeEnd % 100;
403
+ result = twoDigitYear + rangeEndCentury - (isPreviousCentury ? 100 : 0);
404
+ }
405
+ return isCommonEra ? result : 1 - result;
406
+ }
407
+ function isLeapYearIndex$1(year) {
408
+ return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
409
+ }
410
+
411
+ // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
412
+ // | Year | y | yy | yyy | yyyy | yyyyy |
413
+ // |----------|-------|----|-------|-------|-------|
414
+ // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
415
+ // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
416
+ // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
417
+ // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
418
+ // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
419
+ class YearParser extends Parser {
420
+ parse(dateString, token, match) {
421
+ const valueCallback = (year)=>({
422
+ year,
423
+ isTwoDigitYear: token === "yy"
424
+ });
425
+ switch(token){
426
+ case "y":
427
+ return mapValue(parseNDigits(4, dateString), valueCallback);
428
+ case "yo":
429
+ return mapValue(match.ordinalNumber(dateString, {
430
+ unit: "year"
431
+ }), valueCallback);
432
+ default:
433
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
434
+ }
435
+ }
436
+ validate(_date, value) {
437
+ return value.isTwoDigitYear || value.year > 0;
438
+ }
439
+ set(date, flags, value) {
440
+ const currentYear = date.getFullYear();
441
+ if (value.isTwoDigitYear) {
442
+ const normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear);
443
+ date.setFullYear(normalizedTwoDigitYear, 0, 1);
444
+ date.setHours(0, 0, 0, 0);
445
+ return date;
446
+ }
447
+ const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
448
+ date.setFullYear(year, 0, 1);
449
+ date.setHours(0, 0, 0, 0);
450
+ return date;
451
+ }
452
+ constructor(...args){
453
+ super(...args), this.priority = 130, this.incompatibleTokens = [
454
+ "Y",
455
+ "R",
456
+ "u",
457
+ "w",
458
+ "I",
459
+ "i",
460
+ "e",
461
+ "c",
462
+ "t",
463
+ "T"
464
+ ];
465
+ }
466
+ }
467
+
468
+ // Local week-numbering year
469
+ class LocalWeekYearParser extends Parser {
470
+ parse(dateString, token, match) {
471
+ const valueCallback = (year)=>({
472
+ year,
473
+ isTwoDigitYear: token === "YY"
474
+ });
475
+ switch(token){
476
+ case "Y":
477
+ return mapValue(parseNDigits(4, dateString), valueCallback);
478
+ case "Yo":
479
+ return mapValue(match.ordinalNumber(dateString, {
480
+ unit: "year"
481
+ }), valueCallback);
482
+ default:
483
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
484
+ }
485
+ }
486
+ validate(_date, value) {
487
+ return value.isTwoDigitYear || value.year > 0;
488
+ }
489
+ set(date, flags, value, options) {
490
+ const currentYear = getWeekYear(date, options);
491
+ if (value.isTwoDigitYear) {
492
+ const normalizedTwoDigitYear = normalizeTwoDigitYear(value.year, currentYear);
493
+ date.setFullYear(normalizedTwoDigitYear, 0, options.firstWeekContainsDate);
494
+ date.setHours(0, 0, 0, 0);
495
+ return startOfWeek(date, options);
496
+ }
497
+ const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
498
+ date.setFullYear(year, 0, options.firstWeekContainsDate);
499
+ date.setHours(0, 0, 0, 0);
500
+ return startOfWeek(date, options);
501
+ }
502
+ constructor(...args){
503
+ super(...args), this.priority = 130, this.incompatibleTokens = [
504
+ "y",
505
+ "R",
506
+ "u",
507
+ "Q",
508
+ "q",
509
+ "M",
510
+ "L",
511
+ "I",
512
+ "d",
513
+ "D",
514
+ "i",
515
+ "t",
516
+ "T"
517
+ ];
518
+ }
519
+ }
520
+
521
+ // ISO week-numbering year
522
+ class ISOWeekYearParser extends Parser {
523
+ parse(dateString, token) {
524
+ if (token === "R") {
525
+ return parseNDigitsSigned(4, dateString);
526
+ }
527
+ return parseNDigitsSigned(token.length, dateString);
528
+ }
529
+ set(date, _flags, value) {
530
+ const firstWeekOfYear = constructFrom(date, 0);
531
+ firstWeekOfYear.setFullYear(value, 0, 4);
532
+ firstWeekOfYear.setHours(0, 0, 0, 0);
533
+ return startOfISOWeek(firstWeekOfYear);
534
+ }
535
+ constructor(...args){
536
+ super(...args), this.priority = 130, this.incompatibleTokens = [
537
+ "G",
538
+ "y",
539
+ "Y",
540
+ "u",
541
+ "Q",
542
+ "q",
543
+ "M",
544
+ "L",
545
+ "w",
546
+ "d",
547
+ "D",
548
+ "e",
549
+ "c",
550
+ "t",
551
+ "T"
552
+ ];
553
+ }
554
+ }
555
+
556
+ class ExtendedYearParser extends Parser {
557
+ parse(dateString, token) {
558
+ if (token === "u") {
559
+ return parseNDigitsSigned(4, dateString);
560
+ }
561
+ return parseNDigitsSigned(token.length, dateString);
562
+ }
563
+ set(date, _flags, value) {
564
+ date.setFullYear(value, 0, 1);
565
+ date.setHours(0, 0, 0, 0);
566
+ return date;
567
+ }
568
+ constructor(...args){
569
+ super(...args), this.priority = 130, this.incompatibleTokens = [
570
+ "G",
571
+ "y",
572
+ "Y",
573
+ "R",
574
+ "w",
575
+ "I",
576
+ "i",
577
+ "e",
578
+ "c",
579
+ "t",
580
+ "T"
581
+ ];
582
+ }
583
+ }
584
+
585
+ class QuarterParser extends Parser {
586
+ parse(dateString, token, match) {
587
+ switch(token){
588
+ // 1, 2, 3, 4
589
+ case "Q":
590
+ case "QQ":
591
+ return parseNDigits(token.length, dateString);
592
+ // 1st, 2nd, 3rd, 4th
593
+ case "Qo":
594
+ return match.ordinalNumber(dateString, {
595
+ unit: "quarter"
596
+ });
597
+ // Q1, Q2, Q3, Q4
598
+ case "QQQ":
599
+ return match.quarter(dateString, {
600
+ width: "abbreviated",
601
+ context: "formatting"
602
+ }) || match.quarter(dateString, {
603
+ width: "narrow",
604
+ context: "formatting"
605
+ });
606
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
607
+ case "QQQQQ":
608
+ return match.quarter(dateString, {
609
+ width: "narrow",
610
+ context: "formatting"
611
+ });
612
+ // 1st quarter, 2nd quarter, ...
613
+ case "QQQQ":
614
+ default:
615
+ return match.quarter(dateString, {
616
+ width: "wide",
617
+ context: "formatting"
618
+ }) || match.quarter(dateString, {
619
+ width: "abbreviated",
620
+ context: "formatting"
621
+ }) || match.quarter(dateString, {
622
+ width: "narrow",
623
+ context: "formatting"
624
+ });
625
+ }
626
+ }
627
+ validate(_date, value) {
628
+ return value >= 1 && value <= 4;
629
+ }
630
+ set(date, _flags, value) {
631
+ date.setMonth((value - 1) * 3, 1);
632
+ date.setHours(0, 0, 0, 0);
633
+ return date;
634
+ }
635
+ constructor(...args){
636
+ super(...args), this.priority = 120, this.incompatibleTokens = [
637
+ "Y",
638
+ "R",
639
+ "q",
640
+ "M",
641
+ "L",
642
+ "w",
643
+ "I",
644
+ "d",
645
+ "D",
646
+ "i",
647
+ "e",
648
+ "c",
649
+ "t",
650
+ "T"
651
+ ];
652
+ }
653
+ }
654
+
655
+ class StandAloneQuarterParser extends Parser {
656
+ parse(dateString, token, match) {
657
+ switch(token){
658
+ // 1, 2, 3, 4
659
+ case "q":
660
+ case "qq":
661
+ return parseNDigits(token.length, dateString);
662
+ // 1st, 2nd, 3rd, 4th
663
+ case "qo":
664
+ return match.ordinalNumber(dateString, {
665
+ unit: "quarter"
666
+ });
667
+ // Q1, Q2, Q3, Q4
668
+ case "qqq":
669
+ return match.quarter(dateString, {
670
+ width: "abbreviated",
671
+ context: "standalone"
672
+ }) || match.quarter(dateString, {
673
+ width: "narrow",
674
+ context: "standalone"
675
+ });
676
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
677
+ case "qqqqq":
678
+ return match.quarter(dateString, {
679
+ width: "narrow",
680
+ context: "standalone"
681
+ });
682
+ // 1st quarter, 2nd quarter, ...
683
+ case "qqqq":
684
+ default:
685
+ return match.quarter(dateString, {
686
+ width: "wide",
687
+ context: "standalone"
688
+ }) || match.quarter(dateString, {
689
+ width: "abbreviated",
690
+ context: "standalone"
691
+ }) || match.quarter(dateString, {
692
+ width: "narrow",
693
+ context: "standalone"
694
+ });
695
+ }
696
+ }
697
+ validate(_date, value) {
698
+ return value >= 1 && value <= 4;
699
+ }
700
+ set(date, _flags, value) {
701
+ date.setMonth((value - 1) * 3, 1);
702
+ date.setHours(0, 0, 0, 0);
703
+ return date;
704
+ }
705
+ constructor(...args){
706
+ super(...args), this.priority = 120, this.incompatibleTokens = [
707
+ "Y",
708
+ "R",
709
+ "Q",
710
+ "M",
711
+ "L",
712
+ "w",
713
+ "I",
714
+ "d",
715
+ "D",
716
+ "i",
717
+ "e",
718
+ "c",
719
+ "t",
720
+ "T"
721
+ ];
722
+ }
723
+ }
724
+
725
+ class MonthParser extends Parser {
726
+ parse(dateString, token, match) {
727
+ const valueCallback = (value)=>value - 1;
728
+ switch(token){
729
+ // 1, 2, ..., 12
730
+ case "M":
731
+ return mapValue(parseNumericPattern(numericPatterns.month, dateString), valueCallback);
732
+ // 01, 02, ..., 12
733
+ case "MM":
734
+ return mapValue(parseNDigits(2, dateString), valueCallback);
735
+ // 1st, 2nd, ..., 12th
736
+ case "Mo":
737
+ return mapValue(match.ordinalNumber(dateString, {
738
+ unit: "month"
739
+ }), valueCallback);
740
+ // Jan, Feb, ..., Dec
741
+ case "MMM":
742
+ return match.month(dateString, {
743
+ width: "abbreviated",
744
+ context: "formatting"
745
+ }) || match.month(dateString, {
746
+ width: "narrow",
747
+ context: "formatting"
748
+ });
749
+ // J, F, ..., D
750
+ case "MMMMM":
751
+ return match.month(dateString, {
752
+ width: "narrow",
753
+ context: "formatting"
754
+ });
755
+ // January, February, ..., December
756
+ case "MMMM":
757
+ default:
758
+ return match.month(dateString, {
759
+ width: "wide",
760
+ context: "formatting"
761
+ }) || match.month(dateString, {
762
+ width: "abbreviated",
763
+ context: "formatting"
764
+ }) || match.month(dateString, {
765
+ width: "narrow",
766
+ context: "formatting"
767
+ });
768
+ }
769
+ }
770
+ validate(_date, value) {
771
+ return value >= 0 && value <= 11;
772
+ }
773
+ set(date, _flags, value) {
774
+ date.setMonth(value, 1);
775
+ date.setHours(0, 0, 0, 0);
776
+ return date;
777
+ }
778
+ constructor(...args){
779
+ super(...args), this.incompatibleTokens = [
780
+ "Y",
781
+ "R",
782
+ "q",
783
+ "Q",
784
+ "L",
785
+ "w",
786
+ "I",
787
+ "D",
788
+ "i",
789
+ "e",
790
+ "c",
791
+ "t",
792
+ "T"
793
+ ], this.priority = 110;
794
+ }
795
+ }
796
+
797
+ class StandAloneMonthParser extends Parser {
798
+ parse(dateString, token, match) {
799
+ const valueCallback = (value)=>value - 1;
800
+ switch(token){
801
+ // 1, 2, ..., 12
802
+ case "L":
803
+ return mapValue(parseNumericPattern(numericPatterns.month, dateString), valueCallback);
804
+ // 01, 02, ..., 12
805
+ case "LL":
806
+ return mapValue(parseNDigits(2, dateString), valueCallback);
807
+ // 1st, 2nd, ..., 12th
808
+ case "Lo":
809
+ return mapValue(match.ordinalNumber(dateString, {
810
+ unit: "month"
811
+ }), valueCallback);
812
+ // Jan, Feb, ..., Dec
813
+ case "LLL":
814
+ return match.month(dateString, {
815
+ width: "abbreviated",
816
+ context: "standalone"
817
+ }) || match.month(dateString, {
818
+ width: "narrow",
819
+ context: "standalone"
820
+ });
821
+ // J, F, ..., D
822
+ case "LLLLL":
823
+ return match.month(dateString, {
824
+ width: "narrow",
825
+ context: "standalone"
826
+ });
827
+ // January, February, ..., December
828
+ case "LLLL":
829
+ default:
830
+ return match.month(dateString, {
831
+ width: "wide",
832
+ context: "standalone"
833
+ }) || match.month(dateString, {
834
+ width: "abbreviated",
835
+ context: "standalone"
836
+ }) || match.month(dateString, {
837
+ width: "narrow",
838
+ context: "standalone"
839
+ });
840
+ }
841
+ }
842
+ validate(_date, value) {
843
+ return value >= 0 && value <= 11;
844
+ }
845
+ set(date, _flags, value) {
846
+ date.setMonth(value, 1);
847
+ date.setHours(0, 0, 0, 0);
848
+ return date;
849
+ }
850
+ constructor(...args){
851
+ super(...args), this.priority = 110, this.incompatibleTokens = [
852
+ "Y",
853
+ "R",
854
+ "q",
855
+ "Q",
856
+ "M",
857
+ "w",
858
+ "I",
859
+ "D",
860
+ "i",
861
+ "e",
862
+ "c",
863
+ "t",
864
+ "T"
865
+ ];
866
+ }
867
+ }
868
+
869
+ /**
870
+ * The {@link setWeek} function options.
871
+ */ /**
872
+ * @name setWeek
873
+ * @category Week Helpers
874
+ * @summary Set the local week to the given date.
875
+ *
876
+ * @description
877
+ * Set the local week to the given date, saving the weekday number.
878
+ * The exact calculation depends on the values of
879
+ * `options.weekStartsOn` (which is the index of the first day of the week)
880
+ * and `options.firstWeekContainsDate` (which is the day of January, which is always in
881
+ * the first week of the week-numbering year)
882
+ *
883
+ * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
884
+ *
885
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
886
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
887
+ *
888
+ * @param date - The date to be changed
889
+ * @param week - The week of the new date
890
+ * @param options - An object with options
891
+ *
892
+ * @returns The new date with the local week set
893
+ *
894
+ * @example
895
+ * // Set the 1st week to 2 January 2005 with default options:
896
+ * const result = setWeek(new Date(2005, 0, 2), 1)
897
+ * //=> Sun Dec 26 2004 00:00:00
898
+ *
899
+ * @example
900
+ * // Set the 1st week to 2 January 2005,
901
+ * // if Monday is the first day of the week,
902
+ * // and the first week of the year always contains 4 January:
903
+ * const result = setWeek(new Date(2005, 0, 2), 1, {
904
+ * weekStartsOn: 1,
905
+ * firstWeekContainsDate: 4
906
+ * })
907
+ * //=> Sun Jan 4 2004 00:00:00
908
+ */ function setWeek(date, week, options) {
909
+ const date_ = toDate(date, options?.in);
910
+ const diff = getWeek(date_, options) - week;
911
+ date_.setDate(date_.getDate() - diff * 7);
912
+ return toDate(date_, options?.in);
913
+ }
914
+
915
+ // Local week of year
916
+ class LocalWeekParser extends Parser {
917
+ parse(dateString, token, match) {
918
+ switch(token){
919
+ case "w":
920
+ return parseNumericPattern(numericPatterns.week, dateString);
921
+ case "wo":
922
+ return match.ordinalNumber(dateString, {
923
+ unit: "week"
924
+ });
925
+ default:
926
+ return parseNDigits(token.length, dateString);
927
+ }
928
+ }
929
+ validate(_date, value) {
930
+ return value >= 1 && value <= 53;
931
+ }
932
+ set(date, _flags, value, options) {
933
+ return startOfWeek(setWeek(date, value, options), options);
934
+ }
935
+ constructor(...args){
936
+ super(...args), this.priority = 100, this.incompatibleTokens = [
937
+ "y",
938
+ "R",
939
+ "u",
940
+ "q",
941
+ "Q",
942
+ "M",
943
+ "L",
944
+ "I",
945
+ "d",
946
+ "D",
947
+ "i",
948
+ "t",
949
+ "T"
950
+ ];
951
+ }
952
+ }
953
+
954
+ /**
955
+ * The {@link setISOWeek} function options.
956
+ */ /**
957
+ * @name setISOWeek
958
+ * @category ISO Week Helpers
959
+ * @summary Set the ISO week to the given date.
960
+ *
961
+ * @description
962
+ * Set the ISO week to the given date, saving the weekday number.
963
+ *
964
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
965
+ *
966
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
967
+ * @typeParam ResultDate - The `Date` type of the context function.
968
+ *
969
+ * @param date - The date to be changed
970
+ * @param week - The ISO week of the new date
971
+ * @param options - An object with options
972
+ *
973
+ * @returns The new date with the ISO week set
974
+ *
975
+ * @example
976
+ * // Set the 53rd ISO week to 7 August 2004:
977
+ * const result = setISOWeek(new Date(2004, 7, 7), 53)
978
+ * //=> Sat Jan 01 2005 00:00:00
979
+ */ function setISOWeek(date, week, options) {
980
+ const _date = toDate(date, options?.in);
981
+ const diff = getISOWeek(_date, options) - week;
982
+ _date.setDate(_date.getDate() - diff * 7);
983
+ return _date;
984
+ }
985
+
986
+ // ISO week of year
987
+ class ISOWeekParser extends Parser {
988
+ parse(dateString, token, match) {
989
+ switch(token){
990
+ case "I":
991
+ return parseNumericPattern(numericPatterns.week, dateString);
992
+ case "Io":
993
+ return match.ordinalNumber(dateString, {
994
+ unit: "week"
995
+ });
996
+ default:
997
+ return parseNDigits(token.length, dateString);
998
+ }
999
+ }
1000
+ validate(_date, value) {
1001
+ return value >= 1 && value <= 53;
1002
+ }
1003
+ set(date, _flags, value) {
1004
+ return startOfISOWeek(setISOWeek(date, value));
1005
+ }
1006
+ constructor(...args){
1007
+ super(...args), this.priority = 100, this.incompatibleTokens = [
1008
+ "y",
1009
+ "Y",
1010
+ "u",
1011
+ "q",
1012
+ "Q",
1013
+ "M",
1014
+ "L",
1015
+ "w",
1016
+ "d",
1017
+ "D",
1018
+ "e",
1019
+ "c",
1020
+ "t",
1021
+ "T"
1022
+ ];
1023
+ }
1024
+ }
1025
+
1026
+ const DAYS_IN_MONTH = [
1027
+ 31,
1028
+ 28,
1029
+ 31,
1030
+ 30,
1031
+ 31,
1032
+ 30,
1033
+ 31,
1034
+ 31,
1035
+ 30,
1036
+ 31,
1037
+ 30,
1038
+ 31
1039
+ ];
1040
+ const DAYS_IN_MONTH_LEAP_YEAR = [
1041
+ 31,
1042
+ 29,
1043
+ 31,
1044
+ 30,
1045
+ 31,
1046
+ 30,
1047
+ 31,
1048
+ 31,
1049
+ 30,
1050
+ 31,
1051
+ 30,
1052
+ 31
1053
+ ];
1054
+ // Day of the month
1055
+ class DateParser extends Parser {
1056
+ parse(dateString, token, match) {
1057
+ switch(token){
1058
+ case "d":
1059
+ return parseNumericPattern(numericPatterns.date, dateString);
1060
+ case "do":
1061
+ return match.ordinalNumber(dateString, {
1062
+ unit: "date"
1063
+ });
1064
+ default:
1065
+ return parseNDigits(token.length, dateString);
1066
+ }
1067
+ }
1068
+ validate(date, value) {
1069
+ const year = date.getFullYear();
1070
+ const isLeapYear = isLeapYearIndex$1(year);
1071
+ const month = date.getMonth();
1072
+ if (isLeapYear) {
1073
+ return value >= 1 && value <= DAYS_IN_MONTH_LEAP_YEAR[month];
1074
+ } else {
1075
+ return value >= 1 && value <= DAYS_IN_MONTH[month];
1076
+ }
1077
+ }
1078
+ set(date, _flags, value) {
1079
+ date.setDate(value);
1080
+ date.setHours(0, 0, 0, 0);
1081
+ return date;
1082
+ }
1083
+ constructor(...args){
1084
+ super(...args), this.priority = 90, this.subPriority = 1, this.incompatibleTokens = [
1085
+ "Y",
1086
+ "R",
1087
+ "q",
1088
+ "Q",
1089
+ "w",
1090
+ "I",
1091
+ "D",
1092
+ "i",
1093
+ "e",
1094
+ "c",
1095
+ "t",
1096
+ "T"
1097
+ ];
1098
+ }
1099
+ }
1100
+
1101
+ class DayOfYearParser extends Parser {
1102
+ parse(dateString, token, match) {
1103
+ switch(token){
1104
+ case "D":
1105
+ case "DD":
1106
+ return parseNumericPattern(numericPatterns.dayOfYear, dateString);
1107
+ case "Do":
1108
+ return match.ordinalNumber(dateString, {
1109
+ unit: "date"
1110
+ });
1111
+ default:
1112
+ return parseNDigits(token.length, dateString);
1113
+ }
1114
+ }
1115
+ validate(date, value) {
1116
+ const year = date.getFullYear();
1117
+ const isLeapYear = isLeapYearIndex$1(year);
1118
+ if (isLeapYear) {
1119
+ return value >= 1 && value <= 366;
1120
+ } else {
1121
+ return value >= 1 && value <= 365;
1122
+ }
1123
+ }
1124
+ set(date, _flags, value) {
1125
+ date.setMonth(0, value);
1126
+ date.setHours(0, 0, 0, 0);
1127
+ return date;
1128
+ }
1129
+ constructor(...args){
1130
+ super(...args), this.priority = 90, this.subpriority = 1, this.incompatibleTokens = [
1131
+ "Y",
1132
+ "R",
1133
+ "q",
1134
+ "Q",
1135
+ "M",
1136
+ "L",
1137
+ "w",
1138
+ "I",
1139
+ "d",
1140
+ "E",
1141
+ "i",
1142
+ "e",
1143
+ "c",
1144
+ "t",
1145
+ "T"
1146
+ ];
1147
+ }
1148
+ }
1149
+
1150
+ /**
1151
+ * The {@link setDay} function options.
1152
+ */ /**
1153
+ * @name setDay
1154
+ * @category Weekday Helpers
1155
+ * @summary Set the day of the week to the given date.
1156
+ *
1157
+ * @description
1158
+ * Set the day of the week to the given date.
1159
+ *
1160
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
1161
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
1162
+ *
1163
+ * @param date - The date to be changed
1164
+ * @param day - The day of the week of the new date
1165
+ * @param options - An object with options.
1166
+ *
1167
+ * @returns The new date with the day of the week set
1168
+ *
1169
+ * @example
1170
+ * // Set week day to Sunday, with the default weekStartsOn of Sunday:
1171
+ * const result = setDay(new Date(2014, 8, 1), 0)
1172
+ * //=> Sun Aug 31 2014 00:00:00
1173
+ *
1174
+ * @example
1175
+ * // Set week day to Sunday, with a weekStartsOn of Monday:
1176
+ * const result = setDay(new Date(2014, 8, 1), 0, { weekStartsOn: 1 })
1177
+ * //=> Sun Sep 07 2014 00:00:00
1178
+ */ function setDay(date, day, options) {
1179
+ const defaultOptions = getDefaultOptions$1();
1180
+ const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions.weekStartsOn ?? defaultOptions.locale?.options?.weekStartsOn ?? 0;
1181
+ const date_ = toDate(date, options?.in);
1182
+ const currentDay = date_.getDay();
1183
+ const remainder = day % 7;
1184
+ const dayIndex = (remainder + 7) % 7;
1185
+ const delta = 7 - weekStartsOn;
1186
+ const diff = day < 0 || day > 6 ? day - (currentDay + delta) % 7 : (dayIndex + delta) % 7 - (currentDay + delta) % 7;
1187
+ return addDays(date_, diff, options);
1188
+ }
1189
+
1190
+ // Day of week
1191
+ class DayParser extends Parser {
1192
+ parse(dateString, token, match) {
1193
+ switch(token){
1194
+ // Tue
1195
+ case "E":
1196
+ case "EE":
1197
+ case "EEE":
1198
+ return match.day(dateString, {
1199
+ width: "abbreviated",
1200
+ context: "formatting"
1201
+ }) || match.day(dateString, {
1202
+ width: "short",
1203
+ context: "formatting"
1204
+ }) || match.day(dateString, {
1205
+ width: "narrow",
1206
+ context: "formatting"
1207
+ });
1208
+ // T
1209
+ case "EEEEE":
1210
+ return match.day(dateString, {
1211
+ width: "narrow",
1212
+ context: "formatting"
1213
+ });
1214
+ // Tu
1215
+ case "EEEEEE":
1216
+ return match.day(dateString, {
1217
+ width: "short",
1218
+ context: "formatting"
1219
+ }) || match.day(dateString, {
1220
+ width: "narrow",
1221
+ context: "formatting"
1222
+ });
1223
+ // Tuesday
1224
+ case "EEEE":
1225
+ default:
1226
+ return match.day(dateString, {
1227
+ width: "wide",
1228
+ context: "formatting"
1229
+ }) || match.day(dateString, {
1230
+ width: "abbreviated",
1231
+ context: "formatting"
1232
+ }) || match.day(dateString, {
1233
+ width: "short",
1234
+ context: "formatting"
1235
+ }) || match.day(dateString, {
1236
+ width: "narrow",
1237
+ context: "formatting"
1238
+ });
1239
+ }
1240
+ }
1241
+ validate(_date, value) {
1242
+ return value >= 0 && value <= 6;
1243
+ }
1244
+ set(date, _flags, value, options) {
1245
+ date = setDay(date, value, options);
1246
+ date.setHours(0, 0, 0, 0);
1247
+ return date;
1248
+ }
1249
+ constructor(...args){
1250
+ super(...args), this.priority = 90, this.incompatibleTokens = [
1251
+ "D",
1252
+ "i",
1253
+ "e",
1254
+ "c",
1255
+ "t",
1256
+ "T"
1257
+ ];
1258
+ }
1259
+ }
1260
+
1261
+ // Local day of week
1262
+ class LocalDayParser extends Parser {
1263
+ parse(dateString, token, match, options) {
1264
+ const valueCallback = (value)=>{
1265
+ // We want here floor instead of trunc, so we get -7 for value 0 instead of 0
1266
+ const wholeWeekDays = Math.floor((value - 1) / 7) * 7;
1267
+ return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
1268
+ };
1269
+ switch(token){
1270
+ // 3
1271
+ case "e":
1272
+ case "ee":
1273
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
1274
+ // 3rd
1275
+ case "eo":
1276
+ return mapValue(match.ordinalNumber(dateString, {
1277
+ unit: "day"
1278
+ }), valueCallback);
1279
+ // Tue
1280
+ case "eee":
1281
+ return match.day(dateString, {
1282
+ width: "abbreviated",
1283
+ context: "formatting"
1284
+ }) || match.day(dateString, {
1285
+ width: "short",
1286
+ context: "formatting"
1287
+ }) || match.day(dateString, {
1288
+ width: "narrow",
1289
+ context: "formatting"
1290
+ });
1291
+ // T
1292
+ case "eeeee":
1293
+ return match.day(dateString, {
1294
+ width: "narrow",
1295
+ context: "formatting"
1296
+ });
1297
+ // Tu
1298
+ case "eeeeee":
1299
+ return match.day(dateString, {
1300
+ width: "short",
1301
+ context: "formatting"
1302
+ }) || match.day(dateString, {
1303
+ width: "narrow",
1304
+ context: "formatting"
1305
+ });
1306
+ // Tuesday
1307
+ case "eeee":
1308
+ default:
1309
+ return match.day(dateString, {
1310
+ width: "wide",
1311
+ context: "formatting"
1312
+ }) || match.day(dateString, {
1313
+ width: "abbreviated",
1314
+ context: "formatting"
1315
+ }) || match.day(dateString, {
1316
+ width: "short",
1317
+ context: "formatting"
1318
+ }) || match.day(dateString, {
1319
+ width: "narrow",
1320
+ context: "formatting"
1321
+ });
1322
+ }
1323
+ }
1324
+ validate(_date, value) {
1325
+ return value >= 0 && value <= 6;
1326
+ }
1327
+ set(date, _flags, value, options) {
1328
+ date = setDay(date, value, options);
1329
+ date.setHours(0, 0, 0, 0);
1330
+ return date;
1331
+ }
1332
+ constructor(...args){
1333
+ super(...args), this.priority = 90, this.incompatibleTokens = [
1334
+ "y",
1335
+ "R",
1336
+ "u",
1337
+ "q",
1338
+ "Q",
1339
+ "M",
1340
+ "L",
1341
+ "I",
1342
+ "d",
1343
+ "D",
1344
+ "E",
1345
+ "i",
1346
+ "c",
1347
+ "t",
1348
+ "T"
1349
+ ];
1350
+ }
1351
+ }
1352
+
1353
+ // Stand-alone local day of week
1354
+ class StandAloneLocalDayParser extends Parser {
1355
+ parse(dateString, token, match, options) {
1356
+ const valueCallback = (value)=>{
1357
+ // We want here floor instead of trunc, so we get -7 for value 0 instead of 0
1358
+ const wholeWeekDays = Math.floor((value - 1) / 7) * 7;
1359
+ return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
1360
+ };
1361
+ switch(token){
1362
+ // 3
1363
+ case "c":
1364
+ case "cc":
1365
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
1366
+ // 3rd
1367
+ case "co":
1368
+ return mapValue(match.ordinalNumber(dateString, {
1369
+ unit: "day"
1370
+ }), valueCallback);
1371
+ // Tue
1372
+ case "ccc":
1373
+ return match.day(dateString, {
1374
+ width: "abbreviated",
1375
+ context: "standalone"
1376
+ }) || match.day(dateString, {
1377
+ width: "short",
1378
+ context: "standalone"
1379
+ }) || match.day(dateString, {
1380
+ width: "narrow",
1381
+ context: "standalone"
1382
+ });
1383
+ // T
1384
+ case "ccccc":
1385
+ return match.day(dateString, {
1386
+ width: "narrow",
1387
+ context: "standalone"
1388
+ });
1389
+ // Tu
1390
+ case "cccccc":
1391
+ return match.day(dateString, {
1392
+ width: "short",
1393
+ context: "standalone"
1394
+ }) || match.day(dateString, {
1395
+ width: "narrow",
1396
+ context: "standalone"
1397
+ });
1398
+ // Tuesday
1399
+ case "cccc":
1400
+ default:
1401
+ return match.day(dateString, {
1402
+ width: "wide",
1403
+ context: "standalone"
1404
+ }) || match.day(dateString, {
1405
+ width: "abbreviated",
1406
+ context: "standalone"
1407
+ }) || match.day(dateString, {
1408
+ width: "short",
1409
+ context: "standalone"
1410
+ }) || match.day(dateString, {
1411
+ width: "narrow",
1412
+ context: "standalone"
1413
+ });
1414
+ }
1415
+ }
1416
+ validate(_date, value) {
1417
+ return value >= 0 && value <= 6;
1418
+ }
1419
+ set(date, _flags, value, options) {
1420
+ date = setDay(date, value, options);
1421
+ date.setHours(0, 0, 0, 0);
1422
+ return date;
1423
+ }
1424
+ constructor(...args){
1425
+ super(...args), this.priority = 90, this.incompatibleTokens = [
1426
+ "y",
1427
+ "R",
1428
+ "u",
1429
+ "q",
1430
+ "Q",
1431
+ "M",
1432
+ "L",
1433
+ "I",
1434
+ "d",
1435
+ "D",
1436
+ "E",
1437
+ "i",
1438
+ "e",
1439
+ "t",
1440
+ "T"
1441
+ ];
1442
+ }
1443
+ }
1444
+
1445
+ /**
1446
+ * The {@link setISODay} function options.
1447
+ */ /**
1448
+ * @name setISODay
1449
+ * @category Weekday Helpers
1450
+ * @summary Set the day of the ISO week to the given date.
1451
+ *
1452
+ * @description
1453
+ * Set the day of the ISO week to the given date.
1454
+ * ISO week starts with Monday.
1455
+ * 7 is the index of Sunday, 1 is the index of Monday, etc.
1456
+ *
1457
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
1458
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
1459
+ *
1460
+ * @param date - The date to be changed
1461
+ * @param day - The day of the ISO week of the new date
1462
+ * @param options - An object with options
1463
+ *
1464
+ * @returns The new date with the day of the ISO week set
1465
+ *
1466
+ * @example
1467
+ * // Set Sunday to 1 September 2014:
1468
+ * const result = setISODay(new Date(2014, 8, 1), 7)
1469
+ * //=> Sun Sep 07 2014 00:00:00
1470
+ */ function setISODay(date, day, options) {
1471
+ const date_ = toDate(date, options?.in);
1472
+ const currentDay = getISODay(date_, options);
1473
+ const diff = day - currentDay;
1474
+ return addDays(date_, diff, options);
1475
+ }
1476
+
1477
+ // ISO day of week
1478
+ class ISODayParser extends Parser {
1479
+ parse(dateString, token, match) {
1480
+ const valueCallback = (value)=>{
1481
+ if (value === 0) {
1482
+ return 7;
1483
+ }
1484
+ return value;
1485
+ };
1486
+ switch(token){
1487
+ // 2
1488
+ case "i":
1489
+ case "ii":
1490
+ return parseNDigits(token.length, dateString);
1491
+ // 2nd
1492
+ case "io":
1493
+ return match.ordinalNumber(dateString, {
1494
+ unit: "day"
1495
+ });
1496
+ // Tue
1497
+ case "iii":
1498
+ return mapValue(match.day(dateString, {
1499
+ width: "abbreviated",
1500
+ context: "formatting"
1501
+ }) || match.day(dateString, {
1502
+ width: "short",
1503
+ context: "formatting"
1504
+ }) || match.day(dateString, {
1505
+ width: "narrow",
1506
+ context: "formatting"
1507
+ }), valueCallback);
1508
+ // T
1509
+ case "iiiii":
1510
+ return mapValue(match.day(dateString, {
1511
+ width: "narrow",
1512
+ context: "formatting"
1513
+ }), valueCallback);
1514
+ // Tu
1515
+ case "iiiiii":
1516
+ return mapValue(match.day(dateString, {
1517
+ width: "short",
1518
+ context: "formatting"
1519
+ }) || match.day(dateString, {
1520
+ width: "narrow",
1521
+ context: "formatting"
1522
+ }), valueCallback);
1523
+ // Tuesday
1524
+ case "iiii":
1525
+ default:
1526
+ return mapValue(match.day(dateString, {
1527
+ width: "wide",
1528
+ context: "formatting"
1529
+ }) || match.day(dateString, {
1530
+ width: "abbreviated",
1531
+ context: "formatting"
1532
+ }) || match.day(dateString, {
1533
+ width: "short",
1534
+ context: "formatting"
1535
+ }) || match.day(dateString, {
1536
+ width: "narrow",
1537
+ context: "formatting"
1538
+ }), valueCallback);
1539
+ }
1540
+ }
1541
+ validate(_date, value) {
1542
+ return value >= 1 && value <= 7;
1543
+ }
1544
+ set(date, _flags, value) {
1545
+ date = setISODay(date, value);
1546
+ date.setHours(0, 0, 0, 0);
1547
+ return date;
1548
+ }
1549
+ constructor(...args){
1550
+ super(...args), this.priority = 90, this.incompatibleTokens = [
1551
+ "y",
1552
+ "Y",
1553
+ "u",
1554
+ "q",
1555
+ "Q",
1556
+ "M",
1557
+ "L",
1558
+ "w",
1559
+ "d",
1560
+ "D",
1561
+ "E",
1562
+ "e",
1563
+ "c",
1564
+ "t",
1565
+ "T"
1566
+ ];
1567
+ }
1568
+ }
1569
+
1570
+ class AMPMParser extends Parser {
1571
+ parse(dateString, token, match) {
1572
+ switch(token){
1573
+ case "a":
1574
+ case "aa":
1575
+ case "aaa":
1576
+ return match.dayPeriod(dateString, {
1577
+ width: "abbreviated",
1578
+ context: "formatting"
1579
+ }) || match.dayPeriod(dateString, {
1580
+ width: "narrow",
1581
+ context: "formatting"
1582
+ });
1583
+ case "aaaaa":
1584
+ return match.dayPeriod(dateString, {
1585
+ width: "narrow",
1586
+ context: "formatting"
1587
+ });
1588
+ case "aaaa":
1589
+ default:
1590
+ return match.dayPeriod(dateString, {
1591
+ width: "wide",
1592
+ context: "formatting"
1593
+ }) || match.dayPeriod(dateString, {
1594
+ width: "abbreviated",
1595
+ context: "formatting"
1596
+ }) || match.dayPeriod(dateString, {
1597
+ width: "narrow",
1598
+ context: "formatting"
1599
+ });
1600
+ }
1601
+ }
1602
+ set(date, _flags, value) {
1603
+ date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
1604
+ return date;
1605
+ }
1606
+ constructor(...args){
1607
+ super(...args), this.priority = 80, this.incompatibleTokens = [
1608
+ "b",
1609
+ "B",
1610
+ "H",
1611
+ "k",
1612
+ "t",
1613
+ "T"
1614
+ ];
1615
+ }
1616
+ }
1617
+
1618
+ class AMPMMidnightParser extends Parser {
1619
+ parse(dateString, token, match) {
1620
+ switch(token){
1621
+ case "b":
1622
+ case "bb":
1623
+ case "bbb":
1624
+ return match.dayPeriod(dateString, {
1625
+ width: "abbreviated",
1626
+ context: "formatting"
1627
+ }) || match.dayPeriod(dateString, {
1628
+ width: "narrow",
1629
+ context: "formatting"
1630
+ });
1631
+ case "bbbbb":
1632
+ return match.dayPeriod(dateString, {
1633
+ width: "narrow",
1634
+ context: "formatting"
1635
+ });
1636
+ case "bbbb":
1637
+ default:
1638
+ return match.dayPeriod(dateString, {
1639
+ width: "wide",
1640
+ context: "formatting"
1641
+ }) || match.dayPeriod(dateString, {
1642
+ width: "abbreviated",
1643
+ context: "formatting"
1644
+ }) || match.dayPeriod(dateString, {
1645
+ width: "narrow",
1646
+ context: "formatting"
1647
+ });
1648
+ }
1649
+ }
1650
+ set(date, _flags, value) {
1651
+ date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
1652
+ return date;
1653
+ }
1654
+ constructor(...args){
1655
+ super(...args), this.priority = 80, this.incompatibleTokens = [
1656
+ "a",
1657
+ "B",
1658
+ "H",
1659
+ "k",
1660
+ "t",
1661
+ "T"
1662
+ ];
1663
+ }
1664
+ }
1665
+
1666
+ // in the morning, in the afternoon, in the evening, at night
1667
+ class DayPeriodParser extends Parser {
1668
+ parse(dateString, token, match) {
1669
+ switch(token){
1670
+ case "B":
1671
+ case "BB":
1672
+ case "BBB":
1673
+ return match.dayPeriod(dateString, {
1674
+ width: "abbreviated",
1675
+ context: "formatting"
1676
+ }) || match.dayPeriod(dateString, {
1677
+ width: "narrow",
1678
+ context: "formatting"
1679
+ });
1680
+ case "BBBBB":
1681
+ return match.dayPeriod(dateString, {
1682
+ width: "narrow",
1683
+ context: "formatting"
1684
+ });
1685
+ case "BBBB":
1686
+ default:
1687
+ return match.dayPeriod(dateString, {
1688
+ width: "wide",
1689
+ context: "formatting"
1690
+ }) || match.dayPeriod(dateString, {
1691
+ width: "abbreviated",
1692
+ context: "formatting"
1693
+ }) || match.dayPeriod(dateString, {
1694
+ width: "narrow",
1695
+ context: "formatting"
1696
+ });
1697
+ }
1698
+ }
1699
+ set(date, _flags, value) {
1700
+ date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
1701
+ return date;
1702
+ }
1703
+ constructor(...args){
1704
+ super(...args), this.priority = 80, this.incompatibleTokens = [
1705
+ "a",
1706
+ "b",
1707
+ "t",
1708
+ "T"
1709
+ ];
1710
+ }
1711
+ }
1712
+
1713
+ class Hour1to12Parser extends Parser {
1714
+ parse(dateString, token, match) {
1715
+ switch(token){
1716
+ case "h":
1717
+ return parseNumericPattern(numericPatterns.hour12h, dateString);
1718
+ case "ho":
1719
+ return match.ordinalNumber(dateString, {
1720
+ unit: "hour"
1721
+ });
1722
+ default:
1723
+ return parseNDigits(token.length, dateString);
1724
+ }
1725
+ }
1726
+ validate(_date, value) {
1727
+ return value >= 1 && value <= 12;
1728
+ }
1729
+ set(date, _flags, value) {
1730
+ const isPM = date.getHours() >= 12;
1731
+ if (isPM && value < 12) {
1732
+ date.setHours(value + 12, 0, 0, 0);
1733
+ } else if (!isPM && value === 12) {
1734
+ date.setHours(0, 0, 0, 0);
1735
+ } else {
1736
+ date.setHours(value, 0, 0, 0);
1737
+ }
1738
+ return date;
1739
+ }
1740
+ constructor(...args){
1741
+ super(...args), this.priority = 70, this.incompatibleTokens = [
1742
+ "H",
1743
+ "K",
1744
+ "k",
1745
+ "t",
1746
+ "T"
1747
+ ];
1748
+ }
1749
+ }
1750
+
1751
+ class Hour0to23Parser extends Parser {
1752
+ parse(dateString, token, match) {
1753
+ switch(token){
1754
+ case "H":
1755
+ return parseNumericPattern(numericPatterns.hour23h, dateString);
1756
+ case "Ho":
1757
+ return match.ordinalNumber(dateString, {
1758
+ unit: "hour"
1759
+ });
1760
+ default:
1761
+ return parseNDigits(token.length, dateString);
1762
+ }
1763
+ }
1764
+ validate(_date, value) {
1765
+ return value >= 0 && value <= 23;
1766
+ }
1767
+ set(date, _flags, value) {
1768
+ date.setHours(value, 0, 0, 0);
1769
+ return date;
1770
+ }
1771
+ constructor(...args){
1772
+ super(...args), this.priority = 70, this.incompatibleTokens = [
1773
+ "a",
1774
+ "b",
1775
+ "h",
1776
+ "K",
1777
+ "k",
1778
+ "t",
1779
+ "T"
1780
+ ];
1781
+ }
1782
+ }
1783
+
1784
+ class Hour0To11Parser extends Parser {
1785
+ parse(dateString, token, match) {
1786
+ switch(token){
1787
+ case "K":
1788
+ return parseNumericPattern(numericPatterns.hour11h, dateString);
1789
+ case "Ko":
1790
+ return match.ordinalNumber(dateString, {
1791
+ unit: "hour"
1792
+ });
1793
+ default:
1794
+ return parseNDigits(token.length, dateString);
1795
+ }
1796
+ }
1797
+ validate(_date, value) {
1798
+ return value >= 0 && value <= 11;
1799
+ }
1800
+ set(date, _flags, value) {
1801
+ const isPM = date.getHours() >= 12;
1802
+ if (isPM && value < 12) {
1803
+ date.setHours(value + 12, 0, 0, 0);
1804
+ } else {
1805
+ date.setHours(value, 0, 0, 0);
1806
+ }
1807
+ return date;
1808
+ }
1809
+ constructor(...args){
1810
+ super(...args), this.priority = 70, this.incompatibleTokens = [
1811
+ "h",
1812
+ "H",
1813
+ "k",
1814
+ "t",
1815
+ "T"
1816
+ ];
1817
+ }
1818
+ }
1819
+
1820
+ class Hour1To24Parser extends Parser {
1821
+ parse(dateString, token, match) {
1822
+ switch(token){
1823
+ case "k":
1824
+ return parseNumericPattern(numericPatterns.hour24h, dateString);
1825
+ case "ko":
1826
+ return match.ordinalNumber(dateString, {
1827
+ unit: "hour"
1828
+ });
1829
+ default:
1830
+ return parseNDigits(token.length, dateString);
1831
+ }
1832
+ }
1833
+ validate(_date, value) {
1834
+ return value >= 1 && value <= 24;
1835
+ }
1836
+ set(date, _flags, value) {
1837
+ const hours = value <= 24 ? value % 24 : value;
1838
+ date.setHours(hours, 0, 0, 0);
1839
+ return date;
1840
+ }
1841
+ constructor(...args){
1842
+ super(...args), this.priority = 70, this.incompatibleTokens = [
1843
+ "a",
1844
+ "b",
1845
+ "h",
1846
+ "H",
1847
+ "K",
1848
+ "t",
1849
+ "T"
1850
+ ];
1851
+ }
1852
+ }
1853
+
1854
+ class MinuteParser extends Parser {
1855
+ parse(dateString, token, match) {
1856
+ switch(token){
1857
+ case "m":
1858
+ return parseNumericPattern(numericPatterns.minute, dateString);
1859
+ case "mo":
1860
+ return match.ordinalNumber(dateString, {
1861
+ unit: "minute"
1862
+ });
1863
+ default:
1864
+ return parseNDigits(token.length, dateString);
1865
+ }
1866
+ }
1867
+ validate(_date, value) {
1868
+ return value >= 0 && value <= 59;
1869
+ }
1870
+ set(date, _flags, value) {
1871
+ date.setMinutes(value, 0, 0);
1872
+ return date;
1873
+ }
1874
+ constructor(...args){
1875
+ super(...args), this.priority = 60, this.incompatibleTokens = [
1876
+ "t",
1877
+ "T"
1878
+ ];
1879
+ }
1880
+ }
1881
+
1882
+ class SecondParser extends Parser {
1883
+ parse(dateString, token, match) {
1884
+ switch(token){
1885
+ case "s":
1886
+ return parseNumericPattern(numericPatterns.second, dateString);
1887
+ case "so":
1888
+ return match.ordinalNumber(dateString, {
1889
+ unit: "second"
1890
+ });
1891
+ default:
1892
+ return parseNDigits(token.length, dateString);
1893
+ }
1894
+ }
1895
+ validate(_date, value) {
1896
+ return value >= 0 && value <= 59;
1897
+ }
1898
+ set(date, _flags, value) {
1899
+ date.setSeconds(value, 0);
1900
+ return date;
1901
+ }
1902
+ constructor(...args){
1903
+ super(...args), this.priority = 50, this.incompatibleTokens = [
1904
+ "t",
1905
+ "T"
1906
+ ];
1907
+ }
1908
+ }
1909
+
1910
+ class FractionOfSecondParser extends Parser {
1911
+ parse(dateString, token) {
1912
+ const valueCallback = (value)=>Math.trunc(value * Math.pow(10, -token.length + 3));
1913
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
1914
+ }
1915
+ set(date, _flags, value) {
1916
+ date.setMilliseconds(value);
1917
+ return date;
1918
+ }
1919
+ constructor(...args){
1920
+ super(...args), this.priority = 30, this.incompatibleTokens = [
1921
+ "t",
1922
+ "T"
1923
+ ];
1924
+ }
1925
+ }
1926
+
1927
+ // Timezone (ISO-8601. +00:00 is `'Z'`)
1928
+ class ISOTimezoneWithZParser extends Parser {
1929
+ parse(dateString, token) {
1930
+ switch(token){
1931
+ case "X":
1932
+ return parseTimezonePattern(timezonePatterns.basicOptionalMinutes, dateString);
1933
+ case "XX":
1934
+ return parseTimezonePattern(timezonePatterns.basic, dateString);
1935
+ case "XXXX":
1936
+ return parseTimezonePattern(timezonePatterns.basicOptionalSeconds, dateString);
1937
+ case "XXXXX":
1938
+ return parseTimezonePattern(timezonePatterns.extendedOptionalSeconds, dateString);
1939
+ case "XXX":
1940
+ default:
1941
+ return parseTimezonePattern(timezonePatterns.extended, dateString);
1942
+ }
1943
+ }
1944
+ set(date, flags, value) {
1945
+ if (flags.timestampIsSet) return date;
1946
+ return constructFrom(date, date.getTime() - getTimezoneOffsetInMilliseconds(date) - value);
1947
+ }
1948
+ constructor(...args){
1949
+ super(...args), this.priority = 10, this.incompatibleTokens = [
1950
+ "t",
1951
+ "T",
1952
+ "x"
1953
+ ];
1954
+ }
1955
+ }
1956
+
1957
+ // Timezone (ISO-8601)
1958
+ class ISOTimezoneParser extends Parser {
1959
+ parse(dateString, token) {
1960
+ switch(token){
1961
+ case "x":
1962
+ return parseTimezonePattern(timezonePatterns.basicOptionalMinutes, dateString);
1963
+ case "xx":
1964
+ return parseTimezonePattern(timezonePatterns.basic, dateString);
1965
+ case "xxxx":
1966
+ return parseTimezonePattern(timezonePatterns.basicOptionalSeconds, dateString);
1967
+ case "xxxxx":
1968
+ return parseTimezonePattern(timezonePatterns.extendedOptionalSeconds, dateString);
1969
+ case "xxx":
1970
+ default:
1971
+ return parseTimezonePattern(timezonePatterns.extended, dateString);
1972
+ }
1973
+ }
1974
+ set(date, flags, value) {
1975
+ if (flags.timestampIsSet) return date;
1976
+ return constructFrom(date, date.getTime() - getTimezoneOffsetInMilliseconds(date) - value);
1977
+ }
1978
+ constructor(...args){
1979
+ super(...args), this.priority = 10, this.incompatibleTokens = [
1980
+ "t",
1981
+ "T",
1982
+ "X"
1983
+ ];
1984
+ }
1985
+ }
1986
+
1987
+ class TimestampSecondsParser extends Parser {
1988
+ parse(dateString) {
1989
+ return parseAnyDigitsSigned(dateString);
1990
+ }
1991
+ set(date, _flags, value) {
1992
+ return [
1993
+ constructFrom(date, value * 1000),
1994
+ {
1995
+ timestampIsSet: true
1996
+ }
1997
+ ];
1998
+ }
1999
+ constructor(...args){
2000
+ super(...args), this.priority = 40, this.incompatibleTokens = "*";
2001
+ }
2002
+ }
2003
+
2004
+ class TimestampMillisecondsParser extends Parser {
2005
+ parse(dateString) {
2006
+ return parseAnyDigitsSigned(dateString);
2007
+ }
2008
+ set(date, _flags, value) {
2009
+ return [
2010
+ constructFrom(date, value),
2011
+ {
2012
+ timestampIsSet: true
2013
+ }
2014
+ ];
2015
+ }
2016
+ constructor(...args){
2017
+ super(...args), this.priority = 20, this.incompatibleTokens = "*";
2018
+ }
2019
+ }
2020
+
2021
+ /*
2022
+ * | | Unit | | Unit |
2023
+ * |-----|--------------------------------|-----|--------------------------------|
2024
+ * | a | AM, PM | A* | Milliseconds in day |
2025
+ * | b | AM, PM, noon, midnight | B | Flexible day period |
2026
+ * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
2027
+ * | d | Day of month | D | Day of year |
2028
+ * | e | Local day of week | E | Day of week |
2029
+ * | f | | F* | Day of week in month |
2030
+ * | g* | Modified Julian day | G | Era |
2031
+ * | h | Hour [1-12] | H | Hour [0-23] |
2032
+ * | i! | ISO day of week | I! | ISO week of year |
2033
+ * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
2034
+ * | k | Hour [1-24] | K | Hour [0-11] |
2035
+ * | l* | (deprecated) | L | Stand-alone month |
2036
+ * | m | Minute | M | Month |
2037
+ * | n | | N | |
2038
+ * | o! | Ordinal number modifier | O* | Timezone (GMT) |
2039
+ * | p | | P | |
2040
+ * | q | Stand-alone quarter | Q | Quarter |
2041
+ * | r* | Related Gregorian year | R! | ISO week-numbering year |
2042
+ * | s | Second | S | Fraction of second |
2043
+ * | t! | Seconds timestamp | T! | Milliseconds timestamp |
2044
+ * | u | Extended year | U* | Cyclic year |
2045
+ * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
2046
+ * | w | Local week of year | W* | Week of month |
2047
+ * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
2048
+ * | y | Year (abs) | Y | Local week-numbering year |
2049
+ * | z* | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
2050
+ *
2051
+ * Letters marked by * are not implemented but reserved by Unicode standard.
2052
+ *
2053
+ * Letters marked by ! are non-standard, but implemented by date-fns:
2054
+ * - `o` modifies the previous token to turn it into an ordinal (see `parse` docs)
2055
+ * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
2056
+ * i.e. 7 for Sunday, 1 for Monday, etc.
2057
+ * - `I` is ISO week of year, as opposed to `w` which is local week of year.
2058
+ * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
2059
+ * `R` is supposed to be used in conjunction with `I` and `i`
2060
+ * for universal ISO week-numbering date, whereas
2061
+ * `Y` is supposed to be used in conjunction with `w` and `e`
2062
+ * for week-numbering date specific to the locale.
2063
+ */ const parsers = {
2064
+ G: new EraParser(),
2065
+ y: new YearParser(),
2066
+ Y: new LocalWeekYearParser(),
2067
+ R: new ISOWeekYearParser(),
2068
+ u: new ExtendedYearParser(),
2069
+ Q: new QuarterParser(),
2070
+ q: new StandAloneQuarterParser(),
2071
+ M: new MonthParser(),
2072
+ L: new StandAloneMonthParser(),
2073
+ w: new LocalWeekParser(),
2074
+ I: new ISOWeekParser(),
2075
+ d: new DateParser(),
2076
+ D: new DayOfYearParser(),
2077
+ E: new DayParser(),
2078
+ e: new LocalDayParser(),
2079
+ c: new StandAloneLocalDayParser(),
2080
+ i: new ISODayParser(),
2081
+ a: new AMPMParser(),
2082
+ b: new AMPMMidnightParser(),
2083
+ B: new DayPeriodParser(),
2084
+ h: new Hour1to12Parser(),
2085
+ H: new Hour0to23Parser(),
2086
+ K: new Hour0To11Parser(),
2087
+ k: new Hour1To24Parser(),
2088
+ m: new MinuteParser(),
2089
+ s: new SecondParser(),
2090
+ S: new FractionOfSecondParser(),
2091
+ X: new ISOTimezoneWithZParser(),
2092
+ x: new ISOTimezoneParser(),
2093
+ t: new TimestampSecondsParser(),
2094
+ T: new TimestampMillisecondsParser()
2095
+ };
2096
+
2097
+ /**
2098
+ * The {@link parse} function options.
2099
+ */ // This RegExp consists of three parts separated by `|`:
2100
+ // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
2101
+ // (one of the certain letters followed by `o`)
2102
+ // - (\w)\1* matches any sequences of the same letter
2103
+ // - '' matches two quote characters in a row
2104
+ // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
2105
+ // except a single quote symbol, which ends the sequence.
2106
+ // Two quote characters do not end the sequence.
2107
+ // If there is no matching single quote
2108
+ // then the sequence will continue until the end of the string.
2109
+ // - . matches any single character unmatched by previous parts of the RegExps
2110
+ const formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
2111
+ // This RegExp catches symbols escaped by quotes, and also
2112
+ // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
2113
+ const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
2114
+ const escapedStringRegExp = /^'([^]*?)'?$/;
2115
+ const doubleQuoteRegExp = /''/g;
2116
+ const notWhitespaceRegExp = /\S/;
2117
+ const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
2118
+ /**
2119
+ * @name parse
2120
+ * @category Common Helpers
2121
+ * @summary Parse the date.
2122
+ *
2123
+ * @description
2124
+ * Return the date parsed from string using the given format string.
2125
+ *
2126
+ * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
2127
+ * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2128
+ *
2129
+ * The characters in the format string wrapped between two single quotes characters (') are escaped.
2130
+ * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
2131
+ *
2132
+ * Format of the format string is based on Unicode Technical Standard #35:
2133
+ * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
2134
+ * with a few additions (see note 5 below the table).
2135
+ *
2136
+ * Not all tokens are compatible. Combinations that don't make sense or could lead to bugs are prohibited
2137
+ * and will throw `RangeError`. For example usage of 24-hour format token with AM/PM token will throw an exception:
2138
+ *
2139
+ * ```javascript
2140
+ * parse('23 AM', 'HH a', new Date())
2141
+ * //=> RangeError: The format string mustn't contain `HH` and `a` at the same time
2142
+ * ```
2143
+ *
2144
+ * See the compatibility table: https://docs.google.com/spreadsheets/d/e/2PACX-1vQOPU3xUhplll6dyoMmVUXHKl_8CRDs6_ueLmex3SoqwhuolkuN3O05l4rqx5h1dKX8eb46Ul-CCSrq/pubhtml?gid=0&single=true
2145
+ *
2146
+ * Accepted format string patterns:
2147
+ * | Unit |Prior| Pattern | Result examples | Notes |
2148
+ * |---------------------------------|-----|---------|-----------------------------------|-------|
2149
+ * | Era | 140 | G..GGG | AD, BC | |
2150
+ * | | | GGGG | Anno Domini, Before Christ | 2 |
2151
+ * | | | GGGGG | A, B | |
2152
+ * | Calendar year | 130 | y | 44, 1, 1900, 2017, 9999 | 4 |
2153
+ * | | | yo | 44th, 1st, 1900th, 9999999th | 4,5 |
2154
+ * | | | yy | 44, 01, 00, 17 | 4 |
2155
+ * | | | yyy | 044, 001, 123, 999 | 4 |
2156
+ * | | | yyyy | 0044, 0001, 1900, 2017 | 4 |
2157
+ * | | | yyyyy | ... | 2,4 |
2158
+ * | Local week-numbering year | 130 | Y | 44, 1, 1900, 2017, 9000 | 4 |
2159
+ * | | | Yo | 44th, 1st, 1900th, 9999999th | 4,5 |
2160
+ * | | | YY | 44, 01, 00, 17 | 4,6 |
2161
+ * | | | YYY | 044, 001, 123, 999 | 4 |
2162
+ * | | | YYYY | 0044, 0001, 1900, 2017 | 4,6 |
2163
+ * | | | YYYYY | ... | 2,4 |
2164
+ * | ISO week-numbering year | 130 | R | -43, 1, 1900, 2017, 9999, -9999 | 4,5 |
2165
+ * | | | RR | -43, 01, 00, 17 | 4,5 |
2166
+ * | | | RRR | -043, 001, 123, 999, -999 | 4,5 |
2167
+ * | | | RRRR | -0043, 0001, 2017, 9999, -9999 | 4,5 |
2168
+ * | | | RRRRR | ... | 2,4,5 |
2169
+ * | Extended year | 130 | u | -43, 1, 1900, 2017, 9999, -999 | 4 |
2170
+ * | | | uu | -43, 01, 99, -99 | 4 |
2171
+ * | | | uuu | -043, 001, 123, 999, -999 | 4 |
2172
+ * | | | uuuu | -0043, 0001, 2017, 9999, -9999 | 4 |
2173
+ * | | | uuuuu | ... | 2,4 |
2174
+ * | Quarter (formatting) | 120 | Q | 1, 2, 3, 4 | |
2175
+ * | | | Qo | 1st, 2nd, 3rd, 4th | 5 |
2176
+ * | | | QQ | 01, 02, 03, 04 | |
2177
+ * | | | QQQ | Q1, Q2, Q3, Q4 | |
2178
+ * | | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
2179
+ * | | | QQQQQ | 1, 2, 3, 4 | 4 |
2180
+ * | Quarter (stand-alone) | 120 | q | 1, 2, 3, 4 | |
2181
+ * | | | qo | 1st, 2nd, 3rd, 4th | 5 |
2182
+ * | | | qq | 01, 02, 03, 04 | |
2183
+ * | | | qqq | Q1, Q2, Q3, Q4 | |
2184
+ * | | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
2185
+ * | | | qqqqq | 1, 2, 3, 4 | 3 |
2186
+ * | Month (formatting) | 110 | M | 1, 2, ..., 12 | |
2187
+ * | | | Mo | 1st, 2nd, ..., 12th | 5 |
2188
+ * | | | MM | 01, 02, ..., 12 | |
2189
+ * | | | MMM | Jan, Feb, ..., Dec | |
2190
+ * | | | MMMM | January, February, ..., December | 2 |
2191
+ * | | | MMMMM | J, F, ..., D | |
2192
+ * | Month (stand-alone) | 110 | L | 1, 2, ..., 12 | |
2193
+ * | | | Lo | 1st, 2nd, ..., 12th | 5 |
2194
+ * | | | LL | 01, 02, ..., 12 | |
2195
+ * | | | LLL | Jan, Feb, ..., Dec | |
2196
+ * | | | LLLL | January, February, ..., December | 2 |
2197
+ * | | | LLLLL | J, F, ..., D | |
2198
+ * | Local week of year | 100 | w | 1, 2, ..., 53 | |
2199
+ * | | | wo | 1st, 2nd, ..., 53th | 5 |
2200
+ * | | | ww | 01, 02, ..., 53 | |
2201
+ * | ISO week of year | 100 | I | 1, 2, ..., 53 | 5 |
2202
+ * | | | Io | 1st, 2nd, ..., 53th | 5 |
2203
+ * | | | II | 01, 02, ..., 53 | 5 |
2204
+ * | Day of month | 90 | d | 1, 2, ..., 31 | |
2205
+ * | | | do | 1st, 2nd, ..., 31st | 5 |
2206
+ * | | | dd | 01, 02, ..., 31 | |
2207
+ * | Day of year | 90 | D | 1, 2, ..., 365, 366 | 7 |
2208
+ * | | | Do | 1st, 2nd, ..., 365th, 366th | 5 |
2209
+ * | | | DD | 01, 02, ..., 365, 366 | 7 |
2210
+ * | | | DDD | 001, 002, ..., 365, 366 | |
2211
+ * | | | DDDD | ... | 2 |
2212
+ * | Day of week (formatting) | 90 | E..EEE | Mon, Tue, Wed, ..., Sun | |
2213
+ * | | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
2214
+ * | | | EEEEE | M, T, W, T, F, S, S | |
2215
+ * | | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
2216
+ * | ISO day of week (formatting) | 90 | i | 1, 2, 3, ..., 7 | 5 |
2217
+ * | | | io | 1st, 2nd, ..., 7th | 5 |
2218
+ * | | | ii | 01, 02, ..., 07 | 5 |
2219
+ * | | | iii | Mon, Tue, Wed, ..., Sun | 5 |
2220
+ * | | | iiii | Monday, Tuesday, ..., Sunday | 2,5 |
2221
+ * | | | iiiii | M, T, W, T, F, S, S | 5 |
2222
+ * | | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 5 |
2223
+ * | Local day of week (formatting) | 90 | e | 2, 3, 4, ..., 1 | |
2224
+ * | | | eo | 2nd, 3rd, ..., 1st | 5 |
2225
+ * | | | ee | 02, 03, ..., 01 | |
2226
+ * | | | eee | Mon, Tue, Wed, ..., Sun | |
2227
+ * | | | eeee | Monday, Tuesday, ..., Sunday | 2 |
2228
+ * | | | eeeee | M, T, W, T, F, S, S | |
2229
+ * | | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
2230
+ * | Local day of week (stand-alone) | 90 | c | 2, 3, 4, ..., 1 | |
2231
+ * | | | co | 2nd, 3rd, ..., 1st | 5 |
2232
+ * | | | cc | 02, 03, ..., 01 | |
2233
+ * | | | ccc | Mon, Tue, Wed, ..., Sun | |
2234
+ * | | | cccc | Monday, Tuesday, ..., Sunday | 2 |
2235
+ * | | | ccccc | M, T, W, T, F, S, S | |
2236
+ * | | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
2237
+ * | AM, PM | 80 | a..aaa | AM, PM | |
2238
+ * | | | aaaa | a.m., p.m. | 2 |
2239
+ * | | | aaaaa | a, p | |
2240
+ * | AM, PM, noon, midnight | 80 | b..bbb | AM, PM, noon, midnight | |
2241
+ * | | | bbbb | a.m., p.m., noon, midnight | 2 |
2242
+ * | | | bbbbb | a, p, n, mi | |
2243
+ * | Flexible day period | 80 | B..BBB | at night, in the morning, ... | |
2244
+ * | | | BBBB | at night, in the morning, ... | 2 |
2245
+ * | | | BBBBB | at night, in the morning, ... | |
2246
+ * | Hour [1-12] | 70 | h | 1, 2, ..., 11, 12 | |
2247
+ * | | | ho | 1st, 2nd, ..., 11th, 12th | 5 |
2248
+ * | | | hh | 01, 02, ..., 11, 12 | |
2249
+ * | Hour [0-23] | 70 | H | 0, 1, 2, ..., 23 | |
2250
+ * | | | Ho | 0th, 1st, 2nd, ..., 23rd | 5 |
2251
+ * | | | HH | 00, 01, 02, ..., 23 | |
2252
+ * | Hour [0-11] | 70 | K | 1, 2, ..., 11, 0 | |
2253
+ * | | | Ko | 1st, 2nd, ..., 11th, 0th | 5 |
2254
+ * | | | KK | 01, 02, ..., 11, 00 | |
2255
+ * | Hour [1-24] | 70 | k | 24, 1, 2, ..., 23 | |
2256
+ * | | | ko | 24th, 1st, 2nd, ..., 23rd | 5 |
2257
+ * | | | kk | 24, 01, 02, ..., 23 | |
2258
+ * | Minute | 60 | m | 0, 1, ..., 59 | |
2259
+ * | | | mo | 0th, 1st, ..., 59th | 5 |
2260
+ * | | | mm | 00, 01, ..., 59 | |
2261
+ * | Second | 50 | s | 0, 1, ..., 59 | |
2262
+ * | | | so | 0th, 1st, ..., 59th | 5 |
2263
+ * | | | ss | 00, 01, ..., 59 | |
2264
+ * | Seconds timestamp | 40 | t | 512969520 | |
2265
+ * | | | tt | ... | 2 |
2266
+ * | Fraction of second | 30 | S | 0, 1, ..., 9 | |
2267
+ * | | | SS | 00, 01, ..., 99 | |
2268
+ * | | | SSS | 000, 001, ..., 999 | |
2269
+ * | | | SSSS | ... | 2 |
2270
+ * | Milliseconds timestamp | 20 | T | 512969520900 | |
2271
+ * | | | TT | ... | 2 |
2272
+ * | Timezone (ISO-8601 w/ Z) | 10 | X | -08, +0530, Z | |
2273
+ * | | | XX | -0800, +0530, Z | |
2274
+ * | | | XXX | -08:00, +05:30, Z | |
2275
+ * | | | XXXX | -0800, +0530, Z, +123456 | 2 |
2276
+ * | | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
2277
+ * | Timezone (ISO-8601 w/o Z) | 10 | x | -08, +0530, +00 | |
2278
+ * | | | xx | -0800, +0530, +0000 | |
2279
+ * | | | xxx | -08:00, +05:30, +00:00 | 2 |
2280
+ * | | | xxxx | -0800, +0530, +0000, +123456 | |
2281
+ * | | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
2282
+ * | Long localized date | NA | P | 05/29/1453 | 5,8 |
2283
+ * | | | PP | May 29, 1453 | |
2284
+ * | | | PPP | May 29th, 1453 | |
2285
+ * | | | PPPP | Sunday, May 29th, 1453 | 2,5,8 |
2286
+ * | Long localized time | NA | p | 12:00 AM | 5,8 |
2287
+ * | | | pp | 12:00:00 AM | |
2288
+ * | Combination of date and time | NA | Pp | 05/29/1453, 12:00 AM | |
2289
+ * | | | PPpp | May 29, 1453, 12:00:00 AM | |
2290
+ * | | | PPPpp | May 29th, 1453 at ... | |
2291
+ * | | | PPPPpp | Sunday, May 29th, 1453 at ... | 2,5,8 |
2292
+ * Notes:
2293
+ * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
2294
+ * are the same as "stand-alone" units, but are different in some languages.
2295
+ * "Formatting" units are declined according to the rules of the language
2296
+ * in the context of a date. "Stand-alone" units are always nominative singular.
2297
+ * In `format` function, they will produce different result:
2298
+ *
2299
+ * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
2300
+ *
2301
+ * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
2302
+ *
2303
+ * `parse` will try to match both formatting and stand-alone units interchangeably.
2304
+ *
2305
+ * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
2306
+ * the single quote characters (see below).
2307
+ * If the sequence is longer than listed in table:
2308
+ * - for numerical units (`yyyyyyyy`) `parse` will try to match a number
2309
+ * as wide as the sequence
2310
+ * - for text units (`MMMMMMMM`) `parse` will try to match the widest variation of the unit.
2311
+ * These variations are marked with "2" in the last column of the table.
2312
+ *
2313
+ * 3. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
2314
+ * These tokens represent the shortest form of the quarter.
2315
+ *
2316
+ * 4. The main difference between `y` and `u` patterns are B.C. years:
2317
+ *
2318
+ * | Year | `y` | `u` |
2319
+ * |------|-----|-----|
2320
+ * | AC 1 | 1 | 1 |
2321
+ * | BC 1 | 1 | 0 |
2322
+ * | BC 2 | 2 | -1 |
2323
+ *
2324
+ * Also `yy` will try to guess the century of two digit year by proximity with `referenceDate`:
2325
+ *
2326
+ * `parse('50', 'yy', new Date(2018, 0, 1)) //=> Sat Jan 01 2050 00:00:00`
2327
+ *
2328
+ * `parse('75', 'yy', new Date(2018, 0, 1)) //=> Wed Jan 01 1975 00:00:00`
2329
+ *
2330
+ * while `uu` will just assign the year as is:
2331
+ *
2332
+ * `parse('50', 'uu', new Date(2018, 0, 1)) //=> Sat Jan 01 0050 00:00:00`
2333
+ *
2334
+ * `parse('75', 'uu', new Date(2018, 0, 1)) //=> Tue Jan 01 0075 00:00:00`
2335
+ *
2336
+ * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
2337
+ * except local week-numbering years are dependent on `options.weekStartsOn`
2338
+ * and `options.firstWeekContainsDate` (compare [setISOWeekYear](https://date-fns.org/docs/setISOWeekYear)
2339
+ * and [setWeekYear](https://date-fns.org/docs/setWeekYear)).
2340
+ *
2341
+ * 5. These patterns are not in the Unicode Technical Standard #35:
2342
+ * - `i`: ISO day of week
2343
+ * - `I`: ISO week of year
2344
+ * - `R`: ISO week-numbering year
2345
+ * - `o`: ordinal number modifier
2346
+ * - `P`: long localized date
2347
+ * - `p`: long localized time
2348
+ *
2349
+ * 6. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
2350
+ * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2351
+ *
2352
+ * 7. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
2353
+ * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2354
+ *
2355
+ * 8. `P+` tokens do not have a defined priority since they are merely aliases to other tokens based
2356
+ * on the given locale.
2357
+ *
2358
+ * using `en-US` locale: `P` => `MM/dd/yyyy`
2359
+ * using `en-US` locale: `p` => `hh:mm a`
2360
+ * using `pt-BR` locale: `P` => `dd/MM/yyyy`
2361
+ * using `pt-BR` locale: `p` => `HH:mm`
2362
+ *
2363
+ * Values will be assigned to the date in the descending order of its unit's priority.
2364
+ * Units of an equal priority overwrite each other in the order of appearance.
2365
+ *
2366
+ * If no values of higher priority are parsed (e.g. when parsing string 'January 1st' without a year),
2367
+ * the values will be taken from 3rd argument `referenceDate` which works as a context of parsing.
2368
+ *
2369
+ * `referenceDate` must be passed for correct work of the function.
2370
+ * If you're not sure which `referenceDate` to supply, create a new instance of Date:
2371
+ * `parse('02/11/2014', 'MM/dd/yyyy', new Date())`
2372
+ * In this case parsing will be done in the context of the current date.
2373
+ * If `referenceDate` is `Invalid Date` or a value not convertible to valid `Date`,
2374
+ * then `Invalid Date` will be returned.
2375
+ *
2376
+ * The result may vary by locale.
2377
+ *
2378
+ * If `formatString` matches with `dateString` but does not provides tokens, `referenceDate` will be returned.
2379
+ *
2380
+ * If parsing failed, `Invalid Date` will be returned.
2381
+ * Invalid Date is a Date, whose time value is NaN.
2382
+ * Time value of Date: http://es5.github.io/#x15.9.1.1
2383
+ *
2384
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
2385
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
2386
+ *
2387
+ * @param dateStr - The string to parse
2388
+ * @param formatStr - The string of tokens
2389
+ * @param referenceDate - defines values missing from the parsed dateString
2390
+ * @param options - An object with options.
2391
+ * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2392
+ * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2393
+ *
2394
+ * @returns The parsed date
2395
+ *
2396
+ * @throws `options.locale` must contain `match` property
2397
+ * @throws 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
2398
+ * @throws 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
2399
+ * @throws 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
2400
+ * @throws 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
2401
+ * @throws format string contains an unescaped latin alphabet character
2402
+ *
2403
+ * @example
2404
+ * // Parse 11 February 2014 from middle-endian format:
2405
+ * var result = parse('02/11/2014', 'MM/dd/yyyy', new Date())
2406
+ * //=> Tue Feb 11 2014 00:00:00
2407
+ *
2408
+ * @example
2409
+ * // Parse 28th of February in Esperanto locale in the context of 2010 year:
2410
+ * import eo from 'date-fns/locale/eo'
2411
+ * var result = parse('28-a de februaro', "do 'de' MMMM", new Date(2010, 0, 1), {
2412
+ * locale: eo
2413
+ * })
2414
+ * //=> Sun Feb 28 2010 00:00:00
2415
+ */ function parse(dateStr, formatStr, referenceDate, options) {
2416
+ const invalidDate = ()=>constructFrom(referenceDate, NaN);
2417
+ const defaultOptions = getDefaultOptions();
2418
+ const locale = defaultOptions.locale ?? enUS;
2419
+ const firstWeekContainsDate = defaultOptions.firstWeekContainsDate ?? defaultOptions.locale?.options?.firstWeekContainsDate ?? 1;
2420
+ const weekStartsOn = defaultOptions.weekStartsOn ?? defaultOptions.locale?.options?.weekStartsOn ?? 0;
2421
+ if (!formatStr) return dateStr ? invalidDate() : toDate(referenceDate, options?.in);
2422
+ const subFnOptions = {
2423
+ firstWeekContainsDate,
2424
+ weekStartsOn,
2425
+ locale
2426
+ };
2427
+ // If timezone isn't specified, it will try to use the context or
2428
+ // the reference date and fallback to the system time zone.
2429
+ const setters = [
2430
+ new DateTimezoneSetter(options?.in, referenceDate)
2431
+ ];
2432
+ const tokens = formatStr.match(longFormattingTokensRegExp).map((substring)=>{
2433
+ const firstCharacter = substring[0];
2434
+ if (firstCharacter in longFormatters) {
2435
+ const longFormatter = longFormatters[firstCharacter];
2436
+ return longFormatter(substring, locale.formatLong);
2437
+ }
2438
+ return substring;
2439
+ }).join("").match(formattingTokensRegExp);
2440
+ const usedTokens = [];
2441
+ for (let token of tokens){
2442
+ if (isProtectedWeekYearToken(token)) {
2443
+ warnOrThrowProtectedError(token, formatStr, dateStr);
2444
+ }
2445
+ if (isProtectedDayOfYearToken(token)) {
2446
+ warnOrThrowProtectedError(token, formatStr, dateStr);
2447
+ }
2448
+ const firstCharacter = token[0];
2449
+ const parser = parsers[firstCharacter];
2450
+ if (parser) {
2451
+ const { incompatibleTokens } = parser;
2452
+ if (Array.isArray(incompatibleTokens)) {
2453
+ const incompatibleToken = usedTokens.find((usedToken)=>incompatibleTokens.includes(usedToken.token) || usedToken.token === firstCharacter);
2454
+ if (incompatibleToken) {
2455
+ throw new RangeError(`The format string mustn't contain \`${incompatibleToken.fullToken}\` and \`${token}\` at the same time`);
2456
+ }
2457
+ } else if (parser.incompatibleTokens === "*" && usedTokens.length > 0) {
2458
+ throw new RangeError(`The format string mustn't contain \`${token}\` and any other token at the same time`);
2459
+ }
2460
+ usedTokens.push({
2461
+ token: firstCharacter,
2462
+ fullToken: token
2463
+ });
2464
+ const parseResult = parser.run(dateStr, token, locale.match, subFnOptions);
2465
+ if (!parseResult) {
2466
+ return invalidDate();
2467
+ }
2468
+ setters.push(parseResult.setter);
2469
+ dateStr = parseResult.rest;
2470
+ } else {
2471
+ if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
2472
+ throw new RangeError("Format string contains an unescaped latin alphabet character `" + firstCharacter + "`");
2473
+ }
2474
+ // Replace two single quote characters with one single quote character
2475
+ if (token === "''") {
2476
+ token = "'";
2477
+ } else if (firstCharacter === "'") {
2478
+ token = cleanEscapedString(token);
2479
+ }
2480
+ // Cut token from string, or, if string doesn't match the token, return Invalid Date
2481
+ if (dateStr.indexOf(token) === 0) {
2482
+ dateStr = dateStr.slice(token.length);
2483
+ } else {
2484
+ return invalidDate();
2485
+ }
2486
+ }
2487
+ }
2488
+ // Check if the remaining input contains something other than whitespace
2489
+ if (dateStr.length > 0 && notWhitespaceRegExp.test(dateStr)) {
2490
+ return invalidDate();
2491
+ }
2492
+ const uniquePrioritySetters = setters.map((setter)=>setter.priority).sort((a, b)=>b - a).filter((priority, index, array)=>array.indexOf(priority) === index).map((priority)=>setters.filter((setter)=>setter.priority === priority).sort((a, b)=>b.subPriority - a.subPriority)).map((setterArray)=>setterArray[0]);
2493
+ let date = toDate(referenceDate, options?.in);
2494
+ if (isNaN(+date)) return invalidDate();
2495
+ const flags = {};
2496
+ for (const setter of uniquePrioritySetters){
2497
+ if (!setter.validate(date, subFnOptions)) {
2498
+ return invalidDate();
2499
+ }
2500
+ const result = setter.set(date, flags, subFnOptions);
2501
+ // Result is tuple (date, flags)
2502
+ if (Array.isArray(result)) {
2503
+ date = result[0];
2504
+ Object.assign(flags, result[1]);
2505
+ // Result is date
2506
+ } else {
2507
+ date = result;
2508
+ }
2509
+ }
2510
+ return date;
2511
+ }
2512
+ function cleanEscapedString(input) {
2513
+ return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
2514
+ }
2515
+
2516
+ /**
2517
+ * The {@link parseISO} function options.
2518
+ */ /**
2519
+ * @name parseISO
2520
+ * @category Common Helpers
2521
+ * @summary Parse ISO string
2522
+ *
2523
+ * @description
2524
+ * Parse the given string in ISO 8601 format and return an instance of Date.
2525
+ *
2526
+ * Function accepts complete ISO 8601 formats as well as partial implementations.
2527
+ * ISO 8601: http://en.wikipedia.org/wiki/ISO_8601
2528
+ *
2529
+ * If the argument isn't a string, the function cannot parse the string or
2530
+ * the values are invalid, it returns Invalid Date.
2531
+ *
2532
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
2533
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
2534
+ *
2535
+ * @param argument - The value to convert
2536
+ * @param options - An object with options
2537
+ *
2538
+ * @returns The parsed date in the local time zone
2539
+ *
2540
+ * @example
2541
+ * // Convert string '2014-02-11T11:30:30' to date:
2542
+ * const result = parseISO('2014-02-11T11:30:30')
2543
+ * //=> Tue Feb 11 2014 11:30:30
2544
+ *
2545
+ * @example
2546
+ * // Convert string '+02014101' to date,
2547
+ * // if the additional number of digits in the extended year format is 1:
2548
+ * const result = parseISO('+02014101', { additionalDigits: 1 })
2549
+ * //=> Fri Apr 11 2014 00:00:00
2550
+ */ function parseISO(argument, options) {
2551
+ const invalidDate = ()=>constructFrom(options?.in, NaN);
2552
+ const additionalDigits = 2;
2553
+ const dateStrings = splitDateString(argument);
2554
+ let date;
2555
+ if (dateStrings.date) {
2556
+ const parseYearResult = parseYear(dateStrings.date, additionalDigits);
2557
+ date = parseDate(parseYearResult.restDateString, parseYearResult.year);
2558
+ }
2559
+ if (!date || isNaN(+date)) return invalidDate();
2560
+ const timestamp = +date;
2561
+ let time = 0;
2562
+ let offset;
2563
+ if (dateStrings.time) {
2564
+ time = parseTime(dateStrings.time);
2565
+ if (isNaN(time)) return invalidDate();
2566
+ }
2567
+ if (dateStrings.timezone) {
2568
+ offset = parseTimezone(dateStrings.timezone);
2569
+ if (isNaN(offset)) return invalidDate();
2570
+ } else {
2571
+ const tmpDate = new Date(timestamp + time);
2572
+ const result = toDate(0, options?.in);
2573
+ result.setFullYear(tmpDate.getUTCFullYear(), tmpDate.getUTCMonth(), tmpDate.getUTCDate());
2574
+ result.setHours(tmpDate.getUTCHours(), tmpDate.getUTCMinutes(), tmpDate.getUTCSeconds(), tmpDate.getUTCMilliseconds());
2575
+ return result;
2576
+ }
2577
+ return toDate(timestamp + time + offset, options?.in);
2578
+ }
2579
+ const patterns = {
2580
+ dateTimeDelimiter: /[T ]/,
2581
+ timeZoneDelimiter: /[Z ]/i,
2582
+ timezone: /([Z+-].*)$/
2583
+ };
2584
+ const dateRegex = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/;
2585
+ const timeRegex = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/;
2586
+ const timezoneRegex = /^([+-])(\d{2})(?::?(\d{2}))?$/;
2587
+ function splitDateString(dateString) {
2588
+ const dateStrings = {};
2589
+ const array = dateString.split(patterns.dateTimeDelimiter);
2590
+ let timeString;
2591
+ // The regex match should only return at maximum two array elements.
2592
+ // [date], [time], or [date, time].
2593
+ if (array.length > 2) {
2594
+ return dateStrings;
2595
+ }
2596
+ if (/:/.test(array[0])) {
2597
+ timeString = array[0];
2598
+ } else {
2599
+ dateStrings.date = array[0];
2600
+ timeString = array[1];
2601
+ if (patterns.timeZoneDelimiter.test(dateStrings.date)) {
2602
+ dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0];
2603
+ timeString = dateString.substr(dateStrings.date.length, dateString.length);
2604
+ }
2605
+ }
2606
+ if (timeString) {
2607
+ const token = patterns.timezone.exec(timeString);
2608
+ if (token) {
2609
+ dateStrings.time = timeString.replace(token[1], "");
2610
+ dateStrings.timezone = token[1];
2611
+ } else {
2612
+ dateStrings.time = timeString;
2613
+ }
2614
+ }
2615
+ return dateStrings;
2616
+ }
2617
+ function parseYear(dateString, additionalDigits) {
2618
+ const regex = new RegExp("^(?:(\\d{4}|[+-]\\d{" + (4 + additionalDigits) + "})|(\\d{2}|[+-]\\d{" + (2 + additionalDigits) + "})$)");
2619
+ const captures = dateString.match(regex);
2620
+ // Invalid ISO-formatted year
2621
+ if (!captures) return {
2622
+ year: NaN,
2623
+ restDateString: ""
2624
+ };
2625
+ const year = captures[1] ? parseInt(captures[1]) : null;
2626
+ const century = captures[2] ? parseInt(captures[2]) : null;
2627
+ // either year or century is null, not both
2628
+ return {
2629
+ year: century === null ? year : century * 100,
2630
+ restDateString: dateString.slice((captures[1] || captures[2]).length)
2631
+ };
2632
+ }
2633
+ function parseDate(dateString, year) {
2634
+ // Invalid ISO-formatted year
2635
+ if (year === null) return new Date(NaN);
2636
+ const captures = dateString.match(dateRegex);
2637
+ // Invalid ISO-formatted string
2638
+ if (!captures) return new Date(NaN);
2639
+ const isWeekDate = !!captures[4];
2640
+ const dayOfYear = parseDateUnit(captures[1]);
2641
+ const month = parseDateUnit(captures[2]) - 1;
2642
+ const day = parseDateUnit(captures[3]);
2643
+ const week = parseDateUnit(captures[4]);
2644
+ const dayOfWeek = parseDateUnit(captures[5]) - 1;
2645
+ if (isWeekDate) {
2646
+ if (!validateWeekDate(year, week, dayOfWeek)) {
2647
+ return new Date(NaN);
2648
+ }
2649
+ return dayOfISOWeekYear(year, week, dayOfWeek);
2650
+ } else {
2651
+ const date = new Date(0);
2652
+ if (!validateDate(year, month, day) || !validateDayOfYearDate(year, dayOfYear)) {
2653
+ return new Date(NaN);
2654
+ }
2655
+ date.setUTCFullYear(year, month, Math.max(dayOfYear, day));
2656
+ return date;
2657
+ }
2658
+ }
2659
+ function parseDateUnit(value) {
2660
+ return value ? parseInt(value) : 1;
2661
+ }
2662
+ function parseTime(timeString) {
2663
+ const captures = timeString.match(timeRegex);
2664
+ if (!captures) return NaN; // Invalid ISO-formatted time
2665
+ const hours = parseTimeUnit(captures[1]);
2666
+ const minutes = parseTimeUnit(captures[2]);
2667
+ const seconds = parseTimeUnit(captures[3]);
2668
+ if (!validateTime(hours, minutes, seconds)) {
2669
+ return NaN;
2670
+ }
2671
+ return hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * 1000;
2672
+ }
2673
+ function parseTimeUnit(value) {
2674
+ return value && parseFloat(value.replace(",", ".")) || 0;
2675
+ }
2676
+ function parseTimezone(timezoneString) {
2677
+ if (timezoneString === "Z") return 0;
2678
+ const captures = timezoneString.match(timezoneRegex);
2679
+ if (!captures) return 0;
2680
+ const sign = captures[1] === "+" ? -1 : 1;
2681
+ const hours = parseInt(captures[2]);
2682
+ const minutes = captures[3] && parseInt(captures[3]) || 0;
2683
+ if (!validateTimezone(hours, minutes)) {
2684
+ return NaN;
2685
+ }
2686
+ return sign * (hours * millisecondsInHour + minutes * millisecondsInMinute);
2687
+ }
2688
+ function dayOfISOWeekYear(isoWeekYear, week, day) {
2689
+ const date = new Date(0);
2690
+ date.setUTCFullYear(isoWeekYear, 0, 4);
2691
+ const fourthOfJanuaryDay = date.getUTCDay() || 7;
2692
+ const diff = (week - 1) * 7 + day + 1 - fourthOfJanuaryDay;
2693
+ date.setUTCDate(date.getUTCDate() + diff);
2694
+ return date;
2695
+ }
2696
+ // Validation functions
2697
+ // February is null to handle the leap year (using ||)
2698
+ const daysInMonths = [
2699
+ 31,
2700
+ null,
2701
+ 31,
2702
+ 30,
2703
+ 31,
2704
+ 30,
2705
+ 31,
2706
+ 31,
2707
+ 30,
2708
+ 31,
2709
+ 30,
2710
+ 31
2711
+ ];
2712
+ function isLeapYearIndex(year) {
2713
+ return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
2714
+ }
2715
+ function validateDate(year, month, date) {
2716
+ return month >= 0 && month <= 11 && date >= 1 && date <= (daysInMonths[month] || (isLeapYearIndex(year) ? 29 : 28));
2717
+ }
2718
+ function validateDayOfYearDate(year, dayOfYear) {
2719
+ return dayOfYear >= 1 && dayOfYear <= (isLeapYearIndex(year) ? 366 : 365);
2720
+ }
2721
+ function validateWeekDate(_year, week, day) {
2722
+ return week >= 1 && week <= 53 && day >= 0 && day <= 6;
2723
+ }
2724
+ function validateTime(hours, minutes, seconds) {
2725
+ if (hours === 24) {
2726
+ return minutes === 0 && seconds === 0;
2727
+ }
2728
+ return seconds >= 0 && seconds < 60 && minutes >= 0 && minutes < 60 && hours >= 0 && hours < 25;
2729
+ }
2730
+ function validateTimezone(_hours, minutes) {
2731
+ return minutes >= 0 && minutes <= 59;
2732
+ }
2733
+
2734
+ function tryParseDate(value) {
2735
+ if (!value) return undefined;
2736
+ if (value instanceof Date) return isValid(value) ? value : undefined;
2737
+ // 1) tenta ISO
2738
+ const iso = parseISO(value);
2739
+ if (isValid(iso)) return iso;
2740
+ // 2) tenta dd/MM/yyyy
2741
+ const dmy = parse(value, "dd/MM/yyyy", new Date());
2742
+ if (isValid(dmy)) return dmy;
2743
+ // 3) tenta d/M/yyyy (por segurança, cobre 4/9/2025 sem zero à esquerda)
2744
+ const dmyLoose = parse(value, "d/M/yyyy", new Date());
2745
+ if (isValid(dmyLoose)) return dmyLoose;
2746
+ return undefined;
2747
+ }
2748
+
2749
+ const formatDistanceLocale = {
2750
+ lessThanXSeconds: {
2751
+ one: "menos de um segundo",
2752
+ other: "menos de {{count}} segundos"
2753
+ },
2754
+ xSeconds: {
2755
+ one: "1 segundo",
2756
+ other: "{{count}} segundos"
2757
+ },
2758
+ halfAMinute: "meio minuto",
2759
+ lessThanXMinutes: {
2760
+ one: "menos de um minuto",
2761
+ other: "menos de {{count}} minutos"
2762
+ },
2763
+ xMinutes: {
2764
+ one: "1 minuto",
2765
+ other: "{{count}} minutos"
2766
+ },
2767
+ aboutXHours: {
2768
+ one: "cerca de 1 hora",
2769
+ other: "cerca de {{count}} horas"
2770
+ },
2771
+ xHours: {
2772
+ one: "1 hora",
2773
+ other: "{{count}} horas"
2774
+ },
2775
+ xDays: {
2776
+ one: "1 dia",
2777
+ other: "{{count}} dias"
2778
+ },
2779
+ aboutXWeeks: {
2780
+ one: "cerca de 1 semana",
2781
+ other: "cerca de {{count}} semanas"
2782
+ },
2783
+ xWeeks: {
2784
+ one: "1 semana",
2785
+ other: "{{count}} semanas"
2786
+ },
2787
+ aboutXMonths: {
2788
+ one: "cerca de 1 mês",
2789
+ other: "cerca de {{count}} meses"
2790
+ },
2791
+ xMonths: {
2792
+ one: "1 mês",
2793
+ other: "{{count}} meses"
2794
+ },
2795
+ aboutXYears: {
2796
+ one: "cerca de 1 ano",
2797
+ other: "cerca de {{count}} anos"
2798
+ },
2799
+ xYears: {
2800
+ one: "1 ano",
2801
+ other: "{{count}} anos"
2802
+ },
2803
+ overXYears: {
2804
+ one: "mais de 1 ano",
2805
+ other: "mais de {{count}} anos"
2806
+ },
2807
+ almostXYears: {
2808
+ one: "quase 1 ano",
2809
+ other: "quase {{count}} anos"
2810
+ }
2811
+ };
2812
+ const formatDistance = (token, count, options)=>{
2813
+ let result;
2814
+ const tokenValue = formatDistanceLocale[token];
2815
+ if (typeof tokenValue === "string") {
2816
+ result = tokenValue;
2817
+ } else if (count === 1) {
2818
+ result = tokenValue.one;
2819
+ } else {
2820
+ result = tokenValue.other.replace("{{count}}", String(count));
2821
+ }
2822
+ if (options?.addSuffix) {
2823
+ if (options.comparison && options.comparison > 0) {
2824
+ return "em " + result;
2825
+ } else {
2826
+ return "há " + result;
2827
+ }
2828
+ }
2829
+ return result;
2830
+ };
2831
+
2832
+ const dateFormats = {
2833
+ full: "EEEE, d 'de' MMMM 'de' y",
2834
+ long: "d 'de' MMMM 'de' y",
2835
+ medium: "d MMM y",
2836
+ short: "dd/MM/yyyy"
2837
+ };
2838
+ const timeFormats = {
2839
+ full: "HH:mm:ss zzzz",
2840
+ long: "HH:mm:ss z",
2841
+ medium: "HH:mm:ss",
2842
+ short: "HH:mm"
2843
+ };
2844
+ const dateTimeFormats = {
2845
+ full: "{{date}} 'às' {{time}}",
2846
+ long: "{{date}} 'às' {{time}}",
2847
+ medium: "{{date}}, {{time}}",
2848
+ short: "{{date}}, {{time}}"
2849
+ };
2850
+ const formatLong = {
2851
+ date: buildFormatLongFn({
2852
+ formats: dateFormats,
2853
+ defaultWidth: "full"
2854
+ }),
2855
+ time: buildFormatLongFn({
2856
+ formats: timeFormats,
2857
+ defaultWidth: "full"
2858
+ }),
2859
+ dateTime: buildFormatLongFn({
2860
+ formats: dateTimeFormats,
2861
+ defaultWidth: "full"
2862
+ })
2863
+ };
2864
+
2865
+ const formatRelativeLocale = {
2866
+ lastWeek: (date)=>{
2867
+ const weekday = date.getDay();
2868
+ const last = weekday === 0 || weekday === 6 ? "último" : "última";
2869
+ return "'" + last + "' eeee 'às' p";
2870
+ },
2871
+ yesterday: "'ontem às' p",
2872
+ today: "'hoje às' p",
2873
+ tomorrow: "'amanhã às' p",
2874
+ nextWeek: "eeee 'às' p",
2875
+ other: "P"
2876
+ };
2877
+ const formatRelative = (token, date, _baseDate, _options)=>{
2878
+ const format = formatRelativeLocale[token];
2879
+ if (typeof format === "function") {
2880
+ return format(date);
2881
+ }
2882
+ return format;
2883
+ };
2884
+
2885
+ const eraValues = {
2886
+ narrow: [
2887
+ "AC",
2888
+ "DC"
2889
+ ],
2890
+ abbreviated: [
2891
+ "AC",
2892
+ "DC"
2893
+ ],
2894
+ wide: [
2895
+ "antes de cristo",
2896
+ "depois de cristo"
2897
+ ]
2898
+ };
2899
+ const quarterValues = {
2900
+ narrow: [
2901
+ "1",
2902
+ "2",
2903
+ "3",
2904
+ "4"
2905
+ ],
2906
+ abbreviated: [
2907
+ "T1",
2908
+ "T2",
2909
+ "T3",
2910
+ "T4"
2911
+ ],
2912
+ wide: [
2913
+ "1º trimestre",
2914
+ "2º trimestre",
2915
+ "3º trimestre",
2916
+ "4º trimestre"
2917
+ ]
2918
+ };
2919
+ const monthValues = {
2920
+ narrow: [
2921
+ "j",
2922
+ "f",
2923
+ "m",
2924
+ "a",
2925
+ "m",
2926
+ "j",
2927
+ "j",
2928
+ "a",
2929
+ "s",
2930
+ "o",
2931
+ "n",
2932
+ "d"
2933
+ ],
2934
+ abbreviated: [
2935
+ "jan",
2936
+ "fev",
2937
+ "mar",
2938
+ "abr",
2939
+ "mai",
2940
+ "jun",
2941
+ "jul",
2942
+ "ago",
2943
+ "set",
2944
+ "out",
2945
+ "nov",
2946
+ "dez"
2947
+ ],
2948
+ wide: [
2949
+ "janeiro",
2950
+ "fevereiro",
2951
+ "março",
2952
+ "abril",
2953
+ "maio",
2954
+ "junho",
2955
+ "julho",
2956
+ "agosto",
2957
+ "setembro",
2958
+ "outubro",
2959
+ "novembro",
2960
+ "dezembro"
2961
+ ]
2962
+ };
2963
+ const dayValues = {
2964
+ narrow: [
2965
+ "D",
2966
+ "S",
2967
+ "T",
2968
+ "Q",
2969
+ "Q",
2970
+ "S",
2971
+ "S"
2972
+ ],
2973
+ short: [
2974
+ "dom",
2975
+ "seg",
2976
+ "ter",
2977
+ "qua",
2978
+ "qui",
2979
+ "sex",
2980
+ "sab"
2981
+ ],
2982
+ abbreviated: [
2983
+ "domingo",
2984
+ "segunda",
2985
+ "terça",
2986
+ "quarta",
2987
+ "quinta",
2988
+ "sexta",
2989
+ "sábado"
2990
+ ],
2991
+ wide: [
2992
+ "domingo",
2993
+ "segunda-feira",
2994
+ "terça-feira",
2995
+ "quarta-feira",
2996
+ "quinta-feira",
2997
+ "sexta-feira",
2998
+ "sábado"
2999
+ ]
3000
+ };
3001
+ const dayPeriodValues = {
3002
+ narrow: {
3003
+ am: "a",
3004
+ pm: "p",
3005
+ midnight: "mn",
3006
+ noon: "md",
3007
+ morning: "manhã",
3008
+ afternoon: "tarde",
3009
+ evening: "tarde",
3010
+ night: "noite"
3011
+ },
3012
+ abbreviated: {
3013
+ am: "AM",
3014
+ pm: "PM",
3015
+ midnight: "meia-noite",
3016
+ noon: "meio-dia",
3017
+ morning: "manhã",
3018
+ afternoon: "tarde",
3019
+ evening: "tarde",
3020
+ night: "noite"
3021
+ },
3022
+ wide: {
3023
+ am: "a.m.",
3024
+ pm: "p.m.",
3025
+ midnight: "meia-noite",
3026
+ noon: "meio-dia",
3027
+ morning: "manhã",
3028
+ afternoon: "tarde",
3029
+ evening: "tarde",
3030
+ night: "noite"
3031
+ }
3032
+ };
3033
+ const formattingDayPeriodValues = {
3034
+ narrow: {
3035
+ am: "a",
3036
+ pm: "p",
3037
+ midnight: "mn",
3038
+ noon: "md",
3039
+ morning: "da manhã",
3040
+ afternoon: "da tarde",
3041
+ evening: "da tarde",
3042
+ night: "da noite"
3043
+ },
3044
+ abbreviated: {
3045
+ am: "AM",
3046
+ pm: "PM",
3047
+ midnight: "meia-noite",
3048
+ noon: "meio-dia",
3049
+ morning: "da manhã",
3050
+ afternoon: "da tarde",
3051
+ evening: "da tarde",
3052
+ night: "da noite"
3053
+ },
3054
+ wide: {
3055
+ am: "a.m.",
3056
+ pm: "p.m.",
3057
+ midnight: "meia-noite",
3058
+ noon: "meio-dia",
3059
+ morning: "da manhã",
3060
+ afternoon: "da tarde",
3061
+ evening: "da tarde",
3062
+ night: "da noite"
3063
+ }
3064
+ };
3065
+ const ordinalNumber = (dirtyNumber, options)=>{
3066
+ const number = Number(dirtyNumber);
3067
+ if (options?.unit === "week") {
3068
+ return number + "ª";
3069
+ }
3070
+ return number + "º";
3071
+ };
3072
+ const localize = {
3073
+ ordinalNumber,
3074
+ era: buildLocalizeFn({
3075
+ values: eraValues,
3076
+ defaultWidth: "wide"
3077
+ }),
3078
+ quarter: buildLocalizeFn({
3079
+ values: quarterValues,
3080
+ defaultWidth: "wide",
3081
+ argumentCallback: (quarter)=>quarter - 1
3082
+ }),
3083
+ month: buildLocalizeFn({
3084
+ values: monthValues,
3085
+ defaultWidth: "wide"
3086
+ }),
3087
+ day: buildLocalizeFn({
3088
+ values: dayValues,
3089
+ defaultWidth: "wide"
3090
+ }),
3091
+ dayPeriod: buildLocalizeFn({
3092
+ values: dayPeriodValues,
3093
+ defaultWidth: "wide",
3094
+ formattingValues: formattingDayPeriodValues,
3095
+ defaultFormattingWidth: "wide"
3096
+ })
3097
+ };
3098
+
3099
+ const matchOrdinalNumberPattern = /^(\d+)[ºªo]?/i;
3100
+ const parseOrdinalNumberPattern = /\d+/i;
3101
+ const matchEraPatterns = {
3102
+ narrow: /^(ac|dc|a|d)/i,
3103
+ abbreviated: /^(a\.?\s?c\.?|d\.?\s?c\.?)/i,
3104
+ wide: /^(antes de cristo|depois de cristo)/i
3105
+ };
3106
+ const parseEraPatterns = {
3107
+ any: [
3108
+ /^ac/i,
3109
+ /^dc/i
3110
+ ],
3111
+ wide: [
3112
+ /^antes de cristo/i,
3113
+ /^depois de cristo/i
3114
+ ]
3115
+ };
3116
+ const matchQuarterPatterns = {
3117
+ narrow: /^[1234]/i,
3118
+ abbreviated: /^T[1234]/i,
3119
+ wide: /^[1234](º)? trimestre/i
3120
+ };
3121
+ const parseQuarterPatterns = {
3122
+ any: [
3123
+ /1/i,
3124
+ /2/i,
3125
+ /3/i,
3126
+ /4/i
3127
+ ]
3128
+ };
3129
+ const matchMonthPatterns = {
3130
+ narrow: /^[jfmajsond]/i,
3131
+ abbreviated: /^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i,
3132
+ wide: /^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i
3133
+ };
3134
+ const parseMonthPatterns = {
3135
+ narrow: [
3136
+ /^j/i,
3137
+ /^f/i,
3138
+ /^m/i,
3139
+ /^a/i,
3140
+ /^m/i,
3141
+ /^j/i,
3142
+ /^j/i,
3143
+ /^a/i,
3144
+ /^s/i,
3145
+ /^o/i,
3146
+ /^n/i,
3147
+ /^d/i
3148
+ ],
3149
+ any: [
3150
+ /^ja/i,
3151
+ /^fev/i,
3152
+ /^mar/i,
3153
+ /^abr/i,
3154
+ /^mai/i,
3155
+ /^jun/i,
3156
+ /^jul/i,
3157
+ /^ago/i,
3158
+ /^set/i,
3159
+ /^out/i,
3160
+ /^nov/i,
3161
+ /^dez/i
3162
+ ]
3163
+ };
3164
+ const matchDayPatterns = {
3165
+ narrow: /^(dom|[23456]ª?|s[aá]b)/i,
3166
+ short: /^(dom|[23456]ª?|s[aá]b)/i,
3167
+ abbreviated: /^(dom|seg|ter|qua|qui|sex|s[aá]b)/i,
3168
+ wide: /^(domingo|(segunda|ter[cç]a|quarta|quinta|sexta)([- ]feira)?|s[aá]bado)/i
3169
+ };
3170
+ const parseDayPatterns = {
3171
+ short: [
3172
+ /^d/i,
3173
+ /^2/i,
3174
+ /^3/i,
3175
+ /^4/i,
3176
+ /^5/i,
3177
+ /^6/i,
3178
+ /^s[aá]/i
3179
+ ],
3180
+ narrow: [
3181
+ /^d/i,
3182
+ /^2/i,
3183
+ /^3/i,
3184
+ /^4/i,
3185
+ /^5/i,
3186
+ /^6/i,
3187
+ /^s[aá]/i
3188
+ ],
3189
+ any: [
3190
+ /^d/i,
3191
+ /^seg/i,
3192
+ /^t/i,
3193
+ /^qua/i,
3194
+ /^qui/i,
3195
+ /^sex/i,
3196
+ /^s[aá]b/i
3197
+ ]
3198
+ };
3199
+ const matchDayPeriodPatterns = {
3200
+ narrow: /^(a|p|mn|md|(da) (manhã|tarde|noite))/i,
3201
+ any: /^([ap]\.?\s?m\.?|meia[-\s]noite|meio[-\s]dia|(da) (manhã|tarde|noite))/i
3202
+ };
3203
+ const parseDayPeriodPatterns = {
3204
+ any: {
3205
+ am: /^a/i,
3206
+ pm: /^p/i,
3207
+ midnight: /^mn|^meia[-\s]noite/i,
3208
+ noon: /^md|^meio[-\s]dia/i,
3209
+ morning: /manhã/i,
3210
+ afternoon: /tarde/i,
3211
+ evening: /tarde/i,
3212
+ night: /noite/i
3213
+ }
3214
+ };
3215
+ const match = {
3216
+ ordinalNumber: buildMatchPatternFn({
3217
+ matchPattern: matchOrdinalNumberPattern,
3218
+ parsePattern: parseOrdinalNumberPattern,
3219
+ valueCallback: (value)=>parseInt(value, 10)
3220
+ }),
3221
+ era: buildMatchFn({
3222
+ matchPatterns: matchEraPatterns,
3223
+ defaultMatchWidth: "wide",
3224
+ parsePatterns: parseEraPatterns,
3225
+ defaultParseWidth: "any"
3226
+ }),
3227
+ quarter: buildMatchFn({
3228
+ matchPatterns: matchQuarterPatterns,
3229
+ defaultMatchWidth: "wide",
3230
+ parsePatterns: parseQuarterPatterns,
3231
+ defaultParseWidth: "any",
3232
+ valueCallback: (index)=>index + 1
3233
+ }),
3234
+ month: buildMatchFn({
3235
+ matchPatterns: matchMonthPatterns,
3236
+ defaultMatchWidth: "wide",
3237
+ parsePatterns: parseMonthPatterns,
3238
+ defaultParseWidth: "any"
3239
+ }),
3240
+ day: buildMatchFn({
3241
+ matchPatterns: matchDayPatterns,
3242
+ defaultMatchWidth: "wide",
3243
+ parsePatterns: parseDayPatterns,
3244
+ defaultParseWidth: "any"
3245
+ }),
3246
+ dayPeriod: buildMatchFn({
3247
+ matchPatterns: matchDayPeriodPatterns,
3248
+ defaultMatchWidth: "any",
3249
+ parsePatterns: parseDayPeriodPatterns,
3250
+ defaultParseWidth: "any"
3251
+ })
3252
+ };
3253
+
3254
+ /**
3255
+ * @category Locales
3256
+ * @summary Portuguese locale (Brazil).
3257
+ * @language Portuguese
3258
+ * @iso-639-2 por
3259
+ * @author Lucas Duailibe [@duailibe](https://github.com/duailibe)
3260
+ * @author Yago Carballo [@yagocarballo](https://github.com/YagoCarballo)
3261
+ */ const ptBR = {
3262
+ code: "pt-BR",
3263
+ formatDistance: formatDistance,
3264
+ formatLong: formatLong,
3265
+ formatRelative: formatRelative,
3266
+ localize: localize,
3267
+ match: match,
3268
+ options: {
3269
+ weekStartsOn: 0 /* Sunday */ ,
3270
+ firstWeekContainsDate: 1
3271
+ }
3272
+ };
3273
+
3274
+ export { CalendarDays as C, ptBR as p, tryParseDate as t };
3275
+ //# sourceMappingURL=pt-BR-on-YW6Ay.mjs.map