@zealakit/chrono-react 0.0.0-stage → 1.0.0-beta.1
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/LICENSE +21 -0
- package/README.md +624 -2
- package/dist/calendar/components.d.ts +346 -0
- package/dist/calendar/components.js +245 -0
- package/dist/calendar/context.d.ts +636 -0
- package/dist/calendar/context.js +21 -0
- package/dist/calendar/index.d.ts +6 -0
- package/dist/calendar/index.js +6 -0
- package/dist/calendar/mini-calendar.d.ts +60 -0
- package/dist/calendar/mini-calendar.js +50 -0
- package/dist/calendar/options.d.ts +4 -0
- package/dist/calendar/options.js +98 -0
- package/dist/calendar/use-calendar.d.ts +340 -0
- package/dist/calendar/use-calendar.js +156 -0
- package/dist/calendar/use-mini-calendar.d.ts +302 -0
- package/dist/calendar/use-mini-calendar.js +56 -0
- package/dist/calendar/utilities.d.ts +9 -0
- package/dist/calendar/utilities.js +8 -0
- package/dist/date/bind-panel.d.ts +30 -0
- package/dist/date/bind-panel.js +125 -0
- package/dist/date/components.d.ts +197 -0
- package/dist/date/components.js +202 -0
- package/dist/date/context.d.ts +34 -0
- package/dist/date/context.js +19 -0
- package/dist/date/index.d.ts +4 -0
- package/dist/date/index.js +4 -0
- package/dist/date/options.d.ts +7 -0
- package/dist/date/options.js +91 -0
- package/dist/date/use-date-input.d.ts +43 -0
- package/dist/date/use-date-input.js +138 -0
- package/dist/date/use-date-panel.d.ts +81 -0
- package/dist/date/use-date-panel.js +21 -0
- package/dist/date/utilities.d.ts +4 -0
- package/dist/date/utilities.js +4 -0
- package/dist/datetime/components.d.ts +121 -0
- package/dist/datetime/components.js +169 -0
- package/dist/datetime/context.d.ts +8 -0
- package/dist/datetime/context.js +18 -0
- package/dist/datetime/index.d.ts +4 -0
- package/dist/datetime/index.js +4 -0
- package/dist/datetime/options.d.ts +5 -0
- package/dist/datetime/options.js +99 -0
- package/dist/datetime/use-datetime-input.d.ts +44 -0
- package/dist/datetime/use-datetime-input.js +145 -0
- package/dist/datetime/use-datetime-panel.d.ts +128 -0
- package/dist/datetime/use-datetime-panel.js +60 -0
- package/dist/datetime/utilities.d.ts +4 -0
- package/dist/datetime/utilities.js +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/shared/merge-props.d.ts +9 -0
- package/dist/shared/merge-props.js +33 -0
- package/dist/shared/modifiers.d.ts +7 -0
- package/dist/shared/modifiers.js +6 -0
- package/dist/shared/part.d.ts +10 -0
- package/dist/shared/part.js +9 -0
- package/dist/shared/slot.d.ts +12 -0
- package/dist/shared/slot.js +60 -0
- package/dist/shared/style-properties.d.ts +8 -0
- package/dist/shared/style-properties.js +13 -0
- package/dist/shared/to-react-props.d.ts +11 -0
- package/dist/shared/to-react-props.js +27 -0
- package/dist/time/bind-panel.d.ts +19 -0
- package/dist/time/bind-panel.js +97 -0
- package/dist/time/components.d.ts +183 -0
- package/dist/time/components.js +174 -0
- package/dist/time/context.d.ts +24 -0
- package/dist/time/context.js +19 -0
- package/dist/time/index.d.ts +4 -0
- package/dist/time/index.js +4 -0
- package/dist/time/options.d.ts +5 -0
- package/dist/time/options.js +85 -0
- package/dist/time/use-time-input.d.ts +43 -0
- package/dist/time/use-time-input.js +138 -0
- package/dist/time/use-time-panel.d.ts +37 -0
- package/dist/time/use-time-panel.js +18 -0
- package/dist/time/utilities.d.ts +4 -0
- package/dist/time/utilities.js +4 -0
- package/dist/vendor/core/calendar/availability.d.ts +39 -0
- package/dist/vendor/core/calendar/availability.js +74 -0
- package/dist/vendor/core/calendar/controllers/calendar-controller.d.ts +251 -0
- package/dist/vendor/core/calendar/controllers/calendar-controller.js +1448 -0
- package/dist/vendor/core/calendar/controllers/drag-engine.d.ts +99 -0
- package/dist/vendor/core/calendar/controllers/drag-engine.js +382 -0
- package/dist/vendor/core/calendar/controllers/mini-calendar-controller.d.ts +66 -0
- package/dist/vendor/core/calendar/controllers/mini-calendar-controller.js +170 -0
- package/dist/vendor/core/calendar/controllers/shared.d.ts +29 -0
- package/dist/vendor/core/calendar/controllers/shared.js +82 -0
- package/dist/vendor/core/calendar/events/agenda-layout.d.ts +21 -0
- package/dist/vendor/core/calendar/events/agenda-layout.js +71 -0
- package/dist/vendor/core/calendar/events/all-day-row.d.ts +22 -0
- package/dist/vendor/core/calendar/events/all-day-row.js +93 -0
- package/dist/vendor/core/calendar/events/background-layout.d.ts +66 -0
- package/dist/vendor/core/calendar/events/background-layout.js +107 -0
- package/dist/vendor/core/calendar/events/index.d.ts +17 -0
- package/dist/vendor/core/calendar/events/index.js +8 -0
- package/dist/vendor/core/calendar/events/month-layout.d.ts +13 -0
- package/dist/vendor/core/calendar/events/month-layout.js +156 -0
- package/dist/vendor/core/calendar/events/normalize.d.ts +33 -0
- package/dist/vendor/core/calendar/events/normalize.js +159 -0
- package/dist/vendor/core/calendar/events/now-indicator.d.ts +18 -0
- package/dist/vendor/core/calendar/events/now-indicator.js +19 -0
- package/dist/vendor/core/calendar/events/overflow.d.ts +36 -0
- package/dist/vendor/core/calendar/events/overflow.js +112 -0
- package/dist/vendor/core/calendar/events/sort.d.ts +21 -0
- package/dist/vendor/core/calendar/events/sort.js +35 -0
- package/dist/vendor/core/calendar/events/time-grid-layout.d.ts +22 -0
- package/dist/vendor/core/calendar/events/time-grid-layout.js +184 -0
- package/dist/vendor/core/calendar/events/types.d.ts +141 -0
- package/dist/vendor/core/calendar/events/types.js +1 -0
- package/dist/vendor/core/calendar/index.d.ts +70 -0
- package/dist/vendor/core/calendar/index.js +37 -0
- package/dist/vendor/core/calendar/interaction/auto-scroll.d.ts +19 -0
- package/dist/vendor/core/calendar/interaction/auto-scroll.js +64 -0
- package/dist/vendor/core/calendar/interaction/drag-geometry.d.ts +52 -0
- package/dist/vendor/core/calendar/interaction/drag-geometry.js +125 -0
- package/dist/vendor/core/calendar/interaction/drag-keyboard.d.ts +38 -0
- package/dist/vendor/core/calendar/interaction/drag-keyboard.js +56 -0
- package/dist/vendor/core/calendar/interaction/drag-pointer.d.ts +23 -0
- package/dist/vendor/core/calendar/interaction/drag-pointer.js +203 -0
- package/dist/vendor/core/calendar/interaction/event-focus.d.ts +28 -0
- package/dist/vendor/core/calendar/interaction/event-focus.js +44 -0
- package/dist/vendor/core/calendar/interaction/hit-test.d.ts +17 -0
- package/dist/vendor/core/calendar/interaction/hit-test.js +26 -0
- package/dist/vendor/core/calendar/interaction/pending.d.ts +17 -0
- package/dist/vendor/core/calendar/interaction/pending.js +17 -0
- package/dist/vendor/core/calendar/interaction/pointer.d.ts +21 -0
- package/dist/vendor/core/calendar/interaction/pointer.js +119 -0
- package/dist/vendor/core/calendar/interaction/selection.d.ts +29 -0
- package/dist/vendor/core/calendar/interaction/selection.js +47 -0
- package/dist/vendor/core/calendar/internal/equal.d.ts +3 -0
- package/dist/vendor/core/calendar/internal/equal.js +43 -0
- package/dist/vendor/core/calendar/navigation/navigate.d.ts +33 -0
- package/dist/vendor/core/calendar/navigation/navigate.js +83 -0
- package/dist/vendor/core/calendar/navigation/range.d.ts +15 -0
- package/dist/vendor/core/calendar/navigation/range.js +52 -0
- package/dist/vendor/core/calendar/navigation/title.d.ts +12 -0
- package/dist/vendor/core/calendar/navigation/title.js +39 -0
- package/dist/vendor/core/calendar/navigation/view-definition.d.ts +39 -0
- package/dist/vendor/core/calendar/navigation/view-definition.js +61 -0
- package/dist/vendor/core/calendar/navigation/zoom.d.ts +5 -0
- package/dist/vendor/core/calendar/navigation/zoom.js +11 -0
- package/dist/vendor/core/calendar/recurrence/apply.d.ts +50 -0
- package/dist/vendor/core/calendar/recurrence/apply.js +207 -0
- package/dist/vendor/core/calendar/recurrence/expand.d.ts +27 -0
- package/dist/vendor/core/calendar/recurrence/expand.js +302 -0
- package/dist/vendor/core/calendar/recurrence/pack.d.ts +3 -0
- package/dist/vendor/core/calendar/recurrence/pack.js +251 -0
- package/dist/vendor/core/calendar/recurrence/rrule-types.d.ts +30 -0
- package/dist/vendor/core/calendar/recurrence/rrule-types.js +8 -0
- package/dist/vendor/core/calendar/recurrence/rrule.d.ts +12 -0
- package/dist/vendor/core/calendar/recurrence/rrule.js +288 -0
- package/dist/vendor/core/calendar/recurrence/series.d.ts +25 -0
- package/dist/vendor/core/calendar/recurrence/series.js +165 -0
- package/dist/vendor/core/calendar/recurrence/types.d.ts +30 -0
- package/dist/vendor/core/calendar/recurrence/types.js +1 -0
- package/dist/vendor/core/calendar/resources/keys.d.ts +2 -0
- package/dist/vendor/core/calendar/resources/keys.js +2 -0
- package/dist/vendor/core/calendar/resources/resource-time-grid.d.ts +7 -0
- package/dist/vendor/core/calendar/resources/resource-time-grid.js +130 -0
- package/dist/vendor/core/calendar/resources/timeline-axis.d.ts +10 -0
- package/dist/vendor/core/calendar/resources/timeline-axis.js +98 -0
- package/dist/vendor/core/calendar/resources/timeline-layout.d.ts +7 -0
- package/dist/vendor/core/calendar/resources/timeline-layout.js +111 -0
- package/dist/vendor/core/calendar/resources/tree.d.ts +10 -0
- package/dist/vendor/core/calendar/resources/tree.js +86 -0
- package/dist/vendor/core/calendar/resources/types.d.ts +177 -0
- package/dist/vendor/core/calendar/resources/types.js +1 -0
- package/dist/vendor/core/calendar/resources/views.d.ts +7 -0
- package/dist/vendor/core/calendar/resources/views.js +45 -0
- package/dist/vendor/core/calendar/resources/windowing.d.ts +11 -0
- package/dist/vendor/core/calendar/resources/windowing.js +17 -0
- package/dist/vendor/core/calendar/views/day.d.ts +37 -0
- package/dist/vendor/core/calendar/views/day.js +39 -0
- package/dist/vendor/core/calendar/views/list-layout.d.ts +8 -0
- package/dist/vendor/core/calendar/views/list-layout.js +5 -0
- package/dist/vendor/core/calendar/views/mini-calendar.d.ts +23 -0
- package/dist/vendor/core/calendar/views/mini-calendar.js +31 -0
- package/dist/vendor/core/calendar/views/month-layout.d.ts +30 -0
- package/dist/vendor/core/calendar/views/month-layout.js +63 -0
- package/dist/vendor/core/calendar/views/time-grid-layout.d.ts +26 -0
- package/dist/vendor/core/calendar/views/time-grid-layout.js +30 -0
- package/dist/vendor/core/date/index.d.ts +9 -0
- package/dist/vendor/core/date/index.js +9 -0
- package/dist/vendor/core/date/input/date-input-controller.d.ts +97 -0
- package/dist/vendor/core/date/input/date-input-controller.js +478 -0
- package/dist/vendor/core/date/input/date-range-input-controller.d.ts +43 -0
- package/dist/vendor/core/date/input/date-range-input-controller.js +189 -0
- package/dist/vendor/core/date/input/parse.d.ts +22 -0
- package/dist/vendor/core/date/input/parse.js +84 -0
- package/dist/vendor/core/date/input/validity.d.ts +6 -0
- package/dist/vendor/core/date/input/validity.js +13 -0
- package/dist/vendor/core/date/panel/panel-controller.d.ts +176 -0
- package/dist/vendor/core/date/panel/panel-controller.js +726 -0
- package/dist/vendor/core/date/presets.d.ts +22 -0
- package/dist/vendor/core/date/presets.js +104 -0
- package/dist/vendor/core/date/selection/multiple.d.ts +7 -0
- package/dist/vendor/core/date/selection/multiple.js +32 -0
- package/dist/vendor/core/date/selection/range.d.ts +29 -0
- package/dist/vendor/core/date/selection/range.js +39 -0
- package/dist/vendor/core/date/types.d.ts +12 -0
- package/dist/vendor/core/date/types.js +1 -0
- package/dist/vendor/core/datetime/compose.d.ts +24 -0
- package/dist/vendor/core/datetime/compose.js +49 -0
- package/dist/vendor/core/datetime/constraints.d.ts +42 -0
- package/dist/vendor/core/datetime/constraints.js +56 -0
- package/dist/vendor/core/datetime/index.d.ts +9 -0
- package/dist/vendor/core/datetime/index.js +9 -0
- package/dist/vendor/core/datetime/input/datetime-input-controller.d.ts +96 -0
- package/dist/vendor/core/datetime/input/datetime-input-controller.js +395 -0
- package/dist/vendor/core/datetime/input/datetime-range-input-controller.d.ts +46 -0
- package/dist/vendor/core/datetime/input/datetime-range-input-controller.js +182 -0
- package/dist/vendor/core/datetime/input/parse.d.ts +20 -0
- package/dist/vendor/core/datetime/input/parse.js +59 -0
- package/dist/vendor/core/datetime/panel/controller.d.ts +64 -0
- package/dist/vendor/core/datetime/panel/controller.js +197 -0
- package/dist/vendor/core/datetime/panel/range-controller.d.ts +71 -0
- package/dist/vendor/core/datetime/panel/range-controller.js +217 -0
- package/dist/vendor/core/datetime/types.d.ts +12 -0
- package/dist/vendor/core/datetime/types.js +1 -0
- package/dist/vendor/core/datetime/zone/day-instants.d.ts +19 -0
- package/dist/vendor/core/datetime/zone/day-instants.js +54 -0
- package/dist/vendor/core/datetime/zone/resolve.d.ts +16 -0
- package/dist/vendor/core/datetime/zone/resolve.js +26 -0
- package/dist/vendor/core/foundation/a11y/announcer.d.ts +7 -0
- package/dist/vendor/core/foundation/a11y/announcer.js +36 -0
- package/dist/vendor/core/foundation/a11y/grid-navigation.d.ts +19 -0
- package/dist/vendor/core/foundation/a11y/grid-navigation.js +86 -0
- package/dist/vendor/core/foundation/a11y/index.d.ts +8 -0
- package/dist/vendor/core/foundation/a11y/index.js +5 -0
- package/dist/vendor/core/foundation/a11y/labels.d.ts +21 -0
- package/dist/vendor/core/foundation/a11y/labels.js +43 -0
- package/dist/vendor/core/foundation/a11y/messages.d.ts +80 -0
- package/dist/vendor/core/foundation/a11y/messages.js +74 -0
- package/dist/vendor/core/foundation/a11y/roving-focus.d.ts +18 -0
- package/dist/vendor/core/foundation/a11y/roving-focus.js +52 -0
- package/dist/vendor/core/foundation/constraints/availability-rules.d.ts +52 -0
- package/dist/vendor/core/foundation/constraints/availability-rules.js +66 -0
- package/dist/vendor/core/foundation/constraints/availability.d.ts +93 -0
- package/dist/vendor/core/foundation/constraints/availability.js +490 -0
- package/dist/vendor/core/foundation/constraints/date.d.ts +21 -0
- package/dist/vendor/core/foundation/constraints/date.js +41 -0
- package/dist/vendor/core/foundation/constraints/index.d.ts +9 -0
- package/dist/vendor/core/foundation/constraints/index.js +4 -0
- package/dist/vendor/core/foundation/constraints/range.d.ts +44 -0
- package/dist/vendor/core/foundation/constraints/range.js +70 -0
- package/dist/vendor/core/foundation/constraints/time.d.ts +30 -0
- package/dist/vendor/core/foundation/constraints/time.js +56 -0
- package/dist/vendor/core/foundation/grid/index.d.ts +8 -0
- package/dist/vendor/core/foundation/grid/index.js +4 -0
- package/dist/vendor/core/foundation/grid/month-grid.d.ts +33 -0
- package/dist/vendor/core/foundation/grid/month-grid.js +52 -0
- package/dist/vendor/core/foundation/grid/time-axis.d.ts +25 -0
- package/dist/vendor/core/foundation/grid/time-axis.js +32 -0
- package/dist/vendor/core/foundation/grid/weekday-headers.d.ts +17 -0
- package/dist/vendor/core/foundation/grid/weekday-headers.js +26 -0
- package/dist/vendor/core/foundation/grid/year-grid.d.ts +29 -0
- package/dist/vendor/core/foundation/grid/year-grid.js +40 -0
- package/dist/vendor/core/foundation/index.d.ts +8 -0
- package/dist/vendor/core/foundation/index.js +8 -0
- package/dist/vendor/core/foundation/input/form.d.ts +7 -0
- package/dist/vendor/core/foundation/input/form.js +10 -0
- package/dist/vendor/core/foundation/input/index.d.ts +6 -0
- package/dist/vendor/core/foundation/input/index.js +3 -0
- package/dist/vendor/core/foundation/input/segment-engine.d.ts +33 -0
- package/dist/vendor/core/foundation/input/segment-engine.js +49 -0
- package/dist/vendor/core/foundation/input/tokenize.d.ts +19 -0
- package/dist/vendor/core/foundation/input/tokenize.js +24 -0
- package/dist/vendor/core/foundation/locale/digits.d.ts +6 -0
- package/dist/vendor/core/foundation/locale/digits.js +35 -0
- package/dist/vendor/core/foundation/locale/direction.d.ts +1 -0
- package/dist/vendor/core/foundation/locale/direction.js +37 -0
- package/dist/vendor/core/foundation/locale/format.d.ts +31 -0
- package/dist/vendor/core/foundation/locale/format.js +79 -0
- package/dist/vendor/core/foundation/locale/hour-cycle.d.ts +12 -0
- package/dist/vendor/core/foundation/locale/hour-cycle.js +45 -0
- package/dist/vendor/core/foundation/locale/index.d.ts +10 -0
- package/dist/vendor/core/foundation/locale/index.js +8 -0
- package/dist/vendor/core/foundation/locale/names.d.ts +6 -0
- package/dist/vendor/core/foundation/locale/names.js +30 -0
- package/dist/vendor/core/foundation/locale/resolve.d.ts +7 -0
- package/dist/vendor/core/foundation/locale/resolve.js +29 -0
- package/dist/vendor/core/foundation/locale/week-info.d.ts +5 -0
- package/dist/vendor/core/foundation/locale/week-info.js +61 -0
- package/dist/vendor/core/foundation/locale/zone-label.d.ts +6 -0
- package/dist/vendor/core/foundation/locale/zone-label.js +24 -0
- package/dist/vendor/core/foundation/ranges/date-range.d.ts +18 -0
- package/dist/vendor/core/foundation/ranges/date-range.js +40 -0
- package/dist/vendor/core/foundation/ranges/index.d.ts +4 -0
- package/dist/vendor/core/foundation/ranges/index.js +2 -0
- package/dist/vendor/core/foundation/ranges/interval.d.ts +24 -0
- package/dist/vendor/core/foundation/ranges/interval.js +56 -0
- package/dist/vendor/core/foundation/store/attributes.d.ts +19 -0
- package/dist/vendor/core/foundation/store/attributes.js +43 -0
- package/dist/vendor/core/foundation/store/controllable.d.ts +19 -0
- package/dist/vendor/core/foundation/store/controllable.js +50 -0
- package/dist/vendor/core/foundation/store/env.d.ts +1 -0
- package/dist/vendor/core/foundation/store/env.js +3 -0
- package/dist/vendor/core/foundation/store/global-state.d.ts +1 -0
- package/dist/vendor/core/foundation/store/global-state.js +21 -0
- package/dist/vendor/core/foundation/store/ids.d.ts +2 -0
- package/dist/vendor/core/foundation/store/ids.js +7 -0
- package/dist/vendor/core/foundation/store/index.d.ts +11 -0
- package/dist/vendor/core/foundation/store/index.js +7 -0
- package/dist/vendor/core/foundation/store/store.d.ts +7 -0
- package/dist/vendor/core/foundation/store/store.js +25 -0
- package/dist/vendor/core/foundation/store/ticker.d.ts +11 -0
- package/dist/vendor/core/foundation/store/ticker.js +27 -0
- package/dist/vendor/core/foundation/values/clock.d.ts +4 -0
- package/dist/vendor/core/foundation/values/clock.js +21 -0
- package/dist/vendor/core/foundation/values/compare.d.ts +16 -0
- package/dist/vendor/core/foundation/values/compare.js +70 -0
- package/dist/vendor/core/foundation/values/convert.d.ts +31 -0
- package/dist/vendor/core/foundation/values/convert.js +112 -0
- package/dist/vendor/core/foundation/values/epoch-day.d.ts +15 -0
- package/dist/vendor/core/foundation/values/epoch-day.js +47 -0
- package/dist/vendor/core/foundation/values/index.d.ts +14 -0
- package/dist/vendor/core/foundation/values/index.js +10 -0
- package/dist/vendor/core/foundation/values/iso.d.ts +24 -0
- package/dist/vendor/core/foundation/values/iso.js +113 -0
- package/dist/vendor/core/foundation/values/plain-date-time.d.ts +8 -0
- package/dist/vendor/core/foundation/values/plain-date-time.js +25 -0
- package/dist/vendor/core/foundation/values/plain-date.d.ts +33 -0
- package/dist/vendor/core/foundation/values/plain-date.js +105 -0
- package/dist/vendor/core/foundation/values/plain-time.d.ts +15 -0
- package/dist/vendor/core/foundation/values/plain-time.js +45 -0
- package/dist/vendor/core/foundation/values/types.d.ts +37 -0
- package/dist/vendor/core/foundation/values/types.js +1 -0
- package/dist/vendor/core/foundation/values/week.d.ts +9 -0
- package/dist/vendor/core/foundation/values/week.js +31 -0
- package/dist/vendor/core/foundation/values/year-month.d.ts +10 -0
- package/dist/vendor/core/foundation/values/year-month.js +19 -0
- package/dist/vendor/core/foundation/values/zoned.d.ts +16 -0
- package/dist/vendor/core/foundation/values/zoned.js +155 -0
- package/dist/vendor/core/index.d.ts +5 -0
- package/dist/vendor/core/index.js +5 -0
- package/dist/vendor/core/time/index.d.ts +8 -0
- package/dist/vendor/core/time/index.js +8 -0
- package/dist/vendor/core/time/input/parse.d.ts +19 -0
- package/dist/vendor/core/time/input/parse.js +84 -0
- package/dist/vendor/core/time/input/time-input-controller.d.ts +102 -0
- package/dist/vendor/core/time/input/time-input-controller.js +562 -0
- package/dist/vendor/core/time/input/time-range-input-controller.d.ts +49 -0
- package/dist/vendor/core/time/input/time-range-input-controller.js +185 -0
- package/dist/vendor/core/time/input/validity.d.ts +7 -0
- package/dist/vendor/core/time/input/validity.js +16 -0
- package/dist/vendor/core/time/panel/time-panel-controller.d.ts +163 -0
- package/dist/vendor/core/time/panel/time-panel-controller.js +839 -0
- package/dist/vendor/core/time/selection/range.d.ts +25 -0
- package/dist/vendor/core/time/selection/range.js +35 -0
- package/dist/vendor/core/time/selection/slots.d.ts +46 -0
- package/dist/vendor/core/time/selection/slots.js +78 -0
- package/dist/vendor/core/time/types.d.ts +11 -0
- package/dist/vendor/core/time/types.js +1 -0
- package/package.json +90 -4
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { compare } from "../values/compare.js";
|
|
2
|
+
import { plainDateTime, wallSeconds } from "../values/plain-date-time.js";
|
|
3
|
+
import { addDays, fromEpochDay, toEpochDay } from "../values/plain-date.js";
|
|
4
|
+
import { plainTime } from "../values/plain-time.js";
|
|
5
|
+
import { toInstant, toZoned, withTimeZone } from "../values/zoned.js";
|
|
6
|
+
export function intervalsOverlap(a, b) {
|
|
7
|
+
return compare(a.start, b.end) < 0 && compare(b.start, a.end) < 0;
|
|
8
|
+
}
|
|
9
|
+
/** Length in milliseconds: elapsed time for zoned values, wall-clock for plain ones. */
|
|
10
|
+
export function intervalDuration(interval) {
|
|
11
|
+
const { start, end } = interval;
|
|
12
|
+
if ("timeZone" in start && "timeZone" in end) {
|
|
13
|
+
return toInstant(end) - toInstant(start);
|
|
14
|
+
}
|
|
15
|
+
return (wallSeconds(end) - wallSeconds(start)) * 1000;
|
|
16
|
+
}
|
|
17
|
+
function isZoned(value) {
|
|
18
|
+
return "timeZone" in value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Split an interval at midnight. Zoned intervals are split at local midnight
|
|
22
|
+
* in `timeZone` (default: the start's zone), so 23 and 25 hour days come out
|
|
23
|
+
* with their real length. Empty or reversed intervals return no pieces.
|
|
24
|
+
*/
|
|
25
|
+
export function splitIntervalByDay(interval, timeZone) {
|
|
26
|
+
if (compare(interval.start, interval.end) >= 0) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const zoned = isZoned(interval.start);
|
|
30
|
+
const zone = zoned
|
|
31
|
+
? (timeZone ?? interval.start.timeZone)
|
|
32
|
+
: "";
|
|
33
|
+
const start = (zoned ? withTimeZone(interval.start, zone) : interval.start);
|
|
34
|
+
const end = (zoned ? withTimeZone(interval.end, zone) : interval.end);
|
|
35
|
+
const dayStart = (date) => {
|
|
36
|
+
const wall = plainDateTime(date, plainTime(0, 0, 0));
|
|
37
|
+
return zoned ? toZoned(wall, zone) : wall;
|
|
38
|
+
};
|
|
39
|
+
const firstDay = toEpochDay(start);
|
|
40
|
+
const endsAtMidnight = end.hour === 0 && end.minute === 0 && end.second === 0;
|
|
41
|
+
const lastDay = toEpochDay(end) - (endsAtMidnight ? 1 : 0);
|
|
42
|
+
const pieces = [];
|
|
43
|
+
for (let day = firstDay; day <= lastDay; day += 1) {
|
|
44
|
+
const date = fromEpochDay(day);
|
|
45
|
+
const begin = day === firstDay ? interval.start : dayStart(date);
|
|
46
|
+
const finish = day === lastDay ? interval.end : dayStart(addDays(date, 1));
|
|
47
|
+
pieces.push({
|
|
48
|
+
date,
|
|
49
|
+
start: begin,
|
|
50
|
+
end: finish,
|
|
51
|
+
continuesBefore: day > firstDay,
|
|
52
|
+
continuesAfter: day < lastDay,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return pieces;
|
|
56
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attribute records returned by controllers. `true` means "present with an
|
|
3
|
+
* empty value", `false` and `undefined` mean "absent". Adapters turn a record
|
|
4
|
+
* into framework props; controllers never return event handlers.
|
|
5
|
+
*/
|
|
6
|
+
export type Attributes = Record<string, string | number | boolean | undefined>;
|
|
7
|
+
/** Later records win. `undefined` values never override. */
|
|
8
|
+
export declare function mergeAttributes(...records: (Attributes | undefined)[]): Attributes;
|
|
9
|
+
/** Drop absent attributes and turn every value into a string (`true` becomes `""`). */
|
|
10
|
+
export declare function normalizeAttributes(record: Attributes): Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Split `--chrono-*` CSS custom properties out of an attribute record
|
|
13
|
+
* (plan 05 R2): a record key starting with `--chrono-` is a style property,
|
|
14
|
+
* not an attribute. Numbers become unitless strings.
|
|
15
|
+
*/
|
|
16
|
+
export declare function splitProperties(record: Attributes): {
|
|
17
|
+
attributes: Attributes;
|
|
18
|
+
properties: Record<string, string>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Later records win. `undefined` values never override. */
|
|
2
|
+
export function mergeAttributes(...records) {
|
|
3
|
+
const merged = {};
|
|
4
|
+
for (const record of records) {
|
|
5
|
+
for (const [key, value] of Object.entries(record ?? {})) {
|
|
6
|
+
if (value !== undefined) {
|
|
7
|
+
merged[key] = value;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return merged;
|
|
12
|
+
}
|
|
13
|
+
/** Drop absent attributes and turn every value into a string (`true` becomes `""`). */
|
|
14
|
+
export function normalizeAttributes(record) {
|
|
15
|
+
const normalized = {};
|
|
16
|
+
for (const [key, value] of Object.entries(record)) {
|
|
17
|
+
if (value === undefined || value === false) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
normalized[key] = value === true ? "" : String(value);
|
|
21
|
+
}
|
|
22
|
+
return normalized;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Split `--chrono-*` CSS custom properties out of an attribute record
|
|
26
|
+
* (plan 05 R2): a record key starting with `--chrono-` is a style property,
|
|
27
|
+
* not an attribute. Numbers become unitless strings.
|
|
28
|
+
*/
|
|
29
|
+
export function splitProperties(record) {
|
|
30
|
+
const attributes = {};
|
|
31
|
+
const properties = {};
|
|
32
|
+
for (const [key, value] of Object.entries(record)) {
|
|
33
|
+
if (key.startsWith("--chrono-")) {
|
|
34
|
+
if (value !== undefined && value !== false) {
|
|
35
|
+
properties[key] = value === true ? "" : String(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (value !== undefined) {
|
|
39
|
+
attributes[key] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { attributes, properties };
|
|
43
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ControllableOptions<T> = {
|
|
2
|
+
/** Controlled when not `undefined`. */
|
|
3
|
+
value?: T;
|
|
4
|
+
defaultValue: T;
|
|
5
|
+
onChange?: (value: T) => void;
|
|
6
|
+
/** Suppresses change events for equal values (`isSameDay`, ...). */
|
|
7
|
+
equals?: (a: T, b: T) => boolean;
|
|
8
|
+
};
|
|
9
|
+
export type Controllable<T> = {
|
|
10
|
+
get(): T;
|
|
11
|
+
/** Request a new value. Controlled: only calls `onChange`. Uncontrolled: stores it, then calls `onChange`. */
|
|
12
|
+
set(next: T): void;
|
|
13
|
+
isControlled(): boolean;
|
|
14
|
+
/** Re-sync with the latest props. Notifies subscribers when the visible value changed. */
|
|
15
|
+
sync(options: Partial<Omit<ControllableOptions<T>, "defaultValue">>): void;
|
|
16
|
+
subscribe(listener: (value: T) => void): () => void;
|
|
17
|
+
};
|
|
18
|
+
/** The controlled / uncontrolled convention of plan 02 §2.3. */
|
|
19
|
+
export declare function createControllable<T>(options: ControllableOptions<T>): Controllable<T>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** The controlled / uncontrolled convention of plan 02 §2.3. */
|
|
2
|
+
export function createControllable(options) {
|
|
3
|
+
let value = options.value;
|
|
4
|
+
let onChange = options.onChange;
|
|
5
|
+
let equals = options.equals ?? Object.is;
|
|
6
|
+
let internal = options.defaultValue;
|
|
7
|
+
const listeners = new Set();
|
|
8
|
+
const current = () => (value !== undefined ? value : internal);
|
|
9
|
+
const notify = () => {
|
|
10
|
+
const visible = current();
|
|
11
|
+
for (const listener of [...listeners]) {
|
|
12
|
+
listener(visible);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
get: current,
|
|
17
|
+
isControlled: () => value !== undefined,
|
|
18
|
+
set(next) {
|
|
19
|
+
if (equals(current(), next)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (value === undefined) {
|
|
23
|
+
internal = next;
|
|
24
|
+
notify();
|
|
25
|
+
}
|
|
26
|
+
onChange?.(next);
|
|
27
|
+
},
|
|
28
|
+
sync(next) {
|
|
29
|
+
const before = current();
|
|
30
|
+
if ("value" in next) {
|
|
31
|
+
value = next.value;
|
|
32
|
+
}
|
|
33
|
+
if ("onChange" in next) {
|
|
34
|
+
onChange = next.onChange;
|
|
35
|
+
}
|
|
36
|
+
if (next.equals) {
|
|
37
|
+
equals = next.equals;
|
|
38
|
+
}
|
|
39
|
+
if (!equals(before, current())) {
|
|
40
|
+
notify();
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
subscribe(listener) {
|
|
44
|
+
listeners.add(listener);
|
|
45
|
+
return () => {
|
|
46
|
+
listeners.delete(listener);
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBrowser(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getGlobalState<T>(name: string, create: () => T): T;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State shared by every copy of Core loaded on a page.
|
|
3
|
+
*
|
|
4
|
+
* Each adapter ships its own bundled copy of Core, so module-level variables
|
|
5
|
+
* would split per adapter. State that must stay page-global lives on
|
|
6
|
+
* `globalThis` under a versioned `Symbol.for` key. Bump the version when a
|
|
7
|
+
* stored shape changes so incompatible copies never read each other's state.
|
|
8
|
+
*
|
|
9
|
+
* SSR-safe: only `globalThis` is touched, and state is created lazily.
|
|
10
|
+
*/
|
|
11
|
+
const STATE_VERSION = 1;
|
|
12
|
+
export function getGlobalState(name, create) {
|
|
13
|
+
const key = Symbol.for(`@zealakit/chrono-core/v${STATE_VERSION}/${name}`);
|
|
14
|
+
const store = globalThis;
|
|
15
|
+
let value = store[key];
|
|
16
|
+
if (value === undefined) {
|
|
17
|
+
value = create();
|
|
18
|
+
store[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getGlobalState } from "./global-state.js";
|
|
2
|
+
/** A page-wide counter; adapters pass framework ids for SSR instead. */
|
|
3
|
+
export function createId(prefix) {
|
|
4
|
+
const state = getGlobalState("ids", () => ({ count: 0 }));
|
|
5
|
+
state.count += 1;
|
|
6
|
+
return `${prefix}-${state.count}`;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { createStore } from "./store.js";
|
|
2
|
+
export type { Store } from "./store.js";
|
|
3
|
+
export { createControllable } from "./controllable.js";
|
|
4
|
+
export type { Controllable, ControllableOptions } from "./controllable.js";
|
|
5
|
+
export { getGlobalState } from "./global-state.js";
|
|
6
|
+
export { isBrowser } from "./env.js";
|
|
7
|
+
export { mergeAttributes, normalizeAttributes, splitProperties, } from "./attributes.js";
|
|
8
|
+
export type { Attributes } from "./attributes.js";
|
|
9
|
+
export { createTicker } from "./ticker.js";
|
|
10
|
+
export type { Ticker } from "./ticker.js";
|
|
11
|
+
export { createId } from "./ids.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createStore } from "./store.js";
|
|
2
|
+
export { createControllable } from "./controllable.js";
|
|
3
|
+
export { getGlobalState } from "./global-state.js";
|
|
4
|
+
export { isBrowser } from "./env.js";
|
|
5
|
+
export { mergeAttributes, normalizeAttributes, splitProperties, } from "./attributes.js";
|
|
6
|
+
export { createTicker } from "./ticker.js";
|
|
7
|
+
export { createId } from "./ids.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Store<T extends object> = {
|
|
2
|
+
get(): T;
|
|
3
|
+
set(update: Partial<T> | ((state: T) => Partial<T>)): void;
|
|
4
|
+
subscribe(listener: (state: T) => void): () => void;
|
|
5
|
+
};
|
|
6
|
+
/** Synchronous state container. Skips notifying when nothing changed (shallow compare). */
|
|
7
|
+
export declare function createStore<T extends object>(initial: T): Store<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Synchronous state container. Skips notifying when nothing changed (shallow compare). */
|
|
2
|
+
export function createStore(initial) {
|
|
3
|
+
let state = initial;
|
|
4
|
+
const listeners = new Set();
|
|
5
|
+
return {
|
|
6
|
+
get: () => state,
|
|
7
|
+
set(update) {
|
|
8
|
+
const patch = typeof update === "function" ? update(state) : update;
|
|
9
|
+
const keys = Object.keys(patch);
|
|
10
|
+
if (keys.every((key) => Object.is(state[key], patch[key]))) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
state = { ...state, ...patch };
|
|
14
|
+
for (const listener of [...listeners]) {
|
|
15
|
+
listener(state);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
subscribe(listener) {
|
|
19
|
+
listeners.add(listener);
|
|
20
|
+
return () => {
|
|
21
|
+
listeners.delete(listener);
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minute-aligned ticker (plan 05 E19). A `setTimeout` chain, no DOM. The
|
|
3
|
+
* controller starts it only when the app does not inject `now`.
|
|
4
|
+
*/
|
|
5
|
+
export type Ticker = {
|
|
6
|
+
start(nowMs: number): void;
|
|
7
|
+
stop(): void;
|
|
8
|
+
/** Whether the ticker is currently scheduled. */
|
|
9
|
+
running(): boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function createTicker(callback: (nowMs: number) => void): Ticker;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function createTicker(callback) {
|
|
2
|
+
let timer;
|
|
3
|
+
const tick = () => {
|
|
4
|
+
const now = Date.now();
|
|
5
|
+
callback(now);
|
|
6
|
+
// Re-align to the next minute boundary so timer latency never accumulates.
|
|
7
|
+
timer = setTimeout(tick, 60_000 - (now % 60_000));
|
|
8
|
+
};
|
|
9
|
+
return {
|
|
10
|
+
start(nowMs) {
|
|
11
|
+
if (timer !== undefined) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const next = Math.ceil(nowMs / 60_000) * 60_000;
|
|
15
|
+
timer = setTimeout(tick, Math.max(0, next - nowMs));
|
|
16
|
+
},
|
|
17
|
+
stop() {
|
|
18
|
+
if (timer !== undefined) {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
timer = undefined;
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
running() {
|
|
24
|
+
return timer !== undefined;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PlainDate, ZonedDateTime } from "./types.js";
|
|
2
|
+
/** Today's date in `timeZone` (default: the runtime's zone). */
|
|
3
|
+
export declare function today(timeZone?: string, now?: number): PlainDate;
|
|
4
|
+
export declare function nowZoned(timeZone: string, now?: number): ZonedDateTime;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { fromInstant } from "./zoned.js";
|
|
2
|
+
import { plainDate } from "./plain-date.js";
|
|
3
|
+
/**
|
|
4
|
+
* The only place in `values/` that reads the clock, and only when `now` is not
|
|
5
|
+
* passed (D10). Pass the same `now` on server and client to avoid hydration
|
|
6
|
+
* mismatches.
|
|
7
|
+
*/
|
|
8
|
+
function resolveNow(now) {
|
|
9
|
+
return now ?? Date.now();
|
|
10
|
+
}
|
|
11
|
+
function hostTimeZone() {
|
|
12
|
+
return new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
13
|
+
}
|
|
14
|
+
/** Today's date in `timeZone` (default: the runtime's zone). */
|
|
15
|
+
export function today(timeZone, now) {
|
|
16
|
+
const zoned = fromInstant(resolveNow(now), timeZone ?? hostTimeZone());
|
|
17
|
+
return plainDate(zoned.year, zoned.month, zoned.day);
|
|
18
|
+
}
|
|
19
|
+
export function nowZoned(timeZone, now) {
|
|
20
|
+
return fromInstant(resolveNow(now), timeZone);
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PlainDate, PlainDateTime, PlainTime, ZonedDateTime } from "./types.js";
|
|
2
|
+
export type Comparable = PlainDate | PlainTime | PlainDateTime | ZonedDateTime;
|
|
3
|
+
/**
|
|
4
|
+
* Compare two values of the same type: -1, 0 or 1. Zoned values compare by
|
|
5
|
+
* instant, plain date-times by wall time. A date-time compared with a date
|
|
6
|
+
* compares the date only.
|
|
7
|
+
*/
|
|
8
|
+
export declare function compare<T extends Comparable>(a: T, b: T): -1 | 0 | 1;
|
|
9
|
+
export declare function isSameDay(a: PlainDate, b: PlainDate): boolean;
|
|
10
|
+
export declare function isSameMonth(a: Pick<PlainDate, "year" | "month">, b: Pick<PlainDate, "year" | "month">): boolean;
|
|
11
|
+
export declare function isSameYear(a: Pick<PlainDate, "year">, b: Pick<PlainDate, "year">): boolean;
|
|
12
|
+
export declare function isSameTime(a: PlainTime, b: PlainTime): boolean;
|
|
13
|
+
export declare function isBefore<T extends Comparable>(a: T, b: T): boolean;
|
|
14
|
+
export declare function isAfter<T extends Comparable>(a: T, b: T): boolean;
|
|
15
|
+
export declare function minValue<T extends Comparable>(first: T, ...rest: T[]): T;
|
|
16
|
+
export declare function maxValue<T extends Comparable>(first: T, ...rest: T[]): T;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { toEpochDay } from "./plain-date.js";
|
|
2
|
+
import { wallSeconds } from "./plain-date-time.js";
|
|
3
|
+
import { toSecondOfDay } from "./plain-time.js";
|
|
4
|
+
function sign(n) {
|
|
5
|
+
return n < 0 ? -1 : n > 0 ? 1 : 0;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Compare two values of the same type: -1, 0 or 1. Zoned values compare by
|
|
9
|
+
* instant, plain date-times by wall time. A date-time compared with a date
|
|
10
|
+
* compares the date only.
|
|
11
|
+
*/
|
|
12
|
+
export function compare(a, b) {
|
|
13
|
+
const x = a;
|
|
14
|
+
const y = b;
|
|
15
|
+
if (x.timeZone !== undefined && y.timeZone !== undefined) {
|
|
16
|
+
return sign(wallSeconds(a) -
|
|
17
|
+
x.offset * 60 -
|
|
18
|
+
(wallSeconds(b) - y.offset * 60));
|
|
19
|
+
}
|
|
20
|
+
const aDate = x.year !== undefined;
|
|
21
|
+
const bDate = y.year !== undefined;
|
|
22
|
+
const aTime = x.hour !== undefined;
|
|
23
|
+
const bTime = y.hour !== undefined;
|
|
24
|
+
if (aDate && bDate) {
|
|
25
|
+
if (aTime && bTime) {
|
|
26
|
+
return sign(wallSeconds(a) - wallSeconds(b));
|
|
27
|
+
}
|
|
28
|
+
return sign(toEpochDay(a) - toEpochDay(b));
|
|
29
|
+
}
|
|
30
|
+
if (aTime && bTime) {
|
|
31
|
+
return sign(toSecondOfDay(a) - toSecondOfDay(b));
|
|
32
|
+
}
|
|
33
|
+
throw new TypeError("compare() needs two values of the same type.");
|
|
34
|
+
}
|
|
35
|
+
export function isSameDay(a, b) {
|
|
36
|
+
return a.year === b.year && a.month === b.month && a.day === b.day;
|
|
37
|
+
}
|
|
38
|
+
export function isSameMonth(a, b) {
|
|
39
|
+
return a.year === b.year && a.month === b.month;
|
|
40
|
+
}
|
|
41
|
+
export function isSameYear(a, b) {
|
|
42
|
+
return a.year === b.year;
|
|
43
|
+
}
|
|
44
|
+
export function isSameTime(a, b) {
|
|
45
|
+
return a.hour === b.hour && a.minute === b.minute && a.second === b.second;
|
|
46
|
+
}
|
|
47
|
+
export function isBefore(a, b) {
|
|
48
|
+
return compare(a, b) < 0;
|
|
49
|
+
}
|
|
50
|
+
export function isAfter(a, b) {
|
|
51
|
+
return compare(a, b) > 0;
|
|
52
|
+
}
|
|
53
|
+
export function minValue(first, ...rest) {
|
|
54
|
+
let result = first;
|
|
55
|
+
for (const value of rest) {
|
|
56
|
+
if (compare(value, result) < 0) {
|
|
57
|
+
result = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
export function maxValue(first, ...rest) {
|
|
63
|
+
let result = first;
|
|
64
|
+
for (const value of rest) {
|
|
65
|
+
if (compare(value, result) > 0) {
|
|
66
|
+
result = value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DateInput, DateTimeInput, PlainDate, PlainDateTime, PlainTime, TimeInput, ZonedDateTime } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A `Date` as a zoned value. `timeZone` defaults to `"UTC"`, never the host
|
|
4
|
+
* zone, so results do not depend on where the code runs.
|
|
5
|
+
*/
|
|
6
|
+
export declare function fromDate(date: Date, timeZone?: string): ZonedDateTime;
|
|
7
|
+
/**
|
|
8
|
+
* A value as a `Date`. A zoned value keeps its instant; a plain date or
|
|
9
|
+
* date-time is read as wall time in `timeZone` (default `"UTC"`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function toDate(value: PlainDate | PlainDateTime | ZonedDateTime, timeZone?: string): Date;
|
|
12
|
+
export declare function toPlainDate(input: DateInput, timeZone?: string): PlainDate;
|
|
13
|
+
export declare function toPlainTime(input: TimeInput): PlainTime;
|
|
14
|
+
/**
|
|
15
|
+
* A date-time input as a wall-clock {@link PlainDateTime} in `timeZone`
|
|
16
|
+
* (plan 05 R4). Zoned values and strings with an offset or `[Zone]` suffix are
|
|
17
|
+
* converted to `timeZone`; strings without one and plain values are read as
|
|
18
|
+
* wall time in the display zone. Throws a `RangeError` naming the value.
|
|
19
|
+
*/
|
|
20
|
+
export declare function toPlainDateTime(input: DateTimeInput, timeZone?: string): PlainDateTime;
|
|
21
|
+
/**
|
|
22
|
+
* The exclusive all-day `end` for data that stores the last day shown
|
|
23
|
+
* (plan 05 E3): `fromInclusiveEndDate("2026-11-20")` is `2026-11-21`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function fromInclusiveEndDate(lastDay: DateInput, timeZone?: string): PlainDate;
|
|
26
|
+
/**
|
|
27
|
+
* Duck-type a Temporal-like object (`PlainDate`, `PlainTime`, `PlainDateTime`
|
|
28
|
+
* or `ZonedDateTime`) without importing Temporal. Returns the matching Chrono
|
|
29
|
+
* value.
|
|
30
|
+
*/
|
|
31
|
+
export declare function fromTemporalLike(object: object): PlainDate | PlainTime | PlainDateTime | ZonedDateTime;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { parseIsoDate, parseIsoDateTime, parseIsoTime, parseIsoZoned, } from "./iso.js";
|
|
2
|
+
import { datePart, plainDateTime, timePart } from "./plain-date-time.js";
|
|
3
|
+
import { addDays, plainDate } from "./plain-date.js";
|
|
4
|
+
import { plainTime } from "./plain-time.js";
|
|
5
|
+
import { fromInstant, toInstant, toZoned, withTimeZone } from "./zoned.js";
|
|
6
|
+
/**
|
|
7
|
+
* A `Date` as a zoned value. `timeZone` defaults to `"UTC"`, never the host
|
|
8
|
+
* zone, so results do not depend on where the code runs.
|
|
9
|
+
*/
|
|
10
|
+
export function fromDate(date, timeZone = "UTC") {
|
|
11
|
+
const ms = date.getTime();
|
|
12
|
+
if (Number.isNaN(ms)) {
|
|
13
|
+
throw new RangeError("Invalid Date.");
|
|
14
|
+
}
|
|
15
|
+
return fromInstant(ms, timeZone);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A value as a `Date`. A zoned value keeps its instant; a plain date or
|
|
19
|
+
* date-time is read as wall time in `timeZone` (default `"UTC"`).
|
|
20
|
+
*/
|
|
21
|
+
export function toDate(value, timeZone = "UTC") {
|
|
22
|
+
const v = value;
|
|
23
|
+
if (v.timeZone !== undefined) {
|
|
24
|
+
return new Date(toInstant(value));
|
|
25
|
+
}
|
|
26
|
+
const dateTime = plainDateTime(value, plainTime(v.hour ?? 0, v.minute ?? 0, v.second ?? 0));
|
|
27
|
+
return new Date(toInstant(toZoned(dateTime, timeZone)));
|
|
28
|
+
}
|
|
29
|
+
export function toPlainDate(input, timeZone = "UTC") {
|
|
30
|
+
if (typeof input === "string") {
|
|
31
|
+
return parseIsoDate(input);
|
|
32
|
+
}
|
|
33
|
+
if (input instanceof Date) {
|
|
34
|
+
const zoned = fromDate(input, timeZone);
|
|
35
|
+
return plainDate(zoned.year, zoned.month, zoned.day);
|
|
36
|
+
}
|
|
37
|
+
return plainDate(input.year, input.month, input.day);
|
|
38
|
+
}
|
|
39
|
+
export function toPlainTime(input) {
|
|
40
|
+
if (typeof input === "string") {
|
|
41
|
+
return parseIsoTime(input);
|
|
42
|
+
}
|
|
43
|
+
return plainTime(input.hour, input.minute, input.second);
|
|
44
|
+
}
|
|
45
|
+
/** A zoned ISO string has an offset (`Z` or `±hh:mm`) and/or a `[Zone]` suffix. */
|
|
46
|
+
const ZONED_ISO_TAIL = /(?:Z|[+-]\d{2}:\d{2})(?:\[[^\]]+\])?$/;
|
|
47
|
+
/**
|
|
48
|
+
* A date-time input as a wall-clock {@link PlainDateTime} in `timeZone`
|
|
49
|
+
* (plan 05 R4). Zoned values and strings with an offset or `[Zone]` suffix are
|
|
50
|
+
* converted to `timeZone`; strings without one and plain values are read as
|
|
51
|
+
* wall time in the display zone. Throws a `RangeError` naming the value.
|
|
52
|
+
*/
|
|
53
|
+
export function toPlainDateTime(input, timeZone = "UTC") {
|
|
54
|
+
if (typeof input === "string") {
|
|
55
|
+
if (input.includes("[") || ZONED_ISO_TAIL.test(input)) {
|
|
56
|
+
const zoned = withTimeZone(parseIsoZoned(input), timeZone);
|
|
57
|
+
return plainDateTime(datePart(zoned), timePart(zoned));
|
|
58
|
+
}
|
|
59
|
+
return parseIsoDateTime(input);
|
|
60
|
+
}
|
|
61
|
+
if ("timeZone" in input) {
|
|
62
|
+
const zoned = withTimeZone(input, timeZone);
|
|
63
|
+
return plainDateTime(datePart(zoned), timePart(zoned));
|
|
64
|
+
}
|
|
65
|
+
return plainDateTime(datePart(input), timePart(input));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The exclusive all-day `end` for data that stores the last day shown
|
|
69
|
+
* (plan 05 E3): `fromInclusiveEndDate("2026-11-20")` is `2026-11-21`.
|
|
70
|
+
*/
|
|
71
|
+
export function fromInclusiveEndDate(lastDay, timeZone = "UTC") {
|
|
72
|
+
return addDays(toPlainDate(lastDay, timeZone), 1);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Duck-type a Temporal-like object (`PlainDate`, `PlainTime`, `PlainDateTime`
|
|
76
|
+
* or `ZonedDateTime`) without importing Temporal. Returns the matching Chrono
|
|
77
|
+
* value.
|
|
78
|
+
*/
|
|
79
|
+
export function fromTemporalLike(object) {
|
|
80
|
+
const t = object;
|
|
81
|
+
if (t.calendarId !== undefined &&
|
|
82
|
+
t.calendarId !== "iso8601" &&
|
|
83
|
+
t.calendarId !== "gregory") {
|
|
84
|
+
throw new RangeError(`Calendar "${t.calendarId}" is not supported.`);
|
|
85
|
+
}
|
|
86
|
+
const hasDate = t.year !== undefined && t.month !== undefined && t.day !== undefined;
|
|
87
|
+
const hasTime = t.hour !== undefined && t.minute !== undefined;
|
|
88
|
+
if (!hasDate && !hasTime) {
|
|
89
|
+
throw new TypeError("Not a Temporal-like date or time object.");
|
|
90
|
+
}
|
|
91
|
+
const time = hasTime
|
|
92
|
+
? plainTime(t.hour, t.minute, t.second ?? 0)
|
|
93
|
+
: undefined;
|
|
94
|
+
if (!hasDate) {
|
|
95
|
+
return time;
|
|
96
|
+
}
|
|
97
|
+
const date = plainDate(t.year, t.month, t.day);
|
|
98
|
+
if (!time) {
|
|
99
|
+
return date;
|
|
100
|
+
}
|
|
101
|
+
const dateTime = plainDateTime(date, time);
|
|
102
|
+
const zone = t.timeZoneId ?? (typeof t.timeZone === "string" ? t.timeZone : undefined);
|
|
103
|
+
if (zone === undefined) {
|
|
104
|
+
return dateTime;
|
|
105
|
+
}
|
|
106
|
+
const offset = typeof t.offsetNanoseconds === "number"
|
|
107
|
+
? Math.round(t.offsetNanoseconds / 60_000_000_000)
|
|
108
|
+
: typeof t.offset === "number"
|
|
109
|
+
? t.offset
|
|
110
|
+
: toZoned(dateTime, zone).offset;
|
|
111
|
+
return Object.freeze({ ...dateTime, timeZone: zone, offset });
|
|
112
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Epoch-day arithmetic: days since 1970-01-01 using the "days from civil"
|
|
3
|
+
* algorithm. Never uses `Date` (plan 03 D4).
|
|
4
|
+
*/
|
|
5
|
+
export declare function isLeapYear(year: number): boolean;
|
|
6
|
+
export declare function daysInMonth(year: number, month: number): number;
|
|
7
|
+
export declare function daysInYear(year: number): number;
|
|
8
|
+
/** Epoch day of a proleptic Gregorian date. Does not validate its input. */
|
|
9
|
+
export declare function daysFromCivil(year: number, month: number, day: number): number;
|
|
10
|
+
/** Inverse of {@link daysFromCivil}: `[year, month, day]`. */
|
|
11
|
+
export declare function civilFromDays(epochDay: number): [number, number, number];
|
|
12
|
+
/** Floor division that is correct for negative numbers. */
|
|
13
|
+
export declare function floorDiv(a: number, b: number): number;
|
|
14
|
+
export declare const MIN_YEAR = 1;
|
|
15
|
+
export declare const MAX_YEAR = 9999;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Epoch-day arithmetic: days since 1970-01-01 using the "days from civil"
|
|
3
|
+
* algorithm. Never uses `Date` (plan 03 D4).
|
|
4
|
+
*/
|
|
5
|
+
export function isLeapYear(year) {
|
|
6
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
7
|
+
}
|
|
8
|
+
const MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
9
|
+
export function daysInMonth(year, month) {
|
|
10
|
+
return month === 2 && isLeapYear(year) ? 29 : (MONTH_DAYS[month - 1] ?? 0);
|
|
11
|
+
}
|
|
12
|
+
export function daysInYear(year) {
|
|
13
|
+
return isLeapYear(year) ? 366 : 365;
|
|
14
|
+
}
|
|
15
|
+
/** Epoch day of a proleptic Gregorian date. Does not validate its input. */
|
|
16
|
+
export function daysFromCivil(year, month, day) {
|
|
17
|
+
const y = month <= 2 ? year - 1 : year;
|
|
18
|
+
const era = Math.floor(y / 400);
|
|
19
|
+
const yoe = y - era * 400;
|
|
20
|
+
const mp = month > 2 ? month - 3 : month + 9;
|
|
21
|
+
const doy = Math.floor((153 * mp + 2) / 5) + day - 1;
|
|
22
|
+
const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
|
|
23
|
+
return era * 146097 + doe - 719468;
|
|
24
|
+
}
|
|
25
|
+
/** Inverse of {@link daysFromCivil}: `[year, month, day]`. */
|
|
26
|
+
export function civilFromDays(epochDay) {
|
|
27
|
+
const z = epochDay + 719468;
|
|
28
|
+
const era = Math.floor(z / 146097);
|
|
29
|
+
const doe = z - era * 146097;
|
|
30
|
+
const yoe = Math.floor((doe -
|
|
31
|
+
Math.floor(doe / 1460) +
|
|
32
|
+
Math.floor(doe / 36524) -
|
|
33
|
+
Math.floor(doe / 146096)) /
|
|
34
|
+
365);
|
|
35
|
+
const doy = doe - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
|
|
36
|
+
const mp = Math.floor((5 * doy + 2) / 153);
|
|
37
|
+
const day = doy - Math.floor((153 * mp + 2) / 5) + 1;
|
|
38
|
+
const month = mp < 10 ? mp + 3 : mp - 9;
|
|
39
|
+
const year = yoe + era * 400 + (month <= 2 ? 1 : 0);
|
|
40
|
+
return [year, month, day];
|
|
41
|
+
}
|
|
42
|
+
/** Floor division that is correct for negative numbers. */
|
|
43
|
+
export function floorDiv(a, b) {
|
|
44
|
+
return Math.floor(a / b);
|
|
45
|
+
}
|
|
46
|
+
export const MIN_YEAR = 1;
|
|
47
|
+
export const MAX_YEAR = 9999;
|