ivt 0.7.3 → 0.7.5
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.
- package/dist/accordion/index.mjs +13 -15
- package/dist/accordion/index.mjs.map +1 -1
- package/dist/accordion-table/index.mjs +26 -28
- package/dist/accordion-table/index.mjs.map +1 -1
- package/dist/alert/index.mjs +3 -3
- package/dist/alert-dialog/index.mjs +15 -17
- package/dist/alert-dialog/index.mjs.map +1 -1
- package/dist/aspect-ratio/index.mjs +42 -3
- package/dist/aspect-ratio/index.mjs.map +1 -1
- package/dist/auto-complete-multi-select/index.mjs +31 -33
- package/dist/auto-complete-multi-select/index.mjs.map +1 -1
- package/dist/avatar/index.mjs +130 -8
- package/dist/avatar/index.mjs.map +1 -1
- package/dist/badge/index.mjs +3 -3
- package/dist/base/index.d.ts +31 -9
- package/dist/base/index.mjs +79 -164
- package/dist/base/index.mjs.map +1 -1
- package/dist/breadcrumb/index.mjs +5 -5
- package/dist/button/index.d.ts +1 -1
- package/dist/button/index.mjs +3 -3
- package/dist/button-group/index.d.ts +3 -2
- package/dist/button-group/index.mjs +3 -4
- package/dist/button-group/index.mjs.map +1 -1
- package/dist/calendar/index.mjs +9 -9
- package/dist/card/index.mjs +3 -3
- package/dist/carousel/index.mjs +4 -4
- package/dist/chart/index.mjs +2869 -1282
- package/dist/chart/index.mjs.map +1 -1
- package/dist/checkbox/index.mjs +12 -14
- package/dist/checkbox/index.mjs.map +1 -1
- package/dist/chunks/AutoComplete-BpwnFm_u.mjs +106 -0
- package/dist/chunks/AutoComplete-BpwnFm_u.mjs.map +1 -0
- package/dist/chunks/{CalendarRange-C6BJ_i8D.mjs → CalendarRange-BGP7p-ma.mjs} +8 -8
- package/dist/chunks/{CalendarRange-C6BJ_i8D.mjs.map → CalendarRange-BGP7p-ma.mjs.map} +1 -1
- package/dist/chunks/{ComboboxField-DFqOZmlN.mjs → ComboboxField-CzJlHHXv.mjs} +9 -9
- package/dist/chunks/{ComboboxField-DFqOZmlN.mjs.map → ComboboxField-CzJlHHXv.mjs.map} +1 -1
- package/dist/chunks/{Container-BFnURH_3.mjs → Container-77E_UFi2.mjs} +2 -2
- package/dist/chunks/{Container-BFnURH_3.mjs.map → Container-77E_UFi2.mjs.map} +1 -1
- package/dist/chunks/{DeleteConfirmationModal-3tgFcxyU.mjs → DeleteConfirmationModal-DQK05Srx.mjs} +4 -4
- package/dist/chunks/{DeleteConfirmationModal-3tgFcxyU.mjs.map → DeleteConfirmationModal-DQK05Srx.mjs.map} +1 -1
- package/dist/chunks/{ListItem-Dhdqegoz.mjs → ListItem-B0_5JcsU.mjs} +4 -4
- package/dist/chunks/{ListItem-Dhdqegoz.mjs.map → ListItem-B0_5JcsU.mjs.map} +1 -1
- package/dist/chunks/{TooltipIndicator-tYIvoK3x.mjs → TooltipIndicator-Db1poSJI.mjs} +4 -4
- package/dist/chunks/{TooltipIndicator-tYIvoK3x.mjs.map → TooltipIndicator-Db1poSJI.mjs.map} +1 -1
- package/dist/chunks/{_commonjsHelpers-CDajFLDm.mjs → _commonjsHelpers-DkfSKqYE.mjs} +1 -1
- package/dist/chunks/_commonjsHelpers-DkfSKqYE.mjs.map +1 -0
- package/dist/chunks/{accordion-Dig0Vyew.mjs → accordion-DSn7k_RQ.mjs} +9 -11
- package/dist/chunks/{accordion-Dig0Vyew.mjs.map → accordion-DSn7k_RQ.mjs.map} +1 -1
- package/dist/chunks/{alert-CtNiMMMm.mjs → alert-aP6n7wtq.mjs} +2 -2
- package/dist/chunks/{alert-CtNiMMMm.mjs.map → alert-aP6n7wtq.mjs.map} +1 -1
- package/dist/chunks/{badge-CMepcgQ2.mjs → badge-CsUuqHNu.mjs} +2 -2
- package/dist/chunks/{badge-CMepcgQ2.mjs.map → badge-CsUuqHNu.mjs.map} +1 -1
- package/dist/chunks/{bundle-mjs-ByJyReDu.mjs → bundle-mjs-BRbxNcQb.mjs} +228 -154
- package/dist/chunks/bundle-mjs-BRbxNcQb.mjs.map +1 -0
- package/dist/chunks/{button-DHQrVlqk.mjs → button-BW9I4XWU.mjs} +2 -2
- package/dist/chunks/{button-DHQrVlqk.mjs.map → button-BW9I4XWU.mjs.map} +1 -1
- package/dist/chunks/button-C8IZYeQz.d.ts +16 -0
- package/dist/chunks/{calendar-DtKpXGXO.mjs → calendar-C549VT55.mjs} +1181 -797
- package/dist/chunks/calendar-C549VT55.mjs.map +1 -0
- package/dist/chunks/{calendar-days-5V8H0_Qn.mjs → calendar-days-BSzlDBsi.mjs} +2 -2
- package/dist/chunks/{calendar-days-5V8H0_Qn.mjs.map → calendar-days-BSzlDBsi.mjs.map} +1 -1
- package/dist/chunks/{card-DgO3JDtX.mjs → card-Dqm2EuWU.mjs} +2 -2
- package/dist/chunks/{card-DgO3JDtX.mjs.map → card-Dqm2EuWU.mjs.map} +1 -1
- package/dist/chunks/{check-yo43z6YO.mjs → check-CKdwsuVA.mjs} +2 -2
- package/dist/chunks/{check-yo43z6YO.mjs.map → check-CKdwsuVA.mjs.map} +1 -1
- package/dist/chunks/{checkbox-B3xoUcaP.mjs → checkbox-CvaPsjy3.mjs} +9 -11
- package/dist/chunks/{checkbox-B3xoUcaP.mjs.map → checkbox-CvaPsjy3.mjs.map} +1 -1
- package/dist/chunks/{chevron-down-gO34wzc7.mjs → chevron-down-o7NUBnJ4.mjs} +2 -2
- package/dist/chunks/{chevron-down-gO34wzc7.mjs.map → chevron-down-o7NUBnJ4.mjs.map} +1 -1
- package/dist/chunks/{chevron-left-DGlHB7Nw.mjs → chevron-left-BZ8X7kLy.mjs} +2 -2
- package/dist/chunks/{chevron-left-DGlHB7Nw.mjs.map → chevron-left-BZ8X7kLy.mjs.map} +1 -1
- package/dist/chunks/{chevron-right-B6bwFEdI.mjs → chevron-right-jAScR3zY.mjs} +2 -2
- package/dist/chunks/{chevron-right-B6bwFEdI.mjs.map → chevron-right-jAScR3zY.mjs.map} +1 -1
- package/dist/chunks/{chevrons-up-down-StzXyb6Z.mjs → chevrons-up-down-BSIPdamI.mjs} +2 -2
- package/dist/chunks/{chevrons-up-down-StzXyb6Z.mjs.map → chevrons-up-down-BSIPdamI.mjs.map} +1 -1
- package/dist/chunks/{command-BUHV178P.mjs → command-B29vdoVO.mjs} +8 -8
- package/dist/chunks/{command-BUHV178P.mjs.map → command-B29vdoVO.mjs.map} +1 -1
- package/dist/chunks/{createLucideIcon-BrIj5xiA.mjs → createLucideIcon-CkP7424r.mjs} +1 -1
- package/dist/chunks/{createLucideIcon-BrIj5xiA.mjs.map → createLucideIcon-CkP7424r.mjs.map} +1 -1
- package/dist/chunks/{date-re6oTh_O.mjs → date-Y_hKMQVr.mjs} +2 -2
- package/dist/chunks/{date-re6oTh_O.mjs.map → date-Y_hKMQVr.mjs.map} +1 -1
- package/dist/chunks/{dialog-CsH0QGEc.mjs → dialog-BhaHMQnG.mjs} +4 -4
- package/dist/chunks/{dialog-CsH0QGEc.mjs.map → dialog-BhaHMQnG.mjs.map} +1 -1
- package/dist/chunks/{ellipsis-BED2L1d7.mjs → ellipsis-DHAz8TrI.mjs} +2 -2
- package/dist/chunks/{ellipsis-BED2L1d7.mjs.map → ellipsis-DHAz8TrI.mjs.map} +1 -1
- package/dist/chunks/{form-B4-N-eE1.mjs → form-BAxhKbgh.mjs} +299 -150
- package/dist/chunks/form-BAxhKbgh.mjs.map +1 -0
- package/dist/chunks/{format-C24_9AKp.mjs → format-CR4Q6BSq.mjs} +1 -1
- package/dist/chunks/{format-C24_9AKp.mjs.map → format-CR4Q6BSq.mjs.map} +1 -1
- package/dist/chunks/{format-numbers-CksgR7yb.mjs → format-numbers-CWj9Vf7x.mjs} +2 -6
- package/dist/chunks/format-numbers-CWj9Vf7x.mjs.map +1 -0
- package/dist/chunks/{hover-card-Dke495v-.mjs → hover-card-DVmQc78n.mjs} +9 -11
- package/dist/chunks/{hover-card-Dke495v-.mjs.map → hover-card-DVmQc78n.mjs.map} +1 -1
- package/dist/chunks/{index-DIkcxop-.mjs → index-4pJ77hyF.mjs} +1 -1
- package/dist/chunks/{index-DIkcxop-.mjs.map → index-4pJ77hyF.mjs.map} +1 -1
- package/dist/chunks/{index-BrOFvz7z.mjs → index-BN17NQCv.mjs} +1 -1
- package/dist/chunks/{index-BrOFvz7z.mjs.map → index-BN17NQCv.mjs.map} +1 -1
- package/dist/chunks/{index-DmwGzaYt.mjs → index-Bt1elORc.mjs} +9 -11
- package/dist/chunks/{index-DmwGzaYt.mjs.map → index-Bt1elORc.mjs.map} +1 -1
- package/dist/chunks/{index-DHpiwknP.mjs → index-CByz7d8q.mjs} +3 -3
- package/dist/chunks/{index-DHpiwknP.mjs.map → index-CByz7d8q.mjs.map} +1 -1
- package/dist/chunks/{index-BElPX9xn.mjs → index-CS2Lzoed.mjs} +7 -9
- package/dist/chunks/{index-BElPX9xn.mjs.map → index-CS2Lzoed.mjs.map} +1 -1
- package/dist/chunks/{index-C8cUOEOO.mjs → index-CVjOpozG.mjs} +38 -2
- package/dist/chunks/index-CVjOpozG.mjs.map +1 -0
- package/dist/chunks/{index-C-ZwjB4k.mjs → index-Cs9A0tpU.mjs} +1 -1
- package/dist/chunks/{index-C-ZwjB4k.mjs.map → index-Cs9A0tpU.mjs.map} +1 -1
- package/dist/chunks/{index-Bn9j4jd_.mjs → index-Ct610FOk.mjs} +2 -2
- package/dist/chunks/{index-Bn9j4jd_.mjs.map → index-Ct610FOk.mjs.map} +1 -1
- package/dist/chunks/{index-D7mBTwC1.mjs → index-CvVBB5ll.mjs} +4 -5
- package/dist/chunks/{index-D7mBTwC1.mjs.map → index-CvVBB5ll.mjs.map} +1 -1
- package/dist/chunks/{index-7SNyMh-j.mjs → index-D1CSAowX.mjs} +13 -15
- package/dist/chunks/{index-7SNyMh-j.mjs.map → index-D1CSAowX.mjs.map} +1 -1
- package/dist/chunks/{index-DmLyVVSA.mjs → index-D2DYiX9D.mjs} +2 -2
- package/dist/chunks/{index-DmLyVVSA.mjs.map → index-D2DYiX9D.mjs.map} +1 -1
- package/dist/chunks/{index-CFaMr67I.mjs → index-D8mA4n7w.mjs} +1 -1
- package/dist/chunks/{index-CFaMr67I.mjs.map → index-D8mA4n7w.mjs.map} +1 -1
- package/dist/chunks/{index-rXTYYoI9.mjs → index-DCDDoDjL.mjs} +6 -7
- package/dist/chunks/{index-rXTYYoI9.mjs.map → index-DCDDoDjL.mjs.map} +1 -1
- package/dist/chunks/{index-BKxnMSY9.mjs → index-DLqxy-dg.mjs} +12 -2
- package/dist/chunks/index-DLqxy-dg.mjs.map +1 -0
- package/dist/chunks/{index-DLAC_TU-.mjs → index-DNMhNzeD.mjs} +7 -9
- package/dist/chunks/{index-DLAC_TU-.mjs.map → index-DNMhNzeD.mjs.map} +1 -1
- package/dist/chunks/{index-BXScVxAr.mjs → index-DQD35Ges.mjs} +3 -3
- package/dist/chunks/{index-BXScVxAr.mjs.map → index-DQD35Ges.mjs.map} +1 -1
- package/dist/chunks/{index-DjiiXdCh.mjs → index-D_Q4NGnO.mjs} +1 -1
- package/dist/chunks/{index-DjiiXdCh.mjs.map → index-D_Q4NGnO.mjs.map} +1 -1
- package/dist/chunks/{index-BP00_xoF.mjs → index-D_e6adwb.mjs} +12 -5
- package/dist/chunks/index-D_e6adwb.mjs.map +1 -0
- package/dist/chunks/{index-B8RPmvRI.mjs → index-DhI6OG_H.mjs} +2 -2
- package/dist/chunks/{index-B8RPmvRI.mjs.map → index-DhI6OG_H.mjs.map} +1 -1
- package/dist/chunks/{index-DY9hLs8O.mjs → index-Dp_0m03a.mjs} +2 -2
- package/dist/chunks/{index-DY9hLs8O.mjs.map → index-Dp_0m03a.mjs.map} +1 -1
- package/dist/chunks/{index-VN9qcZ4P.mjs → index-oX_tk439.mjs} +1 -1
- package/dist/chunks/{index-VN9qcZ4P.mjs.map → index-oX_tk439.mjs.map} +1 -1
- package/dist/chunks/index.module-Df4mRjmZ.mjs +73 -0
- package/dist/chunks/index.module-Df4mRjmZ.mjs.map +1 -0
- package/dist/chunks/{input-Beaky41D.mjs → input-YpoAHnXb.mjs} +2 -2
- package/dist/chunks/{input-Beaky41D.mjs.map → input-YpoAHnXb.mjs.map} +1 -1
- package/dist/chunks/input-otp-BKqdZwNx.mjs +455 -0
- package/dist/chunks/input-otp-BKqdZwNx.mjs.map +1 -0
- package/dist/chunks/{label-n_pPs58q.mjs → label-D5s6d0et.mjs} +44 -3
- package/dist/chunks/label-D5s6d0et.mjs.map +1 -0
- package/dist/chunks/{loader-circle-CEDL1CbD.mjs → loader-circle-C7StEOZI.mjs} +2 -2
- package/dist/chunks/{loader-circle-CEDL1CbD.mjs.map → loader-circle-C7StEOZI.mjs.map} +1 -1
- package/dist/chunks/{menubar-C8VLP8-v.mjs → menubar-ySifmjAG.mjs} +11 -13
- package/dist/chunks/{menubar-C8VLP8-v.mjs.map → menubar-ySifmjAG.mjs.map} +1 -1
- package/dist/chunks/{multi-select-fLsOx7-e.mjs → multi-select-BsnRMfg7.mjs} +13 -13
- package/dist/chunks/{multi-select-fLsOx7-e.mjs.map → multi-select-BsnRMfg7.mjs.map} +1 -1
- package/dist/chunks/{pagination-iwqbmQ5Q.mjs → pagination-CV6N_Qu_.mjs} +6 -6
- package/dist/chunks/{pagination-iwqbmQ5Q.mjs.map → pagination-CV6N_Qu_.mjs.map} +1 -1
- package/dist/chunks/{popover-Cpht2GgQ.mjs → popover-D3JC54Y3.mjs} +11 -13
- package/dist/chunks/{popover-Cpht2GgQ.mjs.map → popover-D3JC54Y3.mjs.map} +1 -1
- package/dist/chunks/progress-D_Enl4tV.mjs +223 -0
- package/dist/chunks/progress-D_Enl4tV.mjs.map +1 -0
- package/dist/chunks/radio-group-yF1QEewC.mjs +258 -0
- package/dist/chunks/radio-group-yF1QEewC.mjs.map +1 -0
- package/dist/chunks/{react-number-format.es-CcgVtYyo.mjs → react-number-format.es-C3uDZhRo.mjs} +1 -1
- package/dist/chunks/{react-number-format.es-CcgVtYyo.mjs.map → react-number-format.es-C3uDZhRo.mjs.map} +1 -1
- package/dist/chunks/{scroll-area-DuO1U-ha.mjs → scroll-area-CdGRe--S.mjs} +9 -11
- package/dist/chunks/{scroll-area-DuO1U-ha.mjs.map → scroll-area-CdGRe--S.mjs.map} +1 -1
- package/dist/chunks/{select-D5DzfQ8s.mjs → select-B8JYuJE5.mjs} +5 -5
- package/dist/chunks/{select-D5DzfQ8s.mjs.map → select-B8JYuJE5.mjs.map} +1 -1
- package/dist/chunks/{separator-DHnqygnd.mjs → separator-sWF5eZgM.mjs} +44 -3
- package/dist/chunks/separator-sWF5eZgM.mjs.map +1 -0
- package/dist/chunks/{sheet-CXvwS4r9.mjs → sheet-D-4XWzUo.mjs} +4 -4
- package/dist/chunks/{sheet-CXvwS4r9.mjs.map → sheet-D-4XWzUo.mjs.map} +1 -1
- package/dist/chunks/{skeleton-CuuvHTlE.mjs → skeleton-CQlSHSfr.mjs} +2 -2
- package/dist/chunks/{skeleton-CuuvHTlE.mjs.map → skeleton-CQlSHSfr.mjs.map} +1 -1
- package/dist/chunks/slider-CaliGouI.mjs +588 -0
- package/dist/chunks/slider-CaliGouI.mjs.map +1 -0
- package/dist/chunks/{sortable-Dc-PXgOX.mjs → sortable-BoTUMXD0.mjs} +3 -3
- package/dist/chunks/{sortable-Dc-PXgOX.mjs.map → sortable-BoTUMXD0.mjs.map} +1 -1
- package/dist/chunks/styles-C5sFcbz4.mjs +6 -0
- package/dist/chunks/styles-C5sFcbz4.mjs.map +1 -0
- package/dist/chunks/switch-szutUcvb.mjs +138 -0
- package/dist/chunks/switch-szutUcvb.mjs.map +1 -0
- package/dist/chunks/{table-CsRWNDTp.mjs → table-wwce3IsC.mjs} +2 -2
- package/dist/chunks/{table-CsRWNDTp.mjs.map → table-wwce3IsC.mjs.map} +1 -1
- package/dist/chunks/{tabs-Bw6ByWDS.mjs → tabs-BDPMoWeJ.mjs} +9 -10
- package/dist/chunks/{tabs-Bw6ByWDS.mjs.map → tabs-BDPMoWeJ.mjs.map} +1 -1
- package/dist/chunks/{textarea-C7CkvJ9p.mjs → textarea-DYBOxg35.mjs} +2 -2
- package/dist/chunks/{textarea-C7CkvJ9p.mjs.map → textarea-DYBOxg35.mjs.map} +1 -1
- package/dist/chunks/toast-S15TT7Q2.mjs +702 -0
- package/dist/chunks/toast-S15TT7Q2.mjs.map +1 -0
- package/dist/chunks/{toggle-BRsNuICy.mjs → toggle-GXtKRhvr.mjs} +4 -5
- package/dist/chunks/{toggle-BRsNuICy.mjs.map → toggle-GXtKRhvr.mjs.map} +1 -1
- package/dist/chunks/{tooltip-DXG_UtcS.mjs → tooltip-z43eMlPO.mjs} +11 -13
- package/dist/chunks/{tooltip-DXG_UtcS.mjs.map → tooltip-z43eMlPO.mjs.map} +1 -1
- package/dist/chunks/{trash-2-DSHxuneu.mjs → trash-2-CZE_1bXY.mjs} +2 -2
- package/dist/chunks/{trash-2-DSHxuneu.mjs.map → trash-2-CZE_1bXY.mjs.map} +1 -1
- package/dist/chunks/{triangle-alert-8sDAvjNW.mjs → triangle-alert-BeczCtiG.mjs} +2 -2
- package/dist/chunks/{triangle-alert-8sDAvjNW.mjs.map → triangle-alert-BeczCtiG.mjs.map} +1 -1
- package/dist/chunks/{tslib.es6-WVUvgLYj.mjs → tslib.es6-B20VGjW7.mjs} +1 -1
- package/dist/chunks/{tslib.es6-WVUvgLYj.mjs.map → tslib.es6-B20VGjW7.mjs.map} +1 -1
- package/dist/chunks/use-toast-C3gJQZ0s.mjs +137 -0
- package/dist/chunks/use-toast-C3gJQZ0s.mjs.map +1 -0
- package/dist/chunks/{utils-BqIRZT53.mjs → utils-uOfHPBdi.mjs} +2 -2
- package/dist/chunks/{utils-BqIRZT53.mjs.map → utils-uOfHPBdi.mjs.map} +1 -1
- package/dist/chunks/{wand-sparkles-BjK8VloB.mjs → wand-sparkles-COk3z6HL.mjs} +2 -2
- package/dist/chunks/{wand-sparkles-BjK8VloB.mjs.map → wand-sparkles-COk3z6HL.mjs.map} +1 -1
- package/dist/chunks/{x-D7oIZ9hK.mjs → x-D5HL_X5m.mjs} +2 -2
- package/dist/chunks/{x-D7oIZ9hK.mjs.map → x-D5HL_X5m.mjs.map} +1 -1
- package/dist/collapsible/index.mjs +8 -10
- package/dist/collapsible/index.mjs.map +1 -1
- package/dist/combobox/index.mjs +25 -27
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/command/index.d.ts +7 -7
- package/dist/command/index.mjs +19 -21
- package/dist/command/index.mjs.map +1 -1
- package/dist/context-menu/index.mjs +21 -23
- package/dist/context-menu/index.mjs.map +1 -1
- package/dist/dash/index.mjs +25 -26
- package/dist/dash/index.mjs.map +1 -1
- package/dist/data-table/index.mjs +33 -35
- package/dist/data-table/index.mjs.map +1 -1
- package/dist/date-picker/index.d.ts +22 -7
- package/dist/date-picker/index.mjs +26 -28
- package/dist/date-picker/index.mjs.map +1 -1
- package/dist/dialog/index.mjs +18 -20
- package/dist/dialog/index.mjs.map +1 -1
- package/dist/drawer/index.mjs +15 -17
- package/dist/drawer/index.mjs.map +1 -1
- package/dist/dropdown-menu/index.mjs +21 -23
- package/dist/dropdown-menu/index.mjs.map +1 -1
- package/dist/dropzone/index.mjs +19 -133
- package/dist/dropzone/index.mjs.map +1 -1
- package/dist/editable-table/index.mjs +18 -20
- package/dist/editable-table/index.mjs.map +1 -1
- package/dist/empty/index.mjs +2 -2
- package/dist/field/index.d.ts +3 -2
- package/dist/field/index.mjs +4 -5
- package/dist/field/index.mjs.map +1 -1
- package/dist/form/index.mjs +4 -5
- package/dist/form/index.mjs.map +1 -1
- package/dist/form-fields/index.mjs +27 -29
- package/dist/form-fields/index.mjs.map +1 -1
- package/dist/form-layout/index.d.ts +86 -0
- package/dist/form-layout/index.mjs +535 -0
- package/dist/form-layout/index.mjs.map +1 -0
- package/dist/hover-card/index.mjs +14 -16
- package/dist/hover-card/index.mjs.map +1 -1
- package/dist/icon/index.mjs +1 -1
- package/dist/index.css +1 -1
- package/dist/input/index.mjs +3 -3
- package/dist/input-group/index.d.ts +1 -1
- package/dist/input-group/index.mjs +5 -5
- package/dist/input-otp/index.mjs +5 -455
- package/dist/input-otp/index.mjs.map +1 -1
- package/dist/item/index.d.ts +4 -2
- package/dist/item/index.mjs +3 -4
- package/dist/item/index.mjs.map +1 -1
- package/dist/kbd/index.mjs +2 -2
- package/dist/label/index.mjs +3 -4
- package/dist/label/index.mjs.map +1 -1
- package/dist/layout/index.mjs +22 -24
- package/dist/layout/index.mjs.map +1 -1
- package/dist/menubar/index.mjs +22 -24
- package/dist/menubar/index.mjs.map +1 -1
- package/dist/multi-input-list/index.mjs +28 -30
- package/dist/multi-input-list/index.mjs.map +1 -1
- package/dist/multi-select/index.mjs +32 -34
- package/dist/multi-select/index.mjs.map +1 -1
- package/dist/navigation-menu/index.mjs +15 -17
- package/dist/navigation-menu/index.mjs.map +1 -1
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/index.mjs +8 -8
- package/dist/popover/index.mjs +17 -19
- package/dist/popover/index.mjs.map +1 -1
- package/dist/progress/index.mjs +3 -5
- package/dist/progress/index.mjs.map +1 -1
- package/dist/radio-group/index.mjs +18 -264
- package/dist/radio-group/index.mjs.map +1 -1
- package/dist/resizable/index.mjs +3 -3
- package/dist/scroll-area/index.mjs +10 -12
- package/dist/scroll-area/index.mjs.map +1 -1
- package/dist/select/index.mjs +6 -6
- package/dist/separator/index.mjs +3 -4
- package/dist/separator/index.mjs.map +1 -1
- package/dist/shared/index.d.ts +13 -3
- package/dist/shared/index.mjs +6 -6
- package/dist/shared/index.mjs.map +1 -1
- package/dist/sheet/index.d.ts +7 -7
- package/dist/sheet/index.mjs +18 -20
- package/dist/sheet/index.mjs.map +1 -1
- package/dist/sidebar/index.d.ts +17 -4
- package/dist/sidebar/index.mjs +26 -28
- package/dist/sidebar/index.mjs.map +1 -1
- package/dist/skeleton/index.mjs +3 -3
- package/dist/skeleton-component/index.mjs +4 -4
- package/dist/slider/index.mjs +14 -591
- package/dist/slider/index.mjs.map +1 -1
- package/dist/sortable/index.d.ts +12 -3
- package/dist/sortable/index.mjs +4 -4
- package/dist/spinner/index.mjs +4 -4
- package/dist/switch/index.mjs +11 -141
- package/dist/switch/index.mjs.map +1 -1
- package/dist/table/index.mjs +3 -3
- package/dist/table-filter/index.d.ts +8 -3
- package/dist/table-filter/index.mjs +53 -54
- package/dist/table-filter/index.mjs.map +1 -1
- package/dist/tabs/index.mjs +14 -16
- package/dist/tabs/index.mjs.map +1 -1
- package/dist/textarea/index.mjs +3 -3
- package/dist/toast/index.mjs +19 -705
- package/dist/toast/index.mjs.map +1 -1
- package/dist/toaster/index.d.ts +5 -0
- package/dist/toaster/index.mjs +34 -0
- package/dist/toaster/index.mjs.map +1 -0
- package/dist/toggle/index.mjs +6 -7
- package/dist/toggle/index.mjs.map +1 -1
- package/dist/toggle-group/index.mjs +11 -13
- package/dist/toggle-group/index.mjs.map +1 -1
- package/dist/tooltip/index.mjs +16 -18
- package/dist/tooltip/index.mjs.map +1 -1
- package/package.json +10 -2
- package/dist/chunks/_commonjsHelpers-CDajFLDm.mjs.map +0 -1
- package/dist/chunks/bundle-mjs-ByJyReDu.mjs.map +0 -1
- package/dist/chunks/calendar-DtKpXGXO.mjs.map +0 -1
- package/dist/chunks/form-B4-N-eE1.mjs.map +0 -1
- package/dist/chunks/format-numbers-CksgR7yb.mjs.map +0 -1
- package/dist/chunks/index-5s6ltgHF.mjs +0 -40
- package/dist/chunks/index-5s6ltgHF.mjs.map +0 -1
- package/dist/chunks/index-BKxnMSY9.mjs.map +0 -1
- package/dist/chunks/index-BP00_xoF.mjs.map +0 -1
- package/dist/chunks/index-C8cUOEOO.mjs.map +0 -1
- package/dist/chunks/index-DUoETH03.mjs +0 -12
- package/dist/chunks/index-DUoETH03.mjs.map +0 -1
- package/dist/chunks/index.module-acmtZqFz.mjs +0 -68
- package/dist/chunks/index.module-acmtZqFz.mjs.map +0 -1
- package/dist/chunks/label-n_pPs58q.mjs.map +0 -1
- package/dist/chunks/progress-CZnyHYXZ.mjs +0 -99
- package/dist/chunks/progress-CZnyHYXZ.mjs.map +0 -1
- package/dist/chunks/separator-DHnqygnd.mjs.map +0 -1
- package/dist/icon.svg +0 -7
- package/dist/index.cjs.js +0 -1
- package/dist/index.es.js +0 -1
- package/dist/ivt.css +0 -1
- package/dist/ivt.png +0 -0
|
@@ -1,232 +1,572 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { createContext, useContext, useCallback, useRef, useLayoutEffect, useState, useEffect, useMemo } from 'react';
|
|
3
|
-
import { c as cn } from './utils-
|
|
4
|
-
import { t as toDate, c as constructFrom, j as addDays, y as normalizeDates, z as startOfDay, g as getDefaultOptions,
|
|
5
|
-
import { C as ChevronLeft } from './chevron-left-
|
|
6
|
-
import { C as ChevronRight } from './chevron-right-
|
|
7
|
-
import { C as ChevronDown } from './chevron-down-
|
|
8
|
-
import { b as buttonVariants, B as Button$1 } from './button-
|
|
3
|
+
import { c as cn } from './utils-uOfHPBdi.mjs';
|
|
4
|
+
import { t as toDate, c as constructFrom, j as addDays, y as normalizeDates, z as startOfDay, g as getDefaultOptions, l as enUS$1, f as format, A as differenceInCalendarDays, i as getISOWeek, h as getWeek, B as isDate, e as startOfISOWeek, s as startOfWeek, C as startOfYear } from './format-CR4Q6BSq.mjs';
|
|
5
|
+
import { C as ChevronLeft } from './chevron-left-BZ8X7kLy.mjs';
|
|
6
|
+
import { C as ChevronRight } from './chevron-right-jAScR3zY.mjs';
|
|
7
|
+
import { C as ChevronDown } from './chevron-down-o7NUBnJ4.mjs';
|
|
8
|
+
import { b as buttonVariants, B as Button$1 } from './button-BW9I4XWU.mjs';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Time zone name format.
|
|
12
12
|
*/ /**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @summary Add the specified number of months to the given date.
|
|
13
|
+
* The function returns the time zone name for the given date in the specified
|
|
14
|
+
* time zone.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* It uses the `Intl.DateTimeFormat` API and by default outputs the time zone
|
|
17
|
+
* name in a long format, e.g. "Pacific Standard Time" or
|
|
18
|
+
* "Singapore Standard Time".
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
20
|
+
* It is possible to specify the format as the third argument using one of the following options
|
|
22
21
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
22
|
+
* - "short": e.g. "EDT" or "GMT+8".
|
|
23
|
+
* - "long": e.g. "Eastern Daylight Time".
|
|
24
|
+
* - "shortGeneric": e.g. "ET" or "Singapore Time".
|
|
25
|
+
* - "longGeneric": e.g. "Eastern Time" or "Singapore Standard Time".
|
|
26
26
|
*
|
|
27
|
-
*
|
|
27
|
+
* These options correspond to TR35 tokens `z..zzz`, `zzzz`, `v`, and `vvvv` respectively: https://www.unicode.org/reports/tr35/tr35-dates.html#dfst-zone
|
|
28
28
|
*
|
|
29
|
-
* @
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* //=> Sun Feb 01 2015 00:00:00
|
|
29
|
+
* @param timeZone - Time zone name (IANA or UTC offset)
|
|
30
|
+
* @param date - Date object to get the time zone name for
|
|
31
|
+
* @param format - Optional format of the time zone name. Defaults to "long". Can be "short", "long", "shortGeneric", or "longGeneric".
|
|
33
32
|
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const dayOfMonth = _date.getDate();
|
|
45
|
-
// The JS Date object supports date math by accepting out-of-bounds values for
|
|
46
|
-
// month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and
|
|
47
|
-
// new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we
|
|
48
|
-
// want except that dates will wrap around the end of a month, meaning that
|
|
49
|
-
// new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So
|
|
50
|
-
// we'll default to the end of the desired month by adding 1 to the desired
|
|
51
|
-
// month and using a date of 0 to back up one day to the end of the desired
|
|
52
|
-
// month.
|
|
53
|
-
const endOfDesiredMonth = constructFrom(date, _date.getTime());
|
|
54
|
-
endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
|
|
55
|
-
const daysInMonth = endOfDesiredMonth.getDate();
|
|
56
|
-
if (dayOfMonth >= daysInMonth) {
|
|
57
|
-
// If we're already at the end of the month, then this is the correct date
|
|
58
|
-
// and we're done.
|
|
59
|
-
return endOfDesiredMonth;
|
|
60
|
-
} else {
|
|
61
|
-
// Otherwise, we now know that setting the original day-of-month value won't
|
|
62
|
-
// cause an overflow, so set the desired day-of-month. Note that we can't
|
|
63
|
-
// just set the date of `endOfDesiredMonth` because that object may have had
|
|
64
|
-
// its time changed in the unusual case where where a DST transition was on
|
|
65
|
-
// the last day of the month and its local time was in the hour skipped or
|
|
66
|
-
// repeated next to a DST transition. So we use `date` instead which is
|
|
67
|
-
// guaranteed to still have the original time.
|
|
68
|
-
_date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth);
|
|
69
|
-
return _date;
|
|
70
|
-
}
|
|
33
|
+
* @returns Time zone name (e.g. "Singapore Standard Time")
|
|
34
|
+
*/ function tzName(timeZone, date, format = "long") {
|
|
35
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
36
|
+
// Enforces engine to render the time. Without the option JavaScriptCore omits it.
|
|
37
|
+
hour: "numeric",
|
|
38
|
+
timeZone: timeZone,
|
|
39
|
+
timeZoneName: format
|
|
40
|
+
}).format(date).split(/\s/g) // Format.JS uses non-breaking spaces
|
|
41
|
+
.slice(2) // Skip the hour and AM/PM parts
|
|
42
|
+
.join(" ");
|
|
71
43
|
}
|
|
72
44
|
|
|
45
|
+
const offsetFormatCache = {};
|
|
46
|
+
const offsetCache = {};
|
|
73
47
|
/**
|
|
74
|
-
* The
|
|
75
|
-
|
|
76
|
-
* @name addWeeks
|
|
77
|
-
* @category Week Helpers
|
|
78
|
-
* @summary Add the specified number of weeks to the given date.
|
|
79
|
-
*
|
|
80
|
-
* @description
|
|
81
|
-
* Add the specified number of weeks to the given date.
|
|
82
|
-
*
|
|
83
|
-
* @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).
|
|
84
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
48
|
+
* The function extracts UTC offset in minutes from the given date in specified
|
|
49
|
+
* time zone.
|
|
85
50
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
51
|
+
* Unlike `Date.prototype.getTimezoneOffset`, this function returns the value
|
|
52
|
+
* mirrored to the sign of the offset in the time zone. For Asia/Singapore
|
|
53
|
+
* (UTC+8), `tzOffset` returns 480, while `getTimezoneOffset` returns -480.
|
|
89
54
|
*
|
|
90
|
-
* @
|
|
55
|
+
* @param timeZone - Time zone name (IANA or UTC offset)
|
|
56
|
+
* @param date - Date to check the offset for
|
|
91
57
|
*
|
|
92
|
-
* @
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
58
|
+
* @returns UTC offset in minutes
|
|
59
|
+
*/ function tzOffset(timeZone, date) {
|
|
60
|
+
try {
|
|
61
|
+
var _offsetFormatCache, _timeZone;
|
|
62
|
+
const format = (_offsetFormatCache = offsetFormatCache)[_timeZone = timeZone] || (_offsetFormatCache[_timeZone] = new Intl.DateTimeFormat("en-US", {
|
|
63
|
+
timeZone,
|
|
64
|
+
timeZoneName: "longOffset"
|
|
65
|
+
}).format);
|
|
66
|
+
const offsetStr = format(date).split("GMT")[1];
|
|
67
|
+
if (offsetStr in offsetCache) return offsetCache[offsetStr];
|
|
68
|
+
return calcOffset(offsetStr, offsetStr.split(":"));
|
|
69
|
+
} catch {
|
|
70
|
+
// Fallback to manual parsing if the runtime doesn't support ±HH:MM/±HHMM/±HH
|
|
71
|
+
// See: https://github.com/nodejs/node/issues/53419
|
|
72
|
+
if (timeZone in offsetCache) return offsetCache[timeZone];
|
|
73
|
+
const captures = timeZone?.match(offsetRe);
|
|
74
|
+
if (captures) return calcOffset(timeZone, captures.slice(1));
|
|
75
|
+
return NaN;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const offsetRe = /([+-]\d\d):?(\d\d)?/;
|
|
79
|
+
function calcOffset(cacheStr, values) {
|
|
80
|
+
const hours = +(values[0] || 0);
|
|
81
|
+
const minutes = +(values[1] || 0);
|
|
82
|
+
// Convert seconds to minutes by dividing by 60 to keep the function return in minutes.
|
|
83
|
+
const seconds = +(values[2] || 0) / 60;
|
|
84
|
+
return offsetCache[cacheStr] = hours * 60 + minutes > 0 ? hours * 60 + minutes + seconds : hours * 60 - minutes - seconds;
|
|
98
85
|
}
|
|
99
86
|
|
|
87
|
+
class TZDateMini extends Date {
|
|
88
|
+
static tz(tz, ...args) {
|
|
89
|
+
return args.length ? new TZDateMini(...args, tz) : new TZDateMini(Date.now(), tz);
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region time zone
|
|
93
|
+
withTimeZone(timeZone) {
|
|
94
|
+
return new TZDateMini(+this, timeZone);
|
|
95
|
+
}
|
|
96
|
+
getTimezoneOffset() {
|
|
97
|
+
const offset = -tzOffset(this.timeZone, this);
|
|
98
|
+
// Remove the seconds offset
|
|
99
|
+
// use Math.floor for negative GMT timezones and Math.ceil for positive GMT timezones.
|
|
100
|
+
return offset > 0 ? Math.floor(offset) : Math.ceil(offset);
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region time
|
|
104
|
+
setTime(time) {
|
|
105
|
+
Date.prototype.setTime.apply(this, arguments);
|
|
106
|
+
syncToInternal(this);
|
|
107
|
+
return +this;
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region date-fns integration
|
|
111
|
+
[Symbol.for("constructDateFrom")](date) {
|
|
112
|
+
return new TZDateMini(+new Date(date), this.timeZone);
|
|
113
|
+
}
|
|
114
|
+
//#region static
|
|
115
|
+
constructor(...args){
|
|
116
|
+
super();
|
|
117
|
+
if (args.length > 1 && typeof args[args.length - 1] === "string") {
|
|
118
|
+
this.timeZone = args.pop();
|
|
119
|
+
}
|
|
120
|
+
this.internal = new Date();
|
|
121
|
+
if (isNaN(tzOffset(this.timeZone, this))) {
|
|
122
|
+
this.setTime(NaN);
|
|
123
|
+
} else {
|
|
124
|
+
if (!args.length) {
|
|
125
|
+
this.setTime(Date.now());
|
|
126
|
+
} else if (typeof args[0] === "number" && (args.length === 1 || args.length === 2 && typeof args[1] !== "number")) {
|
|
127
|
+
this.setTime(args[0]);
|
|
128
|
+
} else if (typeof args[0] === "string") {
|
|
129
|
+
this.setTime(+new Date(args[0]));
|
|
130
|
+
} else if (args[0] instanceof Date) {
|
|
131
|
+
this.setTime(+args[0]);
|
|
132
|
+
} else {
|
|
133
|
+
this.setTime(+new Date(...args));
|
|
134
|
+
adjustToSystemTZ(this);
|
|
135
|
+
syncToInternal(this);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Assign getters and setters
|
|
141
|
+
const re = /^(get|set)(?!UTC)/;
|
|
142
|
+
Object.getOwnPropertyNames(Date.prototype).forEach((method)=>{
|
|
143
|
+
if (!re.test(method)) return;
|
|
144
|
+
const utcMethod = method.replace(re, "$1UTC");
|
|
145
|
+
// Filter out methods without UTC counterparts
|
|
146
|
+
if (!TZDateMini.prototype[utcMethod]) return;
|
|
147
|
+
if (method.startsWith("get")) {
|
|
148
|
+
// Delegate to internal date's UTC method
|
|
149
|
+
TZDateMini.prototype[method] = function() {
|
|
150
|
+
return this.internal[utcMethod]();
|
|
151
|
+
};
|
|
152
|
+
} else {
|
|
153
|
+
// Assign regular setter
|
|
154
|
+
TZDateMini.prototype[method] = function() {
|
|
155
|
+
Date.prototype[utcMethod].apply(this.internal, arguments);
|
|
156
|
+
syncFromInternal(this);
|
|
157
|
+
return +this;
|
|
158
|
+
};
|
|
159
|
+
// Assign UTC setter
|
|
160
|
+
TZDateMini.prototype[utcMethod] = function() {
|
|
161
|
+
Date.prototype[utcMethod].apply(this, arguments);
|
|
162
|
+
syncToInternal(this);
|
|
163
|
+
return +this;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
});
|
|
100
167
|
/**
|
|
101
|
-
*
|
|
102
|
-
*/ /**
|
|
103
|
-
* @name addYears
|
|
104
|
-
* @category Year Helpers
|
|
105
|
-
* @summary Add the specified number of years to the given date.
|
|
106
|
-
*
|
|
107
|
-
* @description
|
|
108
|
-
* Add the specified number of years to the given date.
|
|
109
|
-
*
|
|
110
|
-
* @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).
|
|
111
|
-
* @typeParam ResultDate - The result `Date` type.
|
|
112
|
-
*
|
|
113
|
-
* @param date - The date to be changed
|
|
114
|
-
* @param amount - The amount of years to be added.
|
|
115
|
-
* @param options - The options
|
|
116
|
-
*
|
|
117
|
-
* @returns The new date with the years added
|
|
168
|
+
* Function syncs time to internal date, applying the time zone offset.
|
|
118
169
|
*
|
|
119
|
-
* @
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*/ function addYears(date, amount, options) {
|
|
124
|
-
return addMonths(date, amount * 12, options);
|
|
170
|
+
* @param {Date} date - Date to sync
|
|
171
|
+
*/ function syncToInternal(date) {
|
|
172
|
+
date.internal.setTime(+date);
|
|
173
|
+
date.internal.setUTCSeconds(date.internal.getUTCSeconds() - Math.round(-tzOffset(date.timeZone, date) * 60));
|
|
125
174
|
}
|
|
126
|
-
|
|
127
175
|
/**
|
|
128
|
-
*
|
|
129
|
-
|
|
130
|
-
* @name max
|
|
131
|
-
* @category Common Helpers
|
|
132
|
-
* @summary Return the latest of the given dates.
|
|
133
|
-
*
|
|
134
|
-
* @description
|
|
135
|
-
* Return the latest of the given dates.
|
|
176
|
+
* Function syncs the internal date UTC values to the date. It allows to get
|
|
177
|
+
* accurate timestamp value.
|
|
136
178
|
*
|
|
137
|
-
* @
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
* @example
|
|
145
|
-
* // Which of these dates is the latest?
|
|
146
|
-
* const result = max([
|
|
147
|
-
* new Date(1989, 6, 10),
|
|
148
|
-
* new Date(1987, 1, 11),
|
|
149
|
-
* new Date(1995, 6, 2),
|
|
150
|
-
* new Date(1990, 0, 1)
|
|
151
|
-
* ])
|
|
152
|
-
* //=> Sun Jul 02 1995 00:00:00
|
|
153
|
-
*/ function max(dates, options) {
|
|
154
|
-
let result;
|
|
155
|
-
let context = options?.in;
|
|
156
|
-
dates.forEach((date)=>{
|
|
157
|
-
// Use the first date object as the context function
|
|
158
|
-
if (!context && typeof date === "object") context = constructFrom.bind(null, date);
|
|
159
|
-
const date_ = toDate(date, context);
|
|
160
|
-
if (!result || result < date_ || isNaN(+date_)) result = date_;
|
|
161
|
-
});
|
|
162
|
-
return constructFrom(context, result || NaN);
|
|
179
|
+
* @param {Date} date - The date to sync
|
|
180
|
+
*/ function syncFromInternal(date) {
|
|
181
|
+
// First we transpose the internal values
|
|
182
|
+
Date.prototype.setFullYear.call(date, date.internal.getUTCFullYear(), date.internal.getUTCMonth(), date.internal.getUTCDate());
|
|
183
|
+
Date.prototype.setHours.call(date, date.internal.getUTCHours(), date.internal.getUTCMinutes(), date.internal.getUTCSeconds(), date.internal.getUTCMilliseconds());
|
|
184
|
+
// Now we have to adjust the date to the system time zone
|
|
185
|
+
adjustToSystemTZ(date);
|
|
163
186
|
}
|
|
164
|
-
|
|
165
187
|
/**
|
|
166
|
-
*
|
|
167
|
-
|
|
168
|
-
* @name min
|
|
169
|
-
* @category Common Helpers
|
|
170
|
-
* @summary Returns the earliest of the given dates.
|
|
171
|
-
*
|
|
172
|
-
* @description
|
|
173
|
-
* Returns the earliest of the given dates.
|
|
174
|
-
*
|
|
175
|
-
* @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).
|
|
176
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
177
|
-
*
|
|
178
|
-
* @param dates - The dates to compare
|
|
179
|
-
*
|
|
180
|
-
* @returns The earliest of the dates
|
|
188
|
+
* Function adjusts the date to the system time zone. It uses the time zone
|
|
189
|
+
* differences to calculate the offset and adjust the date.
|
|
181
190
|
*
|
|
182
|
-
* @
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
191
|
+
* @param {Date} date - Date to adjust
|
|
192
|
+
*/ function adjustToSystemTZ(date) {
|
|
193
|
+
// Save the time zone offset before all the adjustments
|
|
194
|
+
const baseOffset = tzOffset(date.timeZone, date);
|
|
195
|
+
// Remove the seconds offset
|
|
196
|
+
// use Math.floor for negative GMT timezones and Math.ceil for positive GMT timezones.
|
|
197
|
+
const offset = baseOffset > 0 ? Math.floor(baseOffset) : Math.ceil(baseOffset);
|
|
198
|
+
//#region System DST adjustment
|
|
199
|
+
// The biggest problem with using the system time zone is that when we create
|
|
200
|
+
// a date from internal values stored in UTC, the system time zone might end
|
|
201
|
+
// up on the DST hour:
|
|
202
|
+
//
|
|
203
|
+
// $ TZ=America/New_York node
|
|
204
|
+
// > new Date(2020, 2, 8, 1).toString()
|
|
205
|
+
// 'Sun Mar 08 2020 01:00:00 GMT-0500 (Eastern Standard Time)'
|
|
206
|
+
// > new Date(2020, 2, 8, 2).toString()
|
|
207
|
+
// 'Sun Mar 08 2020 03:00:00 GMT-0400 (Eastern Daylight Time)'
|
|
208
|
+
// > new Date(2020, 2, 8, 3).toString()
|
|
209
|
+
// 'Sun Mar 08 2020 03:00:00 GMT-0400 (Eastern Daylight Time)'
|
|
210
|
+
// > new Date(2020, 2, 8, 4).toString()
|
|
211
|
+
// 'Sun Mar 08 2020 04:00:00 GMT-0400 (Eastern Daylight Time)'
|
|
212
|
+
//
|
|
213
|
+
// Here we get the same hour for both 2 and 3, because the system time zone
|
|
214
|
+
// has DST beginning at 8 March 2020, 2 a.m. and jumps to 3 a.m. So we have
|
|
215
|
+
// to adjust the internal date to reflect that.
|
|
216
|
+
//
|
|
217
|
+
// However we want to adjust only if that's the DST hour the change happenes,
|
|
218
|
+
// not the hour where DST moves to.
|
|
219
|
+
// We calculate the previous hour to see if the time zone offset has changed
|
|
220
|
+
// and we have landed on the DST hour.
|
|
221
|
+
const prevHour = new Date(+date);
|
|
222
|
+
// We use UTC methods here as we don't want to land on the same hour again
|
|
223
|
+
// in case of DST.
|
|
224
|
+
prevHour.setUTCHours(prevHour.getUTCHours() - 1);
|
|
225
|
+
// Calculate if we are on the system DST hour.
|
|
226
|
+
const systemOffset = -new Date(+date).getTimezoneOffset();
|
|
227
|
+
const prevHourSystemOffset = -new Date(+prevHour).getTimezoneOffset();
|
|
228
|
+
const systemDSTChange = systemOffset - prevHourSystemOffset;
|
|
229
|
+
// Detect the DST shift. System DST change will occur both on
|
|
230
|
+
const dstShift = Date.prototype.getHours.apply(date) !== date.internal.getUTCHours();
|
|
231
|
+
// Move the internal date when we are on the system DST hour.
|
|
232
|
+
if (systemDSTChange && dstShift) date.internal.setUTCMinutes(date.internal.getUTCMinutes() + systemDSTChange);
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region System diff adjustment
|
|
235
|
+
// Now we need to adjust the date, since we just applied internal values.
|
|
236
|
+
// We need to calculate the difference between the system and date time zones
|
|
237
|
+
// and apply it to the date.
|
|
238
|
+
const offsetDiff = systemOffset - offset;
|
|
239
|
+
if (offsetDiff) Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetDiff);
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region Seconds System diff adjustment
|
|
242
|
+
const systemDate = new Date(+date);
|
|
243
|
+
// Set the UTC seconds to 0 to isolate the timezone offset in seconds.
|
|
244
|
+
systemDate.setUTCSeconds(0);
|
|
245
|
+
// For negative systemOffset, invert the seconds.
|
|
246
|
+
const systemSecondsOffset = systemOffset > 0 ? systemDate.getSeconds() : (systemDate.getSeconds() - 60) % 60;
|
|
247
|
+
// Calculate the seconds offset based on the timezone offset.
|
|
248
|
+
const secondsOffset = Math.round(-(tzOffset(date.timeZone, date) * 60)) % 60;
|
|
249
|
+
if (secondsOffset || systemSecondsOffset) {
|
|
250
|
+
date.internal.setUTCSeconds(date.internal.getUTCSeconds() + secondsOffset);
|
|
251
|
+
Date.prototype.setUTCSeconds.call(date, Date.prototype.getUTCSeconds.call(date) + secondsOffset + systemSecondsOffset);
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region Post-adjustment DST fix
|
|
255
|
+
const postBaseOffset = tzOffset(date.timeZone, date);
|
|
256
|
+
// Remove the seconds offset
|
|
257
|
+
// use Math.floor for negative GMT timezones and Math.ceil for positive GMT timezones.
|
|
258
|
+
const postOffset = postBaseOffset > 0 ? Math.floor(postBaseOffset) : Math.ceil(postBaseOffset);
|
|
259
|
+
const postSystemOffset = -new Date(+date).getTimezoneOffset();
|
|
260
|
+
const postOffsetDiff = postSystemOffset - postOffset;
|
|
261
|
+
const offsetChanged = postOffset !== offset;
|
|
262
|
+
const postDiff = postOffsetDiff - offsetDiff;
|
|
263
|
+
if (offsetChanged && postDiff) {
|
|
264
|
+
Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + postDiff);
|
|
265
|
+
// Now we need to check if got offset change during the post-adjustment.
|
|
266
|
+
// If so, we also need both dates to reflect that.
|
|
267
|
+
const newBaseOffset = tzOffset(date.timeZone, date);
|
|
268
|
+
// Remove the seconds offset
|
|
269
|
+
// use Math.floor for negative GMT timezones and Math.ceil for positive GMT timezones.
|
|
270
|
+
const newOffset = newBaseOffset > 0 ? Math.floor(newBaseOffset) : Math.ceil(newBaseOffset);
|
|
271
|
+
const offsetChange = postOffset - newOffset;
|
|
272
|
+
if (offsetChange) {
|
|
273
|
+
date.internal.setUTCMinutes(date.internal.getUTCMinutes() + offsetChange);
|
|
274
|
+
Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetChange);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
class TZDate extends TZDateMini {
|
|
281
|
+
//#region static
|
|
282
|
+
static tz(tz, ...args) {
|
|
283
|
+
return args.length ? new TZDate(...args, tz) : new TZDate(Date.now(), tz);
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region representation
|
|
287
|
+
toISOString() {
|
|
288
|
+
const [sign, hours, minutes] = this.tzComponents();
|
|
289
|
+
const tz = `${sign}${hours}:${minutes}`;
|
|
290
|
+
return this.internal.toISOString().slice(0, -1) + tz;
|
|
291
|
+
}
|
|
292
|
+
toString() {
|
|
293
|
+
// "Tue Aug 13 2024 07:50:19 GMT+0800 (Singapore Standard Time)";
|
|
294
|
+
return `${this.toDateString()} ${this.toTimeString()}`;
|
|
295
|
+
}
|
|
296
|
+
toDateString() {
|
|
297
|
+
// toUTCString returns RFC 7231 ("Mon, 12 Aug 2024 23:36:08 GMT")
|
|
298
|
+
const [day, date, month, year] = this.internal.toUTCString().split(" ");
|
|
299
|
+
// "Tue Aug 13 2024"
|
|
300
|
+
return `${day?.slice(0, -1)} ${month} ${date} ${year}`;
|
|
301
|
+
}
|
|
302
|
+
toTimeString() {
|
|
303
|
+
// toUTCString returns RFC 7231 ("Mon, 12 Aug 2024 23:36:08 GMT")
|
|
304
|
+
const time = this.internal.toUTCString().split(" ")[4];
|
|
305
|
+
const [sign, hours, minutes] = this.tzComponents();
|
|
306
|
+
// "07:42:23 GMT+0800 (Singapore Standard Time)"
|
|
307
|
+
return `${time} GMT${sign}${hours}${minutes} (${tzName(this.timeZone, this)})`;
|
|
308
|
+
}
|
|
309
|
+
toLocaleString(locales, options) {
|
|
310
|
+
return Date.prototype.toLocaleString.call(this, locales, {
|
|
311
|
+
...options,
|
|
312
|
+
timeZone: options?.timeZone || this.timeZone
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
toLocaleDateString(locales, options) {
|
|
316
|
+
return Date.prototype.toLocaleDateString.call(this, locales, {
|
|
317
|
+
...options,
|
|
318
|
+
timeZone: options?.timeZone || this.timeZone
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
toLocaleTimeString(locales, options) {
|
|
322
|
+
return Date.prototype.toLocaleTimeString.call(this, locales, {
|
|
323
|
+
...options,
|
|
324
|
+
timeZone: options?.timeZone || this.timeZone
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region private
|
|
329
|
+
tzComponents() {
|
|
330
|
+
const offset = this.getTimezoneOffset();
|
|
331
|
+
const sign = offset > 0 ? "-" : "+";
|
|
332
|
+
const hours = String(Math.floor(Math.abs(offset) / 60)).padStart(2, "0");
|
|
333
|
+
const minutes = String(Math.abs(offset) % 60).padStart(2, "0");
|
|
334
|
+
return [
|
|
335
|
+
sign,
|
|
336
|
+
hours,
|
|
337
|
+
minutes
|
|
338
|
+
];
|
|
339
|
+
}
|
|
340
|
+
//#endregion
|
|
341
|
+
withTimeZone(timeZone) {
|
|
342
|
+
return new TZDate(+this, timeZone);
|
|
343
|
+
}
|
|
344
|
+
//#region date-fns integration
|
|
345
|
+
[Symbol.for("constructDateFrom")](date) {
|
|
346
|
+
return new TZDate(+new Date(date), this.timeZone);
|
|
347
|
+
}
|
|
201
348
|
}
|
|
202
349
|
|
|
203
350
|
/**
|
|
204
|
-
* The {@link
|
|
351
|
+
* The {@link addMonths} function options.
|
|
205
352
|
*/ /**
|
|
206
|
-
* @name
|
|
207
|
-
* @category
|
|
208
|
-
* @summary
|
|
353
|
+
* @name addMonths
|
|
354
|
+
* @category Month Helpers
|
|
355
|
+
* @summary Add the specified number of months to the given date.
|
|
209
356
|
*
|
|
210
357
|
* @description
|
|
211
|
-
*
|
|
358
|
+
* Add the specified number of months to the given date.
|
|
212
359
|
*
|
|
213
|
-
* @
|
|
214
|
-
* @
|
|
215
|
-
* @param options - An object with options
|
|
360
|
+
* @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).
|
|
361
|
+
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
216
362
|
*
|
|
217
|
-
* @
|
|
363
|
+
* @param date - The date to be changed
|
|
364
|
+
* @param amount - The amount of months to be added.
|
|
365
|
+
* @param options - The options object
|
|
218
366
|
*
|
|
219
|
-
* @
|
|
220
|
-
* // Are 4 September 06:00:00 and 4 September 18:00:00 in the same day?
|
|
221
|
-
* const result = isSameDay(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 18, 0))
|
|
222
|
-
* //=> true
|
|
367
|
+
* @returns The new date with the months added
|
|
223
368
|
*
|
|
224
369
|
* @example
|
|
225
|
-
* //
|
|
226
|
-
* const result =
|
|
227
|
-
* //=>
|
|
370
|
+
* // Add 5 months to 1 September 2014:
|
|
371
|
+
* const result = addMonths(new Date(2014, 8, 1), 5)
|
|
372
|
+
* //=> Sun Feb 01 2015 00:00:00
|
|
228
373
|
*
|
|
229
|
-
*
|
|
374
|
+
* // Add one month to 30 January 2023:
|
|
375
|
+
* const result = addMonths(new Date(2023, 0, 30), 1)
|
|
376
|
+
* //=> Tue Feb 28 2023 00:00:00
|
|
377
|
+
*/ function addMonths(date, amount, options) {
|
|
378
|
+
const _date = toDate(date, options?.in);
|
|
379
|
+
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
380
|
+
if (!amount) {
|
|
381
|
+
// If 0 months, no-op to avoid changing times in the hour before end of DST
|
|
382
|
+
return _date;
|
|
383
|
+
}
|
|
384
|
+
const dayOfMonth = _date.getDate();
|
|
385
|
+
// The JS Date object supports date math by accepting out-of-bounds values for
|
|
386
|
+
// month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and
|
|
387
|
+
// new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we
|
|
388
|
+
// want except that dates will wrap around the end of a month, meaning that
|
|
389
|
+
// new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So
|
|
390
|
+
// we'll default to the end of the desired month by adding 1 to the desired
|
|
391
|
+
// month and using a date of 0 to back up one day to the end of the desired
|
|
392
|
+
// month.
|
|
393
|
+
const endOfDesiredMonth = constructFrom(date, _date.getTime());
|
|
394
|
+
endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
|
|
395
|
+
const daysInMonth = endOfDesiredMonth.getDate();
|
|
396
|
+
if (dayOfMonth >= daysInMonth) {
|
|
397
|
+
// If we're already at the end of the month, then this is the correct date
|
|
398
|
+
// and we're done.
|
|
399
|
+
return endOfDesiredMonth;
|
|
400
|
+
} else {
|
|
401
|
+
// Otherwise, we now know that setting the original day-of-month value won't
|
|
402
|
+
// cause an overflow, so set the desired day-of-month. Note that we can't
|
|
403
|
+
// just set the date of `endOfDesiredMonth` because that object may have had
|
|
404
|
+
// its time changed in the unusual case where where a DST transition was on
|
|
405
|
+
// the last day of the month and its local time was in the hour skipped or
|
|
406
|
+
// repeated next to a DST transition. So we use `date` instead which is
|
|
407
|
+
// guaranteed to still have the original time.
|
|
408
|
+
_date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth);
|
|
409
|
+
return _date;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* The {@link addWeeks} function options.
|
|
415
|
+
*/ /**
|
|
416
|
+
* @name addWeeks
|
|
417
|
+
* @category Week Helpers
|
|
418
|
+
* @summary Add the specified number of weeks to the given date.
|
|
419
|
+
*
|
|
420
|
+
* @description
|
|
421
|
+
* Add the specified number of weeks to the given date.
|
|
422
|
+
*
|
|
423
|
+
* @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).
|
|
424
|
+
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
425
|
+
*
|
|
426
|
+
* @param date - The date to be changed
|
|
427
|
+
* @param amount - The amount of weeks to be added.
|
|
428
|
+
* @param options - An object with options
|
|
429
|
+
*
|
|
430
|
+
* @returns The new date with the weeks added
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* // Add 4 weeks to 1 September 2014:
|
|
434
|
+
* const result = addWeeks(new Date(2014, 8, 1), 4)
|
|
435
|
+
* //=> Mon Sep 29 2014 00:00:00
|
|
436
|
+
*/ function addWeeks(date, amount, options) {
|
|
437
|
+
return addDays(date, amount * 7, options);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* The {@link addYears} function options.
|
|
442
|
+
*/ /**
|
|
443
|
+
* @name addYears
|
|
444
|
+
* @category Year Helpers
|
|
445
|
+
* @summary Add the specified number of years to the given date.
|
|
446
|
+
*
|
|
447
|
+
* @description
|
|
448
|
+
* Add the specified number of years to the given date.
|
|
449
|
+
*
|
|
450
|
+
* @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).
|
|
451
|
+
* @typeParam ResultDate - The result `Date` type.
|
|
452
|
+
*
|
|
453
|
+
* @param date - The date to be changed
|
|
454
|
+
* @param amount - The amount of years to be added.
|
|
455
|
+
* @param options - The options
|
|
456
|
+
*
|
|
457
|
+
* @returns The new date with the years added
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* // Add 5 years to 1 September 2014:
|
|
461
|
+
* const result = addYears(new Date(2014, 8, 1), 5)
|
|
462
|
+
* //=> Sun Sep 01 2019 00:00:00
|
|
463
|
+
*/ function addYears(date, amount, options) {
|
|
464
|
+
return addMonths(date, amount * 12, options);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* The {@link max} function options.
|
|
469
|
+
*/ /**
|
|
470
|
+
* @name max
|
|
471
|
+
* @category Common Helpers
|
|
472
|
+
* @summary Return the latest of the given dates.
|
|
473
|
+
*
|
|
474
|
+
* @description
|
|
475
|
+
* Return the latest of the given dates.
|
|
476
|
+
*
|
|
477
|
+
* @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).
|
|
478
|
+
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
479
|
+
*
|
|
480
|
+
* @param dates - The dates to compare
|
|
481
|
+
*
|
|
482
|
+
* @returns The latest of the dates
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* // Which of these dates is the latest?
|
|
486
|
+
* const result = max([
|
|
487
|
+
* new Date(1989, 6, 10),
|
|
488
|
+
* new Date(1987, 1, 11),
|
|
489
|
+
* new Date(1995, 6, 2),
|
|
490
|
+
* new Date(1990, 0, 1)
|
|
491
|
+
* ])
|
|
492
|
+
* //=> Sun Jul 02 1995 00:00:00
|
|
493
|
+
*/ function max(dates, options) {
|
|
494
|
+
let result;
|
|
495
|
+
let context = options?.in;
|
|
496
|
+
dates.forEach((date)=>{
|
|
497
|
+
// Use the first date object as the context function
|
|
498
|
+
if (!context && typeof date === "object") context = constructFrom.bind(null, date);
|
|
499
|
+
const date_ = toDate(date, context);
|
|
500
|
+
if (!result || result < date_ || isNaN(+date_)) result = date_;
|
|
501
|
+
});
|
|
502
|
+
return constructFrom(context, result || NaN);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* The {@link min} function options.
|
|
507
|
+
*/ /**
|
|
508
|
+
* @name min
|
|
509
|
+
* @category Common Helpers
|
|
510
|
+
* @summary Returns the earliest of the given dates.
|
|
511
|
+
*
|
|
512
|
+
* @description
|
|
513
|
+
* Returns the earliest of the given dates.
|
|
514
|
+
*
|
|
515
|
+
* @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).
|
|
516
|
+
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
517
|
+
*
|
|
518
|
+
* @param dates - The dates to compare
|
|
519
|
+
*
|
|
520
|
+
* @returns The earliest of the dates
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* // Which of these dates is the earliest?
|
|
524
|
+
* const result = min([
|
|
525
|
+
* new Date(1989, 6, 10),
|
|
526
|
+
* new Date(1987, 1, 11),
|
|
527
|
+
* new Date(1995, 6, 2),
|
|
528
|
+
* new Date(1990, 0, 1)
|
|
529
|
+
* ])
|
|
530
|
+
* //=> Wed Feb 11 1987 00:00:00
|
|
531
|
+
*/ function min(dates, options) {
|
|
532
|
+
let result;
|
|
533
|
+
let context = options?.in;
|
|
534
|
+
dates.forEach((date)=>{
|
|
535
|
+
// Use the first date object as the context function
|
|
536
|
+
if (!context && typeof date === "object") context = constructFrom.bind(null, date);
|
|
537
|
+
const date_ = toDate(date, context);
|
|
538
|
+
if (!result || result > date_ || isNaN(+date_)) result = date_;
|
|
539
|
+
});
|
|
540
|
+
return constructFrom(context, result || NaN);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* The {@link isSameDay} function options.
|
|
545
|
+
*/ /**
|
|
546
|
+
* @name isSameDay
|
|
547
|
+
* @category Day Helpers
|
|
548
|
+
* @summary Are the given dates in the same day (and year and month)?
|
|
549
|
+
*
|
|
550
|
+
* @description
|
|
551
|
+
* Are the given dates in the same day (and year and month)?
|
|
552
|
+
*
|
|
553
|
+
* @param laterDate - The first date to check
|
|
554
|
+
* @param earlierDate - The second date to check
|
|
555
|
+
* @param options - An object with options
|
|
556
|
+
*
|
|
557
|
+
* @returns The dates are in the same day (and year and month)
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* // Are 4 September 06:00:00 and 4 September 18:00:00 in the same day?
|
|
561
|
+
* const result = isSameDay(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 18, 0))
|
|
562
|
+
* //=> true
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* // Are 4 September and 4 October in the same day?
|
|
566
|
+
* const result = isSameDay(new Date(2014, 8, 4), new Date(2014, 9, 4))
|
|
567
|
+
* //=> false
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
230
570
|
* // Are 4 September, 2014 and 4 September, 2015 in the same day?
|
|
231
571
|
* const result = isSameDay(new Date(2014, 8, 4), new Date(2015, 8, 4))
|
|
232
572
|
* //=> false
|
|
@@ -683,439 +1023,99 @@ function normalizeInterval(context, interval) {
|
|
|
683
1023
|
* //=> false
|
|
684
1024
|
*/ function isSameMonth(laterDate, earlierDate, options) {
|
|
685
1025
|
const [laterDate_, earlierDate_] = normalizeDates(options?.in, laterDate, earlierDate);
|
|
686
|
-
return laterDate_.getFullYear() === earlierDate_.getFullYear() && laterDate_.getMonth() === earlierDate_.getMonth();
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
/**
|
|
690
|
-
* The {@link isSameYear} function options.
|
|
691
|
-
*/ /**
|
|
692
|
-
* @name isSameYear
|
|
693
|
-
* @category Year Helpers
|
|
694
|
-
* @summary Are the given dates in the same year?
|
|
695
|
-
*
|
|
696
|
-
* @description
|
|
697
|
-
* Are the given dates in the same year?
|
|
698
|
-
*
|
|
699
|
-
* @param laterDate - The first date to check
|
|
700
|
-
* @param earlierDate - The second date to check
|
|
701
|
-
* @param options - An object with options
|
|
702
|
-
*
|
|
703
|
-
* @returns The dates are in the same year
|
|
704
|
-
*
|
|
705
|
-
* @example
|
|
706
|
-
* // Are 2 September 2014 and 25 September 2014 in the same year?
|
|
707
|
-
* const result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25))
|
|
708
|
-
* //=> true
|
|
709
|
-
*/ function isSameYear(laterDate, earlierDate, options) {
|
|
710
|
-
const [laterDate_, earlierDate_] = normalizeDates(options?.in, laterDate, earlierDate);
|
|
711
|
-
return laterDate_.getFullYear() === earlierDate_.getFullYear();
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* The {@link setMonth} function options.
|
|
716
|
-
*/ /**
|
|
717
|
-
* @name setMonth
|
|
718
|
-
* @category Month Helpers
|
|
719
|
-
* @summary Set the month to the given date.
|
|
720
|
-
*
|
|
721
|
-
* @description
|
|
722
|
-
* Set the month to the given date.
|
|
723
|
-
*
|
|
724
|
-
* @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).
|
|
725
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
726
|
-
*
|
|
727
|
-
* @param date - The date to be changed
|
|
728
|
-
* @param month - The month index to set (0-11)
|
|
729
|
-
* @param options - The options
|
|
730
|
-
*
|
|
731
|
-
* @returns The new date with the month set
|
|
732
|
-
*
|
|
733
|
-
* @example
|
|
734
|
-
* // Set February to 1 September 2014:
|
|
735
|
-
* const result = setMonth(new Date(2014, 8, 1), 1)
|
|
736
|
-
* //=> Sat Feb 01 2014 00:00:00
|
|
737
|
-
*/ function setMonth(date, month, options) {
|
|
738
|
-
const _date = toDate(date, options?.in);
|
|
739
|
-
const year = _date.getFullYear();
|
|
740
|
-
const day = _date.getDate();
|
|
741
|
-
const midMonth = constructFrom(date, 0);
|
|
742
|
-
midMonth.setFullYear(year, month, 15);
|
|
743
|
-
midMonth.setHours(0, 0, 0, 0);
|
|
744
|
-
const daysInMonth = getDaysInMonth(midMonth);
|
|
745
|
-
// Set the earlier date, allows to wrap Jan 31 to Feb 28
|
|
746
|
-
_date.setMonth(month, Math.min(day, daysInMonth));
|
|
747
|
-
return _date;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/**
|
|
751
|
-
* The {@link setYear} function options.
|
|
752
|
-
*/ /**
|
|
753
|
-
* @name setYear
|
|
754
|
-
* @category Year Helpers
|
|
755
|
-
* @summary Set the year to the given date.
|
|
756
|
-
*
|
|
757
|
-
* @description
|
|
758
|
-
* Set the year to the given date.
|
|
759
|
-
*
|
|
760
|
-
* @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).
|
|
761
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
762
|
-
*
|
|
763
|
-
* @param date - The date to be changed
|
|
764
|
-
* @param year - The year of the new date
|
|
765
|
-
* @param options - An object with options.
|
|
766
|
-
*
|
|
767
|
-
* @returns The new date with the year set
|
|
768
|
-
*
|
|
769
|
-
* @example
|
|
770
|
-
* // Set year 2013 to 1 September 2014:
|
|
771
|
-
* const result = setYear(new Date(2014, 8, 1), 2013)
|
|
772
|
-
* //=> Sun Sep 01 2013 00:00:00
|
|
773
|
-
*/ function setYear(date, year, options) {
|
|
774
|
-
const date_ = toDate(date, options?.in);
|
|
775
|
-
// Check if date is Invalid Date because Date.prototype.setFullYear ignores the value of Invalid Date
|
|
776
|
-
if (isNaN(+date_)) return constructFrom(date, NaN);
|
|
777
|
-
date_.setFullYear(year);
|
|
778
|
-
return date_;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
/**
|
|
782
|
-
* Time zone name format.
|
|
783
|
-
*/ /**
|
|
784
|
-
* The function returns the time zone name for the given date in the specified
|
|
785
|
-
* time zone.
|
|
786
|
-
*
|
|
787
|
-
* It uses the `Intl.DateTimeFormat` API and by default outputs the time zone
|
|
788
|
-
* name in a long format, e.g. "Pacific Standard Time" or
|
|
789
|
-
* "Singapore Standard Time".
|
|
790
|
-
*
|
|
791
|
-
* It is possible to specify the format as the third argument using one of the following options
|
|
792
|
-
*
|
|
793
|
-
* - "short": e.g. "EDT" or "GMT+8".
|
|
794
|
-
* - "long": e.g. "Eastern Daylight Time".
|
|
795
|
-
* - "shortGeneric": e.g. "ET" or "Singapore Time".
|
|
796
|
-
* - "longGeneric": e.g. "Eastern Time" or "Singapore Standard Time".
|
|
797
|
-
*
|
|
798
|
-
* These options correspond to TR35 tokens `z..zzz`, `zzzz`, `v`, and `vvvv` respectively: https://www.unicode.org/reports/tr35/tr35-dates.html#dfst-zone
|
|
799
|
-
*
|
|
800
|
-
* @param timeZone - Time zone name (IANA or UTC offset)
|
|
801
|
-
* @param date - Date object to get the time zone name for
|
|
802
|
-
* @param format - Optional format of the time zone name. Defaults to "long". Can be "short", "long", "shortGeneric", or "longGeneric".
|
|
803
|
-
*
|
|
804
|
-
* @returns Time zone name (e.g. "Singapore Standard Time")
|
|
805
|
-
*/ function tzName(timeZone, date, format = "long") {
|
|
806
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
807
|
-
// Enforces engine to render the time. Without the option JavaScriptCore omits it.
|
|
808
|
-
hour: "numeric",
|
|
809
|
-
timeZone: timeZone,
|
|
810
|
-
timeZoneName: format
|
|
811
|
-
}).format(date).split(/\s/g) // Format.JS uses non-breaking spaces
|
|
812
|
-
.slice(2) // Skip the hour and AM/PM parts
|
|
813
|
-
.join(" ");
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
const offsetFormatCache = {};
|
|
817
|
-
const offsetCache = {};
|
|
818
|
-
/**
|
|
819
|
-
* The function extracts UTC offset in minutes from the given date in specified
|
|
820
|
-
* time zone.
|
|
821
|
-
*
|
|
822
|
-
* Unlike `Date.prototype.getTimezoneOffset`, this function returns the value
|
|
823
|
-
* mirrored to the sign of the offset in the time zone. For Asia/Singapore
|
|
824
|
-
* (UTC+8), `tzOffset` returns 480, while `getTimezoneOffset` returns -480.
|
|
825
|
-
*
|
|
826
|
-
* @param timeZone - Time zone name (IANA or UTC offset)
|
|
827
|
-
* @param date - Date to check the offset for
|
|
828
|
-
*
|
|
829
|
-
* @returns UTC offset in minutes
|
|
830
|
-
*/ function tzOffset(timeZone, date) {
|
|
831
|
-
try {
|
|
832
|
-
var _offsetFormatCache, _timeZone;
|
|
833
|
-
const format = (_offsetFormatCache = offsetFormatCache)[_timeZone = timeZone] || (_offsetFormatCache[_timeZone] = new Intl.DateTimeFormat("en-US", {
|
|
834
|
-
timeZone,
|
|
835
|
-
timeZoneName: "longOffset"
|
|
836
|
-
}).format);
|
|
837
|
-
const offsetStr = format(date).split("GMT")[1];
|
|
838
|
-
if (offsetStr in offsetCache) return offsetCache[offsetStr];
|
|
839
|
-
return calcOffset(offsetStr, offsetStr.split(":"));
|
|
840
|
-
} catch {
|
|
841
|
-
// Fallback to manual parsing if the runtime doesn't support ±HH:MM/±HHMM/±HH
|
|
842
|
-
// See: https://github.com/nodejs/node/issues/53419
|
|
843
|
-
if (timeZone in offsetCache) return offsetCache[timeZone];
|
|
844
|
-
const captures = timeZone?.match(offsetRe);
|
|
845
|
-
if (captures) return calcOffset(timeZone, captures.slice(1));
|
|
846
|
-
return NaN;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
const offsetRe = /([+-]\d\d):?(\d\d)?/;
|
|
850
|
-
function calcOffset(cacheStr, values) {
|
|
851
|
-
const hours = +(values[0] || 0);
|
|
852
|
-
const minutes = +(values[1] || 0);
|
|
853
|
-
// Convert seconds to minutes by dividing by 60 to keep the function return in minutes.
|
|
854
|
-
const seconds = +(values[2] || 0) / 60;
|
|
855
|
-
return offsetCache[cacheStr] = hours * 60 + minutes > 0 ? hours * 60 + minutes + seconds : hours * 60 - minutes - seconds;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
class TZDateMini extends Date {
|
|
859
|
-
static tz(tz, ...args) {
|
|
860
|
-
return args.length ? new TZDateMini(...args, tz) : new TZDateMini(Date.now(), tz);
|
|
861
|
-
}
|
|
862
|
-
//#endregion
|
|
863
|
-
//#region time zone
|
|
864
|
-
withTimeZone(timeZone) {
|
|
865
|
-
return new TZDateMini(+this, timeZone);
|
|
866
|
-
}
|
|
867
|
-
getTimezoneOffset() {
|
|
868
|
-
const offset = -tzOffset(this.timeZone, this);
|
|
869
|
-
// Remove the seconds offset
|
|
870
|
-
// use Math.floor for negative GMT timezones and Math.ceil for positive GMT timezones.
|
|
871
|
-
return offset > 0 ? Math.floor(offset) : Math.ceil(offset);
|
|
872
|
-
}
|
|
873
|
-
//#endregion
|
|
874
|
-
//#region time
|
|
875
|
-
setTime(time) {
|
|
876
|
-
Date.prototype.setTime.apply(this, arguments);
|
|
877
|
-
syncToInternal(this);
|
|
878
|
-
return +this;
|
|
879
|
-
}
|
|
880
|
-
//#endregion
|
|
881
|
-
//#region date-fns integration
|
|
882
|
-
[Symbol.for("constructDateFrom")](date) {
|
|
883
|
-
return new TZDateMini(+new Date(date), this.timeZone);
|
|
884
|
-
}
|
|
885
|
-
//#region static
|
|
886
|
-
constructor(...args){
|
|
887
|
-
super();
|
|
888
|
-
if (args.length > 1 && typeof args[args.length - 1] === "string") {
|
|
889
|
-
this.timeZone = args.pop();
|
|
890
|
-
}
|
|
891
|
-
this.internal = new Date();
|
|
892
|
-
if (isNaN(tzOffset(this.timeZone, this))) {
|
|
893
|
-
this.setTime(NaN);
|
|
894
|
-
} else {
|
|
895
|
-
if (!args.length) {
|
|
896
|
-
this.setTime(Date.now());
|
|
897
|
-
} else if (typeof args[0] === "number" && (args.length === 1 || args.length === 2 && typeof args[1] !== "number")) {
|
|
898
|
-
this.setTime(args[0]);
|
|
899
|
-
} else if (typeof args[0] === "string") {
|
|
900
|
-
this.setTime(+new Date(args[0]));
|
|
901
|
-
} else if (args[0] instanceof Date) {
|
|
902
|
-
this.setTime(+args[0]);
|
|
903
|
-
} else {
|
|
904
|
-
this.setTime(+new Date(...args));
|
|
905
|
-
adjustToSystemTZ(this);
|
|
906
|
-
syncToInternal(this);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
// Assign getters and setters
|
|
912
|
-
const re = /^(get|set)(?!UTC)/;
|
|
913
|
-
Object.getOwnPropertyNames(Date.prototype).forEach((method)=>{
|
|
914
|
-
if (!re.test(method)) return;
|
|
915
|
-
const utcMethod = method.replace(re, "$1UTC");
|
|
916
|
-
// Filter out methods without UTC counterparts
|
|
917
|
-
if (!TZDateMini.prototype[utcMethod]) return;
|
|
918
|
-
if (method.startsWith("get")) {
|
|
919
|
-
// Delegate to internal date's UTC method
|
|
920
|
-
TZDateMini.prototype[method] = function() {
|
|
921
|
-
return this.internal[utcMethod]();
|
|
922
|
-
};
|
|
923
|
-
} else {
|
|
924
|
-
// Assign regular setter
|
|
925
|
-
TZDateMini.prototype[method] = function() {
|
|
926
|
-
Date.prototype[utcMethod].apply(this.internal, arguments);
|
|
927
|
-
syncFromInternal(this);
|
|
928
|
-
return +this;
|
|
929
|
-
};
|
|
930
|
-
// Assign UTC setter
|
|
931
|
-
TZDateMini.prototype[utcMethod] = function() {
|
|
932
|
-
Date.prototype[utcMethod].apply(this, arguments);
|
|
933
|
-
syncToInternal(this);
|
|
934
|
-
return +this;
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
});
|
|
938
|
-
/**
|
|
939
|
-
* Function syncs time to internal date, applying the time zone offset.
|
|
940
|
-
*
|
|
941
|
-
* @param {Date} date - Date to sync
|
|
942
|
-
*/ function syncToInternal(date) {
|
|
943
|
-
date.internal.setTime(+date);
|
|
944
|
-
date.internal.setUTCSeconds(date.internal.getUTCSeconds() - Math.round(-tzOffset(date.timeZone, date) * 60));
|
|
945
|
-
}
|
|
946
|
-
/**
|
|
947
|
-
* Function syncs the internal date UTC values to the date. It allows to get
|
|
948
|
-
* accurate timestamp value.
|
|
949
|
-
*
|
|
950
|
-
* @param {Date} date - The date to sync
|
|
951
|
-
*/ function syncFromInternal(date) {
|
|
952
|
-
// First we transpose the internal values
|
|
953
|
-
Date.prototype.setFullYear.call(date, date.internal.getUTCFullYear(), date.internal.getUTCMonth(), date.internal.getUTCDate());
|
|
954
|
-
Date.prototype.setHours.call(date, date.internal.getUTCHours(), date.internal.getUTCMinutes(), date.internal.getUTCSeconds(), date.internal.getUTCMilliseconds());
|
|
955
|
-
// Now we have to adjust the date to the system time zone
|
|
956
|
-
adjustToSystemTZ(date);
|
|
957
|
-
}
|
|
958
|
-
/**
|
|
959
|
-
* Function adjusts the date to the system time zone. It uses the time zone
|
|
960
|
-
* differences to calculate the offset and adjust the date.
|
|
961
|
-
*
|
|
962
|
-
* @param {Date} date - Date to adjust
|
|
963
|
-
*/ function adjustToSystemTZ(date) {
|
|
964
|
-
// Save the time zone offset before all the adjustments
|
|
965
|
-
const baseOffset = tzOffset(date.timeZone, date);
|
|
966
|
-
// Remove the seconds offset
|
|
967
|
-
// use Math.floor for negative GMT timezones and Math.ceil for positive GMT timezones.
|
|
968
|
-
const offset = baseOffset > 0 ? Math.floor(baseOffset) : Math.ceil(baseOffset);
|
|
969
|
-
//#region System DST adjustment
|
|
970
|
-
// The biggest problem with using the system time zone is that when we create
|
|
971
|
-
// a date from internal values stored in UTC, the system time zone might end
|
|
972
|
-
// up on the DST hour:
|
|
973
|
-
//
|
|
974
|
-
// $ TZ=America/New_York node
|
|
975
|
-
// > new Date(2020, 2, 8, 1).toString()
|
|
976
|
-
// 'Sun Mar 08 2020 01:00:00 GMT-0500 (Eastern Standard Time)'
|
|
977
|
-
// > new Date(2020, 2, 8, 2).toString()
|
|
978
|
-
// 'Sun Mar 08 2020 03:00:00 GMT-0400 (Eastern Daylight Time)'
|
|
979
|
-
// > new Date(2020, 2, 8, 3).toString()
|
|
980
|
-
// 'Sun Mar 08 2020 03:00:00 GMT-0400 (Eastern Daylight Time)'
|
|
981
|
-
// > new Date(2020, 2, 8, 4).toString()
|
|
982
|
-
// 'Sun Mar 08 2020 04:00:00 GMT-0400 (Eastern Daylight Time)'
|
|
983
|
-
//
|
|
984
|
-
// Here we get the same hour for both 2 and 3, because the system time zone
|
|
985
|
-
// has DST beginning at 8 March 2020, 2 a.m. and jumps to 3 a.m. So we have
|
|
986
|
-
// to adjust the internal date to reflect that.
|
|
987
|
-
//
|
|
988
|
-
// However we want to adjust only if that's the DST hour the change happenes,
|
|
989
|
-
// not the hour where DST moves to.
|
|
990
|
-
// We calculate the previous hour to see if the time zone offset has changed
|
|
991
|
-
// and we have landed on the DST hour.
|
|
992
|
-
const prevHour = new Date(+date);
|
|
993
|
-
// We use UTC methods here as we don't want to land on the same hour again
|
|
994
|
-
// in case of DST.
|
|
995
|
-
prevHour.setUTCHours(prevHour.getUTCHours() - 1);
|
|
996
|
-
// Calculate if we are on the system DST hour.
|
|
997
|
-
const systemOffset = -new Date(+date).getTimezoneOffset();
|
|
998
|
-
const prevHourSystemOffset = -new Date(+prevHour).getTimezoneOffset();
|
|
999
|
-
const systemDSTChange = systemOffset - prevHourSystemOffset;
|
|
1000
|
-
// Detect the DST shift. System DST change will occur both on
|
|
1001
|
-
const dstShift = Date.prototype.getHours.apply(date) !== date.internal.getUTCHours();
|
|
1002
|
-
// Move the internal date when we are on the system DST hour.
|
|
1003
|
-
if (systemDSTChange && dstShift) date.internal.setUTCMinutes(date.internal.getUTCMinutes() + systemDSTChange);
|
|
1004
|
-
//#endregion
|
|
1005
|
-
//#region System diff adjustment
|
|
1006
|
-
// Now we need to adjust the date, since we just applied internal values.
|
|
1007
|
-
// We need to calculate the difference between the system and date time zones
|
|
1008
|
-
// and apply it to the date.
|
|
1009
|
-
const offsetDiff = systemOffset - offset;
|
|
1010
|
-
if (offsetDiff) Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetDiff);
|
|
1011
|
-
//#endregion
|
|
1012
|
-
//#region Seconds System diff adjustment
|
|
1013
|
-
const systemDate = new Date(+date);
|
|
1014
|
-
// Set the UTC seconds to 0 to isolate the timezone offset in seconds.
|
|
1015
|
-
systemDate.setUTCSeconds(0);
|
|
1016
|
-
// For negative systemOffset, invert the seconds.
|
|
1017
|
-
const systemSecondsOffset = systemOffset > 0 ? systemDate.getSeconds() : (systemDate.getSeconds() - 60) % 60;
|
|
1018
|
-
// Calculate the seconds offset based on the timezone offset.
|
|
1019
|
-
const secondsOffset = Math.round(-(tzOffset(date.timeZone, date) * 60)) % 60;
|
|
1020
|
-
if (secondsOffset || systemSecondsOffset) {
|
|
1021
|
-
date.internal.setUTCSeconds(date.internal.getUTCSeconds() + secondsOffset);
|
|
1022
|
-
Date.prototype.setUTCSeconds.call(date, Date.prototype.getUTCSeconds.call(date) + secondsOffset + systemSecondsOffset);
|
|
1023
|
-
}
|
|
1024
|
-
//#endregion
|
|
1025
|
-
//#region Post-adjustment DST fix
|
|
1026
|
-
const postBaseOffset = tzOffset(date.timeZone, date);
|
|
1027
|
-
// Remove the seconds offset
|
|
1028
|
-
// use Math.floor for negative GMT timezones and Math.ceil for positive GMT timezones.
|
|
1029
|
-
const postOffset = postBaseOffset > 0 ? Math.floor(postBaseOffset) : Math.ceil(postBaseOffset);
|
|
1030
|
-
const postSystemOffset = -new Date(+date).getTimezoneOffset();
|
|
1031
|
-
const postOffsetDiff = postSystemOffset - postOffset;
|
|
1032
|
-
const offsetChanged = postOffset !== offset;
|
|
1033
|
-
const postDiff = postOffsetDiff - offsetDiff;
|
|
1034
|
-
if (offsetChanged && postDiff) {
|
|
1035
|
-
Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + postDiff);
|
|
1036
|
-
// Now we need to check if got offset change during the post-adjustment.
|
|
1037
|
-
// If so, we also need both dates to reflect that.
|
|
1038
|
-
const newBaseOffset = tzOffset(date.timeZone, date);
|
|
1039
|
-
// Remove the seconds offset
|
|
1040
|
-
// use Math.floor for negative GMT timezones and Math.ceil for positive GMT timezones.
|
|
1041
|
-
const newOffset = newBaseOffset > 0 ? Math.floor(newBaseOffset) : Math.ceil(newBaseOffset);
|
|
1042
|
-
const offsetChange = postOffset - newOffset;
|
|
1043
|
-
if (offsetChange) {
|
|
1044
|
-
date.internal.setUTCMinutes(date.internal.getUTCMinutes() + offsetChange);
|
|
1045
|
-
Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetChange);
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
//#endregion
|
|
1026
|
+
return laterDate_.getFullYear() === earlierDate_.getFullYear() && laterDate_.getMonth() === earlierDate_.getMonth();
|
|
1049
1027
|
}
|
|
1050
1028
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1029
|
+
/**
|
|
1030
|
+
* The {@link isSameYear} function options.
|
|
1031
|
+
*/ /**
|
|
1032
|
+
* @name isSameYear
|
|
1033
|
+
* @category Year Helpers
|
|
1034
|
+
* @summary Are the given dates in the same year?
|
|
1035
|
+
*
|
|
1036
|
+
* @description
|
|
1037
|
+
* Are the given dates in the same year?
|
|
1038
|
+
*
|
|
1039
|
+
* @param laterDate - The first date to check
|
|
1040
|
+
* @param earlierDate - The second date to check
|
|
1041
|
+
* @param options - An object with options
|
|
1042
|
+
*
|
|
1043
|
+
* @returns The dates are in the same year
|
|
1044
|
+
*
|
|
1045
|
+
* @example
|
|
1046
|
+
* // Are 2 September 2014 and 25 September 2014 in the same year?
|
|
1047
|
+
* const result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25))
|
|
1048
|
+
* //=> true
|
|
1049
|
+
*/ function isSameYear(laterDate, earlierDate, options) {
|
|
1050
|
+
const [laterDate_, earlierDate_] = normalizeDates(options?.in, laterDate, earlierDate);
|
|
1051
|
+
return laterDate_.getFullYear() === earlierDate_.getFullYear();
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* The {@link setMonth} function options.
|
|
1056
|
+
*/ /**
|
|
1057
|
+
* @name setMonth
|
|
1058
|
+
* @category Month Helpers
|
|
1059
|
+
* @summary Set the month to the given date.
|
|
1060
|
+
*
|
|
1061
|
+
* @description
|
|
1062
|
+
* Set the month to the given date.
|
|
1063
|
+
*
|
|
1064
|
+
* @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).
|
|
1065
|
+
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
1066
|
+
*
|
|
1067
|
+
* @param date - The date to be changed
|
|
1068
|
+
* @param month - The month index to set (0-11)
|
|
1069
|
+
* @param options - The options
|
|
1070
|
+
*
|
|
1071
|
+
* @returns The new date with the month set
|
|
1072
|
+
*
|
|
1073
|
+
* @example
|
|
1074
|
+
* // Set February to 1 September 2014:
|
|
1075
|
+
* const result = setMonth(new Date(2014, 8, 1), 1)
|
|
1076
|
+
* //=> Sat Feb 01 2014 00:00:00
|
|
1077
|
+
*/ function setMonth(date, month, options) {
|
|
1078
|
+
const _date = toDate(date, options?.in);
|
|
1079
|
+
const year = _date.getFullYear();
|
|
1080
|
+
const day = _date.getDate();
|
|
1081
|
+
const midMonth = constructFrom(date, 0);
|
|
1082
|
+
midMonth.setFullYear(year, month, 15);
|
|
1083
|
+
midMonth.setHours(0, 0, 0, 0);
|
|
1084
|
+
const daysInMonth = getDaysInMonth(midMonth);
|
|
1085
|
+
// Set the earlier date, allows to wrap Jan 31 to Feb 28
|
|
1086
|
+
_date.setMonth(month, Math.min(day, daysInMonth));
|
|
1087
|
+
return _date;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* The {@link setYear} function options.
|
|
1092
|
+
*/ /**
|
|
1093
|
+
* @name setYear
|
|
1094
|
+
* @category Year Helpers
|
|
1095
|
+
* @summary Set the year to the given date.
|
|
1096
|
+
*
|
|
1097
|
+
* @description
|
|
1098
|
+
* Set the year to the given date.
|
|
1099
|
+
*
|
|
1100
|
+
* @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).
|
|
1101
|
+
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
1102
|
+
*
|
|
1103
|
+
* @param date - The date to be changed
|
|
1104
|
+
* @param year - The year of the new date
|
|
1105
|
+
* @param options - An object with options.
|
|
1106
|
+
*
|
|
1107
|
+
* @returns The new date with the year set
|
|
1108
|
+
*
|
|
1109
|
+
* @example
|
|
1110
|
+
* // Set year 2013 to 1 September 2014:
|
|
1111
|
+
* const result = setYear(new Date(2014, 8, 1), 2013)
|
|
1112
|
+
* //=> Sun Sep 01 2013 00:00:00
|
|
1113
|
+
*/ function setYear(date, year, options) {
|
|
1114
|
+
const date_ = toDate(date, options?.in);
|
|
1115
|
+
// Check if date is Invalid Date because Date.prototype.setFullYear ignores the value of Invalid Date
|
|
1116
|
+
if (isNaN(+date_)) return constructFrom(date, NaN);
|
|
1117
|
+
date_.setFullYear(year);
|
|
1118
|
+
return date_;
|
|
1119
1119
|
}
|
|
1120
1120
|
|
|
1121
1121
|
const FIVE_WEEKS = 5;
|
|
@@ -1182,6 +1182,74 @@ const FOUR_WEEKS = 4;
|
|
|
1182
1182
|
return endDate;
|
|
1183
1183
|
}
|
|
1184
1184
|
|
|
1185
|
+
/** English (United States) locale extended with DayPicker-specific translations. */ const enUS = {
|
|
1186
|
+
...enUS$1,
|
|
1187
|
+
labels: {
|
|
1188
|
+
labelDayButton: (date, modifiers, options, dateLib)=>{
|
|
1189
|
+
let formatDate;
|
|
1190
|
+
if (dateLib && typeof dateLib.format === "function") {
|
|
1191
|
+
formatDate = dateLib.format.bind(dateLib);
|
|
1192
|
+
} else {
|
|
1193
|
+
formatDate = (d, pattern)=>format(d, pattern, {
|
|
1194
|
+
locale: enUS$1,
|
|
1195
|
+
...options
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
let label = formatDate(date, "PPPP");
|
|
1199
|
+
if (modifiers.today) label = `Today, ${label}`;
|
|
1200
|
+
if (modifiers.selected) label = `${label}, selected`;
|
|
1201
|
+
return label;
|
|
1202
|
+
},
|
|
1203
|
+
labelMonthDropdown: "Choose the Month",
|
|
1204
|
+
labelNext: "Go to the Next Month",
|
|
1205
|
+
labelPrevious: "Go to the Previous Month",
|
|
1206
|
+
labelWeekNumber: (weekNumber)=>`Week ${weekNumber}`,
|
|
1207
|
+
labelYearDropdown: "Choose the Year",
|
|
1208
|
+
labelGrid: (date, options, dateLib)=>{
|
|
1209
|
+
let formatDate;
|
|
1210
|
+
if (dateLib && typeof dateLib.format === "function") {
|
|
1211
|
+
formatDate = dateLib.format.bind(dateLib);
|
|
1212
|
+
} else {
|
|
1213
|
+
formatDate = (d, pattern)=>format(d, pattern, {
|
|
1214
|
+
locale: enUS$1,
|
|
1215
|
+
...options
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
return formatDate(date, "LLLL yyyy");
|
|
1219
|
+
},
|
|
1220
|
+
labelGridcell: (date, modifiers, options, dateLib)=>{
|
|
1221
|
+
let formatDate;
|
|
1222
|
+
if (dateLib && typeof dateLib.format === "function") {
|
|
1223
|
+
formatDate = dateLib.format.bind(dateLib);
|
|
1224
|
+
} else {
|
|
1225
|
+
formatDate = (d, pattern)=>format(d, pattern, {
|
|
1226
|
+
locale: enUS$1,
|
|
1227
|
+
...options
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
let label = formatDate(date, "PPPP");
|
|
1231
|
+
if (modifiers?.today) {
|
|
1232
|
+
label = `Today, ${label}`;
|
|
1233
|
+
}
|
|
1234
|
+
return label;
|
|
1235
|
+
},
|
|
1236
|
+
labelNav: "Navigation bar",
|
|
1237
|
+
labelWeekNumberHeader: "Week Number",
|
|
1238
|
+
labelWeekday: (date, options, dateLib)=>{
|
|
1239
|
+
let formatDate;
|
|
1240
|
+
if (dateLib && typeof dateLib.format === "function") {
|
|
1241
|
+
formatDate = dateLib.format.bind(dateLib);
|
|
1242
|
+
} else {
|
|
1243
|
+
formatDate = (d, pattern)=>format(d, pattern, {
|
|
1244
|
+
locale: enUS$1,
|
|
1245
|
+
...options
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
return formatDate(date, "cccc");
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1185
1253
|
/**
|
|
1186
1254
|
* A wrapper class around [date-fns](http://date-fns.org) that provides utility
|
|
1187
1255
|
* methods for date manipulation and formatting.
|
|
@@ -1661,6 +1729,9 @@ DateLib.yearFirstLocales = new Set([
|
|
|
1661
1729
|
this.displayMonth = displayMonth;
|
|
1662
1730
|
this.outside = Boolean(displayMonth && !dateLib.isSameMonth(date, displayMonth));
|
|
1663
1731
|
this.dateLib = dateLib;
|
|
1732
|
+
this.isoDate = dateLib.format(date, "yyyy-MM-dd");
|
|
1733
|
+
this.displayMonthId = dateLib.format(displayMonth, "yyyy-MM");
|
|
1734
|
+
this.dateMonthId = dateLib.format(date, "yyyy-MM");
|
|
1664
1735
|
}
|
|
1665
1736
|
}
|
|
1666
1737
|
|
|
@@ -2309,7 +2380,7 @@ var components = /*#__PURE__*/Object.freeze({
|
|
|
2309
2380
|
return isSameDay(date, matcher);
|
|
2310
2381
|
}
|
|
2311
2382
|
if (isDatesArray(matcher, dateLib)) {
|
|
2312
|
-
return matcher.
|
|
2383
|
+
return matcher.some((matcherDate)=>isSameDay(date, matcherDate));
|
|
2313
2384
|
}
|
|
2314
2385
|
if (isDateRange(matcher)) {
|
|
2315
2386
|
return rangeIncludesDate(matcher, date, false, dateLib);
|
|
@@ -2358,7 +2429,7 @@ var components = /*#__PURE__*/Object.freeze({
|
|
|
2358
2429
|
* @param dateLib The date library to use for date manipulation.
|
|
2359
2430
|
* @returns A function that retrieves the modifiers for a given `CalendarDay`.
|
|
2360
2431
|
*/ function createGetModifiers(days, props, navStart, navEnd, dateLib) {
|
|
2361
|
-
const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today } = props;
|
|
2432
|
+
const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today = dateLib.today() } = props;
|
|
2362
2433
|
const { isSameDay, isSameMonth, startOfMonth, isBefore, endOfMonth, isAfter } = dateLib;
|
|
2363
2434
|
const computedNavStart = navStart && startOfMonth(navStart);
|
|
2364
2435
|
const computedNavEnd = navEnd && endOfMonth(navEnd);
|
|
@@ -2378,7 +2449,7 @@ var components = /*#__PURE__*/Object.freeze({
|
|
|
2378
2449
|
const isDisabled = Boolean(disabled && dateMatchModifiers(date, disabled, dateLib));
|
|
2379
2450
|
const isHidden = Boolean(hidden && dateMatchModifiers(date, hidden, dateLib)) || isBeforeNavStart || isAfterNavEnd || // Broadcast calendar will show outside days as default
|
|
2380
2451
|
!broadcastCalendar && !showOutsideDays && isOutside || broadcastCalendar && showOutsideDays === false && isOutside;
|
|
2381
|
-
const isToday = isSameDay(date, today
|
|
2452
|
+
const isToday = isSameDay(date, today);
|
|
2382
2453
|
if (isOutside) internalModifiersMap.outside.push(day);
|
|
2383
2454
|
if (isDisabled) internalModifiersMap.disabled.push(day);
|
|
2384
2455
|
if (isHidden) internalModifiersMap.hidden.push(day);
|
|
@@ -2639,136 +2710,26 @@ var defaultFormatters = /*#__PURE__*/Object.freeze({
|
|
|
2639
2710
|
formatWeekNumberHeader: formatWeekNumberHeader,
|
|
2640
2711
|
formatWeekdayName: formatWeekdayName,
|
|
2641
2712
|
formatYearCaption: formatYearCaption,
|
|
2642
|
-
formatYearDropdown: formatYearDropdown
|
|
2643
|
-
});
|
|
2644
|
-
|
|
2645
|
-
/**
|
|
2646
|
-
* Merges custom formatters from the props with the default formatters.
|
|
2647
|
-
*
|
|
2648
|
-
* @param customFormatters The custom formatters provided in the DayPicker
|
|
2649
|
-
* props.
|
|
2650
|
-
* @returns The merged formatters object.
|
|
2651
|
-
*/ function getFormatters(customFormatters) {
|
|
2652
|
-
if (customFormatters?.formatMonthCaption && !customFormatters.formatCaption) {
|
|
2653
|
-
customFormatters.formatCaption = customFormatters.formatMonthCaption;
|
|
2654
|
-
}
|
|
2655
|
-
if (customFormatters?.formatYearCaption && !customFormatters.formatYearDropdown) {
|
|
2656
|
-
customFormatters.formatYearDropdown = customFormatters.formatYearCaption;
|
|
2657
|
-
}
|
|
2658
|
-
return {
|
|
2659
|
-
...defaultFormatters,
|
|
2660
|
-
...customFormatters
|
|
2661
|
-
};
|
|
2662
|
-
}
|
|
2663
|
-
|
|
2664
|
-
/**
|
|
2665
|
-
* Returns the months to show in the dropdown.
|
|
2666
|
-
*
|
|
2667
|
-
* This function generates a list of months for the current year, formatted
|
|
2668
|
-
* using the provided formatter, and determines whether each month should be
|
|
2669
|
-
* disabled based on the navigation range.
|
|
2670
|
-
*
|
|
2671
|
-
* @param displayMonth The currently displayed month.
|
|
2672
|
-
* @param navStart The start date for navigation.
|
|
2673
|
-
* @param navEnd The end date for navigation.
|
|
2674
|
-
* @param formatters The formatters to use for formatting the month labels.
|
|
2675
|
-
* @param dateLib The date library to use for date manipulation.
|
|
2676
|
-
* @returns An array of dropdown options representing the months, or `undefined`
|
|
2677
|
-
* if no months are available.
|
|
2678
|
-
*/ function getMonthOptions(displayMonth, navStart, navEnd, formatters, dateLib) {
|
|
2679
|
-
const { startOfMonth, startOfYear, endOfYear, eachMonthOfInterval, getMonth } = dateLib;
|
|
2680
|
-
const months = eachMonthOfInterval({
|
|
2681
|
-
start: startOfYear(displayMonth),
|
|
2682
|
-
end: endOfYear(displayMonth)
|
|
2683
|
-
});
|
|
2684
|
-
const options = months.map((month)=>{
|
|
2685
|
-
const label = formatters.formatMonthDropdown(month, dateLib);
|
|
2686
|
-
const value = getMonth(month);
|
|
2687
|
-
const disabled = navStart && month < startOfMonth(navStart) || navEnd && month > startOfMonth(navEnd) || false;
|
|
2688
|
-
return {
|
|
2689
|
-
value,
|
|
2690
|
-
label,
|
|
2691
|
-
disabled
|
|
2692
|
-
};
|
|
2693
|
-
});
|
|
2694
|
-
return options;
|
|
2695
|
-
}
|
|
2696
|
-
|
|
2697
|
-
/**
|
|
2698
|
-
* Returns the computed style for a day based on its modifiers.
|
|
2699
|
-
*
|
|
2700
|
-
* This function merges the base styles for the day with any styles associated
|
|
2701
|
-
* with active modifiers.
|
|
2702
|
-
*
|
|
2703
|
-
* @param dayModifiers The modifiers applied to the day.
|
|
2704
|
-
* @param styles The base styles for the calendar elements.
|
|
2705
|
-
* @param modifiersStyles The styles associated with specific modifiers.
|
|
2706
|
-
* @returns The computed style for the day.
|
|
2707
|
-
*/ function getStyleForModifiers(dayModifiers, styles = {}, modifiersStyles = {}) {
|
|
2708
|
-
let style = {
|
|
2709
|
-
...styles?.[UI.Day]
|
|
2710
|
-
};
|
|
2711
|
-
Object.entries(dayModifiers).filter(([, active])=>active === true).forEach(([modifier])=>{
|
|
2712
|
-
style = {
|
|
2713
|
-
...style,
|
|
2714
|
-
...modifiersStyles?.[modifier]
|
|
2715
|
-
};
|
|
2716
|
-
});
|
|
2717
|
-
return style;
|
|
2718
|
-
}
|
|
2713
|
+
formatYearDropdown: formatYearDropdown
|
|
2714
|
+
});
|
|
2719
2715
|
|
|
2720
2716
|
/**
|
|
2721
|
-
*
|
|
2722
|
-
* for formatting weekday names (e.g., Monday, Tuesday, etc.).
|
|
2717
|
+
* Merges custom formatters from the props with the default formatters.
|
|
2723
2718
|
*
|
|
2724
|
-
* @param
|
|
2725
|
-
*
|
|
2726
|
-
* @
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
const today = dateLib.today();
|
|
2731
|
-
const start = ISOWeek ? dateLib.startOfISOWeek(today) : dateLib.startOfWeek(today);
|
|
2732
|
-
const days = [];
|
|
2733
|
-
for(let i = 0; i < 7; i++){
|
|
2734
|
-
const day = dateLib.addDays(start, i);
|
|
2735
|
-
days.push(day);
|
|
2719
|
+
* @param customFormatters The custom formatters provided in the DayPicker
|
|
2720
|
+
* props.
|
|
2721
|
+
* @returns The merged formatters object.
|
|
2722
|
+
*/ function getFormatters(customFormatters) {
|
|
2723
|
+
if (customFormatters?.formatMonthCaption && !customFormatters.formatCaption) {
|
|
2724
|
+
customFormatters.formatCaption = customFormatters.formatMonthCaption;
|
|
2736
2725
|
}
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
* dates, formatted using the provided formatter.
|
|
2745
|
-
*
|
|
2746
|
-
* @param navStart The start date for navigation.
|
|
2747
|
-
* @param navEnd The end date for navigation.
|
|
2748
|
-
* @param formatters The formatters to use for formatting the year labels.
|
|
2749
|
-
* @param dateLib The date library to use for date manipulation.
|
|
2750
|
-
* @param reverse If true, reverses the order of the years (descending).
|
|
2751
|
-
* @returns An array of dropdown options representing the years, or `undefined`
|
|
2752
|
-
* if `navStart` or `navEnd` is not provided.
|
|
2753
|
-
*/ function getYearOptions(navStart, navEnd, formatters, dateLib, reverse = false) {
|
|
2754
|
-
if (!navStart) return undefined;
|
|
2755
|
-
if (!navEnd) return undefined;
|
|
2756
|
-
const { startOfYear, endOfYear, eachYearOfInterval, getYear } = dateLib;
|
|
2757
|
-
const firstNavYear = startOfYear(navStart);
|
|
2758
|
-
const lastNavYear = endOfYear(navEnd);
|
|
2759
|
-
const years = eachYearOfInterval({
|
|
2760
|
-
start: firstNavYear,
|
|
2761
|
-
end: lastNavYear
|
|
2762
|
-
});
|
|
2763
|
-
if (reverse) years.reverse();
|
|
2764
|
-
return years.map((year)=>{
|
|
2765
|
-
const label = formatters.formatYearDropdown(year, dateLib);
|
|
2766
|
-
return {
|
|
2767
|
-
value: getYear(year),
|
|
2768
|
-
label,
|
|
2769
|
-
disabled: false
|
|
2770
|
-
};
|
|
2771
|
-
});
|
|
2726
|
+
if (customFormatters?.formatYearCaption && !customFormatters.formatYearDropdown) {
|
|
2727
|
+
customFormatters.formatYearDropdown = customFormatters.formatYearCaption;
|
|
2728
|
+
}
|
|
2729
|
+
return {
|
|
2730
|
+
...defaultFormatters,
|
|
2731
|
+
...customFormatters
|
|
2732
|
+
};
|
|
2772
2733
|
}
|
|
2773
2734
|
|
|
2774
2735
|
/**
|
|
@@ -2857,6 +2818,7 @@ var defaultFormatters = /*#__PURE__*/Object.freeze({
|
|
|
2857
2818
|
return "";
|
|
2858
2819
|
}
|
|
2859
2820
|
|
|
2821
|
+
const defaultLabel = "Go to the Next Month";
|
|
2860
2822
|
/**
|
|
2861
2823
|
* Generates the ARIA label for the "next month" button.
|
|
2862
2824
|
*
|
|
@@ -2866,8 +2828,8 @@ var defaultFormatters = /*#__PURE__*/Object.freeze({
|
|
|
2866
2828
|
* @returns The ARIA label for the "next month" button.
|
|
2867
2829
|
* @group Labels
|
|
2868
2830
|
* @see https://daypicker.dev/docs/translation#aria-labels
|
|
2869
|
-
*/ function labelNext(_month) {
|
|
2870
|
-
return
|
|
2831
|
+
*/ function labelNext(_month, _options) {
|
|
2832
|
+
return defaultLabel;
|
|
2871
2833
|
}
|
|
2872
2834
|
|
|
2873
2835
|
/**
|
|
@@ -2951,6 +2913,297 @@ var defaultLabels = /*#__PURE__*/Object.freeze({
|
|
|
2951
2913
|
labelYearDropdown: labelYearDropdown
|
|
2952
2914
|
});
|
|
2953
2915
|
|
|
2916
|
+
const resolveLabel = (defaultLabel, customLabel, localeLabel)=>{
|
|
2917
|
+
if (customLabel) return customLabel;
|
|
2918
|
+
if (localeLabel) {
|
|
2919
|
+
return typeof localeLabel === "function" ? localeLabel : (..._args)=>localeLabel;
|
|
2920
|
+
}
|
|
2921
|
+
return defaultLabel;
|
|
2922
|
+
};
|
|
2923
|
+
/**
|
|
2924
|
+
* Merges custom labels from the props with the default labels.
|
|
2925
|
+
*
|
|
2926
|
+
* When available, uses the locale-provided translation for `labelNext`.
|
|
2927
|
+
*
|
|
2928
|
+
* @param customLabels The custom labels provided in the DayPicker props.
|
|
2929
|
+
* @param options Options from the date library, used to resolve locale
|
|
2930
|
+
* translations.
|
|
2931
|
+
* @returns The merged labels object with locale-aware defaults.
|
|
2932
|
+
*/ function getLabels(customLabels, options) {
|
|
2933
|
+
const localeLabels = options.locale?.labels ?? {};
|
|
2934
|
+
return {
|
|
2935
|
+
...defaultLabels,
|
|
2936
|
+
...customLabels ?? {},
|
|
2937
|
+
labelDayButton: resolveLabel(labelDayButton, customLabels?.labelDayButton, localeLabels.labelDayButton),
|
|
2938
|
+
labelMonthDropdown: resolveLabel(labelMonthDropdown, customLabels?.labelMonthDropdown, localeLabels.labelMonthDropdown),
|
|
2939
|
+
labelNext: resolveLabel(labelNext, customLabels?.labelNext, localeLabels.labelNext),
|
|
2940
|
+
labelPrevious: resolveLabel(labelPrevious, customLabels?.labelPrevious, localeLabels.labelPrevious),
|
|
2941
|
+
labelWeekNumber: resolveLabel(labelWeekNumber, customLabels?.labelWeekNumber, localeLabels.labelWeekNumber),
|
|
2942
|
+
labelYearDropdown: resolveLabel(labelYearDropdown, customLabels?.labelYearDropdown, localeLabels.labelYearDropdown),
|
|
2943
|
+
labelGrid: resolveLabel(labelGrid, customLabels?.labelGrid, localeLabels.labelGrid),
|
|
2944
|
+
labelGridcell: resolveLabel(labelGridcell, customLabels?.labelGridcell, localeLabels.labelGridcell),
|
|
2945
|
+
labelNav: resolveLabel(labelNav, customLabels?.labelNav, localeLabels.labelNav),
|
|
2946
|
+
labelWeekNumberHeader: resolveLabel(labelWeekNumberHeader, customLabels?.labelWeekNumberHeader, localeLabels.labelWeekNumberHeader),
|
|
2947
|
+
labelWeekday: resolveLabel(labelWeekday, customLabels?.labelWeekday, localeLabels.labelWeekday)
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
/**
|
|
2952
|
+
* Returns the months to show in the dropdown.
|
|
2953
|
+
*
|
|
2954
|
+
* This function generates a list of months for the current year, formatted
|
|
2955
|
+
* using the provided formatter, and determines whether each month should be
|
|
2956
|
+
* disabled based on the navigation range.
|
|
2957
|
+
*
|
|
2958
|
+
* @param displayMonth The currently displayed month.
|
|
2959
|
+
* @param navStart The start date for navigation.
|
|
2960
|
+
* @param navEnd The end date for navigation.
|
|
2961
|
+
* @param formatters The formatters to use for formatting the month labels.
|
|
2962
|
+
* @param dateLib The date library to use for date manipulation.
|
|
2963
|
+
* @returns An array of dropdown options representing the months, or `undefined`
|
|
2964
|
+
* if no months are available.
|
|
2965
|
+
*/ function getMonthOptions(displayMonth, navStart, navEnd, formatters, dateLib) {
|
|
2966
|
+
const { startOfMonth, startOfYear, endOfYear, eachMonthOfInterval, getMonth } = dateLib;
|
|
2967
|
+
const months = eachMonthOfInterval({
|
|
2968
|
+
start: startOfYear(displayMonth),
|
|
2969
|
+
end: endOfYear(displayMonth)
|
|
2970
|
+
});
|
|
2971
|
+
const options = months.map((month)=>{
|
|
2972
|
+
const label = formatters.formatMonthDropdown(month, dateLib);
|
|
2973
|
+
const value = getMonth(month);
|
|
2974
|
+
const disabled = navStart && month < startOfMonth(navStart) || navEnd && month > startOfMonth(navEnd) || false;
|
|
2975
|
+
return {
|
|
2976
|
+
value,
|
|
2977
|
+
label,
|
|
2978
|
+
disabled
|
|
2979
|
+
};
|
|
2980
|
+
});
|
|
2981
|
+
return options;
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
/**
|
|
2985
|
+
* Returns the computed style for a day based on its modifiers.
|
|
2986
|
+
*
|
|
2987
|
+
* This function merges the base styles for the day with any styles associated
|
|
2988
|
+
* with active modifiers.
|
|
2989
|
+
*
|
|
2990
|
+
* @param dayModifiers The modifiers applied to the day.
|
|
2991
|
+
* @param styles The base styles for the calendar elements.
|
|
2992
|
+
* @param modifiersStyles The styles associated with specific modifiers.
|
|
2993
|
+
* @returns The computed style for the day.
|
|
2994
|
+
*/ function getStyleForModifiers(dayModifiers, styles = {}, modifiersStyles = {}) {
|
|
2995
|
+
let style = {
|
|
2996
|
+
...styles?.[UI.Day]
|
|
2997
|
+
};
|
|
2998
|
+
Object.entries(dayModifiers).filter(([, active])=>active === true).forEach(([modifier])=>{
|
|
2999
|
+
style = {
|
|
3000
|
+
...style,
|
|
3001
|
+
...modifiersStyles?.[modifier]
|
|
3002
|
+
};
|
|
3003
|
+
});
|
|
3004
|
+
return style;
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
/**
|
|
3008
|
+
* Generates a series of 7 days, starting from the beginning of the week, to use
|
|
3009
|
+
* for formatting weekday names (e.g., Monday, Tuesday, etc.).
|
|
3010
|
+
*
|
|
3011
|
+
* @param dateLib The date library to use for date manipulation.
|
|
3012
|
+
* @param ISOWeek Whether to use ISO week numbering (weeks start on Monday).
|
|
3013
|
+
* @param broadcastCalendar Whether to use the broadcast calendar (weeks start
|
|
3014
|
+
* on Monday, but may include adjustments for broadcast-specific rules).
|
|
3015
|
+
* @returns An array of 7 dates representing the weekdays.
|
|
3016
|
+
*/ function getWeekdays(dateLib, ISOWeek, broadcastCalendar, today) {
|
|
3017
|
+
const referenceToday = today ?? dateLib.today();
|
|
3018
|
+
const start = broadcastCalendar ? dateLib.startOfBroadcastWeek(referenceToday, dateLib) : ISOWeek ? dateLib.startOfISOWeek(referenceToday) : dateLib.startOfWeek(referenceToday);
|
|
3019
|
+
const days = [];
|
|
3020
|
+
for(let i = 0; i < 7; i++){
|
|
3021
|
+
const day = dateLib.addDays(start, i);
|
|
3022
|
+
days.push(day);
|
|
3023
|
+
}
|
|
3024
|
+
return days;
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
/**
|
|
3028
|
+
* Returns the years to display in the dropdown.
|
|
3029
|
+
*
|
|
3030
|
+
* This function generates a list of years between the navigation start and end
|
|
3031
|
+
* dates, formatted using the provided formatter.
|
|
3032
|
+
*
|
|
3033
|
+
* @param navStart The start date for navigation.
|
|
3034
|
+
* @param navEnd The end date for navigation.
|
|
3035
|
+
* @param formatters The formatters to use for formatting the year labels.
|
|
3036
|
+
* @param dateLib The date library to use for date manipulation.
|
|
3037
|
+
* @param reverse If true, reverses the order of the years (descending).
|
|
3038
|
+
* @returns An array of dropdown options representing the years, or `undefined`
|
|
3039
|
+
* if `navStart` or `navEnd` is not provided.
|
|
3040
|
+
*/ function getYearOptions(navStart, navEnd, formatters, dateLib, reverse = false) {
|
|
3041
|
+
if (!navStart) return undefined;
|
|
3042
|
+
if (!navEnd) return undefined;
|
|
3043
|
+
const { startOfYear, endOfYear, eachYearOfInterval, getYear } = dateLib;
|
|
3044
|
+
const firstNavYear = startOfYear(navStart);
|
|
3045
|
+
const lastNavYear = endOfYear(navEnd);
|
|
3046
|
+
const years = eachYearOfInterval({
|
|
3047
|
+
start: firstNavYear,
|
|
3048
|
+
end: lastNavYear
|
|
3049
|
+
});
|
|
3050
|
+
if (reverse) years.reverse();
|
|
3051
|
+
return years.map((year)=>{
|
|
3052
|
+
const label = formatters.formatYearDropdown(year, dateLib);
|
|
3053
|
+
return {
|
|
3054
|
+
value: getYear(year),
|
|
3055
|
+
label,
|
|
3056
|
+
disabled: false
|
|
3057
|
+
};
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3061
|
+
/**
|
|
3062
|
+
* Creates `dateLib` overrides that keep all calendar math at noon in the target
|
|
3063
|
+
* time zone. This avoids second-level offset changes (e.g., historical zones
|
|
3064
|
+
* with +03:41:12) from pushing dates backward across midnight.
|
|
3065
|
+
*/ function createNoonOverrides(timeZone, options = {}) {
|
|
3066
|
+
const { weekStartsOn, locale } = options;
|
|
3067
|
+
const fallbackWeekStartsOn = weekStartsOn ?? locale?.options?.weekStartsOn ?? 0;
|
|
3068
|
+
// Keep all internal math anchored at noon in the target zone to avoid
|
|
3069
|
+
// historical second-level offsets from crossing midnight.
|
|
3070
|
+
const toNoonTZDate = (date)=>{
|
|
3071
|
+
const normalizedDate = typeof date === "number" || typeof date === "string" ? new Date(date) : date;
|
|
3072
|
+
return new TZDate(normalizedDate.getFullYear(), normalizedDate.getMonth(), normalizedDate.getDate(), 12, 0, 0, timeZone);
|
|
3073
|
+
};
|
|
3074
|
+
// Convert a value into a host `Date` that represents the same calendar day
|
|
3075
|
+
// as the target-zone noon. This is useful for helpers (e.g., date-fns week
|
|
3076
|
+
// utilities) that expect local `Date` instances rather than `TZDate`s.
|
|
3077
|
+
const toCalendarDate = (date)=>{
|
|
3078
|
+
const zoned = toNoonTZDate(date);
|
|
3079
|
+
return new Date(zoned.getFullYear(), zoned.getMonth(), zoned.getDate(), 0, 0, 0, 0);
|
|
3080
|
+
};
|
|
3081
|
+
return {
|
|
3082
|
+
today: ()=>{
|
|
3083
|
+
return toNoonTZDate(TZDate.tz(timeZone));
|
|
3084
|
+
},
|
|
3085
|
+
newDate: (year, monthIndex, date)=>{
|
|
3086
|
+
return new TZDate(year, monthIndex, date, 12, 0, 0, timeZone);
|
|
3087
|
+
},
|
|
3088
|
+
startOfDay: (date)=>{
|
|
3089
|
+
return toNoonTZDate(date);
|
|
3090
|
+
},
|
|
3091
|
+
startOfWeek: (date, options)=>{
|
|
3092
|
+
const base = toNoonTZDate(date);
|
|
3093
|
+
const weekStartsOnValue = options?.weekStartsOn ?? fallbackWeekStartsOn;
|
|
3094
|
+
const diff = (base.getDay() - weekStartsOnValue + 7) % 7;
|
|
3095
|
+
base.setDate(base.getDate() - diff);
|
|
3096
|
+
return base;
|
|
3097
|
+
},
|
|
3098
|
+
startOfISOWeek: (date)=>{
|
|
3099
|
+
const base = toNoonTZDate(date);
|
|
3100
|
+
const diff = (base.getDay() - 1 + 7) % 7;
|
|
3101
|
+
base.setDate(base.getDate() - diff);
|
|
3102
|
+
return base;
|
|
3103
|
+
},
|
|
3104
|
+
startOfMonth: (date)=>{
|
|
3105
|
+
const base = toNoonTZDate(date);
|
|
3106
|
+
base.setDate(1);
|
|
3107
|
+
return base;
|
|
3108
|
+
},
|
|
3109
|
+
startOfYear: (date)=>{
|
|
3110
|
+
const base = toNoonTZDate(date);
|
|
3111
|
+
base.setMonth(0, 1);
|
|
3112
|
+
return base;
|
|
3113
|
+
},
|
|
3114
|
+
endOfWeek: (date, options)=>{
|
|
3115
|
+
const base = toNoonTZDate(date);
|
|
3116
|
+
const weekStartsOnValue = options?.weekStartsOn ?? fallbackWeekStartsOn;
|
|
3117
|
+
const endDow = (weekStartsOnValue + 6) % 7;
|
|
3118
|
+
const diff = (endDow - base.getDay() + 7) % 7;
|
|
3119
|
+
base.setDate(base.getDate() + diff);
|
|
3120
|
+
return base;
|
|
3121
|
+
},
|
|
3122
|
+
endOfISOWeek: (date)=>{
|
|
3123
|
+
const base = toNoonTZDate(date);
|
|
3124
|
+
const diff = (7 - base.getDay()) % 7;
|
|
3125
|
+
base.setDate(base.getDate() + diff);
|
|
3126
|
+
return base;
|
|
3127
|
+
},
|
|
3128
|
+
endOfMonth: (date)=>{
|
|
3129
|
+
const base = toNoonTZDate(date);
|
|
3130
|
+
base.setMonth(base.getMonth() + 1, 0);
|
|
3131
|
+
return base;
|
|
3132
|
+
},
|
|
3133
|
+
endOfYear: (date)=>{
|
|
3134
|
+
const base = toNoonTZDate(date);
|
|
3135
|
+
base.setMonth(11, 31);
|
|
3136
|
+
return base;
|
|
3137
|
+
},
|
|
3138
|
+
eachMonthOfInterval: (interval)=>{
|
|
3139
|
+
const start = toNoonTZDate(interval.start);
|
|
3140
|
+
const end = toNoonTZDate(interval.end);
|
|
3141
|
+
const result = [];
|
|
3142
|
+
const cursor = new TZDate(start.getFullYear(), start.getMonth(), 1, 12, 0, 0, timeZone);
|
|
3143
|
+
const endKey = end.getFullYear() * 12 + end.getMonth();
|
|
3144
|
+
while(cursor.getFullYear() * 12 + cursor.getMonth() <= endKey){
|
|
3145
|
+
result.push(new TZDate(cursor, timeZone));
|
|
3146
|
+
cursor.setMonth(cursor.getMonth() + 1, 1);
|
|
3147
|
+
}
|
|
3148
|
+
return result;
|
|
3149
|
+
},
|
|
3150
|
+
// Normalize to noon once before arithmetic (avoid DST/midnight edge cases),
|
|
3151
|
+
// mutate the same TZDate, and return it.
|
|
3152
|
+
addDays: (date, amount)=>{
|
|
3153
|
+
const base = toNoonTZDate(date);
|
|
3154
|
+
base.setDate(base.getDate() + amount);
|
|
3155
|
+
return base;
|
|
3156
|
+
},
|
|
3157
|
+
addWeeks: (date, amount)=>{
|
|
3158
|
+
const base = toNoonTZDate(date);
|
|
3159
|
+
base.setDate(base.getDate() + amount * 7);
|
|
3160
|
+
return base;
|
|
3161
|
+
},
|
|
3162
|
+
addMonths: (date, amount)=>{
|
|
3163
|
+
const base = toNoonTZDate(date);
|
|
3164
|
+
base.setMonth(base.getMonth() + amount);
|
|
3165
|
+
return base;
|
|
3166
|
+
},
|
|
3167
|
+
addYears: (date, amount)=>{
|
|
3168
|
+
const base = toNoonTZDate(date);
|
|
3169
|
+
base.setFullYear(base.getFullYear() + amount);
|
|
3170
|
+
return base;
|
|
3171
|
+
},
|
|
3172
|
+
eachYearOfInterval: (interval)=>{
|
|
3173
|
+
const start = toNoonTZDate(interval.start);
|
|
3174
|
+
const end = toNoonTZDate(interval.end);
|
|
3175
|
+
const years = [];
|
|
3176
|
+
const cursor = new TZDate(start.getFullYear(), 0, 1, 12, 0, 0, timeZone);
|
|
3177
|
+
while(cursor.getFullYear() <= end.getFullYear()){
|
|
3178
|
+
years.push(new TZDate(cursor, timeZone));
|
|
3179
|
+
cursor.setFullYear(cursor.getFullYear() + 1, 0, 1);
|
|
3180
|
+
}
|
|
3181
|
+
return years;
|
|
3182
|
+
},
|
|
3183
|
+
getWeek: (date, options)=>{
|
|
3184
|
+
const base = toCalendarDate(date);
|
|
3185
|
+
return getWeek(base, {
|
|
3186
|
+
weekStartsOn: options?.weekStartsOn ?? fallbackWeekStartsOn,
|
|
3187
|
+
firstWeekContainsDate: options?.firstWeekContainsDate ?? locale?.options?.firstWeekContainsDate ?? 1
|
|
3188
|
+
});
|
|
3189
|
+
},
|
|
3190
|
+
getISOWeek: (date)=>{
|
|
3191
|
+
const base = toCalendarDate(date);
|
|
3192
|
+
return getISOWeek(base);
|
|
3193
|
+
},
|
|
3194
|
+
differenceInCalendarDays: (dateLeft, dateRight)=>{
|
|
3195
|
+
const left = toCalendarDate(dateLeft);
|
|
3196
|
+
const right = toCalendarDate(dateRight);
|
|
3197
|
+
return differenceInCalendarDays(left, right);
|
|
3198
|
+
},
|
|
3199
|
+
differenceInCalendarMonths: (dateLeft, dateRight)=>{
|
|
3200
|
+
const left = toCalendarDate(dateLeft);
|
|
3201
|
+
const right = toCalendarDate(dateRight);
|
|
3202
|
+
return differenceInCalendarMonths(left, right);
|
|
3203
|
+
}
|
|
3204
|
+
};
|
|
3205
|
+
}
|
|
3206
|
+
|
|
2954
3207
|
const asHtmlElement = (element)=>{
|
|
2955
3208
|
if (element instanceof HTMLElement) return element;
|
|
2956
3209
|
return null;
|
|
@@ -3114,15 +3367,16 @@ const queryWeekdaysEl = (element)=>asHtmlElement(element.querySelector("[data-an
|
|
|
3114
3367
|
const { ISOWeek, fixedWeeks, broadcastCalendar } = props ?? {};
|
|
3115
3368
|
const { addDays, differenceInCalendarDays, differenceInCalendarMonths, endOfBroadcastWeek, endOfISOWeek, endOfMonth, endOfWeek, isAfter, startOfBroadcastWeek, startOfISOWeek, startOfWeek } = dateLib;
|
|
3116
3369
|
const startWeekFirstDate = broadcastCalendar ? startOfBroadcastWeek(firstMonth, dateLib) : ISOWeek ? startOfISOWeek(firstMonth) : startOfWeek(firstMonth);
|
|
3117
|
-
const
|
|
3118
|
-
|
|
3370
|
+
const displayMonthsWeekEnd = broadcastCalendar ? endOfBroadcastWeek(lastMonth) : ISOWeek ? endOfISOWeek(endOfMonth(lastMonth)) : endOfWeek(endOfMonth(lastMonth));
|
|
3371
|
+
// If maxDate is set, clamp the grid to the end of that week.
|
|
3372
|
+
const constraintWeekEnd = maxDate && (broadcastCalendar ? endOfBroadcastWeek(maxDate) : ISOWeek ? endOfISOWeek(maxDate) : endOfWeek(maxDate));
|
|
3373
|
+
// Pick the earliest week end between the displayed months and the constraint.
|
|
3374
|
+
const gridEndDate = constraintWeekEnd && isAfter(displayMonthsWeekEnd, constraintWeekEnd) ? constraintWeekEnd : displayMonthsWeekEnd;
|
|
3375
|
+
const nOfDays = differenceInCalendarDays(gridEndDate, startWeekFirstDate);
|
|
3119
3376
|
const nOfMonths = differenceInCalendarMonths(lastMonth, firstMonth) + 1;
|
|
3120
3377
|
const dates = [];
|
|
3121
3378
|
for(let i = 0; i <= nOfDays; i++){
|
|
3122
3379
|
const date = addDays(startWeekFirstDate, i);
|
|
3123
|
-
if (maxDate && isAfter(date, maxDate)) {
|
|
3124
|
-
break;
|
|
3125
|
-
}
|
|
3126
3380
|
dates.push(date);
|
|
3127
3381
|
}
|
|
3128
3382
|
// If fixed weeks is enabled, add the extra dates to the array
|
|
@@ -3430,13 +3684,47 @@ const queryWeekdaysEl = (element)=>asHtmlElement(element.querySelector("[data-an
|
|
|
3430
3684
|
}, [
|
|
3431
3685
|
props.timeZone
|
|
3432
3686
|
]);
|
|
3433
|
-
/** The months displayed in the calendar. */
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3687
|
+
/** The months displayed in the calendar. */ // biome-ignore lint/correctness/useExhaustiveDependencies: We want to recompute only when specific props change.
|
|
3688
|
+
const { months, weeks, days, previousMonth, nextMonth } = useMemo(()=>{
|
|
3689
|
+
const displayMonths = getDisplayMonths(firstMonth, navEnd, {
|
|
3690
|
+
numberOfMonths: props.numberOfMonths
|
|
3691
|
+
}, dateLib);
|
|
3692
|
+
const dates = getDates(displayMonths, props.endMonth ? endOfMonth(props.endMonth) : undefined, {
|
|
3693
|
+
ISOWeek: props.ISOWeek,
|
|
3694
|
+
fixedWeeks: props.fixedWeeks,
|
|
3695
|
+
broadcastCalendar: props.broadcastCalendar
|
|
3696
|
+
}, dateLib);
|
|
3697
|
+
const months = getMonths(displayMonths, dates, {
|
|
3698
|
+
broadcastCalendar: props.broadcastCalendar,
|
|
3699
|
+
fixedWeeks: props.fixedWeeks,
|
|
3700
|
+
ISOWeek: props.ISOWeek,
|
|
3701
|
+
reverseMonths: props.reverseMonths
|
|
3702
|
+
}, dateLib);
|
|
3703
|
+
const weeks = getWeeks(months);
|
|
3704
|
+
const days = getDays(months);
|
|
3705
|
+
const previousMonth = getPreviousMonth(firstMonth, navStart, props, dateLib);
|
|
3706
|
+
const nextMonth = getNextMonth(firstMonth, navEnd, props, dateLib);
|
|
3707
|
+
return {
|
|
3708
|
+
months,
|
|
3709
|
+
weeks,
|
|
3710
|
+
days,
|
|
3711
|
+
previousMonth,
|
|
3712
|
+
nextMonth
|
|
3713
|
+
};
|
|
3714
|
+
}, [
|
|
3715
|
+
dateLib,
|
|
3716
|
+
firstMonth.getTime(),
|
|
3717
|
+
navEnd?.getTime(),
|
|
3718
|
+
navStart?.getTime(),
|
|
3719
|
+
props.disableNavigation,
|
|
3720
|
+
props.broadcastCalendar,
|
|
3721
|
+
props.endMonth?.getTime(),
|
|
3722
|
+
props.fixedWeeks,
|
|
3723
|
+
props.ISOWeek,
|
|
3724
|
+
props.numberOfMonths,
|
|
3725
|
+
props.pagedNavigation,
|
|
3726
|
+
props.reverseMonths
|
|
3727
|
+
]);
|
|
3440
3728
|
const { disableNavigation, onMonthChange } = props;
|
|
3441
3729
|
const isDayInCalendar = (day)=>weeks.some((week)=>week.days.some((d)=>d.isEqualTo(day)));
|
|
3442
3730
|
const goToMonth = (date)=>{
|
|
@@ -4042,6 +4330,72 @@ var FocusTargetPriority;
|
|
|
4042
4330
|
}
|
|
4043
4331
|
}
|
|
4044
4332
|
|
|
4333
|
+
/**
|
|
4334
|
+
* Convert a {@link Date} or {@link TZDate} instance to the given time zone.
|
|
4335
|
+
* Reuses the same instance when it is already a {@link TZDate} using the target
|
|
4336
|
+
* time zone to avoid extra allocations.
|
|
4337
|
+
*/ function toTimeZone(date, timeZone) {
|
|
4338
|
+
if (date instanceof TZDate && date.timeZone === timeZone) {
|
|
4339
|
+
return date;
|
|
4340
|
+
}
|
|
4341
|
+
return new TZDate(date, timeZone);
|
|
4342
|
+
}
|
|
4343
|
+
|
|
4344
|
+
function toZoneNoon(date, timeZone, noonSafe) {
|
|
4345
|
+
return toTimeZone(date, timeZone);
|
|
4346
|
+
}
|
|
4347
|
+
function convertMatcher(matcher, timeZone, noonSafe) {
|
|
4348
|
+
if (typeof matcher === "boolean" || typeof matcher === "function") {
|
|
4349
|
+
return matcher;
|
|
4350
|
+
}
|
|
4351
|
+
if (matcher instanceof Date) {
|
|
4352
|
+
return toZoneNoon(matcher, timeZone);
|
|
4353
|
+
}
|
|
4354
|
+
if (Array.isArray(matcher)) {
|
|
4355
|
+
return matcher.map((value)=>value instanceof Date ? toZoneNoon(value, timeZone) : value);
|
|
4356
|
+
}
|
|
4357
|
+
if (isDateRange(matcher)) {
|
|
4358
|
+
return {
|
|
4359
|
+
...matcher,
|
|
4360
|
+
from: matcher.from ? toTimeZone(matcher.from, timeZone) : matcher.from,
|
|
4361
|
+
to: matcher.to ? toTimeZone(matcher.to, timeZone) : matcher.to
|
|
4362
|
+
};
|
|
4363
|
+
}
|
|
4364
|
+
if (isDateInterval(matcher)) {
|
|
4365
|
+
return {
|
|
4366
|
+
before: toZoneNoon(matcher.before, timeZone),
|
|
4367
|
+
after: toZoneNoon(matcher.after, timeZone)
|
|
4368
|
+
};
|
|
4369
|
+
}
|
|
4370
|
+
if (isDateAfterType(matcher)) {
|
|
4371
|
+
return {
|
|
4372
|
+
after: toZoneNoon(matcher.after, timeZone)
|
|
4373
|
+
};
|
|
4374
|
+
}
|
|
4375
|
+
if (isDateBeforeType(matcher)) {
|
|
4376
|
+
return {
|
|
4377
|
+
before: toZoneNoon(matcher.before, timeZone)
|
|
4378
|
+
};
|
|
4379
|
+
}
|
|
4380
|
+
return matcher;
|
|
4381
|
+
}
|
|
4382
|
+
/**
|
|
4383
|
+
* Convert any {@link Matcher} or array of matchers to the specified time zone.
|
|
4384
|
+
*
|
|
4385
|
+
* @param matchers - The matcher or matchers to convert.
|
|
4386
|
+
* @param timeZone - The target IANA time zone.
|
|
4387
|
+
* @returns The converted matcher(s).
|
|
4388
|
+
* @group Utilities
|
|
4389
|
+
*/ function convertMatchersToTimeZone(matchers, timeZone, noonSafe) {
|
|
4390
|
+
if (!matchers) {
|
|
4391
|
+
return matchers;
|
|
4392
|
+
}
|
|
4393
|
+
if (Array.isArray(matchers)) {
|
|
4394
|
+
return matchers.map((matcher)=>convertMatcher(matcher, timeZone));
|
|
4395
|
+
}
|
|
4396
|
+
return convertMatcher(matchers, timeZone);
|
|
4397
|
+
}
|
|
4398
|
+
|
|
4045
4399
|
/**
|
|
4046
4400
|
* Renders the DayPicker calendar component.
|
|
4047
4401
|
*
|
|
@@ -4051,58 +4405,79 @@ var FocusTargetPriority;
|
|
|
4051
4405
|
* @see https://daypicker.dev
|
|
4052
4406
|
*/ function DayPicker(initialProps) {
|
|
4053
4407
|
let props = initialProps;
|
|
4054
|
-
|
|
4408
|
+
const timeZone = props.timeZone;
|
|
4409
|
+
if (timeZone) {
|
|
4055
4410
|
props = {
|
|
4056
|
-
...initialProps
|
|
4411
|
+
...initialProps,
|
|
4412
|
+
timeZone
|
|
4057
4413
|
};
|
|
4058
4414
|
if (props.today) {
|
|
4059
|
-
props.today =
|
|
4415
|
+
props.today = toTimeZone(props.today, timeZone);
|
|
4060
4416
|
}
|
|
4061
4417
|
if (props.month) {
|
|
4062
|
-
props.month =
|
|
4418
|
+
props.month = toTimeZone(props.month, timeZone);
|
|
4063
4419
|
}
|
|
4064
4420
|
if (props.defaultMonth) {
|
|
4065
|
-
props.defaultMonth =
|
|
4421
|
+
props.defaultMonth = toTimeZone(props.defaultMonth, timeZone);
|
|
4066
4422
|
}
|
|
4067
4423
|
if (props.startMonth) {
|
|
4068
|
-
props.startMonth =
|
|
4424
|
+
props.startMonth = toTimeZone(props.startMonth, timeZone);
|
|
4069
4425
|
}
|
|
4070
4426
|
if (props.endMonth) {
|
|
4071
|
-
props.endMonth =
|
|
4427
|
+
props.endMonth = toTimeZone(props.endMonth, timeZone);
|
|
4072
4428
|
}
|
|
4073
4429
|
if (props.mode === "single" && props.selected) {
|
|
4074
|
-
props.selected =
|
|
4430
|
+
props.selected = toTimeZone(props.selected, timeZone);
|
|
4075
4431
|
} else if (props.mode === "multiple" && props.selected) {
|
|
4076
|
-
props.selected = props.selected?.map((date)=>
|
|
4432
|
+
props.selected = props.selected?.map((date)=>toTimeZone(date, timeZone));
|
|
4077
4433
|
} else if (props.mode === "range" && props.selected) {
|
|
4078
4434
|
props.selected = {
|
|
4079
|
-
from: props.selected.from ?
|
|
4080
|
-
to: props.selected.to ?
|
|
4435
|
+
from: props.selected.from ? toTimeZone(props.selected.from, timeZone) : props.selected.from,
|
|
4436
|
+
to: props.selected.to ? toTimeZone(props.selected.to, timeZone) : props.selected.to
|
|
4081
4437
|
};
|
|
4082
4438
|
}
|
|
4439
|
+
if (props.disabled !== undefined) {
|
|
4440
|
+
props.disabled = convertMatchersToTimeZone(props.disabled, timeZone);
|
|
4441
|
+
}
|
|
4442
|
+
if (props.hidden !== undefined) {
|
|
4443
|
+
props.hidden = convertMatchersToTimeZone(props.hidden, timeZone);
|
|
4444
|
+
}
|
|
4445
|
+
if (props.modifiers) {
|
|
4446
|
+
const nextModifiers = {};
|
|
4447
|
+
Object.keys(props.modifiers).forEach((key)=>{
|
|
4448
|
+
nextModifiers[key] = convertMatchersToTimeZone(props.modifiers?.[key], timeZone);
|
|
4449
|
+
});
|
|
4450
|
+
props.modifiers = nextModifiers;
|
|
4451
|
+
}
|
|
4083
4452
|
}
|
|
4084
4453
|
const { components, formatters, labels, dateLib, locale, classNames } = useMemo(()=>{
|
|
4085
4454
|
const locale = {
|
|
4086
4455
|
...enUS,
|
|
4087
4456
|
...props.locale
|
|
4088
4457
|
};
|
|
4458
|
+
const weekStartsOn = props.broadcastCalendar ? 1 : props.weekStartsOn;
|
|
4459
|
+
const noonOverrides = props.noonSafe && props.timeZone ? createNoonOverrides(props.timeZone, {
|
|
4460
|
+
weekStartsOn,
|
|
4461
|
+
locale
|
|
4462
|
+
}) : undefined;
|
|
4463
|
+
const overrides = props.dateLib && noonOverrides ? {
|
|
4464
|
+
...noonOverrides,
|
|
4465
|
+
...props.dateLib
|
|
4466
|
+
} : props.dateLib ?? noonOverrides;
|
|
4089
4467
|
const dateLib = new DateLib({
|
|
4090
4468
|
locale,
|
|
4091
|
-
weekStartsOn
|
|
4469
|
+
weekStartsOn,
|
|
4092
4470
|
firstWeekContainsDate: props.firstWeekContainsDate,
|
|
4093
4471
|
useAdditionalWeekYearTokens: props.useAdditionalWeekYearTokens,
|
|
4094
4472
|
useAdditionalDayOfYearTokens: props.useAdditionalDayOfYearTokens,
|
|
4095
4473
|
timeZone: props.timeZone,
|
|
4096
4474
|
numerals: props.numerals
|
|
4097
|
-
},
|
|
4475
|
+
}, overrides);
|
|
4098
4476
|
return {
|
|
4099
4477
|
dateLib,
|
|
4100
4478
|
components: getComponents(props.components),
|
|
4101
4479
|
formatters: getFormatters(props.formatters),
|
|
4102
|
-
labels:
|
|
4103
|
-
...defaultLabels,
|
|
4104
|
-
...props.labels
|
|
4105
|
-
},
|
|
4480
|
+
labels: getLabels(props.labels, dateLib.options),
|
|
4106
4481
|
locale,
|
|
4107
4482
|
classNames: {
|
|
4108
4483
|
...getDefaultClassNames(),
|
|
@@ -4119,11 +4494,18 @@ var FocusTargetPriority;
|
|
|
4119
4494
|
props.timeZone,
|
|
4120
4495
|
props.numerals,
|
|
4121
4496
|
props.dateLib,
|
|
4497
|
+
props.noonSafe,
|
|
4122
4498
|
props.components,
|
|
4123
4499
|
props.formatters,
|
|
4124
4500
|
props.labels,
|
|
4125
4501
|
props.classNames
|
|
4126
4502
|
]);
|
|
4503
|
+
if (!props.today) {
|
|
4504
|
+
props = {
|
|
4505
|
+
...props,
|
|
4506
|
+
today: dateLib.today()
|
|
4507
|
+
};
|
|
4508
|
+
}
|
|
4127
4509
|
const { captionLayout, mode, navLayout, numberOfMonths = 1, onDayBlur, onDayClick, onDayFocus, onDayKeyDown, onDayMouseEnter, onDayMouseLeave, onNextClick, onPrevClick, showWeekNumber, styles } = props;
|
|
4128
4510
|
const { formatCaption, formatDay, formatMonthDropdown, formatWeekNumber, formatWeekNumberHeader, formatWeekdayName, formatYearDropdown } = formatters;
|
|
4129
4511
|
const calendar = useCalendar(props, dateLib);
|
|
@@ -4132,9 +4514,11 @@ var FocusTargetPriority;
|
|
|
4132
4514
|
const { isSelected, select, selected: selectedValue } = useSelection(props, dateLib) ?? {};
|
|
4133
4515
|
const { blur, focused, isFocusTarget, moveFocus, setFocused } = useFocus(props, calendar, getModifiers, isSelected ?? (()=>false), dateLib);
|
|
4134
4516
|
const { labelDayButton, labelGridcell, labelGrid, labelMonthDropdown, labelNav, labelPrevious, labelNext, labelWeekday, labelWeekNumber, labelWeekNumberHeader, labelYearDropdown } = labels;
|
|
4135
|
-
const weekdays = useMemo(()=>getWeekdays(dateLib, props.ISOWeek), [
|
|
4517
|
+
const weekdays = useMemo(()=>getWeekdays(dateLib, props.ISOWeek, props.broadcastCalendar, props.today), [
|
|
4136
4518
|
dateLib,
|
|
4137
|
-
props.ISOWeek
|
|
4519
|
+
props.ISOWeek,
|
|
4520
|
+
props.broadcastCalendar,
|
|
4521
|
+
props.today
|
|
4138
4522
|
]);
|
|
4139
4523
|
const isInteractive = mode !== undefined || onDayClick !== undefined;
|
|
4140
4524
|
const handlePreviousClick = useCallback(()=>{
|
|
@@ -4159,6 +4543,9 @@ var FocusTargetPriority;
|
|
|
4159
4543
|
e.preventDefault();
|
|
4160
4544
|
e.stopPropagation();
|
|
4161
4545
|
setFocused(day);
|
|
4546
|
+
if (m.disabled) {
|
|
4547
|
+
return;
|
|
4548
|
+
}
|
|
4162
4549
|
select?.(day.date, m, e);
|
|
4163
4550
|
onDayClick?.(day.date, m, e);
|
|
4164
4551
|
}, [
|
|
@@ -4401,8 +4788,7 @@ var FocusTargetPriority;
|
|
|
4401
4788
|
whiteSpace: "nowrap",
|
|
4402
4789
|
wordWrap: "normal"
|
|
4403
4790
|
}
|
|
4404
|
-
}, formatCaption(calendarMonth.date, dateLib.options, dateLib))) :
|
|
4405
|
-
React__default.createElement(components.CaptionLabel, {
|
|
4791
|
+
}, formatCaption(calendarMonth.date, dateLib.options, dateLib))) : React__default.createElement(components.CaptionLabel, {
|
|
4406
4792
|
className: classNames[UI.CaptionLabel],
|
|
4407
4793
|
role: "status",
|
|
4408
4794
|
"aria-live": "polite"
|
|
@@ -4458,8 +4844,7 @@ var FocusTargetPriority;
|
|
|
4458
4844
|
key: week.weekNumber,
|
|
4459
4845
|
style: styles?.[UI.Week],
|
|
4460
4846
|
week: week
|
|
4461
|
-
}, showWeekNumber &&
|
|
4462
|
-
React__default.createElement(components.WeekNumber, {
|
|
4847
|
+
}, showWeekNumber && React__default.createElement(components.WeekNumber, {
|
|
4463
4848
|
week: week,
|
|
4464
4849
|
style: styles?.[UI.WeekNumber],
|
|
4465
4850
|
"aria-label": labelWeekNumber(week.weekNumber, {
|
|
@@ -4483,9 +4868,8 @@ var FocusTargetPriority;
|
|
|
4483
4868
|
const style = getStyleForModifiers(modifiers, styles, props.modifiersStyles);
|
|
4484
4869
|
const className = getClassNamesForModifiers(modifiers, classNames, props.modifiersClassNames);
|
|
4485
4870
|
const ariaLabel = !isInteractive && !modifiers.hidden ? labelGridcell(date, modifiers, dateLib.options, dateLib) : undefined;
|
|
4486
|
-
return(
|
|
4487
|
-
|
|
4488
|
-
key: `${dateLib.format(date, "yyyy-MM-dd")}_${dateLib.format(day.displayMonth, "yyyy-MM")}`,
|
|
4871
|
+
return React__default.createElement(components.Day, {
|
|
4872
|
+
key: `${day.isoDate}_${day.displayMonthId}`,
|
|
4489
4873
|
day: day,
|
|
4490
4874
|
modifiers: modifiers,
|
|
4491
4875
|
className: className.join(" "),
|
|
@@ -4493,8 +4877,8 @@ var FocusTargetPriority;
|
|
|
4493
4877
|
role: "gridcell",
|
|
4494
4878
|
"aria-selected": modifiers.selected || undefined,
|
|
4495
4879
|
"aria-label": ariaLabel,
|
|
4496
|
-
"data-day":
|
|
4497
|
-
"data-month": day.outside ?
|
|
4880
|
+
"data-day": day.isoDate,
|
|
4881
|
+
"data-month": day.outside ? day.dateMonthId : undefined,
|
|
4498
4882
|
"data-selected": modifiers.selected || undefined,
|
|
4499
4883
|
"data-disabled": modifiers.disabled || undefined,
|
|
4500
4884
|
"data-hidden": modifiers.hidden || undefined,
|
|
@@ -4507,7 +4891,8 @@ var FocusTargetPriority;
|
|
|
4507
4891
|
type: "button",
|
|
4508
4892
|
day: day,
|
|
4509
4893
|
modifiers: modifiers,
|
|
4510
|
-
disabled: modifiers.disabled || undefined,
|
|
4894
|
+
disabled: !modifiers.focused && modifiers.disabled || undefined,
|
|
4895
|
+
"aria-disabled": modifiers.focused && modifiers.disabled || undefined,
|
|
4511
4896
|
tabIndex: isFocusTarget(day) ? 0 : -1,
|
|
4512
4897
|
"aria-label": labelDayButton(date, modifiers, dateLib.options, dateLib),
|
|
4513
4898
|
onClick: handleDayClick(day, modifiers),
|
|
@@ -4516,11 +4901,10 @@ var FocusTargetPriority;
|
|
|
4516
4901
|
onKeyDown: handleDayKeyDown(day, modifiers),
|
|
4517
4902
|
onMouseEnter: handleDayMouseEnter(day, modifiers),
|
|
4518
4903
|
onMouseLeave: handleDayMouseLeave(day, modifiers)
|
|
4519
|
-
}, formatDay(date, dateLib.options, dateLib)) : !modifiers.hidden && formatDay(day.date, dateLib.options, dateLib))
|
|
4904
|
+
}, formatDay(date, dateLib.options, dateLib)) : !modifiers.hidden && formatDay(day.date, dateLib.options, dateLib));
|
|
4520
4905
|
}));
|
|
4521
4906
|
}))));
|
|
4522
|
-
})), props.footer &&
|
|
4523
|
-
React__default.createElement(components.Footer, {
|
|
4907
|
+
})), props.footer && React__default.createElement(components.Footer, {
|
|
4524
4908
|
className: classNames[UI.Footer],
|
|
4525
4909
|
style: styles?.[UI.Footer],
|
|
4526
4910
|
role: "status",
|
|
@@ -4635,4 +5019,4 @@ function CalendarDayButton({ className, day, modifiers, ...props }) {
|
|
|
4635
5019
|
}
|
|
4636
5020
|
|
|
4637
5021
|
export { Calendar as C, CalendarDayButton as a, addMonths as b };
|
|
4638
|
-
//# sourceMappingURL=calendar-
|
|
5022
|
+
//# sourceMappingURL=calendar-C549VT55.mjs.map
|