@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,66 @@
|
|
|
1
|
+
import { addDays, dayOfWeek, toEpochDay } from "../values/plain-date.js";
|
|
2
|
+
import { SECONDS_PER_DAY } from "../values/plain-time.js";
|
|
3
|
+
import { fromSecondOfDay } from "../values/plain-time.js";
|
|
4
|
+
import { plainDateTime } from "../values/plain-date-time.js";
|
|
5
|
+
import { parseIsoDate } from "../values/iso.js";
|
|
6
|
+
import { toInstant, toZoned } from "../values/zoned.js";
|
|
7
|
+
const TIME_TOKEN = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/;
|
|
8
|
+
/** Seconds since local midnight for a `"HH:mm"` or `"HH:mm:ss"` token. `"24:00"` is 86400. */
|
|
9
|
+
export function timeTokenToSeconds(token) {
|
|
10
|
+
const match = TIME_TOKEN.exec(token.trim());
|
|
11
|
+
if (!match) {
|
|
12
|
+
throw new RangeError(`Invalid time "${token}": expected "HH:mm".`);
|
|
13
|
+
}
|
|
14
|
+
const hour = Number(match[1]);
|
|
15
|
+
const minute = Number(match[2]);
|
|
16
|
+
const second = Number(match[3] ?? 0);
|
|
17
|
+
if (hour === 24 && minute === 0 && second === 0) {
|
|
18
|
+
return SECONDS_PER_DAY;
|
|
19
|
+
}
|
|
20
|
+
if (hour > 23 || minute > 59 || second > 59) {
|
|
21
|
+
throw new RangeError(`Invalid time "${token}": out of range.`);
|
|
22
|
+
}
|
|
23
|
+
return hour * 3600 + minute * 60 + second;
|
|
24
|
+
}
|
|
25
|
+
/** Normalize `dates` (strings or values) once, at compile time. */
|
|
26
|
+
export function normalizeRule(rule) {
|
|
27
|
+
if (rule.type === "dates") {
|
|
28
|
+
return {
|
|
29
|
+
...rule,
|
|
30
|
+
dates: rule.dates.map((date) => typeof date === "string" ? parseIsoDate(date) : date),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return rule;
|
|
34
|
+
}
|
|
35
|
+
/** Whether a rule applies to `resourceId` (rules without one apply to everything). */
|
|
36
|
+
export function ruleMatchesResource(rule, resourceId) {
|
|
37
|
+
const target = rule.resourceId;
|
|
38
|
+
if (target === undefined) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (resourceId === undefined) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return typeof target === "string"
|
|
45
|
+
? target === resourceId
|
|
46
|
+
: target.includes(resourceId);
|
|
47
|
+
}
|
|
48
|
+
/** The wall-time window of a day-scoped rule on `day`, as instants in `zone`. */
|
|
49
|
+
export function expandRuleDay(rule, day, zone) {
|
|
50
|
+
if (rule.type === "weekly" && !rule.days.includes(dayOfWeek(day))) {
|
|
51
|
+
return { start: 0, end: 0 };
|
|
52
|
+
}
|
|
53
|
+
if (rule.type === "dates" &&
|
|
54
|
+
!rule.dates.some((value) => toEpochDay(value) === toEpochDay(day))) {
|
|
55
|
+
return { start: 0, end: 0 };
|
|
56
|
+
}
|
|
57
|
+
const startSeconds = rule.start === undefined ? 0 : timeTokenToSeconds(rule.start);
|
|
58
|
+
const rawEnd = rule.end === undefined ? SECONDS_PER_DAY : timeTokenToSeconds(rule.end);
|
|
59
|
+
if (rawEnd === startSeconds) {
|
|
60
|
+
throw new RangeError(`Availability ${rule.type} rule start and end are equal ("${rule.start}").`);
|
|
61
|
+
}
|
|
62
|
+
const endDay = rawEnd >= SECONDS_PER_DAY || rawEnd < startSeconds ? addDays(day, 1) : day;
|
|
63
|
+
const start = toInstant(toZoned(plainDateTime(day, fromSecondOfDay(startSeconds)), zone, "compatible"));
|
|
64
|
+
const end = toInstant(toZoned(plainDateTime(endDay, fromSecondOfDay(rawEnd % SECONDS_PER_DAY)), zone, "compatible"));
|
|
65
|
+
return { start, end };
|
|
66
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { DateRange } from "../ranges/date-range.js";
|
|
2
|
+
import type { DayOfWeek, PlainDate, PlainDateTime, PlainTime, ZonedDateTime } from "../values/types.js";
|
|
3
|
+
import { type AvailabilityRule } from "./availability-rules.js";
|
|
4
|
+
export type { AvailabilityRule, AvailabilityRuleMeta, DailyAvailabilityRule, DatesAvailabilityRule, RangeAvailabilityRule, WeeklyAvailabilityRule, } from "./availability-rules.js";
|
|
5
|
+
/** Lead time before `now` (plan 11 V13). Fields combine; the latest bound wins. */
|
|
6
|
+
export type AvailabilityLeadTime = {
|
|
7
|
+
minutes?: number;
|
|
8
|
+
hours?: number;
|
|
9
|
+
days?: number;
|
|
10
|
+
businessDays?: number;
|
|
11
|
+
};
|
|
12
|
+
export type AvailabilityBookingWindow = {
|
|
13
|
+
days?: number;
|
|
14
|
+
months?: number;
|
|
15
|
+
};
|
|
16
|
+
/** The one availability model (plan 11 V1–V5, V13). */
|
|
17
|
+
export type AvailabilitySpec = {
|
|
18
|
+
/** Only times inside an `open` rule are available. Without `open`, everything is open. */
|
|
19
|
+
open?: readonly AvailabilityRule[];
|
|
20
|
+
/** Always unavailable; `blocked` wins over `open`. */
|
|
21
|
+
blocked?: readonly AvailabilityRule[];
|
|
22
|
+
/** The zone the rule wall times are written in. */
|
|
23
|
+
timeZone?: string;
|
|
24
|
+
/** Nothing before `now` + lead time is available. Needs `now` at compile time. */
|
|
25
|
+
leadTime?: AvailabilityLeadTime;
|
|
26
|
+
/** Wall time after which "today" no longer counts for `businessDays` lead time. */
|
|
27
|
+
cutoffTime?: string;
|
|
28
|
+
/** Nothing after `now` + the window is available. */
|
|
29
|
+
bookingWindow?: AvailabilityBookingWindow;
|
|
30
|
+
};
|
|
31
|
+
/** The pre-plan-11 shape, accepted for one minor version (plan 11 R1). */
|
|
32
|
+
export type LegacyAvailabilitySpec = {
|
|
33
|
+
dates?: readonly PlainDate[];
|
|
34
|
+
ranges?: readonly DateRange[];
|
|
35
|
+
weekdays?: readonly DayOfWeek[];
|
|
36
|
+
mode: "available" | "blocked";
|
|
37
|
+
};
|
|
38
|
+
export type AvailabilityStatus = "available" | "partial" | "unavailable";
|
|
39
|
+
/** A contiguous piece of `[start, end)` with a status, in epoch milliseconds. */
|
|
40
|
+
export type AvailabilityInterval = {
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
status: "available" | "unavailable";
|
|
44
|
+
/** The blocked rules overlapping an unavailable piece (lead time is `id: "lead-time"`). */
|
|
45
|
+
rules: readonly AvailabilityRule[];
|
|
46
|
+
};
|
|
47
|
+
/** The compiled availability model (plan 11 V4, R1, R3). */
|
|
48
|
+
export type Availability = {
|
|
49
|
+
/** The zone the spec's wall times are written in (plan 11 V5). */
|
|
50
|
+
readonly timeZone: string;
|
|
51
|
+
readonly spec: AvailabilitySpec;
|
|
52
|
+
/** `"available"` (all potential time is free), `"partial"` (some is blocked), `"unavailable"`. */
|
|
53
|
+
getDayStatus(date: PlainDate, resourceId?: string): AvailabilityStatus;
|
|
54
|
+
/** Contiguous pieces covering exactly `[start, end)` in the display zone. */
|
|
55
|
+
getIntervals(start: AvailabilityInput, end: AvailabilityInput, resourceId?: string): AvailabilityInterval[];
|
|
56
|
+
isTimeAvailable(date: PlainDate, time: PlainTime, resourceId?: string): boolean;
|
|
57
|
+
isRangeAvailable(start: AvailabilityInput, end: AvailabilityInput, resourceId?: string): boolean;
|
|
58
|
+
/** The nearest day strictly after (`1`) or before (`-1`) with some available time. */
|
|
59
|
+
nextAvailable(date: PlainDate, direction: 1 | -1, resourceId?: string): PlainDate | null;
|
|
60
|
+
/** Legacy: `getDayStatus(date) !== "unavailable"` (plan 11 R1). */
|
|
61
|
+
isAvailable(date: PlainDate): boolean;
|
|
62
|
+
};
|
|
63
|
+
export type AvailabilityInput = PlainDate | PlainDateTime | ZonedDateTime | string;
|
|
64
|
+
export type AvailabilityOptions = {
|
|
65
|
+
/** The display zone; defaults to `spec.timeZone`. */
|
|
66
|
+
timeZone?: string;
|
|
67
|
+
/** The instant "now" for lead time and booking windows (epoch ms). */
|
|
68
|
+
now?: number;
|
|
69
|
+
};
|
|
70
|
+
/** `true` for the pre-plan-11 shape (plan 11 R1). */
|
|
71
|
+
export declare function isLegacyAvailabilitySpec(input: AvailabilitySpec | LegacyAvailabilitySpec): input is LegacyAvailabilitySpec;
|
|
72
|
+
/** Convert the old shape into open/blocked rules (plan 11 R1). */
|
|
73
|
+
export declare function legacyToAvailabilitySpec(input: LegacyAvailabilitySpec): AvailabilitySpec;
|
|
74
|
+
/**
|
|
75
|
+
* Compile an availability model (plan 11 V4). Pass `now` for lead time and
|
|
76
|
+
* booking windows; without it those fields are skipped (no implicit clock read).
|
|
77
|
+
*/
|
|
78
|
+
export declare function createAvailability(input: AvailabilitySpec | LegacyAvailabilitySpec, options?: AvailabilityOptions): Availability;
|
|
79
|
+
/** A day with some available time (plan 11 V14). */
|
|
80
|
+
export declare function isBusinessDay(date: PlainDate, availability: Availability): boolean;
|
|
81
|
+
/** Move `count` business days (0 = `date` or the next business day). */
|
|
82
|
+
export declare function addBusinessDays(date: PlainDate, count: number, availability: Availability): PlainDate;
|
|
83
|
+
/** Business days in an inclusive date range (plan 11 V14). */
|
|
84
|
+
export declare function countBusinessDays(range: DateRange, availability: Availability): number;
|
|
85
|
+
/** The first rule's `reason`, if any (plan 11 V12). */
|
|
86
|
+
export declare function getAvailabilityLabel(rules: readonly AvailabilityRule[]): string;
|
|
87
|
+
/**
|
|
88
|
+
* Compile once per spec identity **and** options (plan 11 R7): the same spec in
|
|
89
|
+
* another zone, or with another `now`, is a different model.
|
|
90
|
+
*/
|
|
91
|
+
export declare function compileAvailability(input: AvailabilitySpec | Availability, options?: AvailabilityOptions): Availability;
|
|
92
|
+
/** Time-only components use `daily` rules only (plan 11 V6). */
|
|
93
|
+
export declare function filterDailyRules(spec: AvailabilitySpec): AvailabilitySpec;
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import { addDays, addMonths, fromEpochDay, plainDate, toEpochDay, } from "../values/plain-date.js";
|
|
2
|
+
import { plainDateTime } from "../values/plain-date-time.js";
|
|
3
|
+
import { plainTime } from "../values/plain-time.js";
|
|
4
|
+
import { parseIsoDate, parseIsoDateTime } from "../values/iso.js";
|
|
5
|
+
import { fromInstant, toInstant, toZoned } from "../values/zoned.js";
|
|
6
|
+
import { expandRuleDay, normalizeRule, ruleMatchesResource, timeTokenToSeconds, } from "./availability-rules.js";
|
|
7
|
+
const MIN_DAY = -719162; // 0001-01-01
|
|
8
|
+
const MAX_DAY = 2932896; // 9999-12-31
|
|
9
|
+
const SEARCH_LIMIT = 4000;
|
|
10
|
+
const CACHE_DAYS = 400;
|
|
11
|
+
const LEAD_TIME_RULE = {
|
|
12
|
+
type: "range",
|
|
13
|
+
start: "0001-01-01",
|
|
14
|
+
end: "0001-01-01",
|
|
15
|
+
id: "lead-time",
|
|
16
|
+
reason: "lead time",
|
|
17
|
+
};
|
|
18
|
+
const BOOKING_WINDOW_RULE = {
|
|
19
|
+
type: "range",
|
|
20
|
+
start: "0001-01-01",
|
|
21
|
+
end: "0001-01-01",
|
|
22
|
+
id: "booking-window",
|
|
23
|
+
reason: "booking window",
|
|
24
|
+
};
|
|
25
|
+
let warnedLegacy = false;
|
|
26
|
+
/** `true` for the pre-plan-11 shape (plan 11 R1). */
|
|
27
|
+
export function isLegacyAvailabilitySpec(input) {
|
|
28
|
+
return "mode" in input;
|
|
29
|
+
}
|
|
30
|
+
/** Convert the old shape into open/blocked rules (plan 11 R1). */
|
|
31
|
+
export function legacyToAvailabilitySpec(input) {
|
|
32
|
+
const rules = [];
|
|
33
|
+
if (input.dates?.length) {
|
|
34
|
+
rules.push({ type: "dates", dates: input.dates });
|
|
35
|
+
}
|
|
36
|
+
for (const range of input.ranges ?? []) {
|
|
37
|
+
rules.push({
|
|
38
|
+
type: "range",
|
|
39
|
+
start: range.start,
|
|
40
|
+
// Legacy ranges are inclusive; the new engine is half-open (plan 11 R8).
|
|
41
|
+
end: toEpochDay(range.end) >= MAX_DAY ? range.end : addDays(range.end, 1),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (input.weekdays?.length) {
|
|
45
|
+
rules.push({ type: "weekly", days: input.weekdays });
|
|
46
|
+
}
|
|
47
|
+
return input.mode === "available" ? { open: rules } : { blocked: rules };
|
|
48
|
+
}
|
|
49
|
+
function instantOf(value, zone) {
|
|
50
|
+
if (typeof value === "string") {
|
|
51
|
+
if (value.includes("T")) {
|
|
52
|
+
const dateTime = parseIsoDateTime(value);
|
|
53
|
+
return toInstant(toZoned(dateTime, zone, "compatible"));
|
|
54
|
+
}
|
|
55
|
+
return instantOf(parseIsoDate(value), zone);
|
|
56
|
+
}
|
|
57
|
+
if ("timeZone" in value) {
|
|
58
|
+
return toInstant(value);
|
|
59
|
+
}
|
|
60
|
+
if ("hour" in value) {
|
|
61
|
+
return toInstant(toZoned(value, zone, "compatible"));
|
|
62
|
+
}
|
|
63
|
+
return toInstant(toZoned(plainDateTime(value, plainTime(0, 0)), zone, "compatible"));
|
|
64
|
+
}
|
|
65
|
+
function startOfDayInstant(date, zone) {
|
|
66
|
+
return toInstant(toZoned(plainDateTime(date, plainTime(0, 0)), zone, "compatible"));
|
|
67
|
+
}
|
|
68
|
+
function parseRangeBound(value) {
|
|
69
|
+
if (typeof value !== "string") {
|
|
70
|
+
return { date: value };
|
|
71
|
+
}
|
|
72
|
+
if (value.includes("T")) {
|
|
73
|
+
const dateTime = parseIsoDateTime(value);
|
|
74
|
+
return {
|
|
75
|
+
date: dateTime,
|
|
76
|
+
time: plainTime(dateTime.hour, dateTime.minute, dateTime.second),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return { date: parseIsoDate(value) };
|
|
80
|
+
}
|
|
81
|
+
function rangeSpan(rule, zone) {
|
|
82
|
+
const start = parseRangeBound(rule.start);
|
|
83
|
+
const end = parseRangeBound(rule.end);
|
|
84
|
+
const startAt = start.time
|
|
85
|
+
? toInstant(toZoned(plainDateTime(start.date, start.time), zone, "compatible"))
|
|
86
|
+
: startOfDayInstant(start.date, zone);
|
|
87
|
+
const endAt = end.time
|
|
88
|
+
? toInstant(toZoned(plainDateTime(end.date, end.time), zone, "compatible"))
|
|
89
|
+
: startOfDayInstant(end.date, zone);
|
|
90
|
+
return { start: startAt, end: endAt, rule };
|
|
91
|
+
}
|
|
92
|
+
function mergeSpans(spans) {
|
|
93
|
+
const sorted = [...spans].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
94
|
+
const merged = [];
|
|
95
|
+
for (const span of sorted) {
|
|
96
|
+
if (span.end <= span.start) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const last = merged[merged.length - 1];
|
|
100
|
+
if (last && span.start <= last.end) {
|
|
101
|
+
last.end = Math.max(last.end, span.end);
|
|
102
|
+
if (!last.rule && span.rule) {
|
|
103
|
+
last.rule = span.rule;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
merged.push({ ...span });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return merged;
|
|
111
|
+
}
|
|
112
|
+
/** Contiguous pieces of `[start, end)` from open minus blocked (plan 11 §12.2 step 4). */
|
|
113
|
+
function sweep(open, blocked, start, end) {
|
|
114
|
+
const points = new Set([start, end]);
|
|
115
|
+
for (const span of open) {
|
|
116
|
+
if (span.start > start && span.start < end)
|
|
117
|
+
points.add(span.start);
|
|
118
|
+
if (span.end > start && span.end < end)
|
|
119
|
+
points.add(span.end);
|
|
120
|
+
}
|
|
121
|
+
for (const span of blocked) {
|
|
122
|
+
if (span.start > start && span.start < end)
|
|
123
|
+
points.add(span.start);
|
|
124
|
+
if (span.end > start && span.end < end)
|
|
125
|
+
points.add(span.end);
|
|
126
|
+
}
|
|
127
|
+
const sorted = [...points].sort((a, b) => a - b);
|
|
128
|
+
const pieces = [];
|
|
129
|
+
for (let index = 0; index < sorted.length - 1; index += 1) {
|
|
130
|
+
const from = sorted[index];
|
|
131
|
+
const to = sorted[index + 1];
|
|
132
|
+
if (to <= from) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const mid = (from + to) / 2;
|
|
136
|
+
const isOpen = open.some((span) => span.start <= mid && mid < span.end);
|
|
137
|
+
const blocking = blocked.filter((span) => span.start <= mid && mid < span.end);
|
|
138
|
+
const status = isOpen && blocking.length === 0 ? "available" : "unavailable";
|
|
139
|
+
const previous = pieces[pieces.length - 1];
|
|
140
|
+
const rules = blocking
|
|
141
|
+
.map((span) => span.rule)
|
|
142
|
+
.filter((rule) => rule !== undefined);
|
|
143
|
+
if (previous &&
|
|
144
|
+
previous.status === status &&
|
|
145
|
+
previous.rules.length === rules.length &&
|
|
146
|
+
previous.rules.every((rule, position) => rule === rules[position])) {
|
|
147
|
+
previous.end = to;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
pieces.push({ start: from, end: to, status, rules });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return pieces;
|
|
154
|
+
}
|
|
155
|
+
function sumMs(pieces, status) {
|
|
156
|
+
return pieces
|
|
157
|
+
.filter((piece) => piece.status === status)
|
|
158
|
+
.reduce((total, piece) => total + (piece.end - piece.start), 0);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Compile an availability model (plan 11 V4). Pass `now` for lead time and
|
|
162
|
+
* booking windows; without it those fields are skipped (no implicit clock read).
|
|
163
|
+
*/
|
|
164
|
+
export function createAvailability(input, options = {}) {
|
|
165
|
+
let spec;
|
|
166
|
+
if (isLegacyAvailabilitySpec(input)) {
|
|
167
|
+
if (!warnedLegacy) {
|
|
168
|
+
warnedLegacy = true;
|
|
169
|
+
console.warn("[chrono] The date-only AvailabilitySpec shape is deprecated; use { open, blocked }.");
|
|
170
|
+
}
|
|
171
|
+
spec = legacyToAvailabilitySpec(input);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
spec = input;
|
|
175
|
+
}
|
|
176
|
+
const ruleZone = spec.timeZone ?? options.timeZone ?? "UTC";
|
|
177
|
+
const displayZone = options.timeZone ?? ruleZone;
|
|
178
|
+
const now = options.now;
|
|
179
|
+
const openRules = (spec.open ?? []).map(normalizeRule);
|
|
180
|
+
const blockedRules = (spec.blocked ?? []).map(normalizeRule);
|
|
181
|
+
const hasOpen = spec.open !== undefined;
|
|
182
|
+
const dayCache = new Map();
|
|
183
|
+
const statusCache = new Map();
|
|
184
|
+
const cacheKey = (dayEpoch, resourceId) => `${dayEpoch}|${resourceId ?? ""}`;
|
|
185
|
+
const daySpans = (dayEpoch, resourceId) => {
|
|
186
|
+
const key = cacheKey(dayEpoch, resourceId);
|
|
187
|
+
const cached = dayCache.get(key);
|
|
188
|
+
if (cached) {
|
|
189
|
+
return cached;
|
|
190
|
+
}
|
|
191
|
+
const day = fromEpochDay(dayEpoch);
|
|
192
|
+
const spans = [];
|
|
193
|
+
for (const rule of [...openRules, ...blockedRules]) {
|
|
194
|
+
if (rule.type === "range" || !ruleMatchesResource(rule, resourceId)) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const span = expandRuleDay(rule, day, ruleZone);
|
|
198
|
+
if (span.end > span.start) {
|
|
199
|
+
spans.push({ ...span, rule });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (dayCache.size >= CACHE_DAYS) {
|
|
203
|
+
const oldest = dayCache.keys().next().value;
|
|
204
|
+
if (oldest !== undefined)
|
|
205
|
+
dayCache.delete(oldest);
|
|
206
|
+
}
|
|
207
|
+
dayCache.set(key, spans);
|
|
208
|
+
return spans;
|
|
209
|
+
};
|
|
210
|
+
const spansBetween = (rules, start, end, resourceId) => {
|
|
211
|
+
const spans = [];
|
|
212
|
+
// One-day margin on both sides so rules that cross midnight are included (V2 / §12.2).
|
|
213
|
+
const first = Math.max(MIN_DAY, toEpochDay(fromInstant(start, ruleZone)) - 1);
|
|
214
|
+
const last = Math.min(MAX_DAY, toEpochDay(fromInstant(end, ruleZone)) + 1);
|
|
215
|
+
for (let dayEpoch = first; dayEpoch <= last; dayEpoch += 1) {
|
|
216
|
+
for (const span of daySpans(dayEpoch, resourceId)) {
|
|
217
|
+
if (rules.includes(span.rule)) {
|
|
218
|
+
spans.push(span);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const rule of rules) {
|
|
223
|
+
if (rule.type !== "range") {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (!ruleMatchesResource(rule, resourceId)) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const span = rangeSpan(rule, ruleZone);
|
|
230
|
+
if (span.end > start && span.start < end) {
|
|
231
|
+
spans.push(span);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return spans;
|
|
235
|
+
};
|
|
236
|
+
// The lead-time-free base, so business days never depend on lead time (plan 11 §12.2).
|
|
237
|
+
const baseBusiness = spec.leadTime?.businessDays !== undefined ||
|
|
238
|
+
spec.bookingWindow !== undefined
|
|
239
|
+
? createAvailability({ ...spec, leadTime: undefined, bookingWindow: undefined }, options)
|
|
240
|
+
: undefined;
|
|
241
|
+
const businessDay = (date) => (baseBusiness ?? self).getDayStatus(date) !== "unavailable";
|
|
242
|
+
const shiftBusinessDay = (date, direction) => {
|
|
243
|
+
let day = addDays(date, direction);
|
|
244
|
+
for (let step = 0; step < SEARCH_LIMIT; step += 1) {
|
|
245
|
+
if (businessDay(day))
|
|
246
|
+
return day;
|
|
247
|
+
day = addDays(day, direction);
|
|
248
|
+
}
|
|
249
|
+
throw new RangeError("No business day found within the search limit.");
|
|
250
|
+
};
|
|
251
|
+
const walkBusinessDays = (date, count) => {
|
|
252
|
+
if (count === 0) {
|
|
253
|
+
return businessDay(date) ? date : shiftBusinessDay(date, 1);
|
|
254
|
+
}
|
|
255
|
+
const direction = count > 0 ? 1 : -1;
|
|
256
|
+
let day = date;
|
|
257
|
+
let remaining = Math.abs(count);
|
|
258
|
+
for (let step = 0; step < SEARCH_LIMIT && remaining > 0; step += 1) {
|
|
259
|
+
day = addDays(day, direction);
|
|
260
|
+
if (businessDay(day))
|
|
261
|
+
remaining -= 1;
|
|
262
|
+
}
|
|
263
|
+
if (remaining > 0) {
|
|
264
|
+
throw new RangeError("No business day found within the search limit.");
|
|
265
|
+
}
|
|
266
|
+
return day;
|
|
267
|
+
};
|
|
268
|
+
let notBefore = -Infinity;
|
|
269
|
+
let notAfter = Infinity;
|
|
270
|
+
const lead = spec.leadTime;
|
|
271
|
+
if (now !== undefined) {
|
|
272
|
+
const nowZoned = fromInstant(now, ruleZone);
|
|
273
|
+
const today = plainDate(nowZoned.year, nowZoned.month, nowZoned.day);
|
|
274
|
+
if (lead) {
|
|
275
|
+
if (lead.minutes !== undefined || lead.hours !== undefined) {
|
|
276
|
+
const ms = ((lead.minutes ?? 0) + (lead.hours ?? 0) * 60) * 60_000;
|
|
277
|
+
notBefore = Math.max(notBefore, now + ms);
|
|
278
|
+
}
|
|
279
|
+
if (lead.days !== undefined) {
|
|
280
|
+
notBefore = Math.max(notBefore, startOfDayInstant(addDays(today, lead.days), ruleZone));
|
|
281
|
+
}
|
|
282
|
+
if (lead.businessDays !== undefined) {
|
|
283
|
+
const cutoff = spec.cutoffTime === undefined
|
|
284
|
+
? Infinity
|
|
285
|
+
: timeTokenToSeconds(spec.cutoffTime);
|
|
286
|
+
const nowSeconds = nowZoned.hour * 3600 + nowZoned.minute * 60 + nowZoned.second;
|
|
287
|
+
let orderDay = today;
|
|
288
|
+
if (!businessDay(today) || nowSeconds >= cutoff) {
|
|
289
|
+
orderDay = shiftBusinessDay(today, 1);
|
|
290
|
+
}
|
|
291
|
+
const target = walkBusinessDays(orderDay, lead.businessDays);
|
|
292
|
+
notBefore = Math.max(notBefore, startOfDayInstant(target, ruleZone));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const window = spec.bookingWindow;
|
|
296
|
+
if (window) {
|
|
297
|
+
let lastDay = today;
|
|
298
|
+
if (window.days !== undefined)
|
|
299
|
+
lastDay = addDays(today, window.days);
|
|
300
|
+
if (window.months !== undefined) {
|
|
301
|
+
lastDay = addMonths(today, window.months);
|
|
302
|
+
}
|
|
303
|
+
notAfter = startOfDayInstant(addDays(lastDay, 1), ruleZone);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const blockedSpansFor = (start, end, resourceId) => {
|
|
307
|
+
const spans = spansBetween(blockedRules, start, end, resourceId);
|
|
308
|
+
if (notBefore > -Infinity) {
|
|
309
|
+
spans.push({ start: -Infinity, end: notBefore, rule: LEAD_TIME_RULE });
|
|
310
|
+
}
|
|
311
|
+
if (notAfter < Infinity) {
|
|
312
|
+
spans.push({ start: notAfter, end: Infinity, rule: BOOKING_WINDOW_RULE });
|
|
313
|
+
}
|
|
314
|
+
return spans;
|
|
315
|
+
};
|
|
316
|
+
const openSpansFor = (start, end, resourceId) => hasOpen
|
|
317
|
+
? mergeSpans(spansBetween(openRules, start, end, resourceId))
|
|
318
|
+
: [{ start, end }];
|
|
319
|
+
const piecesBetween = (start, end, resourceId) => {
|
|
320
|
+
if (end <= start) {
|
|
321
|
+
return [];
|
|
322
|
+
}
|
|
323
|
+
const open = openSpansFor(start, end, resourceId);
|
|
324
|
+
const blocked = blockedSpansFor(start, end, resourceId);
|
|
325
|
+
return sweep(open, blocked, start, end);
|
|
326
|
+
};
|
|
327
|
+
const instantAvailable = (at, resourceId) => {
|
|
328
|
+
const pieces = piecesBetween(at - 0.5, at + 0.5, resourceId);
|
|
329
|
+
const piece = pieces.find((value) => value.start <= at && at < value.end);
|
|
330
|
+
return piece?.status === "available";
|
|
331
|
+
};
|
|
332
|
+
const dayWindow = (date) => [
|
|
333
|
+
startOfDayInstant(date, displayZone),
|
|
334
|
+
startOfDayInstant(addDays(date, 1), displayZone),
|
|
335
|
+
];
|
|
336
|
+
const self = {
|
|
337
|
+
timeZone: ruleZone,
|
|
338
|
+
spec,
|
|
339
|
+
getDayStatus(date, resourceId) {
|
|
340
|
+
const statusKey = cacheKey(toEpochDay(date), resourceId);
|
|
341
|
+
const cachedStatus = statusCache.get(statusKey);
|
|
342
|
+
if (cachedStatus) {
|
|
343
|
+
return cachedStatus;
|
|
344
|
+
}
|
|
345
|
+
const [start, end] = dayWindow(date);
|
|
346
|
+
if (end <= start) {
|
|
347
|
+
return "unavailable";
|
|
348
|
+
}
|
|
349
|
+
const open = openSpansFor(start, end, resourceId);
|
|
350
|
+
const blocked = blockedSpansFor(start, end, resourceId);
|
|
351
|
+
const potential = open.reduce((total, span) => total +
|
|
352
|
+
Math.max(0, Math.min(span.end, end) - Math.max(span.start, start)), 0);
|
|
353
|
+
if (potential <= 0) {
|
|
354
|
+
return "unavailable";
|
|
355
|
+
}
|
|
356
|
+
const available = sweep(open, blocked, start, end);
|
|
357
|
+
const availableMs = sumMs(available, "available");
|
|
358
|
+
const status = availableMs <= 0
|
|
359
|
+
? "unavailable"
|
|
360
|
+
: availableMs < potential
|
|
361
|
+
? "partial"
|
|
362
|
+
: "available";
|
|
363
|
+
if (statusCache.size >= CACHE_DAYS) {
|
|
364
|
+
const oldest = statusCache.keys().next().value;
|
|
365
|
+
if (oldest !== undefined)
|
|
366
|
+
statusCache.delete(oldest);
|
|
367
|
+
}
|
|
368
|
+
statusCache.set(statusKey, status);
|
|
369
|
+
return status;
|
|
370
|
+
},
|
|
371
|
+
getIntervals(start, end, resourceId) {
|
|
372
|
+
const from = instantOf(start, displayZone);
|
|
373
|
+
const to = instantOf(end, displayZone);
|
|
374
|
+
return piecesBetween(from, to, resourceId);
|
|
375
|
+
},
|
|
376
|
+
isTimeAvailable(date, time, resourceId) {
|
|
377
|
+
return instantAvailable(instantOf(plainDateTime(date, time), displayZone), resourceId);
|
|
378
|
+
},
|
|
379
|
+
isRangeAvailable(start, end, resourceId) {
|
|
380
|
+
const from = instantOf(start, displayZone);
|
|
381
|
+
const to = instantOf(end, displayZone);
|
|
382
|
+
if (to <= from) {
|
|
383
|
+
return instantAvailable(from, resourceId);
|
|
384
|
+
}
|
|
385
|
+
return piecesBetween(from, to, resourceId).every((piece) => piece.status === "available");
|
|
386
|
+
},
|
|
387
|
+
nextAvailable(date, direction, resourceId) {
|
|
388
|
+
let epochDay = toEpochDay(date) + direction;
|
|
389
|
+
for (let step = 0; step < SEARCH_LIMIT; step += 1) {
|
|
390
|
+
if (epochDay < MIN_DAY || epochDay > MAX_DAY) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
const day = fromEpochDay(epochDay);
|
|
394
|
+
if (self.getDayStatus(day, resourceId) !== "unavailable") {
|
|
395
|
+
return day;
|
|
396
|
+
}
|
|
397
|
+
epochDay += direction;
|
|
398
|
+
}
|
|
399
|
+
return null;
|
|
400
|
+
},
|
|
401
|
+
isAvailable(date) {
|
|
402
|
+
return self.getDayStatus(date) !== "unavailable";
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
return self;
|
|
406
|
+
}
|
|
407
|
+
/** A day with some available time (plan 11 V14). */
|
|
408
|
+
export function isBusinessDay(date, availability) {
|
|
409
|
+
return availability.getDayStatus(date) !== "unavailable";
|
|
410
|
+
}
|
|
411
|
+
/** Move `count` business days (0 = `date` or the next business day). */
|
|
412
|
+
export function addBusinessDays(date, count, availability) {
|
|
413
|
+
if (count === 0) {
|
|
414
|
+
let day = date;
|
|
415
|
+
for (let step = 0; step < SEARCH_LIMIT; step += 1) {
|
|
416
|
+
if (isBusinessDay(day, availability))
|
|
417
|
+
return day;
|
|
418
|
+
day = addDays(day, 1);
|
|
419
|
+
}
|
|
420
|
+
throw new RangeError("No business day found within the search limit.");
|
|
421
|
+
}
|
|
422
|
+
const direction = count > 0 ? 1 : -1;
|
|
423
|
+
let remaining = Math.abs(count);
|
|
424
|
+
let day = date;
|
|
425
|
+
for (let step = 0; step < SEARCH_LIMIT && remaining > 0; step += 1) {
|
|
426
|
+
day = addDays(day, direction);
|
|
427
|
+
if (isBusinessDay(day, availability))
|
|
428
|
+
remaining -= 1;
|
|
429
|
+
}
|
|
430
|
+
if (remaining > 0) {
|
|
431
|
+
throw new RangeError("No business day found within the search limit.");
|
|
432
|
+
}
|
|
433
|
+
return day;
|
|
434
|
+
}
|
|
435
|
+
/** Business days in an inclusive date range (plan 11 V14). */
|
|
436
|
+
export function countBusinessDays(range, availability) {
|
|
437
|
+
let count = 0;
|
|
438
|
+
for (let epochDay = toEpochDay(range.start); epochDay <= toEpochDay(range.end); epochDay += 1) {
|
|
439
|
+
if (isBusinessDay(fromEpochDay(epochDay), availability))
|
|
440
|
+
count += 1;
|
|
441
|
+
}
|
|
442
|
+
return count;
|
|
443
|
+
}
|
|
444
|
+
/** The first rule's `reason`, if any (plan 11 V12). */
|
|
445
|
+
export function getAvailabilityLabel(rules) {
|
|
446
|
+
return rules[0]?.reason ?? "";
|
|
447
|
+
}
|
|
448
|
+
const compileCache = new WeakMap();
|
|
449
|
+
/**
|
|
450
|
+
* Compile once per spec identity **and** options (plan 11 R7): the same spec in
|
|
451
|
+
* another zone, or with another `now`, is a different model.
|
|
452
|
+
*/
|
|
453
|
+
export function compileAvailability(input, options = {}) {
|
|
454
|
+
if (typeof input.getDayStatus === "function") {
|
|
455
|
+
return input;
|
|
456
|
+
}
|
|
457
|
+
const key = `${options.timeZone ?? ""}|${options.now ?? ""}`;
|
|
458
|
+
let byOptions = compileCache.get(input);
|
|
459
|
+
if (!byOptions) {
|
|
460
|
+
byOptions = new Map();
|
|
461
|
+
compileCache.set(input, byOptions);
|
|
462
|
+
}
|
|
463
|
+
const cached = byOptions.get(key);
|
|
464
|
+
if (cached) {
|
|
465
|
+
return cached;
|
|
466
|
+
}
|
|
467
|
+
if (byOptions.size >= 8) {
|
|
468
|
+
// A moving `now` would otherwise grow the map without bound.
|
|
469
|
+
byOptions.clear();
|
|
470
|
+
}
|
|
471
|
+
const value = createAvailability(input, options);
|
|
472
|
+
byOptions.set(key, value);
|
|
473
|
+
return value;
|
|
474
|
+
}
|
|
475
|
+
let warnedDailyOnly = false;
|
|
476
|
+
/** Time-only components use `daily` rules only (plan 11 V6). */
|
|
477
|
+
export function filterDailyRules(spec) {
|
|
478
|
+
const keep = (rules) => rules?.filter((rule) => rule.type === "daily");
|
|
479
|
+
const open = keep(spec.open);
|
|
480
|
+
const blocked = keep(spec.blocked);
|
|
481
|
+
const dropped = (spec.open?.length ?? 0) -
|
|
482
|
+
(open?.length ?? 0) +
|
|
483
|
+
(spec.blocked?.length ?? 0) -
|
|
484
|
+
(blocked?.length ?? 0);
|
|
485
|
+
if (dropped > 0 && !warnedDailyOnly) {
|
|
486
|
+
warnedDailyOnly = true;
|
|
487
|
+
console.warn("[chrono] Time-only components only use `daily` availability rules; other rule types are ignored.");
|
|
488
|
+
}
|
|
489
|
+
return { ...spec, open, blocked };
|
|
490
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PlainDate } from "../values/types.js";
|
|
2
|
+
export type DateConstraints = {
|
|
3
|
+
min?: PlainDate;
|
|
4
|
+
max?: PlainDate;
|
|
5
|
+
isDateDisabled?: (date: PlainDate) => boolean;
|
|
6
|
+
isDateUnavailable?: (date: PlainDate) => boolean;
|
|
7
|
+
};
|
|
8
|
+
export type DateStatusReason = "before-min" | "after-max" | "disabled" | "unavailable";
|
|
9
|
+
/**
|
|
10
|
+
* `disabled` and `unavailable` are separate statuses with the same
|
|
11
|
+
* selectability (D14). Both stay focusable.
|
|
12
|
+
*/
|
|
13
|
+
export type DateStatus = {
|
|
14
|
+
selectable: boolean;
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
unavailable: boolean;
|
|
17
|
+
reason?: DateStatusReason;
|
|
18
|
+
};
|
|
19
|
+
/** Order: min, max, `isDateDisabled`, `isDateUnavailable`. The first hit wins. */
|
|
20
|
+
export declare function getDateStatus(date: PlainDate, constraints?: DateConstraints): DateStatus;
|
|
21
|
+
export declare function isDateSelectable(date: PlainDate, constraints?: DateConstraints): boolean;
|