@six-group/ui-library 3.0.0-beta.1.7 → 3.0.0-beta.1.8
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/cjs/{event-listeners-4a8d66d5.js → event-listeners-74715e62.js} +38 -38
- package/dist/cjs/{execution-control-3bc9c7c4.js → execution-control-46f388e0.js} +35 -35
- package/dist/cjs/{focus-visible-b08d956f.js → focus-visible-0b352c74.js} +40 -40
- package/dist/cjs/{form-control-9e4dffd1.js → form-control-866bbece.js} +25 -25
- package/dist/cjs/{modal-a9679ddf.js → modal-48d42228.js} +41 -41
- package/dist/cjs/{popover-e3781f5a.js → popover-1d2a037c.js} +95 -95
- package/dist/cjs/{scroll-5b8676ba.js → scroll-76e6f5d7.js} +57 -57
- package/dist/cjs/set-attributes_2.cjs.entry.js +57 -57
- package/dist/cjs/six-alert.cjs.entry.js +131 -131
- package/dist/cjs/six-avatar.cjs.entry.js +28 -28
- package/dist/cjs/six-badge.cjs.entry.js +26 -26
- package/dist/cjs/six-button.cjs.entry.js +97 -97
- package/dist/cjs/six-card.cjs.entry.js +8 -8
- package/dist/cjs/six-checkbox.cjs.entry.js +152 -152
- package/dist/cjs/six-datepicker.cjs.entry.js +1189 -1189
- package/dist/cjs/six-details.cjs.entry.js +139 -139
- package/dist/cjs/six-dialog.cjs.entry.js +152 -152
- package/dist/cjs/six-drawer.cjs.entry.js +174 -174
- package/dist/cjs/six-dropdown_3.cjs.entry.js +728 -728
- package/dist/cjs/six-error-page.cjs.entry.js +94 -94
- package/dist/cjs/six-file-list-item.cjs.entry.js +38 -38
- package/dist/cjs/six-file-list.cjs.entry.js +8 -8
- package/dist/cjs/six-file-upload.cjs.entry.js +96 -96
- package/dist/cjs/six-footer.cjs.entry.js +8 -8
- package/dist/cjs/six-form.cjs.entry.js +219 -219
- package/dist/cjs/six-group-label.cjs.entry.js +46 -46
- package/dist/cjs/six-header.cjs.entry.js +149 -149
- package/dist/cjs/six-icon-button.cjs.entry.js +33 -33
- package/dist/cjs/six-icon.cjs.entry.js +24 -24
- package/dist/cjs/six-input.cjs.entry.js +230 -230
- package/dist/cjs/six-item-picker.cjs.entry.js +361 -361
- package/dist/cjs/six-language-switcher.cjs.entry.js +52 -52
- package/dist/cjs/six-layout-grid.cjs.entry.js +19 -19
- package/dist/cjs/six-main-container.cjs.entry.js +11 -11
- package/dist/cjs/six-menu-divider.cjs.entry.js +8 -8
- package/dist/cjs/six-menu-label.cjs.entry.js +8 -8
- package/dist/cjs/six-picto.cjs.entry.js +15 -15
- package/dist/cjs/six-progress-bar.cjs.entry.js +17 -17
- package/dist/cjs/six-progress-ring.cjs.entry.js +31 -31
- package/dist/cjs/six-radio.cjs.entry.js +121 -121
- package/dist/cjs/six-range.cjs.entry.js +198 -198
- package/dist/cjs/six-root.cjs.entry.js +34 -34
- package/dist/cjs/six-search-field.cjs.entry.js +43 -43
- package/dist/cjs/six-select.cjs.entry.js +447 -447
- package/dist/cjs/six-sidebar-item-group.cjs.entry.js +42 -42
- package/dist/cjs/six-sidebar-item.cjs.entry.js +18 -18
- package/dist/cjs/six-sidebar.cjs.entry.js +171 -171
- package/dist/cjs/six-spinner.cjs.entry.js +16 -16
- package/dist/cjs/six-switch.cjs.entry.js +100 -100
- package/dist/cjs/six-tab-group.cjs.entry.js +226 -226
- package/dist/cjs/six-tab-panel.cjs.entry.js +17 -17
- package/dist/cjs/six-tab.cjs.entry.js +42 -42
- package/dist/cjs/six-table-cell_4.cjs.entry.js +70 -70
- package/dist/cjs/six-table.cjs.entry.js +145 -145
- package/dist/cjs/six-tag.cjs.entry.js +40 -40
- package/dist/cjs/six-textarea.cjs.entry.js +211 -211
- package/dist/cjs/six-tile.cjs.entry.js +89 -89
- package/dist/cjs/six-timepicker.cjs.entry.js +489 -489
- package/dist/cjs/{six-timepicker.types-c58cc88b.js → six-timepicker.types-c19ebff3.js} +43 -43
- package/dist/cjs/six-tooltip.cjs.entry.js +172 -172
- package/dist/cjs/{slot-8abe833c.js → slot-ad537f24.js} +42 -42
- package/dist/cjs/{types-65e5c95b.js → types-581e8ff0.js} +12 -12
- package/dist/cjs/{types-0c28e484.js → types-64878648.js} +12 -12
- package/dist/collection/components/six-alert/six-alert.js +366 -366
- package/dist/collection/components/six-avatar/six-avatar.js +131 -131
- package/dist/collection/components/six-badge/six-badge.js +101 -101
- package/dist/collection/components/six-button/six-button.js +466 -466
- package/dist/collection/components/six-card/six-card.js +21 -21
- package/dist/collection/components/six-checkbox/six-checkbox.js +550 -550
- package/dist/collection/components/six-datepicker/components/day-selection.js +13 -13
- package/dist/collection/components/six-datepicker/components/month-selection.js +12 -12
- package/dist/collection/components/six-datepicker/components/year-selection.js +10 -10
- package/dist/collection/components/six-datepicker/six-date-formats.js +23 -23
- package/dist/collection/components/six-datepicker/six-datepicker.js +1343 -1343
- package/dist/collection/components/six-datepicker/test/six-datepicker.test-helpers.js +16 -16
- package/dist/collection/components/six-details/six-details.js +432 -432
- package/dist/collection/components/six-dialog/six-dialog.js +401 -401
- package/dist/collection/components/six-drawer/six-drawer.js +458 -458
- package/dist/collection/components/six-dropdown/six-dropdown.js +939 -939
- package/dist/collection/components/six-error-page/six-error-page.js +199 -199
- package/dist/collection/components/six-file-list/six-file-list.js +20 -20
- package/dist/collection/components/six-file-list-item/six-file-list-item.js +203 -203
- package/dist/collection/components/six-file-upload/six-file-upload.js +272 -272
- package/dist/collection/components/six-footer/six-footer.js +21 -21
- package/dist/collection/components/six-form/six-form.js +408 -408
- package/dist/collection/components/six-group-label/six-group-label.js +166 -166
- package/dist/collection/components/six-header/six-header.js +420 -420
- package/dist/collection/components/six-icon/six-icon.js +77 -77
- package/dist/collection/components/six-icon-button/six-icon-button.js +142 -142
- package/dist/collection/components/six-input/six-input.js +1141 -1141
- package/dist/collection/components/six-item-picker/six-item-picker.js +688 -688
- package/dist/collection/components/six-item-picker/types.js +13 -13
- package/dist/collection/components/six-language-switcher/six-language-switcher.js +128 -128
- package/dist/collection/components/six-layout-grid/six-layout-grid.js +52 -52
- package/dist/collection/components/six-main-container/six-main-container.js +53 -53
- package/dist/collection/components/six-menu/six-menu.js +406 -406
- package/dist/collection/components/six-menu-divider/six-menu-divider.js +22 -22
- package/dist/collection/components/six-menu-item/six-menu-item.js +177 -177
- package/dist/collection/components/six-menu-label/six-menu-label.js +25 -25
- package/dist/collection/components/six-picto/six-picto.js +50 -50
- package/dist/collection/components/six-progress-bar/six-progress-bar.js +77 -77
- package/dist/collection/components/six-progress-ring/six-progress-ring.js +111 -111
- package/dist/collection/components/six-radio/six-radio.js +410 -410
- package/dist/collection/components/six-range/six-range.js +620 -620
- package/dist/collection/components/six-root/six-root.js +167 -167
- package/dist/collection/components/six-search-field/six-search-field.js +171 -171
- package/dist/collection/components/six-select/six-select.js +1105 -1105
- package/dist/collection/components/six-sidebar/six-sidebar.js +455 -455
- package/dist/collection/components/six-sidebar-item/six-sidebar-item.js +89 -89
- package/dist/collection/components/six-sidebar-item-group/six-sidebar-item-group.js +158 -158
- package/dist/collection/components/six-spinner/six-spinner.js +55 -55
- package/dist/collection/components/six-stage-indicator/six-stage-indicator.js +46 -46
- package/dist/collection/components/six-switch/six-switch.js +393 -393
- package/dist/collection/components/six-tab/six-tab.js +198 -198
- package/dist/collection/components/six-tab-group/six-tab-group.js +362 -362
- package/dist/collection/components/six-tab-panel/six-tab-panel.js +75 -75
- package/dist/collection/components/six-table/six-table.js +209 -209
- package/dist/collection/components/six-table/test/helpers.js +13 -13
- package/dist/collection/components/six-table/types.js +8 -8
- package/dist/collection/components/six-table/util/filter-by.js +34 -34
- package/dist/collection/components/six-table/util/from-data.js +33 -33
- package/dist/collection/components/six-table/util/is.js +3 -3
- package/dist/collection/components/six-table/util/quick-filter-by.js +13 -13
- package/dist/collection/components/six-table/util/sort-by.js +25 -25
- package/dist/collection/components/six-table-cell/six-table-cell.js +21 -21
- package/dist/collection/components/six-table-header/six-table-header.js +21 -21
- package/dist/collection/components/six-table-header-cell/get-next-state.js +7 -7
- package/dist/collection/components/six-table-header-cell/icons.js +12 -12
- package/dist/collection/components/six-table-header-cell/six-table-header-cell.js +174 -174
- package/dist/collection/components/six-table-header-cell/types.js +13 -13
- package/dist/collection/components/six-table-header-cell/util/create-model.js +6 -6
- package/dist/collection/components/six-table-header-cell/util/get-next-state.js +7 -7
- package/dist/collection/components/six-table-row/six-table-row.js +21 -21
- package/dist/collection/components/six-tag/six-tag.js +157 -157
- package/dist/collection/components/six-textarea/six-textarea.js +912 -912
- package/dist/collection/components/six-tile/six-tile.js +315 -315
- package/dist/collection/components/six-timepicker/six-time-format.js +14 -14
- package/dist/collection/components/six-timepicker/six-timepicker.js +980 -980
- package/dist/collection/components/six-timepicker/six-timepicker.types.js +40 -40
- package/dist/collection/components/six-tooltip/six-tooltip.js +435 -435
- package/dist/collection/functional-components/form-control/form-control.js +28 -28
- package/dist/collection/index.js +1 -1
- package/dist/collection/testUtil/delay.js +3 -3
- package/dist/collection/utils/as-array.js +1 -1
- package/dist/collection/utils/date-util.js +712 -712
- package/dist/collection/utils/event-listeners.js +39 -39
- package/dist/collection/utils/execution-control.js +38 -38
- package/dist/collection/utils/focus-visible.js +41 -41
- package/dist/collection/utils/matchers.js +2 -2
- package/dist/collection/utils/modal.js +28 -28
- package/dist/collection/utils/offset.js +13 -13
- package/dist/collection/utils/popover.js +113 -113
- package/dist/collection/utils/scroll.js +47 -47
- package/dist/collection/utils/slot.js +59 -59
- package/dist/collection/utils/support.js +15 -15
- package/dist/collection/utils/tabbable.js +22 -22
- package/dist/collection/utils/testing.js +38 -38
- package/dist/collection/utils/time.util.js +74 -74
- package/dist/collection/utils/type-check.js +5 -5
- package/dist/collection/utils/types.js +1 -1
- package/dist/collection/wrappers/set-attributes/set-attributes.js +68 -68
- package/dist/components.json +1 -1
- package/dist/custom-elements/index.js +7595 -7595
- package/dist/esm/{event-listeners-1bef934e.js → event-listeners-570a24ea.js} +38 -38
- package/dist/esm/{execution-control-235f5126.js → execution-control-1a60d709.js} +35 -35
- package/dist/esm/{focus-visible-4b7946aa.js → focus-visible-97933ea9.js} +40 -40
- package/dist/esm/{form-control-17478ad2.js → form-control-24f446af.js} +25 -25
- package/dist/esm/{modal-e5709f6b.js → modal-5ebdc320.js} +41 -41
- package/dist/esm/polyfills/core-js.js +0 -0
- package/dist/esm/polyfills/dom.js +0 -0
- package/dist/esm/polyfills/es5-html-element.js +0 -0
- package/dist/esm/polyfills/index.js +0 -0
- package/dist/esm/polyfills/system.js +0 -0
- package/dist/esm/{popover-5a51f84d.js → popover-1c7a1139.js} +95 -95
- package/dist/esm/{scroll-99b214c2.js → scroll-180b53fd.js} +57 -57
- package/dist/esm/set-attributes_2.entry.js +57 -57
- package/dist/esm/six-alert.entry.js +131 -131
- package/dist/esm/six-avatar.entry.js +28 -28
- package/dist/esm/six-badge.entry.js +26 -26
- package/dist/esm/six-button.entry.js +97 -97
- package/dist/esm/six-card.entry.js +8 -8
- package/dist/esm/six-checkbox.entry.js +152 -152
- package/dist/esm/six-datepicker.entry.js +1189 -1189
- package/dist/esm/six-details.entry.js +139 -139
- package/dist/esm/six-dialog.entry.js +152 -152
- package/dist/esm/six-drawer.entry.js +174 -174
- package/dist/esm/six-dropdown_3.entry.js +728 -728
- package/dist/esm/six-error-page.entry.js +94 -94
- package/dist/esm/six-file-list-item.entry.js +38 -38
- package/dist/esm/six-file-list.entry.js +8 -8
- package/dist/esm/six-file-upload.entry.js +96 -96
- package/dist/esm/six-footer.entry.js +8 -8
- package/dist/esm/six-form.entry.js +219 -219
- package/dist/esm/six-group-label.entry.js +46 -46
- package/dist/esm/six-header.entry.js +149 -149
- package/dist/esm/six-icon-button.entry.js +33 -33
- package/dist/esm/six-icon.entry.js +24 -24
- package/dist/esm/six-input.entry.js +230 -230
- package/dist/esm/six-item-picker.entry.js +361 -361
- package/dist/esm/six-language-switcher.entry.js +52 -52
- package/dist/esm/six-layout-grid.entry.js +19 -19
- package/dist/esm/six-main-container.entry.js +11 -11
- package/dist/esm/six-menu-divider.entry.js +8 -8
- package/dist/esm/six-menu-label.entry.js +8 -8
- package/dist/esm/six-picto.entry.js +15 -15
- package/dist/esm/six-progress-bar.entry.js +17 -17
- package/dist/esm/six-progress-ring.entry.js +31 -31
- package/dist/esm/six-radio.entry.js +121 -121
- package/dist/esm/six-range.entry.js +198 -198
- package/dist/esm/six-root.entry.js +34 -34
- package/dist/esm/six-search-field.entry.js +43 -43
- package/dist/esm/six-select.entry.js +447 -447
- package/dist/esm/six-sidebar-item-group.entry.js +42 -42
- package/dist/esm/six-sidebar-item.entry.js +18 -18
- package/dist/esm/six-sidebar.entry.js +171 -171
- package/dist/esm/six-spinner.entry.js +16 -16
- package/dist/esm/six-switch.entry.js +100 -100
- package/dist/esm/six-tab-group.entry.js +226 -226
- package/dist/esm/six-tab-panel.entry.js +17 -17
- package/dist/esm/six-tab.entry.js +42 -42
- package/dist/esm/six-table-cell_4.entry.js +70 -70
- package/dist/esm/six-table.entry.js +145 -145
- package/dist/esm/six-tag.entry.js +40 -40
- package/dist/esm/six-textarea.entry.js +211 -211
- package/dist/esm/six-tile.entry.js +89 -89
- package/dist/esm/six-timepicker.entry.js +489 -489
- package/dist/esm/{six-timepicker.types-cd6bac03.js → six-timepicker.types-e161a447.js} +43 -43
- package/dist/esm/six-tooltip.entry.js +172 -172
- package/dist/esm/{slot-5253e199.js → slot-6f3984c7.js} +42 -42
- package/dist/esm/{types-a37c1695.js → types-4b10b413.js} +12 -12
- package/dist/esm/{types-33d15673.js → types-ed860f7c.js} +12 -12
- package/dist/types/components/six-alert/six-alert.d.ts +60 -60
- package/dist/types/components/six-avatar/six-avatar.d.ts +27 -27
- package/dist/types/components/six-badge/six-badge.d.ts +20 -20
- package/dist/types/components/six-button/six-button.d.ts +69 -69
- package/dist/types/components/six-card/six-card.d.ts +9 -9
- package/dist/types/components/six-checkbox/six-checkbox.d.ts +86 -86
- package/dist/types/components/six-datepicker/components/day-selection.d.ts +5 -5
- package/dist/types/components/six-datepicker/components/month-selection.d.ts +5 -5
- package/dist/types/components/six-datepicker/components/year-selection.d.ts +5 -5
- package/dist/types/components/six-datepicker/six-date-formats.d.ts +22 -22
- package/dist/types/components/six-datepicker/six-datepicker.d.ts +214 -214
- package/dist/types/components/six-datepicker/test/six-datepicker.test-helpers.d.ts +1 -1
- package/dist/types/components/six-details/six-details.d.ts +61 -61
- package/dist/types/components/six-dialog/six-dialog.d.ts +75 -75
- package/dist/types/components/six-drawer/six-drawer.d.ts +82 -82
- package/dist/types/components/six-dropdown/six-dropdown.d.ts +140 -140
- package/dist/types/components/six-error-page/six-error-page.d.ts +27 -27
- package/dist/types/components/six-file-list/six-file-list.d.ts +8 -8
- package/dist/types/components/six-file-list-item/six-file-list-item.d.ts +35 -35
- package/dist/types/components/six-file-upload/six-file-upload.d.ts +42 -42
- package/dist/types/components/six-footer/six-footer.d.ts +9 -9
- package/dist/types/components/six-form/six-form.d.ts +69 -69
- package/dist/types/components/six-group-label/six-group-label.d.ts +37 -37
- package/dist/types/components/six-header/six-header.d.ts +90 -90
- package/dist/types/components/six-icon/six-icon.d.ts +13 -13
- package/dist/types/components/six-icon-button/six-icon-button.d.ts +28 -28
- package/dist/types/components/six-input/six-input.d.ts +165 -165
- package/dist/types/components/six-item-picker/six-item-picker.d.ts +106 -106
- package/dist/types/components/six-item-picker/types.d.ts +11 -11
- package/dist/types/components/six-language-switcher/six-language-switcher.d.ts +25 -25
- package/dist/types/components/six-layout-grid/six-layout-grid.d.ts +14 -14
- package/dist/types/components/six-main-container/six-main-container.d.ts +16 -16
- package/dist/types/components/six-menu/six-menu.d.ts +81 -81
- package/dist/types/components/six-menu-divider/six-menu-divider.d.ts +11 -11
- package/dist/types/components/six-menu-item/six-menu-item.d.ts +36 -36
- package/dist/types/components/six-menu-label/six-menu-label.d.ts +13 -13
- package/dist/types/components/six-picto/six-picto.d.ts +14 -14
- package/dist/types/components/six-progress-bar/six-progress-bar.d.ts +19 -19
- package/dist/types/components/six-progress-ring/six-progress-ring.d.ts +24 -24
- package/dist/types/components/six-radio/six-radio.d.ts +66 -66
- package/dist/types/components/six-range/six-range.d.ts +101 -101
- package/dist/types/components/six-root/six-root.d.ts +34 -34
- package/dist/types/components/six-search-field/six-search-field.d.ts +32 -32
- package/dist/types/components/six-select/six-select.d.ts +163 -163
- package/dist/types/components/six-sidebar/six-sidebar.d.ts +55 -55
- package/dist/types/components/six-sidebar-item/six-sidebar-item.d.ts +15 -15
- package/dist/types/components/six-sidebar-item-group/six-sidebar-item-group.d.ts +26 -26
- package/dist/types/components/six-spinner/six-spinner.d.ts +15 -15
- package/dist/types/components/six-stage-indicator/six-stage-indicator.d.ts +6 -6
- package/dist/types/components/six-switch/six-switch.d.ts +62 -62
- package/dist/types/components/six-tab/six-tab.d.ts +35 -35
- package/dist/types/components/six-tab-group/six-tab-group.d.ts +62 -62
- package/dist/types/components/six-tab-panel/six-tab-panel.d.ts +19 -19
- package/dist/types/components/six-table/six-table.d.ts +30 -30
- package/dist/types/components/six-table/test/helpers.d.ts +2 -2
- package/dist/types/components/six-table/types.d.ts +33 -33
- package/dist/types/components/six-table/util/filter-by.d.ts +2 -2
- package/dist/types/components/six-table/util/from-data.d.ts +8 -8
- package/dist/types/components/six-table/util/is.d.ts +3 -3
- package/dist/types/components/six-table/util/quick-filter-by.d.ts +2 -2
- package/dist/types/components/six-table/util/sort-by.d.ts +2 -2
- package/dist/types/components/six-table-cell/six-table-cell.d.ts +9 -9
- package/dist/types/components/six-table-header/six-table-header.d.ts +9 -9
- package/dist/types/components/six-table-header-cell/get-next-state.d.ts +2 -2
- package/dist/types/components/six-table-header-cell/icons.d.ts +3 -3
- package/dist/types/components/six-table-header-cell/six-table-header-cell.d.ts +32 -32
- package/dist/types/components/six-table-header-cell/types.d.ts +11 -11
- package/dist/types/components/six-table-header-cell/util/create-model.d.ts +4 -4
- package/dist/types/components/six-table-header-cell/util/get-next-state.d.ts +3 -3
- package/dist/types/components/six-table-row/six-table-row.d.ts +9 -9
- package/dist/types/components/six-tag/six-tag.d.ts +30 -30
- package/dist/types/components/six-textarea/six-textarea.d.ts +134 -134
- package/dist/types/components/six-tile/six-tile.d.ts +40 -40
- package/dist/types/components/six-timepicker/six-time-format.d.ts +13 -13
- package/dist/types/components/six-timepicker/six-timepicker.d.ts +184 -184
- package/dist/types/components/six-timepicker/six-timepicker.types.d.ts +36 -36
- package/dist/types/components/six-tooltip/six-tooltip.d.ts +72 -72
- package/dist/types/functional-components/form-control/form-control.d.ts +34 -34
- package/dist/types/index.d.ts +1 -1
- package/dist/types/testUtil/delay.d.ts +1 -1
- package/dist/types/utils/as-array.d.ts +1 -1
- package/dist/types/utils/date-util.d.ts +194 -194
- package/dist/types/utils/event-listeners.d.ts +15 -15
- package/dist/types/utils/execution-control.d.ts +26 -26
- package/dist/types/utils/focus-visible.d.ts +6 -6
- package/dist/types/utils/matchers.d.ts +2 -2
- package/dist/types/utils/modal.d.ts +13 -13
- package/dist/types/utils/offset.d.ts +4 -4
- package/dist/types/utils/popover.d.ts +27 -27
- package/dist/types/utils/scroll.d.ts +3 -3
- package/dist/types/utils/slot.d.ts +9 -9
- package/dist/types/utils/support.d.ts +1 -1
- package/dist/types/utils/tabbable.d.ts +2 -2
- package/dist/types/utils/testing.d.ts +2 -2
- package/dist/types/utils/time.util.d.ts +10 -10
- package/dist/types/utils/type-check.d.ts +4 -4
- package/dist/types/utils/types.d.ts +4 -4
- package/dist/types/wrappers/set-attributes/set-attributes.d.ts +9 -9
- package/dist/ui-library/{p-a8c225f2.entry.js → p-007bc8e8.entry.js} +1 -1
- package/dist/ui-library/{p-f9c0cfb7.entry.js → p-044b784e.entry.js} +1 -1
- package/dist/ui-library/{p-c733dead.js → p-0786fa7c.js} +0 -0
- package/dist/ui-library/{p-12cc24c3.js → p-07d1e830.js} +0 -0
- package/dist/ui-library/{p-48ea4419.entry.js → p-09cb13fa.entry.js} +1 -1
- package/dist/ui-library/{p-e96dcf96.entry.js → p-0c596054.entry.js} +1 -1
- package/dist/ui-library/{p-a77a6442.entry.js → p-1b8dc7b7.entry.js} +1 -1
- package/dist/ui-library/{p-68d31736.js → p-25a3bf57.js} +0 -0
- package/dist/ui-library/{p-ebaea182.entry.js → p-281e8c2d.entry.js} +1 -1
- package/dist/ui-library/{p-9f2dc381.entry.js → p-2924f82f.entry.js} +1 -1
- package/dist/ui-library/{p-ea1fcff2.entry.js → p-2d7ed407.entry.js} +1 -1
- package/dist/ui-library/{p-89f68e76.entry.js → p-4162dcdd.entry.js} +1 -1
- package/dist/ui-library/{p-6f67f986.entry.js → p-4d3a4e93.entry.js} +1 -1
- package/dist/ui-library/{p-8bd0873f.entry.js → p-4ed023b8.entry.js} +1 -1
- package/dist/ui-library/{p-af3d757c.js → p-4f8394d7.js} +0 -0
- package/dist/ui-library/{p-1b92cc7a.entry.js → p-530ea6ec.entry.js} +1 -1
- package/dist/ui-library/{p-19543c96.entry.js → p-531ab886.entry.js} +1 -1
- package/dist/ui-library/{p-fdb455d7.entry.js → p-54c48654.entry.js} +1 -1
- package/dist/ui-library/{p-c948d3db.entry.js → p-55c64cbc.entry.js} +1 -1
- package/dist/ui-library/{p-1c9f0dc6.js → p-5f1c6a5f.js} +0 -0
- package/dist/ui-library/{p-60491176.entry.js → p-675a8243.entry.js} +1 -1
- package/dist/ui-library/{p-b9fb8455.entry.js → p-6d622ed0.entry.js} +1 -1
- package/dist/ui-library/{p-572e3690.js → p-75297ad7.js} +0 -0
- package/dist/ui-library/{p-2ff97cdf.entry.js → p-90b26447.entry.js} +1 -1
- package/dist/ui-library/{p-fcd2356c.entry.js → p-93945629.entry.js} +1 -1
- package/dist/ui-library/{p-7735d99f.js → p-9a860acc.js} +0 -0
- package/dist/ui-library/{p-4cc01afc.entry.js → p-aa37e45a.entry.js} +1 -1
- package/dist/ui-library/{p-191f958b.js → p-b1e66136.js} +0 -0
- package/dist/ui-library/{p-c09dc3a9.js → p-b4dfb7cf.js} +0 -0
- package/dist/ui-library/{p-968c5169.entry.js → p-c24292b3.entry.js} +1 -1
- package/dist/ui-library/{p-ed21cc57.entry.js → p-cd79de73.entry.js} +1 -1
- package/dist/ui-library/{p-34e6d8e8.js → p-d12c6092.js} +0 -0
- package/dist/ui-library/{p-f0e91e17.entry.js → p-d28ac80a.entry.js} +1 -1
- package/dist/ui-library/{p-5ead7b2f.entry.js → p-d837e5a8.entry.js} +1 -1
- package/dist/ui-library/{p-ec1ecc2a.entry.js → p-dd3cae68.entry.js} +1 -1
- package/dist/ui-library/{p-044c6bf9.js → p-eb8f05a9.js} +0 -0
- package/dist/ui-library/ui-library.esm.js +1 -1
- package/package.json +1 -1
|
@@ -1,712 +1,712 @@
|
|
|
1
|
-
import { isDate, isNil, isNumber, isString } from './type-check';
|
|
2
|
-
export const i18nDate = {
|
|
3
|
-
en: {
|
|
4
|
-
months: [
|
|
5
|
-
'January',
|
|
6
|
-
'February',
|
|
7
|
-
'March',
|
|
8
|
-
'April',
|
|
9
|
-
'May',
|
|
10
|
-
'June',
|
|
11
|
-
'July',
|
|
12
|
-
'August',
|
|
13
|
-
'September',
|
|
14
|
-
'October',
|
|
15
|
-
'November',
|
|
16
|
-
'December',
|
|
17
|
-
],
|
|
18
|
-
monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
|
19
|
-
monthsShortGrouped: [
|
|
20
|
-
['Jan', 'Feb', 'Mar', 'Apr'],
|
|
21
|
-
['May', 'Jun', 'Jul', 'Aug'],
|
|
22
|
-
['Sep', 'Oct', 'Nov', 'Dec'],
|
|
23
|
-
],
|
|
24
|
-
weekdays: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
|
25
|
-
weekdaysShort: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
26
|
-
weekdaysMin: ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'],
|
|
27
|
-
},
|
|
28
|
-
de: {
|
|
29
|
-
months: [
|
|
30
|
-
'Januar',
|
|
31
|
-
'Februar',
|
|
32
|
-
'März',
|
|
33
|
-
'April',
|
|
34
|
-
'Mai',
|
|
35
|
-
'Juni',
|
|
36
|
-
'Juli',
|
|
37
|
-
'August',
|
|
38
|
-
'September',
|
|
39
|
-
'Oktober',
|
|
40
|
-
'November',
|
|
41
|
-
'Dezember',
|
|
42
|
-
],
|
|
43
|
-
monthsShort: ['Jan.', 'Feb.', 'März', 'Apr.', 'Mai', 'Juni', 'Juli', 'Aug.', 'Sep.', 'Okt.', 'Nov.', 'Dez.'],
|
|
44
|
-
monthsShortGrouped: [
|
|
45
|
-
['Jan.', 'Feb.', 'März', 'Apr.'],
|
|
46
|
-
['Mai', 'Juni', 'Juli', 'Aug.'],
|
|
47
|
-
['Sep.', 'Okt.', 'Nov.', 'Dez.'],
|
|
48
|
-
],
|
|
49
|
-
weekdays: ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'],
|
|
50
|
-
weekdaysShort: ['Mo.', 'Di.', 'Mi.', 'Do.', 'Fr.', 'Sa.', 'So.'],
|
|
51
|
-
weekdaysMin: ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'],
|
|
52
|
-
},
|
|
53
|
-
fr: {
|
|
54
|
-
months: [
|
|
55
|
-
'janvier',
|
|
56
|
-
'février',
|
|
57
|
-
'mars',
|
|
58
|
-
'avril',
|
|
59
|
-
'mai',
|
|
60
|
-
'juin',
|
|
61
|
-
'juillet',
|
|
62
|
-
'août',
|
|
63
|
-
'septembre',
|
|
64
|
-
'octobre',
|
|
65
|
-
'novembre',
|
|
66
|
-
'décembre',
|
|
67
|
-
],
|
|
68
|
-
monthsShort: ['janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
|
|
69
|
-
monthsShortGrouped: [
|
|
70
|
-
['janv.', 'févr.', 'mars', 'avr.'],
|
|
71
|
-
['mai', 'juin', 'juil.', 'août'],
|
|
72
|
-
['sept.', 'oct.', 'nov.', 'déc.'],
|
|
73
|
-
],
|
|
74
|
-
weekdays: ['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'],
|
|
75
|
-
weekdaysShort: ['lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.', 'dim.'],
|
|
76
|
-
weekdaysMin: ['lu', 'ma', 'me', 'je', 've', 'sa', 'di'],
|
|
77
|
-
},
|
|
78
|
-
it: {
|
|
79
|
-
months: [
|
|
80
|
-
'gennaio',
|
|
81
|
-
'febbraio',
|
|
82
|
-
'marzo',
|
|
83
|
-
'aprile',
|
|
84
|
-
'maggio',
|
|
85
|
-
'giugno',
|
|
86
|
-
'luglio',
|
|
87
|
-
'agosto',
|
|
88
|
-
'settembre',
|
|
89
|
-
'ottobre',
|
|
90
|
-
'novembre',
|
|
91
|
-
'dicembre',
|
|
92
|
-
],
|
|
93
|
-
monthsShort: ['gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic'],
|
|
94
|
-
monthsShortGrouped: [
|
|
95
|
-
['gen', 'feb', 'mar', 'apr'],
|
|
96
|
-
['mag', 'giu', 'lug', 'ago'],
|
|
97
|
-
['set', 'ott', 'nov', 'dic'],
|
|
98
|
-
],
|
|
99
|
-
weekdays: ['lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato', 'domenica'],
|
|
100
|
-
weekdaysShort: ['lun', 'mar', 'mer', 'gio', 'ven', 'sab', 'dom'],
|
|
101
|
-
weekdaysMin: ['lu', 'ma', 'me', 'gi', 've', 'sa', 'do'],
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Returns a JS Date instance of the exact moment
|
|
106
|
-
*
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const date = now()
|
|
109
|
-
* // Wed Mar 10 2021 20:30:32 GMT+0100 (Central European Standard Time)
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export const now = () => new Date();
|
|
113
|
-
export const pad = (value) => String(value).padStart(2, '0');
|
|
114
|
-
/**
|
|
115
|
-
* Returns `true` if the given date is valid
|
|
116
|
-
*/
|
|
117
|
-
export const isValidDate = (value) => {
|
|
118
|
-
if (isNil(value)) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
if (isNumber(value)) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
if (isDate(value)) {
|
|
125
|
-
return !isNaN(value.getTime());
|
|
126
|
-
}
|
|
127
|
-
return new Date(value).toString() !== 'Invalid Date';
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Returns the year number of the given date
|
|
131
|
-
*
|
|
132
|
-
* ```typescript
|
|
133
|
-
* year(new Date(2020, 0, 1)) // 2020
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
export const year = (date) => {
|
|
137
|
-
if (date && isValidDate(date)) {
|
|
138
|
-
return date.getFullYear();
|
|
139
|
-
}
|
|
140
|
-
throw new Error('Not a valid date');
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Returns the month number of the given date
|
|
144
|
-
*
|
|
145
|
-
* ```typescript
|
|
146
|
-
* month(new Date(2020, 0, 1)) // 0
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
export const month = (date) => {
|
|
150
|
-
if (date && isValidDate(date)) {
|
|
151
|
-
return date.getMonth();
|
|
152
|
-
}
|
|
153
|
-
throw new Error('Not a valid date');
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Returns the day number of the given date
|
|
157
|
-
*
|
|
158
|
-
* ```typescript
|
|
159
|
-
* day(new Date(2020, 0, 1)) // 1
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
export const day = (date) => {
|
|
163
|
-
if (date && isValidDate(date)) {
|
|
164
|
-
return date.getDate();
|
|
165
|
-
}
|
|
166
|
-
throw new Error('Not a valid date');
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* Returns the hours of the given date
|
|
170
|
-
*/
|
|
171
|
-
export const hours = (date) => {
|
|
172
|
-
if (date && isValidDate(date)) {
|
|
173
|
-
return date.getHours();
|
|
174
|
-
}
|
|
175
|
-
throw new Error('Not a valid date');
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Returns the minutes of the given date
|
|
179
|
-
*/
|
|
180
|
-
export const minutes = (date) => {
|
|
181
|
-
if (date && isValidDate(date)) {
|
|
182
|
-
return date.getMinutes();
|
|
183
|
-
}
|
|
184
|
-
throw new Error('Not a valid date');
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* Returns the seconds of the given date
|
|
188
|
-
*/
|
|
189
|
-
export const seconds = (date) => {
|
|
190
|
-
if (date && isValidDate(date)) {
|
|
191
|
-
return date.getSeconds();
|
|
192
|
-
}
|
|
193
|
-
throw new Error('Not a valid date');
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* Returns the first day of the week of the given date.
|
|
197
|
-
*/
|
|
198
|
-
export const getFirstDayOfTheWeek = (date) => {
|
|
199
|
-
const weekdayDiff = [6, 0, 1, 2, 3, 4, 5];
|
|
200
|
-
const day = new Date(date);
|
|
201
|
-
day.setDate(day.getDate() - weekdayDiff[day.getDay()]);
|
|
202
|
-
return day;
|
|
203
|
-
};
|
|
204
|
-
/**
|
|
205
|
-
* Returns `true` when the year of the dates are the same
|
|
206
|
-
*/
|
|
207
|
-
export const isSameYear = (a, b) => (a === null || a === void 0 ? void 0 : a.getFullYear()) === (b === null || b === void 0 ? void 0 : b.getFullYear());
|
|
208
|
-
/**
|
|
209
|
-
* Returns `true` when the month of the dates are the same
|
|
210
|
-
*/
|
|
211
|
-
export const isSameMonth = (a, b) => isSameYear(a, b) && (a === null || a === void 0 ? void 0 : a.getMonth()) === (b === null || b === void 0 ? void 0 : b.getMonth());
|
|
212
|
-
/**
|
|
213
|
-
* Returns `true` when the day of the dates are the same
|
|
214
|
-
*/
|
|
215
|
-
export const isSameDay = (a, b) => isSameMonth(a, b) && (a === null || a === void 0 ? void 0 : a.getDate()) === (b === null || b === void 0 ? void 0 : b.getDate());
|
|
216
|
-
/**
|
|
217
|
-
* Returns `true` when the week of the dates are the same
|
|
218
|
-
*/
|
|
219
|
-
export const isSameWeek = (a, b) => isSameDay(getFirstDayOfTheWeek(a), getFirstDayOfTheWeek(b));
|
|
220
|
-
const localDatetime = (date) => new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
221
|
-
/**
|
|
222
|
-
* Returns the ISO string `yyyy-mm-dd` of the given date
|
|
223
|
-
*
|
|
224
|
-
* ```typescript
|
|
225
|
-
* isoString(new Date(2020, 0, 13)) // '2020-01-13'
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
export const isoString = (date) => {
|
|
229
|
-
if (isNil(date) || Date.toString() === 'Invalid Date') {
|
|
230
|
-
return '';
|
|
231
|
-
}
|
|
232
|
-
return `${year(date)}-${pad(month(date) + 1)}-${pad(day(date))}`;
|
|
233
|
-
};
|
|
234
|
-
/**
|
|
235
|
-
* Returns the ISO string `yyyy-mm-dd` of the given parameters year, month and day
|
|
236
|
-
*
|
|
237
|
-
* ```typescript
|
|
238
|
-
* newDateString(2020, 0, 13) // '2020-01-13'
|
|
239
|
-
* or
|
|
240
|
-
* newDateString(new Date(2020, 0, 13)) // '2020-01-13'
|
|
241
|
-
* ```
|
|
242
|
-
*/
|
|
243
|
-
export const newDateString = (yearOrDate, month, day) => {
|
|
244
|
-
let date;
|
|
245
|
-
if (isDate(yearOrDate)) {
|
|
246
|
-
date = localDatetime(yearOrDate);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
date = new Date(Date.UTC(yearOrDate, month - 1, day));
|
|
250
|
-
}
|
|
251
|
-
return isoString(date);
|
|
252
|
-
};
|
|
253
|
-
/**
|
|
254
|
-
* Returns `true` if the given datestring is valid
|
|
255
|
-
*/
|
|
256
|
-
export const isValidDateString = (datestring, format) => {
|
|
257
|
-
if (!isString(datestring) || !isString(format)) {
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
if (datestring.length < 6 || format.length < 6) {
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
const { day, month } = getDateParts(datestring, format);
|
|
264
|
-
if (day > 31 || month > 11 || day <= 0 || month < 0) {
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
const date = toDate(datestring, format);
|
|
268
|
-
if (isNil(date)) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
return date.toString() !== 'Invalid Date';
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
274
|
-
* Returns `true` when the given date is not smaller than the minDate and not bigger than the maxDate.
|
|
275
|
-
*
|
|
276
|
-
* ```typescript
|
|
277
|
-
* isInRange(new Date(2020, 1, 1), new Date(2020, 0, 1), new Date(2020, 2, 1)) // true
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
export const isInRange = (date, minDate, maxDate) => {
|
|
281
|
-
if (!date) {
|
|
282
|
-
return true;
|
|
283
|
-
}
|
|
284
|
-
if (minDate && date < minDate) {
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
if (maxDate && maxDate < date) {
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
return true;
|
|
291
|
-
};
|
|
292
|
-
const validateTwoDates = (first, second, validateFn) => {
|
|
293
|
-
if (isNil(first) && isNil(second)) {
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
const _first = new Date(first);
|
|
297
|
-
const _second = new Date(second);
|
|
298
|
-
if (!isValidDate(_first) || !isValidDate(_second)) {
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
return validateFn(_first, _second);
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* Returns `true` when the given date is not smaller than the before date.
|
|
305
|
-
*
|
|
306
|
-
* ```typescript
|
|
307
|
-
* isBefore(new Date(2020, 1, 1), new Date(2020, 3, 1)) // true
|
|
308
|
-
* ```
|
|
309
|
-
*/
|
|
310
|
-
export const isBefore = (date, beforeDate) => validateTwoDates(date, beforeDate, (first, second) => first < second);
|
|
311
|
-
/**
|
|
312
|
-
* Returns `true` when the given date is not smaller than the before date.
|
|
313
|
-
*
|
|
314
|
-
* ```typescript
|
|
315
|
-
* isAfter(new Date(2020, 5, 1), new Date(2020, 3, 1)) // true
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
export const isAfter = (date, afterDate) => validateTwoDates(date, afterDate, (first, second) => first > second);
|
|
319
|
-
/**
|
|
320
|
-
* Increases the year of a date and retunrs the result
|
|
321
|
-
*
|
|
322
|
-
* ```typescript
|
|
323
|
-
* increaseYear(new Date(2020, 0, 1), 1) // 2021
|
|
324
|
-
* ```
|
|
325
|
-
*/
|
|
326
|
-
export const increaseYear = (date, years) => year(date) + years;
|
|
327
|
-
/**
|
|
328
|
-
* Decreases the year of a date and retunrs the result
|
|
329
|
-
*
|
|
330
|
-
* ```typescript
|
|
331
|
-
* decreaseYear(new Date(2020, 0, 1), 1) // 2019
|
|
332
|
-
* ```
|
|
333
|
-
*/
|
|
334
|
-
export const decreaseYear = (date, years) => year(date) - years;
|
|
335
|
-
const lookAhead = (iFormat, format, match, length = 2) => {
|
|
336
|
-
const increment = length - 1;
|
|
337
|
-
const followingCharacterMatches = format.charAt(iFormat + increment) === match;
|
|
338
|
-
const hasProperLength = iFormat + increment < format.length;
|
|
339
|
-
return hasProperLength && followingCharacterMatches;
|
|
340
|
-
};
|
|
341
|
-
const formatNumber = (value, len) => {
|
|
342
|
-
let num = String(value);
|
|
343
|
-
while (num.length < len) {
|
|
344
|
-
num = '0' + num;
|
|
345
|
-
}
|
|
346
|
-
return num;
|
|
347
|
-
};
|
|
348
|
-
export const formatDate = (date, format) => {
|
|
349
|
-
if (!date) {
|
|
350
|
-
return '';
|
|
351
|
-
}
|
|
352
|
-
let output = '';
|
|
353
|
-
for (let iFormat = 0; iFormat < format.length; iFormat++) {
|
|
354
|
-
switch (format.charAt(iFormat)) {
|
|
355
|
-
case 'd':
|
|
356
|
-
if (lookAhead(iFormat, format, 'd')) {
|
|
357
|
-
output += formatNumber(date.getDate(), 2);
|
|
358
|
-
iFormat++;
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
output += String(date.getDate());
|
|
362
|
-
}
|
|
363
|
-
break;
|
|
364
|
-
case 'm':
|
|
365
|
-
if (lookAhead(iFormat, format, 'm')) {
|
|
366
|
-
output += formatNumber(date.getMonth() + 1, 2);
|
|
367
|
-
iFormat++;
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
output += String(date.getMonth() + 1);
|
|
371
|
-
}
|
|
372
|
-
break;
|
|
373
|
-
case 'y':
|
|
374
|
-
if (lookAhead(iFormat, format, 'y', 4)) {
|
|
375
|
-
iFormat += 3;
|
|
376
|
-
output += date.getFullYear();
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
output += (date.getFullYear() % 100 < 10 ? '0' : '') + (date.getFullYear() % 100);
|
|
380
|
-
iFormat++;
|
|
381
|
-
}
|
|
382
|
-
break;
|
|
383
|
-
case 'h':
|
|
384
|
-
if (lookAhead(iFormat, format, 'h')) {
|
|
385
|
-
output += formatNumber(date.getHours(), 2);
|
|
386
|
-
iFormat++;
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
output += String(date.getHours());
|
|
390
|
-
}
|
|
391
|
-
break;
|
|
392
|
-
case 'M':
|
|
393
|
-
if (lookAhead(iFormat, format, 'M')) {
|
|
394
|
-
output += formatNumber(date.getMinutes(), 2);
|
|
395
|
-
iFormat++;
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
output += String(date.getMinutes());
|
|
399
|
-
}
|
|
400
|
-
break;
|
|
401
|
-
case 's':
|
|
402
|
-
if (lookAhead(iFormat, format, 's')) {
|
|
403
|
-
output += formatNumber(date.getSeconds(), 2);
|
|
404
|
-
iFormat++;
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
output += String(date.getSeconds());
|
|
408
|
-
}
|
|
409
|
-
break;
|
|
410
|
-
default:
|
|
411
|
-
output += format.charAt(iFormat);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return output;
|
|
415
|
-
};
|
|
416
|
-
const daylightSavingAdjust = (date) => {
|
|
417
|
-
if (!date) {
|
|
418
|
-
return null;
|
|
419
|
-
}
|
|
420
|
-
date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
|
|
421
|
-
return date;
|
|
422
|
-
};
|
|
423
|
-
const getDaysCountInMonth = (month, year) => 32 - daylightSavingAdjust(new Date(year, month, 32)).getDate();
|
|
424
|
-
export const parseDate = (value, format, locale) => {
|
|
425
|
-
if (format == null || value == null) {
|
|
426
|
-
throw 'Invalid arguments';
|
|
427
|
-
}
|
|
428
|
-
value = typeof value === 'object' ? value.toString() : value + '';
|
|
429
|
-
if (value === '') {
|
|
430
|
-
return null;
|
|
431
|
-
}
|
|
432
|
-
let iFormat;
|
|
433
|
-
let dim;
|
|
434
|
-
let extra;
|
|
435
|
-
let iValue = 0;
|
|
436
|
-
let shortYearCutoff = 100;
|
|
437
|
-
let year = -1;
|
|
438
|
-
let month = -1;
|
|
439
|
-
let day = -1;
|
|
440
|
-
let doy = -1;
|
|
441
|
-
let literal = false;
|
|
442
|
-
let date;
|
|
443
|
-
let lookAhead = (match, len = 2) => {
|
|
444
|
-
const increment = len - 1;
|
|
445
|
-
let matches = iFormat + increment < format.length && format.charAt(iFormat + increment) === match;
|
|
446
|
-
if (matches) {
|
|
447
|
-
iFormat += increment;
|
|
448
|
-
}
|
|
449
|
-
return matches;
|
|
450
|
-
};
|
|
451
|
-
let getNumber = (match, len = 2) => {
|
|
452
|
-
let isDoubled = lookAhead(match, len), size = match === '@' ? 14 : match === '!' ? 20 : match === 'y' && isDoubled ? 4 : match === 'o' ? 3 : 2, minSize = match === 'y' ? size : 1, digits = new RegExp('^\\d{' + minSize + ',' + size + '}'), num = value.substring(iValue).match(digits);
|
|
453
|
-
if (!num) {
|
|
454
|
-
throw 'Missing number at position ' + iValue;
|
|
455
|
-
}
|
|
456
|
-
iValue += num[0].length;
|
|
457
|
-
return parseInt(num[0], 10);
|
|
458
|
-
};
|
|
459
|
-
let getName = (match, shortNames, longNames) => {
|
|
460
|
-
let index = -1;
|
|
461
|
-
let arr = lookAhead(match) ? longNames : shortNames;
|
|
462
|
-
let names = [];
|
|
463
|
-
for (let i = 0; i < arr.length; i++) {
|
|
464
|
-
names.push([i, arr[i]]);
|
|
465
|
-
}
|
|
466
|
-
names.sort((a, b) => {
|
|
467
|
-
return -(a[1].length - b[1].length);
|
|
468
|
-
});
|
|
469
|
-
for (let i = 0; i < names.length; i++) {
|
|
470
|
-
let name = names[i][1];
|
|
471
|
-
if (value.substr(iValue, name.length).toLowerCase() === name.toLowerCase()) {
|
|
472
|
-
index = names[i][0];
|
|
473
|
-
iValue += name.length;
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
if (index !== -1) {
|
|
478
|
-
return index + 1;
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
throw 'Unknown name at position ' + iValue;
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
let checkLiteral = () => {
|
|
485
|
-
if (value.charAt(iValue) !== format.charAt(iFormat)) {
|
|
486
|
-
throw 'Unexpected literal at position ' + iValue;
|
|
487
|
-
}
|
|
488
|
-
iValue++;
|
|
489
|
-
};
|
|
490
|
-
for (iFormat = 0; iFormat < format.length; iFormat++) {
|
|
491
|
-
if (literal) {
|
|
492
|
-
if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
|
|
493
|
-
literal = false;
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
checkLiteral();
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
switch (format.charAt(iFormat)) {
|
|
501
|
-
case 'd':
|
|
502
|
-
day = getNumber('d');
|
|
503
|
-
break;
|
|
504
|
-
case 'D':
|
|
505
|
-
getName('D', i18nDate[locale].weekdaysShort, i18nDate[locale].weekdays);
|
|
506
|
-
break;
|
|
507
|
-
case 'm':
|
|
508
|
-
month = getNumber('m');
|
|
509
|
-
break;
|
|
510
|
-
case 'M':
|
|
511
|
-
month = getName('M', i18nDate[locale].monthsShort, i18nDate[locale].months);
|
|
512
|
-
break;
|
|
513
|
-
case 'y':
|
|
514
|
-
year = getNumber('y', 4);
|
|
515
|
-
break;
|
|
516
|
-
default:
|
|
517
|
-
checkLiteral();
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (iValue < value.length) {
|
|
522
|
-
extra = value.substr(iValue);
|
|
523
|
-
if (!/^\s+/.test(extra)) {
|
|
524
|
-
throw 'Extra/unparsed characters found in date: ' + extra;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
if (year === -1) {
|
|
528
|
-
year = new Date().getFullYear();
|
|
529
|
-
}
|
|
530
|
-
else if (year < 100) {
|
|
531
|
-
year += new Date().getFullYear() - (new Date().getFullYear() % 100) + (year <= shortYearCutoff ? 0 : -100);
|
|
532
|
-
}
|
|
533
|
-
if (doy > -1) {
|
|
534
|
-
month = 1;
|
|
535
|
-
day = doy;
|
|
536
|
-
do {
|
|
537
|
-
dim = getDaysCountInMonth(year, month - 1);
|
|
538
|
-
if (day <= dim) {
|
|
539
|
-
break;
|
|
540
|
-
}
|
|
541
|
-
month++;
|
|
542
|
-
day -= dim;
|
|
543
|
-
} while (true);
|
|
544
|
-
}
|
|
545
|
-
date = daylightSavingAdjust(new Date(year, month - 1, day));
|
|
546
|
-
if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
|
|
547
|
-
throw 'Invalid date'; // E.g. 31/02/00
|
|
548
|
-
}
|
|
549
|
-
return date;
|
|
550
|
-
};
|
|
551
|
-
const FORMATTING_TOKENS = /(\[[^\[]*\])|(mm|dd|yyyy|yy|hh|MM|ss|.)/g;
|
|
552
|
-
const TWO_NUMERICS_REGEX = /\d\d/; // 00 - 99
|
|
553
|
-
const FOUR_NUMERICS_REGEX = /\d{4}/; // 0000 - 9999
|
|
554
|
-
const NON_NUMERIC_REGEX = /[^0-9]/g;
|
|
555
|
-
const YEAR = 'year';
|
|
556
|
-
const MONTH = 'month';
|
|
557
|
-
const DAY = 'day';
|
|
558
|
-
const HOUR = 'hour';
|
|
559
|
-
const MINUTE = 'minute';
|
|
560
|
-
const SECOND = 'second';
|
|
561
|
-
const parseFlags = {};
|
|
562
|
-
const addParseFlag = (token, regex, callback) => {
|
|
563
|
-
const tokens = Array.isArray(token) ? token : [token];
|
|
564
|
-
let func;
|
|
565
|
-
if (typeof callback === 'string') {
|
|
566
|
-
func = (input) => {
|
|
567
|
-
const value = parseInt(input, 10);
|
|
568
|
-
return { [callback]: value };
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
else {
|
|
572
|
-
func = callback;
|
|
573
|
-
}
|
|
574
|
-
tokens.forEach((key) => {
|
|
575
|
-
parseFlags[key] = [regex, func];
|
|
576
|
-
});
|
|
577
|
-
};
|
|
578
|
-
addParseFlag('yy', TWO_NUMERICS_REGEX, (input) => {
|
|
579
|
-
const year = new Date().getFullYear();
|
|
580
|
-
const cent = Math.floor(year / 100);
|
|
581
|
-
let value = parseInt(input, 10);
|
|
582
|
-
value = (value > 68 ? cent - 1 : cent) * 100 + value;
|
|
583
|
-
return { [YEAR]: value };
|
|
584
|
-
});
|
|
585
|
-
addParseFlag('yyyy', FOUR_NUMERICS_REGEX, YEAR);
|
|
586
|
-
addParseFlag('mm', TWO_NUMERICS_REGEX, (input) => ({ [MONTH]: parseInt(input, 10) - 1 }));
|
|
587
|
-
addParseFlag('dd', TWO_NUMERICS_REGEX, DAY);
|
|
588
|
-
addParseFlag('hh', TWO_NUMERICS_REGEX, HOUR);
|
|
589
|
-
addParseFlag('MM', TWO_NUMERICS_REGEX, MINUTE);
|
|
590
|
-
addParseFlag('ss', TWO_NUMERICS_REGEX, SECOND);
|
|
591
|
-
const getFullInputArray = (input, backupDate = new Date()) => {
|
|
592
|
-
const result = [0, 0, 1, 0, 0, 0];
|
|
593
|
-
const backupArr = [
|
|
594
|
-
backupDate.getFullYear(),
|
|
595
|
-
backupDate.getMonth(),
|
|
596
|
-
backupDate.getDate(),
|
|
597
|
-
backupDate.getHours(),
|
|
598
|
-
backupDate.getMinutes(),
|
|
599
|
-
backupDate.getSeconds(),
|
|
600
|
-
];
|
|
601
|
-
let useBackup = true;
|
|
602
|
-
for (let i = 0; i < 7; i++) {
|
|
603
|
-
if (input[i] === undefined) {
|
|
604
|
-
result[i] = useBackup ? backupArr[i] : result[i];
|
|
605
|
-
}
|
|
606
|
-
else {
|
|
607
|
-
result[i] = input[i];
|
|
608
|
-
useBackup = false;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return result;
|
|
612
|
-
};
|
|
613
|
-
const createDate = (year, month, day, hour, minute, second) => {
|
|
614
|
-
if (!(year < 100 && year >= 0)) {
|
|
615
|
-
return new Date(year, month, day, hour, minute, second);
|
|
616
|
-
}
|
|
617
|
-
const date = new Date(year + 400, month, day, hour, minute, second);
|
|
618
|
-
if (isFinite(date.getFullYear())) {
|
|
619
|
-
date.setFullYear(year);
|
|
620
|
-
}
|
|
621
|
-
return date;
|
|
622
|
-
};
|
|
623
|
-
const makeParser = (dateString, format) => {
|
|
624
|
-
const tokens = format.match(FORMATTING_TOKENS);
|
|
625
|
-
if (!tokens) {
|
|
626
|
-
throw new Error();
|
|
627
|
-
}
|
|
628
|
-
const { length } = tokens;
|
|
629
|
-
let mark = {};
|
|
630
|
-
for (let i = 0; i < length; i += 1) {
|
|
631
|
-
const token = tokens[i];
|
|
632
|
-
const parseTo = parseFlags[token];
|
|
633
|
-
if (!parseTo) {
|
|
634
|
-
const word = token.replace(/^\[|\]$/g, '');
|
|
635
|
-
if (dateString.indexOf(word) === 0) {
|
|
636
|
-
dateString = dateString.substr(word.length);
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
throw new Error('not match');
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
const regex = parseTo[0];
|
|
644
|
-
const parser = parseTo[1];
|
|
645
|
-
const value = (regex.exec(dateString) || [])[0];
|
|
646
|
-
const obj = parser(value);
|
|
647
|
-
mark = Object.assign(Object.assign({}, mark), obj);
|
|
648
|
-
dateString = dateString.replace(value, '');
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
return mark;
|
|
652
|
-
};
|
|
653
|
-
const getCleanDateString = (dirtyDateString, format) => {
|
|
654
|
-
if (dirtyDateString.length === format.length) {
|
|
655
|
-
return dirtyDateString;
|
|
656
|
-
}
|
|
657
|
-
const separator = dirtyDateString.match(NON_NUMERIC_REGEX)[0];
|
|
658
|
-
// pad signle digits to follow supported dateformats
|
|
659
|
-
return dirtyDateString
|
|
660
|
-
.split(separator)
|
|
661
|
-
.map((s) => (s.length === 1 ? '0' + s : s))
|
|
662
|
-
.join(separator);
|
|
663
|
-
};
|
|
664
|
-
const getDateParts = (dirtyDateString, format) => {
|
|
665
|
-
const dateString = getCleanDateString(dirtyDateString, format);
|
|
666
|
-
return makeParser(dateString, format);
|
|
667
|
-
};
|
|
668
|
-
export const toDate = (dirtyDateString, format) => {
|
|
669
|
-
try {
|
|
670
|
-
const { backupDate = new Date() } = {};
|
|
671
|
-
const { year, month, day, hour, minute, second, date } = getDateParts(dirtyDateString, format);
|
|
672
|
-
if (date) {
|
|
673
|
-
return date;
|
|
674
|
-
}
|
|
675
|
-
const inputArray = [year, month, day, hour, minute, second];
|
|
676
|
-
let parsedDate;
|
|
677
|
-
const result = getFullInputArray(inputArray, backupDate);
|
|
678
|
-
parsedDate = createDate(...result);
|
|
679
|
-
return parsedDate;
|
|
680
|
-
}
|
|
681
|
-
catch (e) {
|
|
682
|
-
return new Date(NaN);
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
export const createCalendarGrid = (calendarGridArguments) => {
|
|
686
|
-
const { firstDateOfBox, allowedDates, dateFormat, selectedDate, minDate, maxDate, pointerDate } = calendarGridArguments;
|
|
687
|
-
const weekDatePointer = new Date(firstDateOfBox);
|
|
688
|
-
const dayDatePointer = new Date(firstDateOfBox);
|
|
689
|
-
let calendar = [];
|
|
690
|
-
do {
|
|
691
|
-
let row = [];
|
|
692
|
-
do {
|
|
693
|
-
row = [
|
|
694
|
-
...row,
|
|
695
|
-
{
|
|
696
|
-
date: new Date(dayDatePointer),
|
|
697
|
-
display: formatDate(dayDatePointer, dateFormat),
|
|
698
|
-
dateString: formatDate(dayDatePointer, dateFormat),
|
|
699
|
-
label: day(dayDatePointer).toString(),
|
|
700
|
-
isToday: isSameDay(dayDatePointer, now()),
|
|
701
|
-
isSelected: selectedDate && isSameDay(dayDatePointer, selectedDate),
|
|
702
|
-
isDisabled: !allowedDates(dayDatePointer) || !isInRange(dayDatePointer, minDate, maxDate),
|
|
703
|
-
isOutdated: pointerDate.month !== dayDatePointer.getMonth() || !isInRange(dayDatePointer, minDate, maxDate),
|
|
704
|
-
},
|
|
705
|
-
];
|
|
706
|
-
dayDatePointer.setDate(dayDatePointer.getDate() + 1);
|
|
707
|
-
} while (isSameWeek(dayDatePointer, weekDatePointer));
|
|
708
|
-
calendar = [...calendar, row];
|
|
709
|
-
weekDatePointer.setDate(weekDatePointer.getDate() + 7);
|
|
710
|
-
} while (isSameMonth(new Date(pointerDate.year, pointerDate.month, pointerDate.day), dayDatePointer));
|
|
711
|
-
return calendar;
|
|
712
|
-
};
|
|
1
|
+
import { isDate, isNil, isNumber, isString } from './type-check';
|
|
2
|
+
export const i18nDate = {
|
|
3
|
+
en: {
|
|
4
|
+
months: [
|
|
5
|
+
'January',
|
|
6
|
+
'February',
|
|
7
|
+
'March',
|
|
8
|
+
'April',
|
|
9
|
+
'May',
|
|
10
|
+
'June',
|
|
11
|
+
'July',
|
|
12
|
+
'August',
|
|
13
|
+
'September',
|
|
14
|
+
'October',
|
|
15
|
+
'November',
|
|
16
|
+
'December',
|
|
17
|
+
],
|
|
18
|
+
monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
|
19
|
+
monthsShortGrouped: [
|
|
20
|
+
['Jan', 'Feb', 'Mar', 'Apr'],
|
|
21
|
+
['May', 'Jun', 'Jul', 'Aug'],
|
|
22
|
+
['Sep', 'Oct', 'Nov', 'Dec'],
|
|
23
|
+
],
|
|
24
|
+
weekdays: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
|
25
|
+
weekdaysShort: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
26
|
+
weekdaysMin: ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'],
|
|
27
|
+
},
|
|
28
|
+
de: {
|
|
29
|
+
months: [
|
|
30
|
+
'Januar',
|
|
31
|
+
'Februar',
|
|
32
|
+
'März',
|
|
33
|
+
'April',
|
|
34
|
+
'Mai',
|
|
35
|
+
'Juni',
|
|
36
|
+
'Juli',
|
|
37
|
+
'August',
|
|
38
|
+
'September',
|
|
39
|
+
'Oktober',
|
|
40
|
+
'November',
|
|
41
|
+
'Dezember',
|
|
42
|
+
],
|
|
43
|
+
monthsShort: ['Jan.', 'Feb.', 'März', 'Apr.', 'Mai', 'Juni', 'Juli', 'Aug.', 'Sep.', 'Okt.', 'Nov.', 'Dez.'],
|
|
44
|
+
monthsShortGrouped: [
|
|
45
|
+
['Jan.', 'Feb.', 'März', 'Apr.'],
|
|
46
|
+
['Mai', 'Juni', 'Juli', 'Aug.'],
|
|
47
|
+
['Sep.', 'Okt.', 'Nov.', 'Dez.'],
|
|
48
|
+
],
|
|
49
|
+
weekdays: ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'],
|
|
50
|
+
weekdaysShort: ['Mo.', 'Di.', 'Mi.', 'Do.', 'Fr.', 'Sa.', 'So.'],
|
|
51
|
+
weekdaysMin: ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'],
|
|
52
|
+
},
|
|
53
|
+
fr: {
|
|
54
|
+
months: [
|
|
55
|
+
'janvier',
|
|
56
|
+
'février',
|
|
57
|
+
'mars',
|
|
58
|
+
'avril',
|
|
59
|
+
'mai',
|
|
60
|
+
'juin',
|
|
61
|
+
'juillet',
|
|
62
|
+
'août',
|
|
63
|
+
'septembre',
|
|
64
|
+
'octobre',
|
|
65
|
+
'novembre',
|
|
66
|
+
'décembre',
|
|
67
|
+
],
|
|
68
|
+
monthsShort: ['janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
|
|
69
|
+
monthsShortGrouped: [
|
|
70
|
+
['janv.', 'févr.', 'mars', 'avr.'],
|
|
71
|
+
['mai', 'juin', 'juil.', 'août'],
|
|
72
|
+
['sept.', 'oct.', 'nov.', 'déc.'],
|
|
73
|
+
],
|
|
74
|
+
weekdays: ['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'],
|
|
75
|
+
weekdaysShort: ['lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.', 'dim.'],
|
|
76
|
+
weekdaysMin: ['lu', 'ma', 'me', 'je', 've', 'sa', 'di'],
|
|
77
|
+
},
|
|
78
|
+
it: {
|
|
79
|
+
months: [
|
|
80
|
+
'gennaio',
|
|
81
|
+
'febbraio',
|
|
82
|
+
'marzo',
|
|
83
|
+
'aprile',
|
|
84
|
+
'maggio',
|
|
85
|
+
'giugno',
|
|
86
|
+
'luglio',
|
|
87
|
+
'agosto',
|
|
88
|
+
'settembre',
|
|
89
|
+
'ottobre',
|
|
90
|
+
'novembre',
|
|
91
|
+
'dicembre',
|
|
92
|
+
],
|
|
93
|
+
monthsShort: ['gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic'],
|
|
94
|
+
monthsShortGrouped: [
|
|
95
|
+
['gen', 'feb', 'mar', 'apr'],
|
|
96
|
+
['mag', 'giu', 'lug', 'ago'],
|
|
97
|
+
['set', 'ott', 'nov', 'dic'],
|
|
98
|
+
],
|
|
99
|
+
weekdays: ['lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato', 'domenica'],
|
|
100
|
+
weekdaysShort: ['lun', 'mar', 'mer', 'gio', 'ven', 'sab', 'dom'],
|
|
101
|
+
weekdaysMin: ['lu', 'ma', 'me', 'gi', 've', 'sa', 'do'],
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Returns a JS Date instance of the exact moment
|
|
106
|
+
*
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const date = now()
|
|
109
|
+
* // Wed Mar 10 2021 20:30:32 GMT+0100 (Central European Standard Time)
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export const now = () => new Date();
|
|
113
|
+
export const pad = (value) => String(value).padStart(2, '0');
|
|
114
|
+
/**
|
|
115
|
+
* Returns `true` if the given date is valid
|
|
116
|
+
*/
|
|
117
|
+
export const isValidDate = (value) => {
|
|
118
|
+
if (isNil(value)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (isNumber(value)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (isDate(value)) {
|
|
125
|
+
return !isNaN(value.getTime());
|
|
126
|
+
}
|
|
127
|
+
return new Date(value).toString() !== 'Invalid Date';
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Returns the year number of the given date
|
|
131
|
+
*
|
|
132
|
+
* ```typescript
|
|
133
|
+
* year(new Date(2020, 0, 1)) // 2020
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export const year = (date) => {
|
|
137
|
+
if (date && isValidDate(date)) {
|
|
138
|
+
return date.getFullYear();
|
|
139
|
+
}
|
|
140
|
+
throw new Error('Not a valid date');
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Returns the month number of the given date
|
|
144
|
+
*
|
|
145
|
+
* ```typescript
|
|
146
|
+
* month(new Date(2020, 0, 1)) // 0
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export const month = (date) => {
|
|
150
|
+
if (date && isValidDate(date)) {
|
|
151
|
+
return date.getMonth();
|
|
152
|
+
}
|
|
153
|
+
throw new Error('Not a valid date');
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Returns the day number of the given date
|
|
157
|
+
*
|
|
158
|
+
* ```typescript
|
|
159
|
+
* day(new Date(2020, 0, 1)) // 1
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export const day = (date) => {
|
|
163
|
+
if (date && isValidDate(date)) {
|
|
164
|
+
return date.getDate();
|
|
165
|
+
}
|
|
166
|
+
throw new Error('Not a valid date');
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Returns the hours of the given date
|
|
170
|
+
*/
|
|
171
|
+
export const hours = (date) => {
|
|
172
|
+
if (date && isValidDate(date)) {
|
|
173
|
+
return date.getHours();
|
|
174
|
+
}
|
|
175
|
+
throw new Error('Not a valid date');
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Returns the minutes of the given date
|
|
179
|
+
*/
|
|
180
|
+
export const minutes = (date) => {
|
|
181
|
+
if (date && isValidDate(date)) {
|
|
182
|
+
return date.getMinutes();
|
|
183
|
+
}
|
|
184
|
+
throw new Error('Not a valid date');
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Returns the seconds of the given date
|
|
188
|
+
*/
|
|
189
|
+
export const seconds = (date) => {
|
|
190
|
+
if (date && isValidDate(date)) {
|
|
191
|
+
return date.getSeconds();
|
|
192
|
+
}
|
|
193
|
+
throw new Error('Not a valid date');
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Returns the first day of the week of the given date.
|
|
197
|
+
*/
|
|
198
|
+
export const getFirstDayOfTheWeek = (date) => {
|
|
199
|
+
const weekdayDiff = [6, 0, 1, 2, 3, 4, 5];
|
|
200
|
+
const day = new Date(date);
|
|
201
|
+
day.setDate(day.getDate() - weekdayDiff[day.getDay()]);
|
|
202
|
+
return day;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Returns `true` when the year of the dates are the same
|
|
206
|
+
*/
|
|
207
|
+
export const isSameYear = (a, b) => (a === null || a === void 0 ? void 0 : a.getFullYear()) === (b === null || b === void 0 ? void 0 : b.getFullYear());
|
|
208
|
+
/**
|
|
209
|
+
* Returns `true` when the month of the dates are the same
|
|
210
|
+
*/
|
|
211
|
+
export const isSameMonth = (a, b) => isSameYear(a, b) && (a === null || a === void 0 ? void 0 : a.getMonth()) === (b === null || b === void 0 ? void 0 : b.getMonth());
|
|
212
|
+
/**
|
|
213
|
+
* Returns `true` when the day of the dates are the same
|
|
214
|
+
*/
|
|
215
|
+
export const isSameDay = (a, b) => isSameMonth(a, b) && (a === null || a === void 0 ? void 0 : a.getDate()) === (b === null || b === void 0 ? void 0 : b.getDate());
|
|
216
|
+
/**
|
|
217
|
+
* Returns `true` when the week of the dates are the same
|
|
218
|
+
*/
|
|
219
|
+
export const isSameWeek = (a, b) => isSameDay(getFirstDayOfTheWeek(a), getFirstDayOfTheWeek(b));
|
|
220
|
+
const localDatetime = (date) => new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
221
|
+
/**
|
|
222
|
+
* Returns the ISO string `yyyy-mm-dd` of the given date
|
|
223
|
+
*
|
|
224
|
+
* ```typescript
|
|
225
|
+
* isoString(new Date(2020, 0, 13)) // '2020-01-13'
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export const isoString = (date) => {
|
|
229
|
+
if (isNil(date) || Date.toString() === 'Invalid Date') {
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
232
|
+
return `${year(date)}-${pad(month(date) + 1)}-${pad(day(date))}`;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Returns the ISO string `yyyy-mm-dd` of the given parameters year, month and day
|
|
236
|
+
*
|
|
237
|
+
* ```typescript
|
|
238
|
+
* newDateString(2020, 0, 13) // '2020-01-13'
|
|
239
|
+
* or
|
|
240
|
+
* newDateString(new Date(2020, 0, 13)) // '2020-01-13'
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
export const newDateString = (yearOrDate, month, day) => {
|
|
244
|
+
let date;
|
|
245
|
+
if (isDate(yearOrDate)) {
|
|
246
|
+
date = localDatetime(yearOrDate);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
date = new Date(Date.UTC(yearOrDate, month - 1, day));
|
|
250
|
+
}
|
|
251
|
+
return isoString(date);
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Returns `true` if the given datestring is valid
|
|
255
|
+
*/
|
|
256
|
+
export const isValidDateString = (datestring, format) => {
|
|
257
|
+
if (!isString(datestring) || !isString(format)) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (datestring.length < 6 || format.length < 6) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
const { day, month } = getDateParts(datestring, format);
|
|
264
|
+
if (day > 31 || month > 11 || day <= 0 || month < 0) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
const date = toDate(datestring, format);
|
|
268
|
+
if (isNil(date)) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
return date.toString() !== 'Invalid Date';
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Returns `true` when the given date is not smaller than the minDate and not bigger than the maxDate.
|
|
275
|
+
*
|
|
276
|
+
* ```typescript
|
|
277
|
+
* isInRange(new Date(2020, 1, 1), new Date(2020, 0, 1), new Date(2020, 2, 1)) // true
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
export const isInRange = (date, minDate, maxDate) => {
|
|
281
|
+
if (!date) {
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
if (minDate && date < minDate) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
if (maxDate && maxDate < date) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
return true;
|
|
291
|
+
};
|
|
292
|
+
const validateTwoDates = (first, second, validateFn) => {
|
|
293
|
+
if (isNil(first) && isNil(second)) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
const _first = new Date(first);
|
|
297
|
+
const _second = new Date(second);
|
|
298
|
+
if (!isValidDate(_first) || !isValidDate(_second)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return validateFn(_first, _second);
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Returns `true` when the given date is not smaller than the before date.
|
|
305
|
+
*
|
|
306
|
+
* ```typescript
|
|
307
|
+
* isBefore(new Date(2020, 1, 1), new Date(2020, 3, 1)) // true
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
export const isBefore = (date, beforeDate) => validateTwoDates(date, beforeDate, (first, second) => first < second);
|
|
311
|
+
/**
|
|
312
|
+
* Returns `true` when the given date is not smaller than the before date.
|
|
313
|
+
*
|
|
314
|
+
* ```typescript
|
|
315
|
+
* isAfter(new Date(2020, 5, 1), new Date(2020, 3, 1)) // true
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
export const isAfter = (date, afterDate) => validateTwoDates(date, afterDate, (first, second) => first > second);
|
|
319
|
+
/**
|
|
320
|
+
* Increases the year of a date and retunrs the result
|
|
321
|
+
*
|
|
322
|
+
* ```typescript
|
|
323
|
+
* increaseYear(new Date(2020, 0, 1), 1) // 2021
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
export const increaseYear = (date, years) => year(date) + years;
|
|
327
|
+
/**
|
|
328
|
+
* Decreases the year of a date and retunrs the result
|
|
329
|
+
*
|
|
330
|
+
* ```typescript
|
|
331
|
+
* decreaseYear(new Date(2020, 0, 1), 1) // 2019
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
export const decreaseYear = (date, years) => year(date) - years;
|
|
335
|
+
const lookAhead = (iFormat, format, match, length = 2) => {
|
|
336
|
+
const increment = length - 1;
|
|
337
|
+
const followingCharacterMatches = format.charAt(iFormat + increment) === match;
|
|
338
|
+
const hasProperLength = iFormat + increment < format.length;
|
|
339
|
+
return hasProperLength && followingCharacterMatches;
|
|
340
|
+
};
|
|
341
|
+
const formatNumber = (value, len) => {
|
|
342
|
+
let num = String(value);
|
|
343
|
+
while (num.length < len) {
|
|
344
|
+
num = '0' + num;
|
|
345
|
+
}
|
|
346
|
+
return num;
|
|
347
|
+
};
|
|
348
|
+
export const formatDate = (date, format) => {
|
|
349
|
+
if (!date) {
|
|
350
|
+
return '';
|
|
351
|
+
}
|
|
352
|
+
let output = '';
|
|
353
|
+
for (let iFormat = 0; iFormat < format.length; iFormat++) {
|
|
354
|
+
switch (format.charAt(iFormat)) {
|
|
355
|
+
case 'd':
|
|
356
|
+
if (lookAhead(iFormat, format, 'd')) {
|
|
357
|
+
output += formatNumber(date.getDate(), 2);
|
|
358
|
+
iFormat++;
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
output += String(date.getDate());
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
case 'm':
|
|
365
|
+
if (lookAhead(iFormat, format, 'm')) {
|
|
366
|
+
output += formatNumber(date.getMonth() + 1, 2);
|
|
367
|
+
iFormat++;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
output += String(date.getMonth() + 1);
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
case 'y':
|
|
374
|
+
if (lookAhead(iFormat, format, 'y', 4)) {
|
|
375
|
+
iFormat += 3;
|
|
376
|
+
output += date.getFullYear();
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
output += (date.getFullYear() % 100 < 10 ? '0' : '') + (date.getFullYear() % 100);
|
|
380
|
+
iFormat++;
|
|
381
|
+
}
|
|
382
|
+
break;
|
|
383
|
+
case 'h':
|
|
384
|
+
if (lookAhead(iFormat, format, 'h')) {
|
|
385
|
+
output += formatNumber(date.getHours(), 2);
|
|
386
|
+
iFormat++;
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
output += String(date.getHours());
|
|
390
|
+
}
|
|
391
|
+
break;
|
|
392
|
+
case 'M':
|
|
393
|
+
if (lookAhead(iFormat, format, 'M')) {
|
|
394
|
+
output += formatNumber(date.getMinutes(), 2);
|
|
395
|
+
iFormat++;
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
output += String(date.getMinutes());
|
|
399
|
+
}
|
|
400
|
+
break;
|
|
401
|
+
case 's':
|
|
402
|
+
if (lookAhead(iFormat, format, 's')) {
|
|
403
|
+
output += formatNumber(date.getSeconds(), 2);
|
|
404
|
+
iFormat++;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
output += String(date.getSeconds());
|
|
408
|
+
}
|
|
409
|
+
break;
|
|
410
|
+
default:
|
|
411
|
+
output += format.charAt(iFormat);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return output;
|
|
415
|
+
};
|
|
416
|
+
const daylightSavingAdjust = (date) => {
|
|
417
|
+
if (!date) {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
|
|
421
|
+
return date;
|
|
422
|
+
};
|
|
423
|
+
const getDaysCountInMonth = (month, year) => 32 - daylightSavingAdjust(new Date(year, month, 32)).getDate();
|
|
424
|
+
export const parseDate = (value, format, locale) => {
|
|
425
|
+
if (format == null || value == null) {
|
|
426
|
+
throw 'Invalid arguments';
|
|
427
|
+
}
|
|
428
|
+
value = typeof value === 'object' ? value.toString() : value + '';
|
|
429
|
+
if (value === '') {
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
let iFormat;
|
|
433
|
+
let dim;
|
|
434
|
+
let extra;
|
|
435
|
+
let iValue = 0;
|
|
436
|
+
let shortYearCutoff = 100;
|
|
437
|
+
let year = -1;
|
|
438
|
+
let month = -1;
|
|
439
|
+
let day = -1;
|
|
440
|
+
let doy = -1;
|
|
441
|
+
let literal = false;
|
|
442
|
+
let date;
|
|
443
|
+
let lookAhead = (match, len = 2) => {
|
|
444
|
+
const increment = len - 1;
|
|
445
|
+
let matches = iFormat + increment < format.length && format.charAt(iFormat + increment) === match;
|
|
446
|
+
if (matches) {
|
|
447
|
+
iFormat += increment;
|
|
448
|
+
}
|
|
449
|
+
return matches;
|
|
450
|
+
};
|
|
451
|
+
let getNumber = (match, len = 2) => {
|
|
452
|
+
let isDoubled = lookAhead(match, len), size = match === '@' ? 14 : match === '!' ? 20 : match === 'y' && isDoubled ? 4 : match === 'o' ? 3 : 2, minSize = match === 'y' ? size : 1, digits = new RegExp('^\\d{' + minSize + ',' + size + '}'), num = value.substring(iValue).match(digits);
|
|
453
|
+
if (!num) {
|
|
454
|
+
throw 'Missing number at position ' + iValue;
|
|
455
|
+
}
|
|
456
|
+
iValue += num[0].length;
|
|
457
|
+
return parseInt(num[0], 10);
|
|
458
|
+
};
|
|
459
|
+
let getName = (match, shortNames, longNames) => {
|
|
460
|
+
let index = -1;
|
|
461
|
+
let arr = lookAhead(match) ? longNames : shortNames;
|
|
462
|
+
let names = [];
|
|
463
|
+
for (let i = 0; i < arr.length; i++) {
|
|
464
|
+
names.push([i, arr[i]]);
|
|
465
|
+
}
|
|
466
|
+
names.sort((a, b) => {
|
|
467
|
+
return -(a[1].length - b[1].length);
|
|
468
|
+
});
|
|
469
|
+
for (let i = 0; i < names.length; i++) {
|
|
470
|
+
let name = names[i][1];
|
|
471
|
+
if (value.substr(iValue, name.length).toLowerCase() === name.toLowerCase()) {
|
|
472
|
+
index = names[i][0];
|
|
473
|
+
iValue += name.length;
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (index !== -1) {
|
|
478
|
+
return index + 1;
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
throw 'Unknown name at position ' + iValue;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
let checkLiteral = () => {
|
|
485
|
+
if (value.charAt(iValue) !== format.charAt(iFormat)) {
|
|
486
|
+
throw 'Unexpected literal at position ' + iValue;
|
|
487
|
+
}
|
|
488
|
+
iValue++;
|
|
489
|
+
};
|
|
490
|
+
for (iFormat = 0; iFormat < format.length; iFormat++) {
|
|
491
|
+
if (literal) {
|
|
492
|
+
if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
|
|
493
|
+
literal = false;
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
checkLiteral();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
switch (format.charAt(iFormat)) {
|
|
501
|
+
case 'd':
|
|
502
|
+
day = getNumber('d');
|
|
503
|
+
break;
|
|
504
|
+
case 'D':
|
|
505
|
+
getName('D', i18nDate[locale].weekdaysShort, i18nDate[locale].weekdays);
|
|
506
|
+
break;
|
|
507
|
+
case 'm':
|
|
508
|
+
month = getNumber('m');
|
|
509
|
+
break;
|
|
510
|
+
case 'M':
|
|
511
|
+
month = getName('M', i18nDate[locale].monthsShort, i18nDate[locale].months);
|
|
512
|
+
break;
|
|
513
|
+
case 'y':
|
|
514
|
+
year = getNumber('y', 4);
|
|
515
|
+
break;
|
|
516
|
+
default:
|
|
517
|
+
checkLiteral();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (iValue < value.length) {
|
|
522
|
+
extra = value.substr(iValue);
|
|
523
|
+
if (!/^\s+/.test(extra)) {
|
|
524
|
+
throw 'Extra/unparsed characters found in date: ' + extra;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (year === -1) {
|
|
528
|
+
year = new Date().getFullYear();
|
|
529
|
+
}
|
|
530
|
+
else if (year < 100) {
|
|
531
|
+
year += new Date().getFullYear() - (new Date().getFullYear() % 100) + (year <= shortYearCutoff ? 0 : -100);
|
|
532
|
+
}
|
|
533
|
+
if (doy > -1) {
|
|
534
|
+
month = 1;
|
|
535
|
+
day = doy;
|
|
536
|
+
do {
|
|
537
|
+
dim = getDaysCountInMonth(year, month - 1);
|
|
538
|
+
if (day <= dim) {
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
month++;
|
|
542
|
+
day -= dim;
|
|
543
|
+
} while (true);
|
|
544
|
+
}
|
|
545
|
+
date = daylightSavingAdjust(new Date(year, month - 1, day));
|
|
546
|
+
if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
|
|
547
|
+
throw 'Invalid date'; // E.g. 31/02/00
|
|
548
|
+
}
|
|
549
|
+
return date;
|
|
550
|
+
};
|
|
551
|
+
const FORMATTING_TOKENS = /(\[[^\[]*\])|(mm|dd|yyyy|yy|hh|MM|ss|.)/g;
|
|
552
|
+
const TWO_NUMERICS_REGEX = /\d\d/; // 00 - 99
|
|
553
|
+
const FOUR_NUMERICS_REGEX = /\d{4}/; // 0000 - 9999
|
|
554
|
+
const NON_NUMERIC_REGEX = /[^0-9]/g;
|
|
555
|
+
const YEAR = 'year';
|
|
556
|
+
const MONTH = 'month';
|
|
557
|
+
const DAY = 'day';
|
|
558
|
+
const HOUR = 'hour';
|
|
559
|
+
const MINUTE = 'minute';
|
|
560
|
+
const SECOND = 'second';
|
|
561
|
+
const parseFlags = {};
|
|
562
|
+
const addParseFlag = (token, regex, callback) => {
|
|
563
|
+
const tokens = Array.isArray(token) ? token : [token];
|
|
564
|
+
let func;
|
|
565
|
+
if (typeof callback === 'string') {
|
|
566
|
+
func = (input) => {
|
|
567
|
+
const value = parseInt(input, 10);
|
|
568
|
+
return { [callback]: value };
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
func = callback;
|
|
573
|
+
}
|
|
574
|
+
tokens.forEach((key) => {
|
|
575
|
+
parseFlags[key] = [regex, func];
|
|
576
|
+
});
|
|
577
|
+
};
|
|
578
|
+
addParseFlag('yy', TWO_NUMERICS_REGEX, (input) => {
|
|
579
|
+
const year = new Date().getFullYear();
|
|
580
|
+
const cent = Math.floor(year / 100);
|
|
581
|
+
let value = parseInt(input, 10);
|
|
582
|
+
value = (value > 68 ? cent - 1 : cent) * 100 + value;
|
|
583
|
+
return { [YEAR]: value };
|
|
584
|
+
});
|
|
585
|
+
addParseFlag('yyyy', FOUR_NUMERICS_REGEX, YEAR);
|
|
586
|
+
addParseFlag('mm', TWO_NUMERICS_REGEX, (input) => ({ [MONTH]: parseInt(input, 10) - 1 }));
|
|
587
|
+
addParseFlag('dd', TWO_NUMERICS_REGEX, DAY);
|
|
588
|
+
addParseFlag('hh', TWO_NUMERICS_REGEX, HOUR);
|
|
589
|
+
addParseFlag('MM', TWO_NUMERICS_REGEX, MINUTE);
|
|
590
|
+
addParseFlag('ss', TWO_NUMERICS_REGEX, SECOND);
|
|
591
|
+
const getFullInputArray = (input, backupDate = new Date()) => {
|
|
592
|
+
const result = [0, 0, 1, 0, 0, 0];
|
|
593
|
+
const backupArr = [
|
|
594
|
+
backupDate.getFullYear(),
|
|
595
|
+
backupDate.getMonth(),
|
|
596
|
+
backupDate.getDate(),
|
|
597
|
+
backupDate.getHours(),
|
|
598
|
+
backupDate.getMinutes(),
|
|
599
|
+
backupDate.getSeconds(),
|
|
600
|
+
];
|
|
601
|
+
let useBackup = true;
|
|
602
|
+
for (let i = 0; i < 7; i++) {
|
|
603
|
+
if (input[i] === undefined) {
|
|
604
|
+
result[i] = useBackup ? backupArr[i] : result[i];
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
result[i] = input[i];
|
|
608
|
+
useBackup = false;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return result;
|
|
612
|
+
};
|
|
613
|
+
const createDate = (year, month, day, hour, minute, second) => {
|
|
614
|
+
if (!(year < 100 && year >= 0)) {
|
|
615
|
+
return new Date(year, month, day, hour, minute, second);
|
|
616
|
+
}
|
|
617
|
+
const date = new Date(year + 400, month, day, hour, minute, second);
|
|
618
|
+
if (isFinite(date.getFullYear())) {
|
|
619
|
+
date.setFullYear(year);
|
|
620
|
+
}
|
|
621
|
+
return date;
|
|
622
|
+
};
|
|
623
|
+
const makeParser = (dateString, format) => {
|
|
624
|
+
const tokens = format.match(FORMATTING_TOKENS);
|
|
625
|
+
if (!tokens) {
|
|
626
|
+
throw new Error();
|
|
627
|
+
}
|
|
628
|
+
const { length } = tokens;
|
|
629
|
+
let mark = {};
|
|
630
|
+
for (let i = 0; i < length; i += 1) {
|
|
631
|
+
const token = tokens[i];
|
|
632
|
+
const parseTo = parseFlags[token];
|
|
633
|
+
if (!parseTo) {
|
|
634
|
+
const word = token.replace(/^\[|\]$/g, '');
|
|
635
|
+
if (dateString.indexOf(word) === 0) {
|
|
636
|
+
dateString = dateString.substr(word.length);
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
throw new Error('not match');
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
const regex = parseTo[0];
|
|
644
|
+
const parser = parseTo[1];
|
|
645
|
+
const value = (regex.exec(dateString) || [])[0];
|
|
646
|
+
const obj = parser(value);
|
|
647
|
+
mark = Object.assign(Object.assign({}, mark), obj);
|
|
648
|
+
dateString = dateString.replace(value, '');
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return mark;
|
|
652
|
+
};
|
|
653
|
+
const getCleanDateString = (dirtyDateString, format) => {
|
|
654
|
+
if (dirtyDateString.length === format.length) {
|
|
655
|
+
return dirtyDateString;
|
|
656
|
+
}
|
|
657
|
+
const separator = dirtyDateString.match(NON_NUMERIC_REGEX)[0];
|
|
658
|
+
// pad signle digits to follow supported dateformats
|
|
659
|
+
return dirtyDateString
|
|
660
|
+
.split(separator)
|
|
661
|
+
.map((s) => (s.length === 1 ? '0' + s : s))
|
|
662
|
+
.join(separator);
|
|
663
|
+
};
|
|
664
|
+
const getDateParts = (dirtyDateString, format) => {
|
|
665
|
+
const dateString = getCleanDateString(dirtyDateString, format);
|
|
666
|
+
return makeParser(dateString, format);
|
|
667
|
+
};
|
|
668
|
+
export const toDate = (dirtyDateString, format) => {
|
|
669
|
+
try {
|
|
670
|
+
const { backupDate = new Date() } = {};
|
|
671
|
+
const { year, month, day, hour, minute, second, date } = getDateParts(dirtyDateString, format);
|
|
672
|
+
if (date) {
|
|
673
|
+
return date;
|
|
674
|
+
}
|
|
675
|
+
const inputArray = [year, month, day, hour, minute, second];
|
|
676
|
+
let parsedDate;
|
|
677
|
+
const result = getFullInputArray(inputArray, backupDate);
|
|
678
|
+
parsedDate = createDate(...result);
|
|
679
|
+
return parsedDate;
|
|
680
|
+
}
|
|
681
|
+
catch (e) {
|
|
682
|
+
return new Date(NaN);
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
export const createCalendarGrid = (calendarGridArguments) => {
|
|
686
|
+
const { firstDateOfBox, allowedDates, dateFormat, selectedDate, minDate, maxDate, pointerDate } = calendarGridArguments;
|
|
687
|
+
const weekDatePointer = new Date(firstDateOfBox);
|
|
688
|
+
const dayDatePointer = new Date(firstDateOfBox);
|
|
689
|
+
let calendar = [];
|
|
690
|
+
do {
|
|
691
|
+
let row = [];
|
|
692
|
+
do {
|
|
693
|
+
row = [
|
|
694
|
+
...row,
|
|
695
|
+
{
|
|
696
|
+
date: new Date(dayDatePointer),
|
|
697
|
+
display: formatDate(dayDatePointer, dateFormat),
|
|
698
|
+
dateString: formatDate(dayDatePointer, dateFormat),
|
|
699
|
+
label: day(dayDatePointer).toString(),
|
|
700
|
+
isToday: isSameDay(dayDatePointer, now()),
|
|
701
|
+
isSelected: selectedDate && isSameDay(dayDatePointer, selectedDate),
|
|
702
|
+
isDisabled: !allowedDates(dayDatePointer) || !isInRange(dayDatePointer, minDate, maxDate),
|
|
703
|
+
isOutdated: pointerDate.month !== dayDatePointer.getMonth() || !isInRange(dayDatePointer, minDate, maxDate),
|
|
704
|
+
},
|
|
705
|
+
];
|
|
706
|
+
dayDatePointer.setDate(dayDatePointer.getDate() + 1);
|
|
707
|
+
} while (isSameWeek(dayDatePointer, weekDatePointer));
|
|
708
|
+
calendar = [...calendar, row];
|
|
709
|
+
weekDatePointer.setDate(weekDatePointer.getDate() + 7);
|
|
710
|
+
} while (isSameMonth(new Date(pointerDate.year, pointerDate.month, pointerDate.day), dayDatePointer));
|
|
711
|
+
return calendar;
|
|
712
|
+
};
|