@zimyo/ui 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +79 -80
- package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -11
- package/dist/components/index.d.ts +0 -59
- package/dist/components/ui/accordion.d.ts +0 -9
- package/dist/components/ui/accordion.js +0 -53
- package/dist/components/ui/alert-dialog.d.ts +0 -16
- package/dist/components/ui/alert-dialog.js +0 -107
- package/dist/components/ui/alert.d.ts +0 -12
- package/dist/components/ui/alert.js +0 -53
- package/dist/components/ui/aspect-ratio.d.ts +0 -6
- package/dist/components/ui/aspect-ratio.js +0 -12
- package/dist/components/ui/avatar.d.ts +0 -8
- package/dist/components/ui/avatar.js +0 -38
- package/dist/components/ui/badge.d.ts +0 -12
- package/dist/components/ui/badge.js +0 -37
- package/dist/components/ui/breadcrumb.d.ts +0 -13
- package/dist/components/ui/breadcrumb.js +0 -90
- package/dist/components/ui/button.d.ts +0 -13
- package/dist/components/ui/button.js +0 -49
- package/dist/components/ui/calendar.d.ts +0 -12
- package/dist/components/ui/calendar.js +0 -134
- package/dist/components/ui/card.d.ts +0 -11
- package/dist/components/ui/card.js +0 -77
- package/dist/components/ui/carousel.d.ts +0 -24
- package/dist/components/ui/carousel.js +0 -163
- package/dist/components/ui/chart.d.ts +0 -43
- package/dist/components/ui/chart.js +0 -187
- package/dist/components/ui/checkbox.d.ts +0 -6
- package/dist/components/ui/checkbox.js +0 -24
- package/dist/components/ui/collapsible.d.ts +0 -8
- package/dist/components/ui/collapsible.js +0 -24
- package/dist/components/ui/command.d.ts +0 -21
- package/dist/components/ui/command.js +0 -110
- package/dist/components/ui/context-menu.d.ts +0 -27
- package/dist/components/ui/context-menu.js +0 -158
- package/dist/components/ui/dialog.d.ts +0 -17
- package/dist/components/ui/dialog.js +0 -102
- package/dist/components/ui/drawer.d.ts +0 -15
- package/dist/components/ui/drawer.js +0 -97
- package/dist/components/ui/dropdown-menu.d.ts +0 -27
- package/dist/components/ui/dropdown-menu.js +0 -160
- package/dist/components/ui/form.d.ts +0 -26
- package/dist/components/ui/form.js +0 -125
- package/dist/components/ui/hover-card.d.ts +0 -8
- package/dist/components/ui/hover-card.js +0 -36
- package/dist/components/ui/input-otp.d.ts +0 -13
- package/dist/components/ui/input-otp.js +0 -61
- package/dist/components/ui/input.d.ts +0 -5
- package/dist/components/ui/input.js +0 -19
- package/dist/components/ui/label.d.ts +0 -6
- package/dist/components/ui/label.js +0 -18
- package/dist/components/ui/menubar.d.ts +0 -28
- package/dist/components/ui/menubar.js +0 -178
- package/dist/components/ui/navigation-menu.d.ts +0 -17
- package/dist/components/ui/navigation-menu.js +0 -102
- package/dist/components/ui/pagination.d.ts +0 -17
- package/dist/components/ui/pagination.js +0 -95
- package/dist/components/ui/popover.d.ts +0 -9
- package/dist/components/ui/popover.js +0 -40
- package/dist/components/ui/progress.d.ts +0 -6
- package/dist/components/ui/progress.js +0 -25
- package/dist/components/ui/radio-group.d.ts +0 -7
- package/dist/components/ui/radio-group.js +0 -34
- package/dist/components/ui/resizable.d.ts +0 -10
- package/dist/components/ui/resizable.js +0 -40
- package/dist/components/ui/scroll-area.d.ts +0 -7
- package/dist/components/ui/scroll-area.js +0 -37
- package/dist/components/ui/select.d.ts +0 -17
- package/dist/components/ui/select.js +0 -118
- package/dist/components/ui/separator.d.ts +0 -6
- package/dist/components/ui/separator.js +0 -22
- package/dist/components/ui/sheet.d.ts +0 -15
- package/dist/components/ui/sheet.js +0 -101
- package/dist/components/ui/sidebar.d.ts +0 -73
- package/dist/components/ui/sidebar.js +0 -484
- package/dist/components/ui/skeleton.d.ts +0 -5
- package/dist/components/ui/skeleton.js +0 -16
- package/dist/components/ui/slider.d.ts +0 -6
- package/dist/components/ui/slider.js +0 -39
- package/dist/components/ui/sonner.d.ts +0 -6
- package/dist/components/ui/sonner.js +0 -18
- package/dist/components/ui/switch.d.ts +0 -6
- package/dist/components/ui/switch.js +0 -21
- package/dist/components/ui/table.d.ts +0 -12
- package/dist/components/ui/table.js +0 -90
- package/dist/components/ui/tabs.d.ts +0 -9
- package/dist/components/ui/tabs.js +0 -48
- package/dist/components/ui/textarea.d.ts +0 -5
- package/dist/components/ui/textarea.js +0 -17
- package/dist/components/ui/toggle-group.d.ts +0 -10
- package/dist/components/ui/toggle-group.js +0 -52
- package/dist/components/ui/toggle.d.ts +0 -12
- package/dist/components/ui/toggle.js +0 -42
- package/dist/components/ui/tooltip.d.ts +0 -9
- package/dist/components/ui/tooltip.js +0 -45
- package/dist/index.d.ts +0 -61
- package/dist/index.js +0 -47
- package/dist/lib/utils.d.ts +0 -5
- package/dist/lib/utils.js +0 -8
- package/dist/node_modules/@date-fns/tz/date/index.js +0 -101
- package/dist/node_modules/@date-fns/tz/date/mini.js +0 -207
- package/dist/node_modules/@date-fns/tz/tzOffset/index.js +0 -43
- package/dist/node_modules/@radix-ui/primitive/dist/index.js +0 -11
- package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js +0 -39
- package/dist/node_modules/@radix-ui/react-context/dist/index.js +0 -79
- package/dist/node_modules/@radix-ui/react-dialog/dist/index.js +0 -321
- package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +0 -211
- package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js +0 -29
- package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js +0 -207
- package/dist/node_modules/@radix-ui/react-id/dist/index.js +0 -15
- package/dist/node_modules/@radix-ui/react-portal/dist/index.js +0 -17
- package/dist/node_modules/@radix-ui/react-presence/dist/index.js +0 -130
- package/dist/node_modules/@radix-ui/react-primitive/dist/index.js +0 -43
- package/dist/node_modules/@radix-ui/react-slot/dist/index.js +0 -89
- package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js +0 -12
- package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js +0 -70
- package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +0 -18
- package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js +0 -7
- package/dist/node_modules/aria-hidden/dist/es2015/index.js +0 -137
- package/dist/node_modules/class-variance-authority/dist/index.js +0 -44
- package/dist/node_modules/clsx/dist/clsx.js +0 -3
- package/dist/node_modules/cmdk/dist/chunk-NZJY6EH4.js +0 -3
- package/dist/node_modules/cmdk/dist/index.js +0 -10
- package/dist/node_modules/date-fns/_lib/addLeadingZeros.js +0 -7
- package/dist/node_modules/date-fns/_lib/defaultOptions.js +0 -7
- package/dist/node_modules/date-fns/_lib/format/formatters.js +0 -775
- package/dist/node_modules/date-fns/_lib/format/lightFormatters.js +0 -94
- package/dist/node_modules/date-fns/_lib/format/longFormatters.js +0 -66
- package/dist/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js +0 -31
- package/dist/node_modules/date-fns/_lib/normalizeDates.js +0 -11
- package/dist/node_modules/date-fns/_lib/normalizeInterval.js +0 -8
- package/dist/node_modules/date-fns/_lib/protectedTokens.js +0 -25
- package/dist/node_modules/date-fns/addDays.js +0 -41
- package/dist/node_modules/date-fns/addMonths.js +0 -75
- package/dist/node_modules/date-fns/addWeeks.js +0 -33
- package/dist/node_modules/date-fns/addYears.js +0 -33
- package/dist/node_modules/date-fns/constants.js +0 -46
- package/dist/node_modules/date-fns/constructFrom.js +0 -49
- package/dist/node_modules/date-fns/differenceInCalendarDays.js +0 -62
- package/dist/node_modules/date-fns/differenceInCalendarMonths.js +0 -42
- package/dist/node_modules/date-fns/eachMonthOfInterval.js +0 -65
- package/dist/node_modules/date-fns/endOfISOWeek.js +0 -35
- package/dist/node_modules/date-fns/endOfMonth.js +0 -37
- package/dist/node_modules/date-fns/endOfWeek.js +0 -53
- package/dist/node_modules/date-fns/endOfYear.js +0 -37
- package/dist/node_modules/date-fns/format.js +0 -423
- package/dist/node_modules/date-fns/getDayOfYear.js +0 -34
- package/dist/node_modules/date-fns/getDaysInMonth.js +0 -36
- package/dist/node_modules/date-fns/getISOWeek.js +0 -40
- package/dist/node_modules/date-fns/getISOWeekYear.js +0 -52
- package/dist/node_modules/date-fns/getMonth.js +0 -29
- package/dist/node_modules/date-fns/getWeek.js +0 -54
- package/dist/node_modules/date-fns/getWeekYear.js +0 -75
- package/dist/node_modules/date-fns/getYear.js +0 -29
- package/dist/node_modules/date-fns/isAfter.js +0 -25
- package/dist/node_modules/date-fns/isBefore.js +0 -25
- package/dist/node_modules/date-fns/isDate.js +0 -41
- package/dist/node_modules/date-fns/isSameDay.js +0 -46
- package/dist/node_modules/date-fns/isSameMonth.js +0 -43
- package/dist/node_modules/date-fns/isSameYear.js +0 -35
- package/dist/node_modules/date-fns/isValid.js +0 -39
- package/dist/node_modules/date-fns/locale/_lib/buildFormatLongFn.js +0 -10
- package/dist/node_modules/date-fns/locale/_lib/buildLocalizeFn.js +0 -64
- package/dist/node_modules/date-fns/locale/_lib/buildMatchFn.js +0 -59
- package/dist/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js +0 -22
- package/dist/node_modules/date-fns/locale/en-US/_lib/formatDistance.js +0 -103
- package/dist/node_modules/date-fns/locale/en-US/_lib/formatLong.js +0 -41
- package/dist/node_modules/date-fns/locale/en-US/_lib/formatRelative.js +0 -13
- package/dist/node_modules/date-fns/locale/en-US/_lib/localize.js +0 -189
- package/dist/node_modules/date-fns/locale/en-US/_lib/match.js +0 -134
- package/dist/node_modules/date-fns/locale/en-US.js +0 -28
- package/dist/node_modules/date-fns/max.js +0 -49
- package/dist/node_modules/date-fns/min.js +0 -49
- package/dist/node_modules/date-fns/setMonth.js +0 -46
- package/dist/node_modules/date-fns/setYear.js +0 -40
- package/dist/node_modules/date-fns/startOfDay.js +0 -35
- package/dist/node_modules/date-fns/startOfISOWeek.js +0 -35
- package/dist/node_modules/date-fns/startOfISOWeekYear.js +0 -42
- package/dist/node_modules/date-fns/startOfMonth.js +0 -37
- package/dist/node_modules/date-fns/startOfWeek.js +0 -53
- package/dist/node_modules/date-fns/startOfWeekYear.js +0 -64
- package/dist/node_modules/date-fns/startOfYear.js +0 -36
- package/dist/node_modules/date-fns/toDate.js +0 -46
- package/dist/node_modules/embla-carousel/esm/embla-carousel.esm.js +0 -1669
- package/dist/node_modules/embla-carousel-react/esm/embla-carousel-react.esm.js +0 -37
- package/dist/node_modules/embla-carousel-reactive-utils/esm/embla-carousel-reactive-utils.esm.js +0 -38
- package/dist/node_modules/get-nonce/dist/es2015/index.js +0 -8
- package/dist/node_modules/input-otp/dist/index.js +0 -24
- package/dist/node_modules/react-day-picker/dist/esm/DayPicker.js +0 -285
- package/dist/node_modules/react-day-picker/dist/esm/UI.js +0 -122
- package/dist/node_modules/react-day-picker/dist/esm/classes/CalendarDay.js +0 -30
- package/dist/node_modules/react-day-picker/dist/esm/classes/CalendarMonth.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/classes/CalendarWeek.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/classes/DateLib.js +0 -522
- package/dist/node_modules/react-day-picker/dist/esm/components/Button.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/CaptionLabel.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/Chevron.js +0 -18
- package/dist/node_modules/react-day-picker/dist/esm/components/Day.js +0 -18
- package/dist/node_modules/react-day-picker/dist/esm/components/DayButton.js +0 -19
- package/dist/node_modules/react-day-picker/dist/esm/components/Dropdown.js +0 -21
- package/dist/node_modules/react-day-picker/dist/esm/components/DropdownNav.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/Footer.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/Month.js +0 -15
- package/dist/node_modules/react-day-picker/dist/esm/components/MonthCaption.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/components/MonthGrid.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/Months.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/MonthsDropdown.js +0 -15
- package/dist/node_modules/react-day-picker/dist/esm/components/Nav.js +0 -31
- package/dist/node_modules/react-day-picker/dist/esm/components/NextMonthButton.js +0 -15
- package/dist/node_modules/react-day-picker/dist/esm/components/Option.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/PreviousMonthButton.js +0 -15
- package/dist/node_modules/react-day-picker/dist/esm/components/Root.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/components/Select.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/Week.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/components/WeekNumber.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/components/WeekNumberHeader.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/Weekday.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/Weekdays.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/components/Weeks.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/components/YearsDropdown.js +0 -15
- package/dist/node_modules/react-day-picker/dist/esm/components/custom-components.js +0 -26
- package/dist/node_modules/react-day-picker/dist/esm/formatters/formatCaption.js +0 -25
- package/dist/node_modules/react-day-picker/dist/esm/formatters/formatDay.js +0 -19
- package/dist/node_modules/react-day-picker/dist/esm/formatters/formatMonthDropdown.js +0 -18
- package/dist/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumber.js +0 -21
- package/dist/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumberHeader.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/formatters/formatWeekdayName.js +0 -19
- package/dist/node_modules/react-day-picker/dist/esm/formatters/formatYearDropdown.js +0 -23
- package/dist/node_modules/react-day-picker/dist/esm/formatters/index.js +0 -7
- package/dist/node_modules/react-day-picker/dist/esm/helpers/calculateFocusTarget.js +0 -73
- package/dist/node_modules/react-day-picker/dist/esm/helpers/createGetModifiers.js +0 -95
- package/dist/node_modules/react-day-picker/dist/esm/helpers/endOfBroadcastWeek.js +0 -22
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getBroadcastWeeksInMonth.js +0 -28
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getClassNamesForModifiers.js +0 -33
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getComponents.js +0 -20
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getDataAttributes.js +0 -27
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getDates.js +0 -51
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getDays.js +0 -19
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getDefaultClassNames.js +0 -33
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getDisplayMonths.js +0 -24
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getFocusableDate.js +0 -46
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getFormatters.js +0 -24
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getInitialMonth.js +0 -28
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getMonthOptions.js +0 -33
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getMonths.js +0 -69
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getNavMonth.js +0 -51
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getNextFocus.js +0 -39
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getNextMonth.js +0 -36
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getPreviousMonth.js +0 -37
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getStyleForModifiers.js +0 -27
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getWeekdays.js +0 -24
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getWeeks.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/helpers/getYearOptions.js +0 -38
- package/dist/node_modules/react-day-picker/dist/esm/helpers/startOfBroadcastWeek.js +0 -27
- package/dist/node_modules/react-day-picker/dist/esm/helpers/useControlledValue.js +0 -31
- package/dist/node_modules/react-day-picker/dist/esm/labels/index.js +0 -11
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelDayButton.js +0 -32
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelGrid.js +0 -24
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelGridcell.js +0 -22
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelMonthDropdown.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelNav.js +0 -13
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelNext.js +0 -15
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelPrevious.js +0 -15
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelWeekNumber.js +0 -15
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelWeekNumberHeader.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelWeekday.js +0 -18
- package/dist/node_modules/react-day-picker/dist/esm/labels/labelYearDropdown.js +0 -14
- package/dist/node_modules/react-day-picker/dist/esm/selection/useMulti.js +0 -57
- package/dist/node_modules/react-day-picker/dist/esm/selection/useRange.js +0 -45
- package/dist/node_modules/react-day-picker/dist/esm/selection/useSingle.js +0 -44
- package/dist/node_modules/react-day-picker/dist/esm/useAnimation.js +0 -175
- package/dist/node_modules/react-day-picker/dist/esm/useCalendar.js +0 -85
- package/dist/node_modules/react-day-picker/dist/esm/useDayPicker.js +0 -25
- package/dist/node_modules/react-day-picker/dist/esm/useFocus.js +0 -50
- package/dist/node_modules/react-day-picker/dist/esm/useSelection.js +0 -31
- package/dist/node_modules/react-day-picker/dist/esm/utils/addToRange.js +0 -92
- package/dist/node_modules/react-day-picker/dist/esm/utils/dateMatchModifiers.js +0 -62
- package/dist/node_modules/react-day-picker/dist/esm/utils/rangeContainsDayOfWeek.js +0 -30
- package/dist/node_modules/react-day-picker/dist/esm/utils/rangeContainsModifiers.js +0 -74
- package/dist/node_modules/react-day-picker/dist/esm/utils/rangeIncludesDate.js +0 -35
- package/dist/node_modules/react-day-picker/dist/esm/utils/rangeOverlaps.js +0 -21
- package/dist/node_modules/react-day-picker/dist/esm/utils/typeguards.js +0 -66
- package/dist/node_modules/react-hook-form/dist/index.esm.js +0 -507
- package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js +0 -9
- package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js +0 -160
- package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js +0 -38
- package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js +0 -21
- package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js +0 -110
- package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js +0 -5
- package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js +0 -7
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js +0 -56
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js +0 -10
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js +0 -31
- package/dist/node_modules/react-resizable-panels/dist/react-resizable-panels.js +0 -2407
- package/dist/node_modules/react-style-singleton/dist/es2015/component.js +0 -19
- package/dist/node_modules/react-style-singleton/dist/es2015/hook.js +0 -25
- package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js +0 -51
- package/dist/node_modules/sonner/dist/index.js +0 -1125
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +0 -2956
- package/dist/node_modules/tslib/tslib.es6.js +0 -56
- package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js +0 -24
- package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js +0 -48
- package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js +0 -42
- package/dist/node_modules/use-sidecar/dist/es2015/exports.js +0 -21
- package/dist/node_modules/use-sidecar/dist/es2015/medium.js +0 -77
- package/dist/node_modules/vaul/dist/index.js +0 -1627
- package/dist/styles.css +0 -1
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { addLeadingZeros } from '../addLeadingZeros.js';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* | | Unit | | Unit |
|
|
5
|
-
* |-----|--------------------------------|-----|--------------------------------|
|
|
6
|
-
* | a | AM, PM | A* | |
|
|
7
|
-
* | d | Day of month | D | |
|
|
8
|
-
* | h | Hour [1-12] | H | Hour [0-23] |
|
|
9
|
-
* | m | Minute | M | Month |
|
|
10
|
-
* | s | Second | S | Fraction of second |
|
|
11
|
-
* | y | Year (abs) | Y | |
|
|
12
|
-
*
|
|
13
|
-
* Letters marked by * are not implemented but reserved by Unicode standard.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const lightFormatters = {
|
|
17
|
-
// Year
|
|
18
|
-
y(date, token) {
|
|
19
|
-
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
|
|
20
|
-
// | Year | y | yy | yyy | yyyy | yyyyy |
|
|
21
|
-
// |----------|-------|----|-------|-------|-------|
|
|
22
|
-
// | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
|
|
23
|
-
// | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
|
|
24
|
-
// | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
|
|
25
|
-
// | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
|
|
26
|
-
// | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
|
|
27
|
-
|
|
28
|
-
const signedYear = date.getFullYear();
|
|
29
|
-
// Returns 1 for 1 BC (which is year 0 in JavaScript)
|
|
30
|
-
const year = signedYear > 0 ? signedYear : 1 - signedYear;
|
|
31
|
-
return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
// Month
|
|
35
|
-
M(date, token) {
|
|
36
|
-
const month = date.getMonth();
|
|
37
|
-
return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
// Day of the month
|
|
41
|
-
d(date, token) {
|
|
42
|
-
return addLeadingZeros(date.getDate(), token.length);
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
// AM or PM
|
|
46
|
-
a(date, token) {
|
|
47
|
-
const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
|
|
48
|
-
|
|
49
|
-
switch (token) {
|
|
50
|
-
case "a":
|
|
51
|
-
case "aa":
|
|
52
|
-
return dayPeriodEnumValue.toUpperCase();
|
|
53
|
-
case "aaa":
|
|
54
|
-
return dayPeriodEnumValue;
|
|
55
|
-
case "aaaaa":
|
|
56
|
-
return dayPeriodEnumValue[0];
|
|
57
|
-
case "aaaa":
|
|
58
|
-
default:
|
|
59
|
-
return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
// Hour [1-12]
|
|
64
|
-
h(date, token) {
|
|
65
|
-
return addLeadingZeros(date.getHours() % 12 || 12, token.length);
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
// Hour [0-23]
|
|
69
|
-
H(date, token) {
|
|
70
|
-
return addLeadingZeros(date.getHours(), token.length);
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
// Minute
|
|
74
|
-
m(date, token) {
|
|
75
|
-
return addLeadingZeros(date.getMinutes(), token.length);
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
// Second
|
|
79
|
-
s(date, token) {
|
|
80
|
-
return addLeadingZeros(date.getSeconds(), token.length);
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
// Fraction of second
|
|
84
|
-
S(date, token) {
|
|
85
|
-
const numberOfDigits = token.length;
|
|
86
|
-
const milliseconds = date.getMilliseconds();
|
|
87
|
-
const fractionalSeconds = Math.trunc(
|
|
88
|
-
milliseconds * Math.pow(10, numberOfDigits - 3),
|
|
89
|
-
);
|
|
90
|
-
return addLeadingZeros(fractionalSeconds, token.length);
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export { lightFormatters };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const dateLongFormatter = (pattern, formatLong) => {
|
|
2
|
-
switch (pattern) {
|
|
3
|
-
case "P":
|
|
4
|
-
return formatLong.date({ width: "short" });
|
|
5
|
-
case "PP":
|
|
6
|
-
return formatLong.date({ width: "medium" });
|
|
7
|
-
case "PPP":
|
|
8
|
-
return formatLong.date({ width: "long" });
|
|
9
|
-
case "PPPP":
|
|
10
|
-
default:
|
|
11
|
-
return formatLong.date({ width: "full" });
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const timeLongFormatter = (pattern, formatLong) => {
|
|
16
|
-
switch (pattern) {
|
|
17
|
-
case "p":
|
|
18
|
-
return formatLong.time({ width: "short" });
|
|
19
|
-
case "pp":
|
|
20
|
-
return formatLong.time({ width: "medium" });
|
|
21
|
-
case "ppp":
|
|
22
|
-
return formatLong.time({ width: "long" });
|
|
23
|
-
case "pppp":
|
|
24
|
-
default:
|
|
25
|
-
return formatLong.time({ width: "full" });
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const dateTimeLongFormatter = (pattern, formatLong) => {
|
|
30
|
-
const matchResult = pattern.match(/(P+)(p+)?/) || [];
|
|
31
|
-
const datePattern = matchResult[1];
|
|
32
|
-
const timePattern = matchResult[2];
|
|
33
|
-
|
|
34
|
-
if (!timePattern) {
|
|
35
|
-
return dateLongFormatter(pattern, formatLong);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let dateTimeFormat;
|
|
39
|
-
|
|
40
|
-
switch (datePattern) {
|
|
41
|
-
case "P":
|
|
42
|
-
dateTimeFormat = formatLong.dateTime({ width: "short" });
|
|
43
|
-
break;
|
|
44
|
-
case "PP":
|
|
45
|
-
dateTimeFormat = formatLong.dateTime({ width: "medium" });
|
|
46
|
-
break;
|
|
47
|
-
case "PPP":
|
|
48
|
-
dateTimeFormat = formatLong.dateTime({ width: "long" });
|
|
49
|
-
break;
|
|
50
|
-
case "PPPP":
|
|
51
|
-
default:
|
|
52
|
-
dateTimeFormat = formatLong.dateTime({ width: "full" });
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return dateTimeFormat
|
|
57
|
-
.replace("{{date}}", dateLongFormatter(datePattern, formatLong))
|
|
58
|
-
.replace("{{time}}", timeLongFormatter(timePattern, formatLong));
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const longFormatters = {
|
|
62
|
-
p: timeLongFormatter,
|
|
63
|
-
P: dateTimeLongFormatter,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export { longFormatters };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { toDate } from '../toDate.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
|
|
5
|
-
* They usually appear for dates that denote time before the timezones were introduced
|
|
6
|
-
* (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
|
|
7
|
-
* and GMT+01:00:00 after that date)
|
|
8
|
-
*
|
|
9
|
-
* Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
|
|
10
|
-
* which would lead to incorrect calculations.
|
|
11
|
-
*
|
|
12
|
-
* This function returns the timezone offset in milliseconds that takes seconds in account.
|
|
13
|
-
*/
|
|
14
|
-
function getTimezoneOffsetInMilliseconds(date) {
|
|
15
|
-
const _date = toDate(date);
|
|
16
|
-
const utcDate = new Date(
|
|
17
|
-
Date.UTC(
|
|
18
|
-
_date.getFullYear(),
|
|
19
|
-
_date.getMonth(),
|
|
20
|
-
_date.getDate(),
|
|
21
|
-
_date.getHours(),
|
|
22
|
-
_date.getMinutes(),
|
|
23
|
-
_date.getSeconds(),
|
|
24
|
-
_date.getMilliseconds(),
|
|
25
|
-
),
|
|
26
|
-
);
|
|
27
|
-
utcDate.setUTCFullYear(_date.getFullYear());
|
|
28
|
-
return +date - +utcDate;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { getTimezoneOffsetInMilliseconds };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { constructFrom } from '../constructFrom.js';
|
|
2
|
-
|
|
3
|
-
function normalizeDates(context, ...dates) {
|
|
4
|
-
const normalize = constructFrom.bind(
|
|
5
|
-
null,
|
|
6
|
-
dates.find((date) => typeof date === "object"),
|
|
7
|
-
);
|
|
8
|
-
return dates.map(normalize);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { normalizeDates };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const dayOfYearTokenRE = /^D+$/;
|
|
2
|
-
const weekYearTokenRE = /^Y+$/;
|
|
3
|
-
|
|
4
|
-
const throwTokens = ["D", "DD", "YY", "YYYY"];
|
|
5
|
-
|
|
6
|
-
function isProtectedDayOfYearToken(token) {
|
|
7
|
-
return dayOfYearTokenRE.test(token);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function isProtectedWeekYearToken(token) {
|
|
11
|
-
return weekYearTokenRE.test(token);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function warnOrThrowProtectedError(token, format, input) {
|
|
15
|
-
const _message = message(token, format, input);
|
|
16
|
-
console.warn(_message);
|
|
17
|
-
if (throwTokens.includes(token)) throw new RangeError(_message);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function message(token, format, input) {
|
|
21
|
-
const subject = token[0] === "Y" ? "years" : "days of the month";
|
|
22
|
-
return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { isProtectedDayOfYearToken, isProtectedWeekYearToken, warnOrThrowProtectedError };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { constructFrom } from './constructFrom.js';
|
|
2
|
-
import { toDate } from './toDate.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The {@link addDays} function options.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @name addDays
|
|
10
|
-
* @category Day Helpers
|
|
11
|
-
* @summary Add the specified number of days to the given date.
|
|
12
|
-
*
|
|
13
|
-
* @description
|
|
14
|
-
* Add the specified number of days to the given date.
|
|
15
|
-
*
|
|
16
|
-
* @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).
|
|
17
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
18
|
-
*
|
|
19
|
-
* @param date - The date to be changed
|
|
20
|
-
* @param amount - The amount of days to be added.
|
|
21
|
-
* @param options - An object with options
|
|
22
|
-
*
|
|
23
|
-
* @returns The new date with the days added
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // Add 10 days to 1 September 2014:
|
|
27
|
-
* const result = addDays(new Date(2014, 8, 1), 10)
|
|
28
|
-
* //=> Thu Sep 11 2014 00:00:00
|
|
29
|
-
*/
|
|
30
|
-
function addDays(date, amount, options) {
|
|
31
|
-
const _date = toDate(date, options?.in);
|
|
32
|
-
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
33
|
-
|
|
34
|
-
// If 0 days, no-op to avoid changing times in the hour before end of DST
|
|
35
|
-
if (!amount) return _date;
|
|
36
|
-
|
|
37
|
-
_date.setDate(_date.getDate() + amount);
|
|
38
|
-
return _date;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { addDays, addDays as default };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { constructFrom } from './constructFrom.js';
|
|
2
|
-
import { toDate } from './toDate.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The {@link addMonths} function options.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @name addMonths
|
|
10
|
-
* @category Month Helpers
|
|
11
|
-
* @summary Add the specified number of months to the given date.
|
|
12
|
-
*
|
|
13
|
-
* @description
|
|
14
|
-
* Add the specified number of months to the given date.
|
|
15
|
-
*
|
|
16
|
-
* @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).
|
|
17
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
18
|
-
*
|
|
19
|
-
* @param date - The date to be changed
|
|
20
|
-
* @param amount - The amount of months to be added.
|
|
21
|
-
* @param options - The options object
|
|
22
|
-
*
|
|
23
|
-
* @returns The new date with the months added
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // Add 5 months to 1 September 2014:
|
|
27
|
-
* const result = addMonths(new Date(2014, 8, 1), 5)
|
|
28
|
-
* //=> Sun Feb 01 2015 00:00:00
|
|
29
|
-
*
|
|
30
|
-
* // Add one month to 30 January 2023:
|
|
31
|
-
* const result = addMonths(new Date(2023, 0, 30), 1)
|
|
32
|
-
* //=> Tue Feb 28 2023 00:00:00
|
|
33
|
-
*/
|
|
34
|
-
function addMonths(date, amount, options) {
|
|
35
|
-
const _date = toDate(date, options?.in);
|
|
36
|
-
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
37
|
-
if (!amount) {
|
|
38
|
-
// If 0 months, no-op to avoid changing times in the hour before end of DST
|
|
39
|
-
return _date;
|
|
40
|
-
}
|
|
41
|
-
const dayOfMonth = _date.getDate();
|
|
42
|
-
|
|
43
|
-
// The JS Date object supports date math by accepting out-of-bounds values for
|
|
44
|
-
// month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and
|
|
45
|
-
// new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we
|
|
46
|
-
// want except that dates will wrap around the end of a month, meaning that
|
|
47
|
-
// new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So
|
|
48
|
-
// we'll default to the end of the desired month by adding 1 to the desired
|
|
49
|
-
// month and using a date of 0 to back up one day to the end of the desired
|
|
50
|
-
// month.
|
|
51
|
-
const endOfDesiredMonth = constructFrom(date, _date.getTime());
|
|
52
|
-
endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
|
|
53
|
-
const daysInMonth = endOfDesiredMonth.getDate();
|
|
54
|
-
if (dayOfMonth >= daysInMonth) {
|
|
55
|
-
// If we're already at the end of the month, then this is the correct date
|
|
56
|
-
// and we're done.
|
|
57
|
-
return endOfDesiredMonth;
|
|
58
|
-
} else {
|
|
59
|
-
// Otherwise, we now know that setting the original day-of-month value won't
|
|
60
|
-
// cause an overflow, so set the desired day-of-month. Note that we can't
|
|
61
|
-
// just set the date of `endOfDesiredMonth` because that object may have had
|
|
62
|
-
// its time changed in the unusual case where where a DST transition was on
|
|
63
|
-
// the last day of the month and its local time was in the hour skipped or
|
|
64
|
-
// repeated next to a DST transition. So we use `date` instead which is
|
|
65
|
-
// guaranteed to still have the original time.
|
|
66
|
-
_date.setFullYear(
|
|
67
|
-
endOfDesiredMonth.getFullYear(),
|
|
68
|
-
endOfDesiredMonth.getMonth(),
|
|
69
|
-
dayOfMonth,
|
|
70
|
-
);
|
|
71
|
-
return _date;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { addMonths, addMonths as default };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { addDays } from './addDays.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The {@link addWeeks} function options.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @name addWeeks
|
|
9
|
-
* @category Week Helpers
|
|
10
|
-
* @summary Add the specified number of weeks to the given date.
|
|
11
|
-
*
|
|
12
|
-
* @description
|
|
13
|
-
* Add the specified number of weeks to the given date.
|
|
14
|
-
*
|
|
15
|
-
* @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).
|
|
16
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
17
|
-
*
|
|
18
|
-
* @param date - The date to be changed
|
|
19
|
-
* @param amount - The amount of weeks to be added.
|
|
20
|
-
* @param options - An object with options
|
|
21
|
-
*
|
|
22
|
-
* @returns The new date with the weeks added
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* // Add 4 weeks to 1 September 2014:
|
|
26
|
-
* const result = addWeeks(new Date(2014, 8, 1), 4)
|
|
27
|
-
* //=> Mon Sep 29 2014 00:00:00
|
|
28
|
-
*/
|
|
29
|
-
function addWeeks(date, amount, options) {
|
|
30
|
-
return addDays(date, amount * 7, options);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { addWeeks, addWeeks as default };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { addMonths } from './addMonths.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The {@link addYears} function options.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @name addYears
|
|
9
|
-
* @category Year Helpers
|
|
10
|
-
* @summary Add the specified number of years to the given date.
|
|
11
|
-
*
|
|
12
|
-
* @description
|
|
13
|
-
* Add the specified number of years to the given date.
|
|
14
|
-
*
|
|
15
|
-
* @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).
|
|
16
|
-
* @typeParam ResultDate - The result `Date` type.
|
|
17
|
-
*
|
|
18
|
-
* @param date - The date to be changed
|
|
19
|
-
* @param amount - The amount of years to be added.
|
|
20
|
-
* @param options - The options
|
|
21
|
-
*
|
|
22
|
-
* @returns The new date with the years added
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* // Add 5 years to 1 September 2014:
|
|
26
|
-
* const result = addYears(new Date(2014, 8, 1), 5)
|
|
27
|
-
* //=> Sun Sep 01 2019 00:00:00
|
|
28
|
-
*/
|
|
29
|
-
function addYears(date, amount, options) {
|
|
30
|
-
return addMonths(date, amount * 12, options);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { addYears, addYears as default };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module constants
|
|
3
|
-
* @summary Useful constants
|
|
4
|
-
* @description
|
|
5
|
-
* Collection of useful date constants.
|
|
6
|
-
*
|
|
7
|
-
* The constants could be imported from `date-fns/constants`:
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { maxTime, minTime } from "./constants/date-fns/constants";
|
|
11
|
-
*
|
|
12
|
-
* function isAllowedTime(time) {
|
|
13
|
-
* return time <= maxTime && time >= minTime;
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @constant
|
|
21
|
-
* @name millisecondsInWeek
|
|
22
|
-
* @summary Milliseconds in 1 week.
|
|
23
|
-
*/
|
|
24
|
-
const millisecondsInWeek = 604800000;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @constant
|
|
28
|
-
* @name millisecondsInDay
|
|
29
|
-
* @summary Milliseconds in 1 day.
|
|
30
|
-
*/
|
|
31
|
-
const millisecondsInDay = 86400000;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @constant
|
|
35
|
-
* @name constructFromSymbol
|
|
36
|
-
* @summary Symbol enabling Date extensions to inherit properties from the reference date.
|
|
37
|
-
*
|
|
38
|
-
* The symbol is used to enable the `constructFrom` function to construct a date
|
|
39
|
-
* using a reference date and a value. It allows to transfer extra properties
|
|
40
|
-
* from the reference date to the new date. It's useful for extensions like
|
|
41
|
-
* [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
|
|
42
|
-
* a constructor argument.
|
|
43
|
-
*/
|
|
44
|
-
const constructFromSymbol = Symbol.for("constructDateFrom");
|
|
45
|
-
|
|
46
|
-
export { constructFromSymbol, millisecondsInDay, millisecondsInWeek };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { constructFromSymbol } from './constants.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @name constructFrom
|
|
5
|
-
* @category Generic Helpers
|
|
6
|
-
* @summary Constructs a date using the reference date and the value
|
|
7
|
-
*
|
|
8
|
-
* @description
|
|
9
|
-
* The function constructs a new date using the constructor from the reference
|
|
10
|
-
* date and the given value. It helps to build generic functions that accept
|
|
11
|
-
* date extensions.
|
|
12
|
-
*
|
|
13
|
-
* It defaults to `Date` if the passed reference date is a number or a string.
|
|
14
|
-
*
|
|
15
|
-
* Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
|
|
16
|
-
* enabling to transfer extra properties from the reference date to the new date.
|
|
17
|
-
* It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
|
|
18
|
-
* that accept a time zone as a constructor argument.
|
|
19
|
-
*
|
|
20
|
-
* @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).
|
|
21
|
-
*
|
|
22
|
-
* @param date - The reference date to take constructor from
|
|
23
|
-
* @param value - The value to create the date
|
|
24
|
-
*
|
|
25
|
-
* @returns Date initialized using the given date and value
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* import { constructFrom } from "./constructFrom/date-fns";
|
|
29
|
-
*
|
|
30
|
-
* // A function that clones a date preserving the original type
|
|
31
|
-
* function cloneDate<DateType extends Date>(date: DateType): DateType {
|
|
32
|
-
* return constructFrom(
|
|
33
|
-
* date, // Use constructor from the given date
|
|
34
|
-
* date.getTime() // Use the date value to create a new date
|
|
35
|
-
* );
|
|
36
|
-
* }
|
|
37
|
-
*/
|
|
38
|
-
function constructFrom(date, value) {
|
|
39
|
-
if (typeof date === "function") return date(value);
|
|
40
|
-
|
|
41
|
-
if (date && typeof date === "object" && constructFromSymbol in date)
|
|
42
|
-
return date[constructFromSymbol](value);
|
|
43
|
-
|
|
44
|
-
if (date instanceof Date) return new date.constructor(value);
|
|
45
|
-
|
|
46
|
-
return new Date(value);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { constructFrom, constructFrom as default };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { getTimezoneOffsetInMilliseconds } from './_lib/getTimezoneOffsetInMilliseconds.js';
|
|
2
|
-
import { normalizeDates } from './_lib/normalizeDates.js';
|
|
3
|
-
import { millisecondsInDay } from './constants.js';
|
|
4
|
-
import { startOfDay } from './startOfDay.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The {@link differenceInCalendarDays} function options.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @name differenceInCalendarDays
|
|
12
|
-
* @category Day Helpers
|
|
13
|
-
* @summary Get the number of calendar days between the given dates.
|
|
14
|
-
*
|
|
15
|
-
* @description
|
|
16
|
-
* Get the number of calendar days between the given dates. This means that the times are removed
|
|
17
|
-
* from the dates and then the difference in days is calculated.
|
|
18
|
-
*
|
|
19
|
-
* @param laterDate - The later date
|
|
20
|
-
* @param earlierDate - The earlier date
|
|
21
|
-
* @param options - The options object
|
|
22
|
-
*
|
|
23
|
-
* @returns The number of calendar days
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // How many calendar days are between
|
|
27
|
-
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
|
28
|
-
* const result = differenceInCalendarDays(
|
|
29
|
-
* new Date(2012, 6, 2, 0, 0),
|
|
30
|
-
* new Date(2011, 6, 2, 23, 0)
|
|
31
|
-
* )
|
|
32
|
-
* //=> 366
|
|
33
|
-
* // How many calendar days are between
|
|
34
|
-
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
|
35
|
-
* const result = differenceInCalendarDays(
|
|
36
|
-
* new Date(2011, 6, 3, 0, 1),
|
|
37
|
-
* new Date(2011, 6, 2, 23, 59)
|
|
38
|
-
* )
|
|
39
|
-
* //=> 1
|
|
40
|
-
*/
|
|
41
|
-
function differenceInCalendarDays(laterDate, earlierDate, options) {
|
|
42
|
-
const [laterDate_, earlierDate_] = normalizeDates(
|
|
43
|
-
options?.in,
|
|
44
|
-
laterDate,
|
|
45
|
-
earlierDate,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const laterStartOfDay = startOfDay(laterDate_);
|
|
49
|
-
const earlierStartOfDay = startOfDay(earlierDate_);
|
|
50
|
-
|
|
51
|
-
const laterTimestamp =
|
|
52
|
-
+laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
|
|
53
|
-
const earlierTimestamp =
|
|
54
|
-
+earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
|
|
55
|
-
|
|
56
|
-
// Round the number of days to the nearest integer because the number of
|
|
57
|
-
// milliseconds in a day is not constant (e.g. it's different in the week of
|
|
58
|
-
// the daylight saving time clock shift).
|
|
59
|
-
return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { differenceInCalendarDays as default, differenceInCalendarDays };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { normalizeDates } from './_lib/normalizeDates.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The {@link differenceInCalendarMonths} function options.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @name differenceInCalendarMonths
|
|
9
|
-
* @category Month Helpers
|
|
10
|
-
* @summary Get the number of calendar months between the given dates.
|
|
11
|
-
*
|
|
12
|
-
* @description
|
|
13
|
-
* Get the number of calendar months between the given dates.
|
|
14
|
-
*
|
|
15
|
-
* @param laterDate - The later date
|
|
16
|
-
* @param earlierDate - The earlier date
|
|
17
|
-
* @param options - An object with options
|
|
18
|
-
*
|
|
19
|
-
* @returns The number of calendar months
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* // How many calendar months are between 31 January 2014 and 1 September 2014?
|
|
23
|
-
* const result = differenceInCalendarMonths(
|
|
24
|
-
* new Date(2014, 8, 1),
|
|
25
|
-
* new Date(2014, 0, 31)
|
|
26
|
-
* )
|
|
27
|
-
* //=> 8
|
|
28
|
-
*/
|
|
29
|
-
function differenceInCalendarMonths(laterDate, earlierDate, options) {
|
|
30
|
-
const [laterDate_, earlierDate_] = normalizeDates(
|
|
31
|
-
options?.in,
|
|
32
|
-
laterDate,
|
|
33
|
-
earlierDate,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const yearsDiff = laterDate_.getFullYear() - earlierDate_.getFullYear();
|
|
37
|
-
const monthsDiff = laterDate_.getMonth() - earlierDate_.getMonth();
|
|
38
|
-
|
|
39
|
-
return yearsDiff * 12 + monthsDiff;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { differenceInCalendarMonths as default, differenceInCalendarMonths };
|