ivt 0.5.0 → 0.5.2

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