@super-calendar/core 2.17.0 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -10
- package/dist/index.mjs +9 -11
- package/dist/{recurrence-CvIJfSMl.mjs → recurrence-BqpCShcV.mjs} +402 -101
- package/dist/{recurrence-D_oJ7A9D.js → recurrence-CTjr6nxJ.js} +454 -99
- package/dist/{timezone-vbd68uRS.d.mts → timezone-DhGhYIeB.d.mts} +150 -13
- package/dist/{timezone-vbd68uRS.d.ts → timezone-DhGhYIeB.d.ts} +150 -13
- package/dist/vanilla.d.mts +2 -2
- package/dist/vanilla.d.ts +2 -2
- package/dist/vanilla.js +10 -1
- package/dist/vanilla.mjs +1 -1
- package/package.json +1 -1
- package/src/types.ts +7 -0
- package/src/utils/dates.ts +7 -2
- package/src/utils/drag.ts +14 -6
- package/src/utils/eventSource.ts +2 -0
- package/src/utils/ical.ts +5 -0
- package/src/utils/layout.ts +19 -5
- package/src/utils/monthGrid.ts +135 -1
- package/src/utils/multiWeekGrid.ts +2 -1
- package/src/utils/recurrence.ts +203 -77
- package/src/utils/timezone.ts +151 -48
- package/src/utils/useMonthGrid.ts +5 -0
- package/src/utils/useNow.ts +4 -9
- package/src/utils/zoneFields.ts +71 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addDays,
|
|
1
|
+
import { addDays, differenceInCalendarDays, eachDayOfInterval, endOfMonth, endOfWeek, format, getHours, getMinutes, isAfter, isBefore, isSameDay, isSameMonth, isToday, max, min, startOfDay, startOfMonth, startOfWeek } from "date-fns";
|
|
2
2
|
// src/tokens.ts
|
|
3
3
|
/** The default light-theme colour palette. */
|
|
4
4
|
const lightColors = {
|
|
@@ -159,8 +159,12 @@ const isWeekend = (date) => {
|
|
|
159
159
|
const day = date.getDay();
|
|
160
160
|
return day === 0 || day === 6;
|
|
161
161
|
};
|
|
162
|
-
/**
|
|
163
|
-
|
|
162
|
+
/**
|
|
163
|
+
* True when `date` falls on the current calendar day. Pass `today` to compare
|
|
164
|
+
* against that day instead of the device clock, e.g. the result of
|
|
165
|
+
* `nowInTimeZone` for a calendar displayed in another time zone.
|
|
166
|
+
*/
|
|
167
|
+
const getIsToday = (date, today) => today ? isSameDay(date, today) : isToday(date);
|
|
164
168
|
/** True when `a` and `b` are the same calendar day (ignoring the time of day). */
|
|
165
169
|
const isSameCalendarDay = (a, b) => isSameDay(a, b);
|
|
166
170
|
/** Minutes elapsed since midnight (0–1439). */
|
|
@@ -291,7 +295,7 @@ const clockSpan = (from, to, dayStart, nextDayStart) => {
|
|
|
291
295
|
function layoutDayEvents(events, day) {
|
|
292
296
|
const dayStart = startOfDay(day);
|
|
293
297
|
const nextDayStart = addDays(dayStart, 1);
|
|
294
|
-
const segments = events.filter((event) => !isAllDayEvent(event) && !isBackgroundEvent(event)).filter((event) => event.start < nextDayStart && event.end > dayStart).map((event) => {
|
|
298
|
+
const segments = events.filter((event) => !isAllDayEvent(event) && !isBackgroundEvent(event)).filter((event) => event.start < nextDayStart && (event.end > dayStart || event.end.getTime() === event.start.getTime() && event.start >= dayStart)).map((event) => {
|
|
295
299
|
const segStart = max([event.start, dayStart]);
|
|
296
300
|
const segEnd = min([event.end, nextDayStart]);
|
|
297
301
|
return {
|
|
@@ -304,6 +308,7 @@ function layoutDayEvents(events, day) {
|
|
|
304
308
|
const positioned = [];
|
|
305
309
|
let cluster = [];
|
|
306
310
|
let clusterEnd = Number.NEGATIVE_INFINITY;
|
|
311
|
+
const drawnEndOf = (seg) => Math.max(seg.end, seg.start + MIN_DURATION_HOURS);
|
|
307
312
|
const flushCluster = () => {
|
|
308
313
|
const columnEnds = [];
|
|
309
314
|
const columnOf = /* @__PURE__ */ new Map();
|
|
@@ -311,8 +316,8 @@ function layoutDayEvents(events, day) {
|
|
|
311
316
|
let column = columnEnds.findIndex((end) => end <= seg.start);
|
|
312
317
|
if (column === -1) {
|
|
313
318
|
column = columnEnds.length;
|
|
314
|
-
columnEnds.push(seg
|
|
315
|
-
} else columnEnds[column] = seg
|
|
319
|
+
columnEnds.push(drawnEndOf(seg));
|
|
320
|
+
} else columnEnds[column] = drawnEndOf(seg);
|
|
316
321
|
columnOf.set(seg, column);
|
|
317
322
|
}
|
|
318
323
|
for (const seg of cluster) positioned.push({
|
|
@@ -329,7 +334,7 @@ function layoutDayEvents(events, day) {
|
|
|
329
334
|
for (const seg of segments) {
|
|
330
335
|
if (cluster.length > 0 && seg.start >= clusterEnd) flushCluster();
|
|
331
336
|
cluster.push(seg);
|
|
332
|
-
clusterEnd = Math.max(clusterEnd, seg
|
|
337
|
+
clusterEnd = Math.max(clusterEnd, drawnEndOf(seg));
|
|
333
338
|
}
|
|
334
339
|
if (cluster.length > 0) flushCluster();
|
|
335
340
|
return positioned;
|
|
@@ -354,7 +359,7 @@ function eventDayKeys(event) {
|
|
|
354
359
|
const lastInstant = event.end > event.start ? /* @__PURE__ */ new Date(event.end.getTime() - 1) : event.start;
|
|
355
360
|
const last = startOfDay(lastInstant);
|
|
356
361
|
const keys = [];
|
|
357
|
-
for (let cursor = first; cursor <= last; cursor = addDays(cursor, 1)) keys.push(cursor.toISOString());
|
|
362
|
+
for (let cursor = first; cursor <= last; cursor = startOfDay(addDays(cursor, 1))) keys.push(cursor.toISOString());
|
|
358
363
|
return keys;
|
|
359
364
|
}
|
|
360
365
|
/**
|
|
@@ -456,11 +461,19 @@ function backgroundBandsForDay(events, day) {
|
|
|
456
461
|
// src/utils/drag.ts
|
|
457
462
|
/**
|
|
458
463
|
* True when two time ranges overlap. Edges touching (one ends exactly when the
|
|
459
|
-
* next begins) do not count as an overlap.
|
|
460
|
-
*
|
|
464
|
+
* next begins) do not count as an overlap. A zero-length range occupies its own
|
|
465
|
+
* instant: it overlaps a range that contains that instant or starts at it, and
|
|
466
|
+
* another zero-length range at the same instant. Compares absolute instants, so
|
|
467
|
+
* events at the same wall-clock time on different days do not overlap.
|
|
461
468
|
*/
|
|
462
469
|
function eventsOverlap(aStart, aEnd, bStart, bEnd) {
|
|
463
|
-
|
|
470
|
+
const a0 = aStart.getTime();
|
|
471
|
+
const a1 = aEnd.getTime();
|
|
472
|
+
const b0 = bStart.getTime();
|
|
473
|
+
const b1 = bEnd.getTime();
|
|
474
|
+
if (a0 === a1) return b0 === b1 ? a0 === b0 : b0 <= a0 && a0 < b1;
|
|
475
|
+
if (b0 === b1) return a0 <= b0 && b0 < a1;
|
|
476
|
+
return a0 < b1 && b0 < a1;
|
|
464
477
|
}
|
|
465
478
|
/**
|
|
466
479
|
* True when the range `[start, end)` would overlap any event in `events` other
|
|
@@ -579,8 +592,8 @@ function resolveDraggedBounds(start, end, deltaStartMinutes, deltaEndMinutes, sn
|
|
|
579
592
|
}
|
|
580
593
|
/**
|
|
581
594
|
* The all-day range swept out between two day cells of the month grid, ordered
|
|
582
|
-
* whichever way the sweep ran: `start` is
|
|
583
|
-
*
|
|
595
|
+
* whichever way the sweep ran: `start` is the first local day's start and `end` is
|
|
596
|
+
* the next day's start after the last, so a one-day sweep yields a usable event. Shared
|
|
584
597
|
* by both renderers so a month drag-to-create means the same thing on each.
|
|
585
598
|
*/
|
|
586
599
|
function monthCreateRange(anchor, hover) {
|
|
@@ -590,7 +603,7 @@ function monthCreateRange(anchor, hover) {
|
|
|
590
603
|
const last = a.getTime() <= b.getTime() ? b : a;
|
|
591
604
|
return {
|
|
592
605
|
start: first,
|
|
593
|
-
end: addDays(last, 1)
|
|
606
|
+
end: startOfDay(addDays(last, 1))
|
|
594
607
|
};
|
|
595
608
|
}
|
|
596
609
|
/**
|
|
@@ -800,6 +813,56 @@ function monthVisibleCount(total, capacity) {
|
|
|
800
813
|
if (total <= capacity.full) return total;
|
|
801
814
|
return Math.max(1, capacity.withMore);
|
|
802
815
|
}
|
|
816
|
+
// src/utils/zoneFields.ts
|
|
817
|
+
const MAX_ZONE_FORMATTERS = 32;
|
|
818
|
+
const zoneFormatters = /* @__PURE__ */ new Map();
|
|
819
|
+
function zoneFormatter(timeZone) {
|
|
820
|
+
let formatter = zoneFormatters.get(timeZone);
|
|
821
|
+
if (!formatter) {
|
|
822
|
+
formatter = new Intl.DateTimeFormat("en-US", {
|
|
823
|
+
timeZone,
|
|
824
|
+
hourCycle: "h23",
|
|
825
|
+
year: "numeric",
|
|
826
|
+
month: "2-digit",
|
|
827
|
+
day: "2-digit",
|
|
828
|
+
hour: "2-digit",
|
|
829
|
+
minute: "2-digit",
|
|
830
|
+
second: "2-digit"
|
|
831
|
+
});
|
|
832
|
+
if (zoneFormatters.size >= MAX_ZONE_FORMATTERS) zoneFormatters.clear();
|
|
833
|
+
zoneFormatters.set(timeZone, formatter);
|
|
834
|
+
}
|
|
835
|
+
return formatter;
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* The wall-clock fields `date` reads in `timeZone`, as plain numbers. Unlike a
|
|
839
|
+
* device-local `Date` holding those fields, the result can't be bent by the
|
|
840
|
+
* device's own DST changes.
|
|
841
|
+
*/
|
|
842
|
+
function zoneFields(date, timeZone) {
|
|
843
|
+
const parts = zoneFormatter(timeZone).formatToParts(date);
|
|
844
|
+
const field = (type) => {
|
|
845
|
+
const part = parts.find((p) => p.type === type);
|
|
846
|
+
return part ? Number(part.value) : 0;
|
|
847
|
+
};
|
|
848
|
+
return [
|
|
849
|
+
field("year"),
|
|
850
|
+
field("month") - 1,
|
|
851
|
+
field("day"),
|
|
852
|
+
field("hour") % 24,
|
|
853
|
+
field("minute"),
|
|
854
|
+
field("second")
|
|
855
|
+
];
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* A calendar reading as a UTC time value. Fields may overflow and roll over.
|
|
859
|
+
* Setters, not `Date.UTC`, which reads a year below 100 as 19xx.
|
|
860
|
+
*/
|
|
861
|
+
function utcTime(year, month, day, hour = 0, minute = 0, second = 0, ms = 0) {
|
|
862
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
863
|
+
date.setUTCFullYear(year, month, day);
|
|
864
|
+
return date.setUTCHours(hour, minute, second, ms);
|
|
865
|
+
}
|
|
803
866
|
// src/utils/timezone.ts
|
|
804
867
|
/**
|
|
805
868
|
* Reinterpret an instant as its wall-clock time in `timeZone`, returned as a
|
|
@@ -812,51 +875,125 @@ function monthVisibleCount(total, capacity) {
|
|
|
812
875
|
* original UTC instant, so don't round-trip it back to a real time.
|
|
813
876
|
*/
|
|
814
877
|
function toZonedTime(date, timeZone) {
|
|
815
|
-
const
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
return part ? Number(part.value) : 0;
|
|
828
|
-
};
|
|
829
|
-
const hour = field("hour") % 24;
|
|
830
|
-
return new Date(field("year"), field("month") - 1, field("day"), hour, field("minute"), field("second"), date.getMilliseconds());
|
|
878
|
+
const [year, month, day, hour, minute, second] = zoneFields(date, timeZone);
|
|
879
|
+
return new Date(year, month, day, hour, minute, second, date.getMilliseconds());
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* The current instant, or the fixed `now` when given, as the wall clock of
|
|
883
|
+
* `timeZone` (see {@link toZonedTime}). Without a `timeZone` it is the instant
|
|
884
|
+
* itself, read on the device clock. Compare calendar days against it to find
|
|
885
|
+
* "today" for a calendar displayed in another time zone.
|
|
886
|
+
*/
|
|
887
|
+
function nowInTimeZone(now, timeZone) {
|
|
888
|
+
const instant = now ?? /* @__PURE__ */ new Date();
|
|
889
|
+
return timeZone ? toZonedTime(instant, timeZone) : instant;
|
|
831
890
|
}
|
|
832
891
|
function zoneOffsetMs(instant, timeZone) {
|
|
833
|
-
const
|
|
834
|
-
return
|
|
892
|
+
const [year, month, day, hour, minute, second] = zoneFields(instant, timeZone);
|
|
893
|
+
return utcTime(year, month, day, hour, minute, second, instant.getUTCMilliseconds()) - instant.getTime();
|
|
835
894
|
}
|
|
836
895
|
/**
|
|
837
896
|
* The inverse of {@link toZonedTime}: given a wall-clock time in `timeZone`,
|
|
838
897
|
* return the absolute UTC instant. Pass the wall clock as a `Date` whose **UTC**
|
|
839
898
|
* fields hold the components (e.g. `new Date(Date.UTC(y, m, d, h, min))`). Used to
|
|
840
|
-
* resolve iCal `TZID` times; DST-correct via a two-pass offset
|
|
841
|
-
*
|
|
899
|
+
* resolve iCal `TZID` times; DST-correct via a two-pass offset. A time in the
|
|
900
|
+
* hour a spring-forward change skips names no instant; it resolves the same
|
|
901
|
+
* distance after the skipped hour (02:30 becomes 03:30), as a device clock does.
|
|
842
902
|
*/
|
|
843
903
|
function zonedTimeToUtc(wallClock, timeZone) {
|
|
844
904
|
const guess = wallClock.getTime();
|
|
845
905
|
const firstPass = zoneOffsetMs(new Date(guess), timeZone);
|
|
846
906
|
const secondPass = zoneOffsetMs(new Date(guess - firstPass), timeZone);
|
|
847
|
-
|
|
907
|
+
const instant = new Date(guess - secondPass);
|
|
908
|
+
if (firstPass !== secondPass && zoneOffsetMs(instant, timeZone) !== secondPass) return new Date(guess - Math.min(firstPass, secondPass));
|
|
909
|
+
return instant;
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* The inverse of {@link toZonedTime}: the real instant for a date whose
|
|
913
|
+
* device-local fields hold a wall-clock time in `timeZone`, such as a date a
|
|
914
|
+
* calendar displaying that zone reports. DST-correct via {@link zonedTimeToUtc}.
|
|
915
|
+
*/
|
|
916
|
+
function fromZonedTime(date, timeZone) {
|
|
917
|
+
return zonedTimeToUtc(new Date(utcTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())), timeZone);
|
|
848
918
|
}
|
|
919
|
+
const zonedSources = /* @__PURE__ */ new WeakMap();
|
|
849
920
|
/**
|
|
850
|
-
*
|
|
851
|
-
* displays them in `timeZone`. Other fields are preserved.
|
|
852
|
-
* (
|
|
921
|
+
* Shift every timed event's `start`/`end` through {@link toZonedTime} so the
|
|
922
|
+
* calendar displays them in `timeZone`. Other fields are preserved. All-day
|
|
923
|
+
* events (see `isAllDayEvent`) name calendar days, not instants, so they are
|
|
924
|
+
* returned as they are and stay on their days. Memoize the result (e.g. with
|
|
925
|
+
* `useMemo`) since it allocates new dates.
|
|
853
926
|
*/
|
|
854
927
|
function eventsInTimeZone(events, timeZone) {
|
|
855
|
-
return events.map((event) =>
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
928
|
+
return events.map((event) => {
|
|
929
|
+
if (isAllDayEvent(event)) return event;
|
|
930
|
+
const zoned = {
|
|
931
|
+
...event,
|
|
932
|
+
start: toZonedTime(event.start, timeZone),
|
|
933
|
+
end: toZonedTime(event.end, timeZone)
|
|
934
|
+
};
|
|
935
|
+
zonedSources.set(zoned, {
|
|
936
|
+
event,
|
|
937
|
+
timeZone
|
|
938
|
+
});
|
|
939
|
+
return zoned;
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* The event a display copy made by {@link eventsInTimeZone} stands for, with its
|
|
944
|
+
* real `start` and `end`. Any other event is returned as it is. Use it in the
|
|
945
|
+
* callbacks of a view that displays zoned events, to get back the event you
|
|
946
|
+
* passed in.
|
|
947
|
+
*/
|
|
948
|
+
function zonedEventSource(event) {
|
|
949
|
+
return zonedSources.get(event)?.event ?? event;
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Convert the bounds a view reports for a dragged event back to real instants.
|
|
953
|
+
* `event` is the displayed event the view passed to `onDragEvent`, and `start`
|
|
954
|
+
* / `end` the bounds it reported. For a display copy made by
|
|
955
|
+
* {@link eventsInTimeZone}, each bound is read as a wall-clock time in that
|
|
956
|
+
* zone, following the zone's own DST changes; an edge the drag left alone keeps
|
|
957
|
+
* the source event's exact instant. Bounds of any other event (an all-day
|
|
958
|
+
* event, or one that was never shifted) are returned unchanged.
|
|
959
|
+
*
|
|
960
|
+
* Returns `null` when the reported span doesn't survive the conversion: an edge
|
|
961
|
+
* dropped into the hour a spring-forward change skips moves to after it, which
|
|
962
|
+
* can leave the event ending at or before its start. Reject such a drop.
|
|
963
|
+
*/
|
|
964
|
+
function zonedDragBounds(event, start, end, { keepDuration = false } = {}) {
|
|
965
|
+
const zoned = zonedSources.get(event);
|
|
966
|
+
if (!zoned) return {
|
|
967
|
+
start,
|
|
968
|
+
end
|
|
969
|
+
};
|
|
970
|
+
const source = zoned.event;
|
|
971
|
+
const startMoved = start.getTime() !== event.start.getTime();
|
|
972
|
+
const endMoved = end.getTime() !== event.end.getTime();
|
|
973
|
+
const realStart = startMoved ? fromZonedTime(start, zoned.timeZone) : source.start;
|
|
974
|
+
if (keepDuration && startMoved && endMoved) {
|
|
975
|
+
const durationMs = source.end.getTime() - source.start.getTime();
|
|
976
|
+
return {
|
|
977
|
+
start: realStart,
|
|
978
|
+
end: new Date(realStart.getTime() + durationMs)
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
return orderedLike(start, end, realStart, endMoved ? fromZonedTime(end, zoned.timeZone) : source.end);
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Convert a wall-clock range a view reports in `timeZone` (a created event, for
|
|
985
|
+
* example) to real instants. Returns `null` when the span doesn't survive the
|
|
986
|
+
* conversion: a time in the hour a spring-forward change skips moves to after
|
|
987
|
+
* it, which can leave the range ending at or before its start.
|
|
988
|
+
*/
|
|
989
|
+
function fromZonedRange(start, end, timeZone) {
|
|
990
|
+
return orderedLike(start, end, fromZonedTime(start, timeZone), fromZonedTime(end, timeZone));
|
|
991
|
+
}
|
|
992
|
+
function orderedLike(start, end, realStart, realEnd) {
|
|
993
|
+
return end.getTime() > start.getTime() && realEnd.getTime() <= realStart.getTime() ? null : {
|
|
994
|
+
start: realStart,
|
|
995
|
+
end: realEnd
|
|
996
|
+
};
|
|
860
997
|
}
|
|
861
998
|
// src/utils/ical.ts
|
|
862
999
|
const RRULE_FREQ = {
|
|
@@ -990,6 +1127,8 @@ function parseRRule(value) {
|
|
|
990
1127
|
}
|
|
991
1128
|
if (plain.length) rule.weekdays = plain;
|
|
992
1129
|
}
|
|
1130
|
+
const wkst = BYDAY.indexOf(parts.get("WKST")?.trim().toUpperCase());
|
|
1131
|
+
if (wkst >= 0) rule.weekStartsOn = wkst;
|
|
993
1132
|
const bymonthday = parts.get("BYMONTHDAY");
|
|
994
1133
|
if (bymonthday) {
|
|
995
1134
|
const days = bymonthday.split(",").map((d) => Number(d.trim())).filter((d) => Number.isInteger(d) && d !== 0);
|
|
@@ -1009,6 +1148,7 @@ function formatRRule(rule) {
|
|
|
1009
1148
|
if (rule.until) parts.push(`UNTIL=${formatUtc(rule.until)}`);
|
|
1010
1149
|
if (rule.nthWeekday) parts.push(`BYDAY=${rule.nthWeekday.week}${BYDAY[rule.nthWeekday.weekday]}`);
|
|
1011
1150
|
else if (rule.weekdays?.length) parts.push(`BYDAY=${rule.weekdays.map((d) => BYDAY[d]).join(",")}`);
|
|
1151
|
+
if (rule.weekStartsOn != null && BYDAY[rule.weekStartsOn]) parts.push(`WKST=${BYDAY[rule.weekStartsOn]}`);
|
|
1012
1152
|
if (rule.monthDays?.length) parts.push(`BYMONTHDAY=${rule.monthDays.join(",")}`);
|
|
1013
1153
|
if (rule.months?.length) parts.push(`BYMONTH=${rule.months.join(",")}`);
|
|
1014
1154
|
return parts.join(";");
|
|
@@ -1202,6 +1342,7 @@ function recurrenceFromJSON(value, field) {
|
|
|
1202
1342
|
if (input.until !== void 0) rule.until = dateFromJSON(input.until, `${field}.until`);
|
|
1203
1343
|
for (const key of ["exdates", "rdates"]) if (input[key] !== void 0) rule[key] = arrayFromJSON(input[key], `${field}.${key}`).map((date, index) => dateFromJSON(date, `${field}.${key}[${index}]`));
|
|
1204
1344
|
if (input.weekdays !== void 0) rule.weekdays = arrayFromJSON(input.weekdays, `${field}.weekdays`).map((day) => weekdayFromJSON(day, `${field}.weekdays`));
|
|
1345
|
+
if (input.weekStartsOn !== void 0) rule.weekStartsOn = weekdayFromJSON(input.weekStartsOn, `${field}.weekStartsOn`);
|
|
1205
1346
|
if (input.months !== void 0) rule.months = arrayFromJSON(input.months, `${field}.months`).map((month) => integerFromJSON(month, `${field}.months`, 1, 12));
|
|
1206
1347
|
if (input.monthDays !== void 0) rule.monthDays = arrayFromJSON(input.monthDays, `${field}.monthDays`).map((day) => {
|
|
1207
1348
|
const parsed = integerFromJSON(day, `${field}.monthDays`, -31, 31);
|
|
@@ -1317,6 +1458,102 @@ function layoutMonthWeek(days, events) {
|
|
|
1317
1458
|
laneCount: laneEnds.length
|
|
1318
1459
|
};
|
|
1319
1460
|
}
|
|
1461
|
+
/**
|
|
1462
|
+
* The columns of a week row that show one lane more than the row. A row whose
|
|
1463
|
+
* lanes overflow shows `visibleLanes` of them and folds each day's rest into a
|
|
1464
|
+
* "+N more" label. A day whose only hidden event sits on lane `visibleLanes` draws
|
|
1465
|
+
* that event in the label's place instead of "+1 more". Call it only when
|
|
1466
|
+
* a bar on lane `visibleLanes` fits in the cell.
|
|
1467
|
+
*/
|
|
1468
|
+
function monthExtraLaneColumns(layout, visibleLanes, columnCount) {
|
|
1469
|
+
const hidden = Array.from({ length: columnCount }, () => 0);
|
|
1470
|
+
const onFirstHiddenLane = Array.from({ length: columnCount }, () => false);
|
|
1471
|
+
for (const segment of layout.segments) {
|
|
1472
|
+
if (segment.lane < visibleLanes) continue;
|
|
1473
|
+
for (let col = segment.startCol; col <= segment.endCol; col++) {
|
|
1474
|
+
hidden[col]++;
|
|
1475
|
+
if (segment.lane === visibleLanes) onFirstHiddenLane[col] = true;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
return hidden.map((count, col) => count === 1 && onFirstHiddenLane[col]);
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
* The bars a week row draws: every segment above `visibleLanes`, plus the parts of
|
|
1482
|
+
* a segment on lane `visibleLanes` that cross `extraLane` columns (see
|
|
1483
|
+
* {@link monthExtraLaneColumns}), one bar per run of such columns. A bar cut short
|
|
1484
|
+
* by a column that hides the event is marked as continuing past that edge.
|
|
1485
|
+
*/
|
|
1486
|
+
function monthVisibleBars(layout, visibleLanes, extraLane) {
|
|
1487
|
+
const bars = [];
|
|
1488
|
+
for (const segment of layout.segments) {
|
|
1489
|
+
if (segment.lane < visibleLanes) {
|
|
1490
|
+
bars.push(segment);
|
|
1491
|
+
continue;
|
|
1492
|
+
}
|
|
1493
|
+
if (segment.lane !== visibleLanes) continue;
|
|
1494
|
+
let runStart = -1;
|
|
1495
|
+
for (let col = segment.startCol; col <= segment.endCol + 1; col++) {
|
|
1496
|
+
const shown = col <= segment.endCol && extraLane[col] === true;
|
|
1497
|
+
if (shown && runStart === -1) runStart = col;
|
|
1498
|
+
if (!shown && runStart !== -1) {
|
|
1499
|
+
bars.push({
|
|
1500
|
+
...segment,
|
|
1501
|
+
startCol: runStart,
|
|
1502
|
+
endCol: col - 1,
|
|
1503
|
+
continuesBefore: segment.continuesBefore || runStart > segment.startCol,
|
|
1504
|
+
continuesAfter: segment.continuesAfter || col - 1 < segment.endCol
|
|
1505
|
+
});
|
|
1506
|
+
runStart = -1;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return bars;
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
* `eventsByDay` with a create draft added to every day it covers, where an event
|
|
1514
|
+
* appended to the calendar's events would go: last in each day, or among the
|
|
1515
|
+
* day's events in `compareDayEvents` order when `sorted`. Lay a week row out
|
|
1516
|
+
* from the result to place the draft where the created event will land.
|
|
1517
|
+
*/
|
|
1518
|
+
function withDraftEventDays(eventsByDay, draft, sorted = true) {
|
|
1519
|
+
const days = new Map(eventsByDay);
|
|
1520
|
+
for (const key of eventDayKeys(draft)) {
|
|
1521
|
+
const list = [...days.get(key) ?? [], draft];
|
|
1522
|
+
if (sorted) list.sort(compareDayEvents);
|
|
1523
|
+
days.set(key, list);
|
|
1524
|
+
}
|
|
1525
|
+
return days;
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* A week row's layout with a create draft kept in view. `withDraft` lays the row
|
|
1529
|
+
* out with the draft where the created event will land. When the row would hide
|
|
1530
|
+
* that lane, the draft moves to lane 0 instead and the row's other bars
|
|
1531
|
+
* (`withoutDraft`) move down one lane. A draft on the first hidden lane stays put
|
|
1532
|
+
* when every day it covers draws that lane in place of its label. A row the draft
|
|
1533
|
+
* misses comes back as `withDraft`.
|
|
1534
|
+
*/
|
|
1535
|
+
function keepMonthDraftVisible(withDraft, withoutDraft, draft, { visibleLanes, extraLaneFits }) {
|
|
1536
|
+
const segment = withDraft.segments.find((s) => s.event === draft);
|
|
1537
|
+
if (!segment) return withDraft;
|
|
1538
|
+
const shown = visibleLanes(withDraft.laneCount);
|
|
1539
|
+
if (segment.lane < shown) return withDraft;
|
|
1540
|
+
if (segment.lane === shown && extraLaneFits?.(shown)) {
|
|
1541
|
+
const extraLane = monthExtraLaneColumns(withDraft, shown, Math.max(...withDraft.segments.map((s) => s.endCol)) + 1);
|
|
1542
|
+
let drawn = true;
|
|
1543
|
+
for (let col = segment.startCol; col <= segment.endCol; col++) drawn &&= extraLane[col];
|
|
1544
|
+
if (drawn) return withDraft;
|
|
1545
|
+
}
|
|
1546
|
+
return {
|
|
1547
|
+
segments: [{
|
|
1548
|
+
...segment,
|
|
1549
|
+
lane: 0
|
|
1550
|
+
}, ...withoutDraft.segments.map((s) => ({
|
|
1551
|
+
...s,
|
|
1552
|
+
lane: s.lane + 1
|
|
1553
|
+
}))],
|
|
1554
|
+
laneCount: withoutDraft.laneCount + 1
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1320
1557
|
/** date-fns tokens for each {@link WeekdayFormat}. */
|
|
1321
1558
|
const WEEKDAY_TOKENS = {
|
|
1322
1559
|
narrow: "EEEEE",
|
|
@@ -1337,7 +1574,7 @@ function weekdayFormatToken(format) {
|
|
|
1337
1574
|
* data outside React; inside a component prefer {@link useMonthGrid}.
|
|
1338
1575
|
*/
|
|
1339
1576
|
function buildMonthGrid(month, options = {}) {
|
|
1340
|
-
const { weekStartsOn = 0, weekdayFormat = "short", showSixWeeks = false, isRTL = false, hiddenDays, selectedDates, selectedRange, minDate, maxDate, isDateDisabled, locale } = options;
|
|
1577
|
+
const { weekStartsOn = 0, weekdayFormat = "short", showSixWeeks = false, isRTL = false, hiddenDays, selectedDates, selectedRange, minDate, maxDate, isDateDisabled, locale, today } = options;
|
|
1341
1578
|
const rows = buildMonthWeeks(month, weekStartsOn, {
|
|
1342
1579
|
showSixWeeks,
|
|
1343
1580
|
isRTL,
|
|
@@ -1350,7 +1587,7 @@ function buildMonthGrid(month, options = {}) {
|
|
|
1350
1587
|
id: format(date, "yyyy-MM-dd"),
|
|
1351
1588
|
label: format(date, "d"),
|
|
1352
1589
|
isCurrentMonth: isSameMonth(date, month),
|
|
1353
|
-
isToday: getIsToday(date),
|
|
1590
|
+
isToday: getIsToday(date, today),
|
|
1354
1591
|
isWeekend: isWeekend(date),
|
|
1355
1592
|
...daySelectionState(date, {
|
|
1356
1593
|
selectedDates,
|
|
@@ -1388,7 +1625,7 @@ function buildMonthGrid(month, options = {}) {
|
|
|
1388
1625
|
* safe integer, or the last week falls outside the range `Date` can represent.
|
|
1389
1626
|
*/
|
|
1390
1627
|
function buildMultiWeekGrid(date, options = {}) {
|
|
1391
|
-
const { numberOfWeeks = 2, weekStartsOn = 0, weekdayFormat = "short", isRTL = false, hiddenDays, selectedDates, selectedRange, minDate, maxDate, isDateDisabled, locale } = options;
|
|
1628
|
+
const { numberOfWeeks = 2, weekStartsOn = 0, weekdayFormat = "short", isRTL = false, hiddenDays, selectedDates, selectedRange, minDate, maxDate, isDateDisabled, locale, today } = options;
|
|
1392
1629
|
if (!(date instanceof Date) || Number.isNaN(date.getTime())) throw new RangeError("buildMultiWeekGrid: date must be a valid Date.");
|
|
1393
1630
|
if (!Number.isSafeInteger(numberOfWeeks) || numberOfWeeks < 1) throw new RangeError(`buildMultiWeekGrid: numberOfWeeks must be a positive whole number, received ${String(numberOfWeeks)}.`);
|
|
1394
1631
|
const start = startOfWeek(date, { weekStartsOn });
|
|
@@ -1421,7 +1658,7 @@ function buildMultiWeekGrid(date, options = {}) {
|
|
|
1421
1658
|
date: day,
|
|
1422
1659
|
id: format(day, "yyyy-MM-dd"),
|
|
1423
1660
|
label: format(day, "d"),
|
|
1424
|
-
isToday: getIsToday(day),
|
|
1661
|
+
isToday: getIsToday(day, today),
|
|
1425
1662
|
isWeekend: isWeekend(day),
|
|
1426
1663
|
...daySelectionState(day, selection, constraints)
|
|
1427
1664
|
}))
|
|
@@ -1446,12 +1683,6 @@ function buildMultiWeekGrid(date, options = {}) {
|
|
|
1446
1683
|
};
|
|
1447
1684
|
}
|
|
1448
1685
|
// src/utils/recurrence.ts
|
|
1449
|
-
const STEP = {
|
|
1450
|
-
daily: addDays,
|
|
1451
|
-
weekly: addWeeks,
|
|
1452
|
-
monthly: addMonths,
|
|
1453
|
-
yearly: addYears
|
|
1454
|
-
};
|
|
1455
1686
|
const MAX_OCCURRENCES = 5e3;
|
|
1456
1687
|
const APPROX_STEP_MS = {
|
|
1457
1688
|
daily: 864e5,
|
|
@@ -1459,23 +1690,58 @@ const APPROX_STEP_MS = {
|
|
|
1459
1690
|
monthly: 2629746e3,
|
|
1460
1691
|
yearly: 31556952e3
|
|
1461
1692
|
};
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1693
|
+
const WEEKDAYS = /* @__PURE__ */ new Set([
|
|
1694
|
+
0,
|
|
1695
|
+
1,
|
|
1696
|
+
2,
|
|
1697
|
+
3,
|
|
1698
|
+
4,
|
|
1699
|
+
5,
|
|
1700
|
+
6
|
|
1701
|
+
]);
|
|
1702
|
+
const DEVICE_CLOCK = {
|
|
1703
|
+
fields: (instant) => [
|
|
1704
|
+
instant.getFullYear(),
|
|
1705
|
+
instant.getMonth(),
|
|
1706
|
+
instant.getDate(),
|
|
1707
|
+
instant.getHours(),
|
|
1708
|
+
instant.getMinutes(),
|
|
1709
|
+
instant.getSeconds(),
|
|
1710
|
+
instant.getMilliseconds()
|
|
1711
|
+
],
|
|
1712
|
+
at(year, month, day, hour, minute, second, ms) {
|
|
1713
|
+
const date = new Date(2e3, 0, 1);
|
|
1714
|
+
date.setFullYear(year, month, day);
|
|
1715
|
+
date.setHours(hour, minute, second, ms);
|
|
1716
|
+
return date;
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
function zoneClock(timeZone, start) {
|
|
1720
|
+
const fields = (instant) => [...zoneFields(instant, timeZone), instant.getUTCMilliseconds()];
|
|
1721
|
+
const origin = fields(start);
|
|
1722
|
+
return {
|
|
1723
|
+
fields,
|
|
1724
|
+
at(...reading) {
|
|
1725
|
+
if (reading.every((value, index) => value === origin[index])) return new Date(start);
|
|
1726
|
+
const wallClock = utcTime(...reading);
|
|
1727
|
+
if (!(Math.abs(wallClock) <= 86399999136e5)) return /* @__PURE__ */ new Date(NaN);
|
|
1728
|
+
return zonedTimeToUtc(new Date(wallClock), timeZone);
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1466
1731
|
}
|
|
1732
|
+
const weekdayOf = (year, month, day) => new Date(utcTime(year, month, day)).getUTCDay();
|
|
1733
|
+
const daysInMonth = (year, month) => new Date(utcTime(year, month + 1, 0)).getUTCDate();
|
|
1467
1734
|
function nthWeekdayOfMonth(year, month, week, weekday) {
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
}
|
|
1473
|
-
const day = 1 + (weekday - new Date(year, month, 1).getDay() + 7) % 7 + (week - 1) * 7;
|
|
1474
|
-
const date = new Date(year, month, day);
|
|
1475
|
-
return date.getMonth() === month ? date : null;
|
|
1735
|
+
const lastDay = daysInMonth(year, month);
|
|
1736
|
+
if (week === -1) return lastDay - (weekdayOf(year, month, lastDay) - weekday + 7) % 7;
|
|
1737
|
+
const day = 1 + (weekday - weekdayOf(year, month, 1) + 7) % 7 + (week - 1) * 7;
|
|
1738
|
+
return day <= lastDay ? day : null;
|
|
1476
1739
|
}
|
|
1477
|
-
function* occurrenceStarts(start, rule, earliestStart, rangeEnd) {
|
|
1740
|
+
function* occurrenceStarts(start, rule, earliestStart, rangeEnd, clock) {
|
|
1478
1741
|
const interval = Math.max(1, Math.trunc(rule.interval ?? 1));
|
|
1742
|
+
const [startYear, startMonth, startDay, hour, minute, second, ms] = clock.fields(start);
|
|
1743
|
+
const onDay = (year, month, day) => clock.at(year, month, day, hour, minute, second, ms);
|
|
1744
|
+
const dayStart = (year, month, day) => clock.at(year, month, day, 0, 0, 0, 0);
|
|
1479
1745
|
let produced = 0;
|
|
1480
1746
|
let emitted = 0;
|
|
1481
1747
|
const consider = (date) => {
|
|
@@ -1490,29 +1756,29 @@ function* occurrenceStarts(start, rule, earliestStart, rangeEnd) {
|
|
|
1490
1756
|
return "emit";
|
|
1491
1757
|
};
|
|
1492
1758
|
if (rule.freq === "weekly" && rule.weekdays?.length) {
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1759
|
+
const weekStartsOn = WEEKDAYS.has(rule.weekStartsOn) ? rule.weekStartsOn : 1;
|
|
1760
|
+
const offsets = [...new Set(rule.weekdays.map((day) => (day - weekStartsOn + 7) % 7))].sort((a, b) => a - b);
|
|
1761
|
+
let weekStart = startDay - (weekdayOf(startYear, startMonth, startDay) - weekStartsOn + 7) % 7;
|
|
1495
1762
|
while (true) {
|
|
1496
|
-
for (const
|
|
1497
|
-
const date =
|
|
1763
|
+
for (const offset of offsets) {
|
|
1764
|
+
const date = onDay(startYear, startMonth, weekStart + offset);
|
|
1498
1765
|
const verdict = consider(date);
|
|
1499
1766
|
if (verdict === "stop") return;
|
|
1500
1767
|
if (verdict === "skip") continue;
|
|
1501
1768
|
yield date;
|
|
1502
1769
|
}
|
|
1503
|
-
|
|
1504
|
-
if (!(
|
|
1505
|
-
weekStart = nextWeek;
|
|
1770
|
+
weekStart += 7 * interval;
|
|
1771
|
+
if (!(dayStart(startYear, startMonth, weekStart).getTime() <= rangeEnd.getTime())) return;
|
|
1506
1772
|
}
|
|
1507
1773
|
}
|
|
1508
1774
|
if (rule.freq === "monthly" && rule.monthDays?.length) {
|
|
1509
|
-
let year =
|
|
1510
|
-
let month =
|
|
1775
|
+
let year = startYear;
|
|
1776
|
+
let month = startMonth;
|
|
1511
1777
|
while (true) {
|
|
1512
|
-
const
|
|
1513
|
-
const days = [...new Set(rule.monthDays.map((d) => d < 0 ?
|
|
1778
|
+
const lastDay = daysInMonth(year, month);
|
|
1779
|
+
const days = [...new Set(rule.monthDays.map((d) => d < 0 ? lastDay + d + 1 : d))].filter((d) => d >= 1 && d <= lastDay).sort((a, b) => a - b);
|
|
1514
1780
|
for (const d of days) {
|
|
1515
|
-
const date =
|
|
1781
|
+
const date = onDay(year, month, d);
|
|
1516
1782
|
const verdict = consider(date);
|
|
1517
1783
|
if (verdict === "stop") return;
|
|
1518
1784
|
if (verdict === "skip") continue;
|
|
@@ -1521,18 +1787,18 @@ function* occurrenceStarts(start, rule, earliestStart, rangeEnd) {
|
|
|
1521
1787
|
month += interval;
|
|
1522
1788
|
year += Math.floor(month / 12);
|
|
1523
1789
|
month = (month % 12 + 12) % 12;
|
|
1524
|
-
if (!(
|
|
1790
|
+
if (!(dayStart(year, month, 1).getTime() <= rangeEnd.getTime())) return;
|
|
1525
1791
|
}
|
|
1526
1792
|
}
|
|
1527
1793
|
if ((rule.freq === "monthly" || rule.freq === "yearly") && rule.nthWeekday) {
|
|
1528
1794
|
const { week, weekday } = rule.nthWeekday;
|
|
1529
1795
|
const stepMonths = rule.freq === "monthly" ? interval : 12 * interval;
|
|
1530
|
-
let year =
|
|
1531
|
-
let month =
|
|
1796
|
+
let year = startYear;
|
|
1797
|
+
let month = startMonth;
|
|
1532
1798
|
while (true) {
|
|
1533
1799
|
const day = nthWeekdayOfMonth(year, month, week, weekday);
|
|
1534
|
-
if (day) {
|
|
1535
|
-
const date =
|
|
1800
|
+
if (day !== null) {
|
|
1801
|
+
const date = onDay(year, month, day);
|
|
1536
1802
|
const verdict = consider(date);
|
|
1537
1803
|
if (verdict === "stop") return;
|
|
1538
1804
|
if (verdict === "emit") yield date;
|
|
@@ -1540,28 +1806,34 @@ function* occurrenceStarts(start, rule, earliestStart, rangeEnd) {
|
|
|
1540
1806
|
month += stepMonths;
|
|
1541
1807
|
year += Math.floor(month / 12);
|
|
1542
1808
|
month = (month % 12 + 12) % 12;
|
|
1543
|
-
if (!(
|
|
1809
|
+
if (!(dayStart(year, month, 1).getTime() <= rangeEnd.getTime())) return;
|
|
1544
1810
|
}
|
|
1545
1811
|
}
|
|
1546
1812
|
if (rule.freq === "yearly" && rule.months?.length) {
|
|
1547
|
-
const day = start.getDate();
|
|
1548
1813
|
const months = [...new Set(rule.months)].filter((m) => m >= 1 && m <= 12).sort((a, b) => a - b);
|
|
1549
|
-
let year =
|
|
1814
|
+
let year = startYear;
|
|
1550
1815
|
while (true) {
|
|
1551
1816
|
for (const m of months) {
|
|
1552
1817
|
const month = m - 1;
|
|
1553
|
-
if (
|
|
1554
|
-
const date =
|
|
1818
|
+
if (startDay > daysInMonth(year, month)) continue;
|
|
1819
|
+
const date = onDay(year, month, startDay);
|
|
1555
1820
|
const verdict = consider(date);
|
|
1556
1821
|
if (verdict === "stop") return;
|
|
1557
1822
|
if (verdict === "skip") continue;
|
|
1558
1823
|
yield date;
|
|
1559
1824
|
}
|
|
1560
1825
|
year += interval;
|
|
1561
|
-
if (!(
|
|
1826
|
+
if (!(dayStart(year, 0, 1).getTime() <= rangeEnd.getTime())) return;
|
|
1562
1827
|
}
|
|
1563
1828
|
}
|
|
1564
|
-
const occAt = (n) =>
|
|
1829
|
+
const occAt = (n) => {
|
|
1830
|
+
if (n === 0) return new Date(start.getTime());
|
|
1831
|
+
const steps = n * interval;
|
|
1832
|
+
if (rule.freq === "daily") return onDay(startYear, startMonth, startDay + steps);
|
|
1833
|
+
if (rule.freq === "weekly") return onDay(startYear, startMonth, startDay + 7 * steps);
|
|
1834
|
+
const month = startMonth + (rule.freq === "monthly" ? steps : 12 * steps);
|
|
1835
|
+
return onDay(startYear, month, Math.min(startDay, daysInMonth(startYear, month)));
|
|
1836
|
+
};
|
|
1565
1837
|
const lowerBound = earliestStart.getTime();
|
|
1566
1838
|
let n = 0;
|
|
1567
1839
|
if (occAt(0).getTime() < lowerBound) {
|
|
@@ -1589,13 +1861,18 @@ function instanceAt(event, start, durationMs) {
|
|
|
1589
1861
|
delete instance.recurrence;
|
|
1590
1862
|
return instance;
|
|
1591
1863
|
}
|
|
1864
|
+
const zonedOrInvalid = (date, timeZone) => Number.isNaN(date.getTime()) ? date : toZonedTime(date, timeZone);
|
|
1865
|
+
const isMidnight = (fields) => fields[3] === 0 && fields[4] === 0 && fields[5] === 0 && fields[6] === 0;
|
|
1592
1866
|
/**
|
|
1593
1867
|
* Materialise recurring events into concrete occurrences overlapping
|
|
1594
1868
|
* `[rangeStart, rangeEnd]`. Non-recurring events pass through untouched, so the
|
|
1595
1869
|
* result is ready to hand to `<Calendar events={...} />`. Each occurrence keeps
|
|
1596
1870
|
* the original event's duration and fields (minus `recurrence`).
|
|
1871
|
+
*
|
|
1872
|
+
* Pass `timeZone` to repeat timed events on that zone's wall clock instead of
|
|
1873
|
+
* the device's. `rangeStart` and `rangeEnd` are real instants either way.
|
|
1597
1874
|
*/
|
|
1598
|
-
function expandRecurringEvents(events, rangeStart, rangeEnd) {
|
|
1875
|
+
function expandRecurringEvents(events, rangeStart, rangeEnd, { timeZone } = {}) {
|
|
1599
1876
|
const out = [];
|
|
1600
1877
|
for (const event of events) {
|
|
1601
1878
|
if (!event.recurrence) {
|
|
@@ -1603,23 +1880,47 @@ function expandRecurringEvents(events, rangeStart, rangeEnd) {
|
|
|
1603
1880
|
continue;
|
|
1604
1881
|
}
|
|
1605
1882
|
const durationMs = event.end.getTime() - event.start.getTime();
|
|
1606
|
-
const
|
|
1883
|
+
const zoned = timeZone != null && !isAllDayEvent(event) && !Number.isNaN(event.start.getTime());
|
|
1884
|
+
const clock = zoned ? zoneClock(timeZone, event.start) : DEVICE_CLOCK;
|
|
1885
|
+
const [from, to] = timeZone != null && isAllDayEvent(event) ? [zonedOrInvalid(rangeStart, timeZone), zonedOrInvalid(rangeEnd, timeZone)] : [rangeStart, rangeEnd];
|
|
1886
|
+
const starts = /* @__PURE__ */ new Map();
|
|
1887
|
+
const earliestStart = new Date(from.getTime() - durationMs);
|
|
1888
|
+
for (const start of occurrenceStarts(event.start, event.recurrence, earliestStart, to, clock)) starts.set(start.getTime(), start);
|
|
1889
|
+
for (const rdate of event.recurrence.rdates ?? []) if (rdate.getTime() <= to.getTime()) starts.set(rdate.getTime(), rdate);
|
|
1890
|
+
const dayKey = (fields) => `${fields[0]}-${fields[1]}-${fields[2]}`;
|
|
1607
1891
|
const excludedDays = /* @__PURE__ */ new Set();
|
|
1608
1892
|
const excludedInstants = /* @__PURE__ */ new Set();
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
const
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1893
|
+
const startFields = clock.fields(event.start);
|
|
1894
|
+
const rdateTimes = new Set((event.recurrence.rdates ?? []).map((rdate) => rdate.getTime()));
|
|
1895
|
+
for (const exdate of event.recurrence.exdates ?? []) {
|
|
1896
|
+
if (Number.isNaN(exdate.getTime())) continue;
|
|
1897
|
+
const onDevice = DEVICE_CLOCK.fields(exdate);
|
|
1898
|
+
if (!zoned) {
|
|
1899
|
+
if (isMidnight(onDevice)) excludedDays.add(dayKey(onDevice));
|
|
1900
|
+
else excludedInstants.add(exdate.getTime());
|
|
1901
|
+
continue;
|
|
1902
|
+
}
|
|
1903
|
+
const inZone = clock.fields(exdate);
|
|
1904
|
+
excludedInstants.add(exdate.getTime());
|
|
1905
|
+
if (rdateTimes.has(exdate.getTime())) continue;
|
|
1906
|
+
if ([
|
|
1907
|
+
3,
|
|
1908
|
+
4,
|
|
1909
|
+
5,
|
|
1910
|
+
6
|
|
1911
|
+
].every((index) => inZone[index] === startFields[index])) continue;
|
|
1912
|
+
if (isMidnight(onDevice)) excludedDays.add(dayKey(onDevice));
|
|
1913
|
+
else if (isMidnight(inZone)) excludedDays.add(dayKey(inZone));
|
|
1914
|
+
}
|
|
1615
1915
|
const ordered = [...starts.values()].sort((a, b) => a.getTime() - b.getTime());
|
|
1616
1916
|
for (const start of ordered) {
|
|
1617
|
-
if (start.getTime() + durationMs <
|
|
1618
|
-
if (
|
|
1917
|
+
if (start.getTime() + durationMs < from.getTime()) continue;
|
|
1918
|
+
if (excludedInstants.has(start.getTime())) continue;
|
|
1919
|
+
if (excludedDays.size > 0 && excludedDays.has(dayKey(clock.fields(start)))) continue;
|
|
1619
1920
|
const instance = instanceAt(event, start, durationMs);
|
|
1620
1921
|
if (Number.isFinite(instance.end.getTime())) out.push(instance);
|
|
1621
1922
|
}
|
|
1622
1923
|
}
|
|
1623
1924
|
return out;
|
|
1624
1925
|
}
|
|
1625
|
-
export {
|
|
1926
|
+
export { isBackgroundEvent as $, titleNumberOfLines as A, overlapsOtherEvents as B, eventChipLayout as C, monthEventCapacity as D, isTimeVisibleAtHeight as E, clampMoveStartMinutes as F, backgroundBandsForDay as G, resolveDraggedBounds as H, eventsOverlap as I, compareDayEvents as J, clockHoursBetween as K, monthCreateRange as L, defaultCalendarLabels as M, resolveCalendarLabels as N, monthVisibleCount as O, cellRangeFromDrag as P, isAllDayEvent as Q, monthDropBounds as R, eventAccessibilityLabel as S, lightColors as St, formatHour as T, shiftMinutes as U, pageStepDays as V, snapDeltaMinutes as W, eventDayKeys as X, drawnEnd as Y, groupEventsByDay as Z, toZonedTime as _, weekDaysCount as _t, layoutMonthWeek as a, isWithinDateRange as at, zonedTimeToUtc as b, rangeBandKind as bt, weekdayFormatToken as c, filterHiddenDays as ct, parseICalendar as d, getWeekDays as dt, layoutDayEvents as et, toICalendar as f, getYearMonths as ft, nowInTimeZone as g, viewDayCount as gt, fromZonedTime as h, minutesIntoDay as ht, keepMonthDraftVisible as i, isRangeEndpoint as it, dayAccessibilityLabel as j, titleEllipsizeMode as k, withDraftEventDays as l, getIsToday as lt, fromZonedRange as m, isWeekend as mt, buildMultiWeekGrid as n, daySelectionState as nt, monthExtraLaneColumns as o, nextDateRange as ot, eventsInTimeZone as p, isSameCalendarDay as pt, closedHourBands as q, buildMonthGrid as r, isDateSelectable as rt, monthVisibleBars as s, buildMonthWeeks as st, expandRecurringEvents as t, wallClockHours as tt, loadEventSource as u, getViewDays as ut, zonedDragBounds as v, bandRounding as vt, eventTimeLabel as w, MIN_BOX_HEIGHT_FOR_TIME as x, darkColors as xt, zonedEventSource as y, dayBadgeKind as yt, movedClockSpan as z };
|