@jsb188/schedule 1.1.2

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.
Files changed (60) hide show
  1. package/package.json +62 -0
  2. package/src/constants/schedule.ts +549 -0
  3. package/src/css.d.ts +7 -0
  4. package/src/libs/gantt-geometry.ts +771 -0
  5. package/src/libs/gantt-histogram.ts +124 -0
  6. package/src/libs/gantt-keyboard.ts +113 -0
  7. package/src/libs/gantt-state.ts +57 -0
  8. package/src/libs/gantt-url.ts +63 -0
  9. package/src/modules/Gantt.helpers.ts +119 -0
  10. package/src/modules/Gantt.tsx +584 -0
  11. package/src/types/schedule.d.ts +1149 -0
  12. package/src/ui/ActivityFormUI.tsx +133 -0
  13. package/src/ui/GanttEditorsUI.tsx +102 -0
  14. package/src/ui/GanttHistogramUI.tsx +236 -0
  15. package/src/ui/GanttUI.tsx +792 -0
  16. package/src/ui/ProjectFormUI.tsx +250 -0
  17. package/src/ui/ProjectMobileListUI.tsx +80 -0
  18. package/src/ui/ProjectToolbarUI.tsx +54 -0
  19. package/src/ui/RelationshipListUI.tsx +176 -0
  20. package/src/ui/ScheduleRunUI.tsx +173 -0
  21. package/src/ui/ScheduleSettingsUI.tsx +420 -0
  22. package/src/utils/coverage.helpers.ts +679 -0
  23. package/src/utils/coverage.ts +630 -0
  24. package/src/utils/cpm.helpers.ts +674 -0
  25. package/src/utils/cpm.ts +907 -0
  26. package/src/utils/cpmLeveling.helpers.ts +564 -0
  27. package/src/utils/cpmLeveling.ts +367 -0
  28. package/src/utils/defaults.ts +8 -0
  29. package/src/utils/eligibility.ts +457 -0
  30. package/src/utils/planCsv.ts +344 -0
  31. package/src/utils/predecessorText.ts +96 -0
  32. package/src/utils/recurrence.ts +616 -0
  33. package/src/utils/request.ts +153 -0
  34. package/src/utils/resource.ts +182 -0
  35. package/src/utils/rule.ts +216 -0
  36. package/src/utils/run.ts +43 -0
  37. package/src/utils/series.ts +161 -0
  38. package/src/utils/slot.ts +208 -0
  39. package/src/utils/workTime.ts +1382 -0
  40. package/tests/coverage.fixtures.ts +111 -0
  41. package/tests/coverage.test.ts +503 -0
  42. package/tests/cpm.bench.test.ts +154 -0
  43. package/tests/cpm.test.ts +354 -0
  44. package/tests/cpmCorrectness.test.ts +327 -0
  45. package/tests/cpmLeveling.test.ts +471 -0
  46. package/tests/eligibility.test.ts +320 -0
  47. package/tests/gantt-geometry.test.ts +367 -0
  48. package/tests/gantt-histogram.test.ts +78 -0
  49. package/tests/gantt-keyboard.test.ts +69 -0
  50. package/tests/helpers/cpmFixtures.ts +101 -0
  51. package/tests/projectInputs.test.ts +165 -0
  52. package/tests/recurrence.test.ts +68 -0
  53. package/tests/request.test.ts +99 -0
  54. package/tests/resource.test.ts +95 -0
  55. package/tests/rule.test.ts +98 -0
  56. package/tests/series.test.ts +120 -0
  57. package/tests/workTime.test.ts +1007 -0
  58. package/tests/workTimeContracts.test.ts +111 -0
  59. package/tsconfig.json +13 -0
  60. package/vitest.config.ts +8 -0
@@ -0,0 +1,616 @@
1
+ import {
2
+ DEFAULT_TIMEZONE,
3
+ isValidTimeZone,
4
+ } from '@jsb188/app/utils/timeZone.ts';
5
+ import { DateTime } from 'luxon';
6
+ import {
7
+ SCHEDULE_MATERIALIZATION_HORIZON_DAYS,
8
+ SCHEDULE_OCCURRENCE_MAX_DURATION_MINUTES,
9
+ SCHEDULE_RECURRENCE_FREQ_ENUMS,
10
+ SCHEDULE_RECURRENCE_LAST_DAY_OF_MONTH,
11
+ SCHEDULE_RECURRENCE_MAX_INTERVAL,
12
+ SCHEDULE_RECURRENCE_MAX_ITERATIONS,
13
+ } from '../constants/schedule.ts';
14
+ import type {
15
+ ScheduleExpandedInstance,
16
+ ScheduleRecurrenceObj,
17
+ } from '../types/schedule.d.ts';
18
+
19
+ /**
20
+ * Recurrence expansion for calendar series, shared by the server
21
+ * materialization job and any client-side preview of a recurring series.
22
+ *
23
+ * Expansion walks LOCAL calendar dates in the series timezone and stamps the
24
+ * anchor's wall-clock time onto each one, so a 7:00am shift stays 7:00am
25
+ * across a daylight-saving transition instead of drifting to 6:00 or 8:00.
26
+ */
27
+
28
+ // Longest each month can ever be; February counts a leap day so a "February
29
+ // 29th" yearly rule stays valid
30
+ const MAX_DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
31
+
32
+ interface ScheduleAnchorTime {
33
+ hour: number;
34
+ minute: number;
35
+ second: number;
36
+ millisecond: number;
37
+ }
38
+
39
+ interface ScheduleExpandOptions {
40
+ // Only instances starting at or after this instant are returned
41
+ from?: Date | null;
42
+ // Only instances starting strictly before this instant are returned
43
+ to?: Date | null;
44
+ // Largest number of instances to return
45
+ limit?: number | null;
46
+ }
47
+
48
+ /**
49
+ * The series facts expansion needs. Accepting this shape rather than a full
50
+ * row lets a client preview an unsaved series.
51
+ */
52
+ export interface ScheduleExpandableSeries {
53
+ recurrence: ScheduleRecurrenceObj;
54
+ timeZone: string;
55
+ startsAt: Date | string;
56
+ endsAt?: Date | string | null;
57
+ durationMinutes: number;
58
+ allDay?: boolean | null;
59
+ }
60
+
61
+ /*
62
+ * Coerce one value into a Date, returning null when it cannot be read as one.
63
+ */
64
+
65
+ function toDateOrNull(value?: Date | string | number | null): Date | null {
66
+ if (value === null || value === undefined) {
67
+ return null;
68
+ }
69
+
70
+ const date = value instanceof Date ? value : new Date(value);
71
+
72
+ return Number.isNaN(date.getTime()) ? null : date;
73
+ }
74
+
75
+ /*
76
+ * Return a de-duplicated, ascending list of the integers in one input array,
77
+ * keeping only values that pass the caller's range test.
78
+ */
79
+
80
+ function getNormalizedIntegerList(
81
+ values: unknown,
82
+ isInRange: (value: number) => boolean,
83
+ ): number[] | null {
84
+ if (!Array.isArray(values) || !values.length) {
85
+ return null;
86
+ }
87
+
88
+ const normalized = new Set<number>();
89
+
90
+ for (const value of values) {
91
+ const int = Number(value);
92
+ if (!Number.isInteger(int) || !isInRange(int)) {
93
+ return null;
94
+ }
95
+
96
+ normalized.add(int);
97
+ }
98
+
99
+ return Array.from(normalized).sort((a, b) => a - b);
100
+ }
101
+
102
+ /*
103
+ * Order month days so expansion emits them chronologically; the "last day of
104
+ * the month" sentinel always sorts last.
105
+ */
106
+
107
+ function getSortedMonthDays(monthDays: number[]): number[] {
108
+ return [...monthDays].sort(
109
+ (a, b) =>
110
+ (a === SCHEDULE_RECURRENCE_LAST_DAY_OF_MONTH ? 32 : a) -
111
+ (b === SCHEDULE_RECURRENCE_LAST_DAY_OF_MONTH ? 32 : b),
112
+ );
113
+ }
114
+
115
+ /*
116
+ * Order a plain list of calendar units ascending. Every generator below must
117
+ * emit chronologically because the expander stops at the first instance past
118
+ * its bound; an unordered list would silently drop earlier units.
119
+ */
120
+
121
+ function getSortedRecurrenceUnits(units: number[]): number[] {
122
+ return [...units].sort((a, b) => a - b);
123
+ }
124
+
125
+ /**
126
+ * Validate and normalize one recurrence input into the shape stored in
127
+ * schedule_series."recurrence". Returns the normalized rule or a human
128
+ * readable error; never throws.
129
+ */
130
+
131
+ export function validateScheduleRecurrence(input: unknown): {
132
+ recurrence?: ScheduleRecurrenceObj;
133
+ error?: string;
134
+ } {
135
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
136
+ return { error: 'Recurrence must be an object.' };
137
+ }
138
+
139
+ const raw = input as Record<string, unknown>;
140
+ const freq = String(raw.freq || '');
141
+
142
+ if (
143
+ !SCHEDULE_RECURRENCE_FREQ_ENUMS.includes(
144
+ freq as ScheduleRecurrenceObj['freq'],
145
+ )
146
+ ) {
147
+ return {
148
+ error: `Recurrence frequency must be one of: ${SCHEDULE_RECURRENCE_FREQ_ENUMS.join(', ')}.`,
149
+ };
150
+ }
151
+
152
+ const interval =
153
+ raw.interval === undefined || raw.interval === null
154
+ ? 1
155
+ : Number(raw.interval);
156
+ if (
157
+ !Number.isInteger(interval) ||
158
+ interval < 1 ||
159
+ interval > SCHEDULE_RECURRENCE_MAX_INTERVAL
160
+ ) {
161
+ return {
162
+ error: `Recurrence interval must be a whole number between 1 and ${SCHEDULE_RECURRENCE_MAX_INTERVAL}.`,
163
+ };
164
+ }
165
+
166
+ const recurrence: ScheduleRecurrenceObj = {
167
+ freq: freq as ScheduleRecurrenceObj['freq'],
168
+ interval,
169
+ };
170
+
171
+ if (raw.byWeekday !== undefined && raw.byWeekday !== null) {
172
+ const byWeekday = getNormalizedIntegerList(
173
+ raw.byWeekday,
174
+ (value) => value >= 0 && value <= 6,
175
+ );
176
+ if (!byWeekday) {
177
+ return {
178
+ error:
179
+ 'Recurrence weekdays must be whole numbers from 0 (Sunday) to 6 (Saturday).',
180
+ };
181
+ }
182
+
183
+ recurrence.byWeekday = byWeekday;
184
+ }
185
+
186
+ if (raw.byMonthDay !== undefined && raw.byMonthDay !== null) {
187
+ const byMonthDay = getNormalizedIntegerList(
188
+ raw.byMonthDay,
189
+ (value) =>
190
+ (value >= 1 && value <= 31) ||
191
+ value === SCHEDULE_RECURRENCE_LAST_DAY_OF_MONTH,
192
+ );
193
+ if (!byMonthDay) {
194
+ return {
195
+ error:
196
+ 'Recurrence month days must be whole numbers from 1 to 31, or -1 for the last day of the month.',
197
+ };
198
+ }
199
+
200
+ recurrence.byMonthDay = byMonthDay;
201
+ }
202
+
203
+ if (raw.byMonth !== undefined && raw.byMonth !== null) {
204
+ const byMonth = getNormalizedIntegerList(
205
+ raw.byMonth,
206
+ (value) => value >= 1 && value <= 12,
207
+ );
208
+ if (!byMonth) {
209
+ return {
210
+ error:
211
+ 'Recurrence months must be whole numbers from 1 (January) to 12 (December).',
212
+ };
213
+ }
214
+
215
+ recurrence.byMonth = byMonth;
216
+ }
217
+
218
+ if (raw.count !== undefined && raw.count !== null) {
219
+ const count = Number(raw.count);
220
+ if (!Number.isInteger(count) || count < 1) {
221
+ return { error: 'Recurrence count must be a whole number of 1 or more.' };
222
+ }
223
+
224
+ recurrence.count = count;
225
+ }
226
+
227
+ if (raw.until !== undefined && raw.until !== null) {
228
+ const until = toDateOrNull(raw.until as string);
229
+ if (!until) {
230
+ return { error: 'Recurrence end date is not a valid date.' };
231
+ }
232
+
233
+ recurrence.until = until.toISOString();
234
+ }
235
+
236
+ // Narrowing only means something for the frequency that iterates over
237
+ // that unit; silently keeping it would make two different-looking rules
238
+ // behave identically
239
+ if (recurrence.byWeekday && recurrence.freq !== 'WEEKLY') {
240
+ return {
241
+ error: 'Recurrence weekdays can only be used with a weekly frequency.',
242
+ };
243
+ }
244
+
245
+ if (
246
+ recurrence.byMonthDay &&
247
+ recurrence.freq !== 'MONTHLY' &&
248
+ recurrence.freq !== 'YEARLY'
249
+ ) {
250
+ return {
251
+ error:
252
+ 'Recurrence month days can only be used with a monthly or yearly frequency.',
253
+ };
254
+ }
255
+
256
+ if (recurrence.byMonth && recurrence.freq !== 'YEARLY') {
257
+ return {
258
+ error: 'Recurrence months can only be used with a yearly frequency.',
259
+ };
260
+ }
261
+
262
+ // A yearly rule can name a day its months never reach ("February 30th");
263
+ // it would produce a series that silently never fires
264
+ if (
265
+ recurrence.freq === 'YEARLY' &&
266
+ recurrence.byMonth?.length &&
267
+ recurrence.byMonthDay?.length
268
+ ) {
269
+ const longestListedMonth = Math.max(
270
+ ...recurrence.byMonth.map((month) => MAX_DAYS_IN_MONTH[month - 1] || 0),
271
+ );
272
+ const reachesAnyDay = recurrence.byMonthDay.some(
273
+ (monthDay) =>
274
+ monthDay === SCHEDULE_RECURRENCE_LAST_DAY_OF_MONTH ||
275
+ monthDay <= longestListedMonth,
276
+ );
277
+
278
+ if (!reachesAnyDay) {
279
+ return {
280
+ error:
281
+ 'Recurrence never occurs: none of the selected months contain any of the selected days.',
282
+ };
283
+ }
284
+ }
285
+
286
+ return { recurrence };
287
+ }
288
+
289
+ /*
290
+ * Return the series timezone, falling back to the platform default when the
291
+ * stored value is missing or is not a zone this runtime knows.
292
+ */
293
+
294
+ function getSeriesTimeZone(timeZone?: string | null): string {
295
+ return timeZone && isValidTimeZone(timeZone) ? timeZone : DEFAULT_TIMEZONE;
296
+ }
297
+
298
+ /*
299
+ * Read the local wall-clock time one series repeats at.
300
+ */
301
+
302
+ function getAnchorTime(anchor: DateTime): ScheduleAnchorTime {
303
+ return {
304
+ hour: anchor.hour,
305
+ minute: anchor.minute,
306
+ second: anchor.second,
307
+ millisecond: anchor.millisecond,
308
+ };
309
+ }
310
+
311
+ /*
312
+ * Stamp the series wall-clock time onto one local calendar date. A local time
313
+ * inside a spring-forward gap is moved forward past the gap by luxon rather
314
+ * than dropped.
315
+ */
316
+
317
+ function getInstanceStart(
318
+ localDate: DateTime,
319
+ anchorTime: ScheduleAnchorTime,
320
+ ): DateTime | null {
321
+ const start = localDate.set(anchorTime);
322
+
323
+ return start.isValid ? start : null;
324
+ }
325
+
326
+ /*
327
+ * Generate candidate local dates for a DAILY rule. Every generator bounds its
328
+ * OWN step count so a rule that yields nothing cannot spin forever.
329
+ */
330
+
331
+ function* iterateDailyDates(
332
+ anchorDate: DateTime,
333
+ interval: number,
334
+ ): Generator<DateTime> {
335
+ for (let step = 0; step < SCHEDULE_RECURRENCE_MAX_ITERATIONS; step++) {
336
+ yield anchorDate.plus({ days: step * interval });
337
+ }
338
+ }
339
+
340
+ /*
341
+ * Generate candidate local dates for a WEEKLY rule.
342
+ */
343
+
344
+ function* iterateWeeklyDates(
345
+ anchorDate: DateTime,
346
+ interval: number,
347
+ byWeekday?: number[] | null,
348
+ ): Generator<DateTime> {
349
+ // Luxon weekdays run 1 (Monday) to 7 (Sunday); the stored rule uses the
350
+ // JavaScript convention of 0 (Sunday) to 6 (Saturday)
351
+ const anchorWeekday = anchorDate.weekday % 7;
352
+ const weekdays = byWeekday?.length
353
+ ? getSortedRecurrenceUnits(byWeekday)
354
+ : [anchorWeekday];
355
+ const firstWeekStart = anchorDate.minus({ days: anchorWeekday });
356
+
357
+ for (let step = 0; step < SCHEDULE_RECURRENCE_MAX_ITERATIONS; step++) {
358
+ const weekStart = firstWeekStart.plus({ weeks: step * interval });
359
+
360
+ for (const weekday of weekdays) {
361
+ yield weekStart.plus({ days: weekday });
362
+ }
363
+ }
364
+ }
365
+
366
+ /*
367
+ * Yield the requested month days that actually exist inside one month, in
368
+ * ascending order and at most once each.
369
+ */
370
+
371
+ function* iterateMonthDaysWithin(
372
+ monthStart: DateTime,
373
+ monthDays: number[],
374
+ ): Generator<DateTime> {
375
+ const daysInMonth = monthStart.daysInMonth || 0;
376
+ const emitted = new Set<number>();
377
+
378
+ for (const monthDay of monthDays) {
379
+ const day =
380
+ monthDay === SCHEDULE_RECURRENCE_LAST_DAY_OF_MONTH
381
+ ? daysInMonth
382
+ : monthDay;
383
+
384
+ if (day && day <= daysInMonth && !emitted.has(day)) {
385
+ emitted.add(day);
386
+ yield monthStart.set({ day });
387
+ }
388
+ }
389
+ }
390
+
391
+ /*
392
+ * Generate candidate local dates for a MONTHLY rule.
393
+ */
394
+
395
+ function* iterateMonthlyDates(
396
+ anchorDate: DateTime,
397
+ interval: number,
398
+ byMonthDay?: number[] | null,
399
+ ): Generator<DateTime> {
400
+ const monthDays = getSortedMonthDays(
401
+ byMonthDay?.length ? byMonthDay : [anchorDate.day],
402
+ );
403
+ const firstMonthStart = anchorDate.startOf('month');
404
+
405
+ for (let step = 0; step < SCHEDULE_RECURRENCE_MAX_ITERATIONS; step++) {
406
+ yield* iterateMonthDaysWithin(
407
+ firstMonthStart.plus({ months: step * interval }),
408
+ monthDays,
409
+ );
410
+ }
411
+ }
412
+
413
+ /*
414
+ * Generate candidate local dates for a YEARLY rule.
415
+ */
416
+
417
+ function* iterateYearlyDates(
418
+ anchorDate: DateTime,
419
+ interval: number,
420
+ byMonth?: number[] | null,
421
+ byMonthDay?: number[] | null,
422
+ ): Generator<DateTime> {
423
+ const months = byMonth?.length
424
+ ? getSortedRecurrenceUnits(byMonth)
425
+ : [anchorDate.month];
426
+ const monthDays = getSortedMonthDays(
427
+ byMonthDay?.length ? byMonthDay : [anchorDate.day],
428
+ );
429
+ const firstYearStart = anchorDate.startOf('year');
430
+
431
+ for (let step = 0; step < SCHEDULE_RECURRENCE_MAX_ITERATIONS; step++) {
432
+ const yearStart = firstYearStart.plus({ years: step * interval });
433
+
434
+ for (const month of months) {
435
+ yield* iterateMonthDaysWithin(yearStart.set({ month }), monthDays);
436
+ }
437
+ }
438
+ }
439
+
440
+ /*
441
+ * Pick the candidate-date generator for one recurrence frequency.
442
+ */
443
+
444
+ function getRecurrenceDateIterator(
445
+ recurrence: ScheduleRecurrenceObj,
446
+ anchorDate: DateTime,
447
+ ): Generator<DateTime> {
448
+ const interval =
449
+ recurrence.interval && recurrence.interval > 0 ? recurrence.interval : 1;
450
+
451
+ switch (recurrence.freq) {
452
+ case 'DAILY':
453
+ return iterateDailyDates(anchorDate, interval);
454
+ case 'WEEKLY':
455
+ return iterateWeeklyDates(anchorDate, interval, recurrence.byWeekday);
456
+ case 'MONTHLY':
457
+ return iterateMonthlyDates(anchorDate, interval, recurrence.byMonthDay);
458
+ case 'YEARLY':
459
+ return iterateYearlyDates(
460
+ anchorDate,
461
+ interval,
462
+ recurrence.byMonth,
463
+ recurrence.byMonthDay,
464
+ );
465
+ }
466
+ }
467
+
468
+ /**
469
+ * Compute one occurrence's end instant. All-day entries advance by local
470
+ * calendar days so a day stays a day across a daylight-saving transition;
471
+ * timed entries advance by absolute minutes.
472
+ */
473
+
474
+ export function getScheduleOccurrenceEndAt(
475
+ startAt: Date,
476
+ durationMinutes: number,
477
+ timeZone: string,
478
+ allDay?: boolean | null,
479
+ ): Date {
480
+ if (!allDay) {
481
+ return new Date(startAt.getTime() + durationMinutes * 60_000);
482
+ }
483
+
484
+ const days = Math.max(1, Math.round(durationMinutes / 1440));
485
+
486
+ return DateTime.fromJSDate(startAt)
487
+ .setZone(getSeriesTimeZone(timeZone))
488
+ .plus({ days })
489
+ .toJSDate();
490
+ }
491
+
492
+ /**
493
+ * Expand one recurring series into concrete instances, in chronological order
494
+ * from the series start so "count" stays meaningful even when only a later
495
+ * window is requested.
496
+ */
497
+
498
+ export function expandScheduleSeriesInstances(
499
+ series: ScheduleExpandableSeries,
500
+ options: ScheduleExpandOptions = {},
501
+ ): ScheduleExpandedInstance[] {
502
+ const startsAt = toDateOrNull(series.startsAt);
503
+ if (!startsAt) {
504
+ return [];
505
+ }
506
+
507
+ const zone = getSeriesTimeZone(series.timeZone);
508
+ const anchor = DateTime.fromJSDate(startsAt).setZone(zone);
509
+ if (!anchor.isValid) {
510
+ return [];
511
+ }
512
+
513
+ const anchorTime = getAnchorTime(anchor);
514
+ const anchorDate = anchor.startOf('day');
515
+ const from = toDateOrNull(options.from);
516
+ const to = toDateOrNull(options.to);
517
+ const limit =
518
+ options.limit && options.limit > 0
519
+ ? options.limit
520
+ : Number.POSITIVE_INFINITY;
521
+ const until = toDateOrNull(series.recurrence?.until);
522
+ const seriesEndsAt = toDateOrNull(series.endsAt);
523
+ const maxCount =
524
+ series.recurrence?.count && series.recurrence.count > 0
525
+ ? series.recurrence.count
526
+ : Number.POSITIVE_INFINITY;
527
+
528
+ const instances: ScheduleExpandedInstance[] = [];
529
+ let emittedFromSeriesStart = 0;
530
+ const emittedDates = new Set<string>();
531
+
532
+ for (const localDate of getRecurrenceDateIterator(
533
+ series.recurrence,
534
+ anchorDate,
535
+ )) {
536
+ const start = getInstanceStart(localDate, anchorTime);
537
+ if (!start) {
538
+ continue;
539
+ }
540
+
541
+ const startAt = start.toJSDate();
542
+
543
+ // Weekly and monthly iteration can emit dates inside the anchor's own
544
+ // week or month that fall before the series began
545
+ if (startAt < startsAt) {
546
+ continue;
547
+ }
548
+
549
+ if (until && startAt > until) {
550
+ break;
551
+ }
552
+
553
+ if (seriesEndsAt && startAt > seriesEndsAt) {
554
+ break;
555
+ }
556
+
557
+ if (to && startAt >= to) {
558
+ break;
559
+ }
560
+
561
+ emittedFromSeriesStart++;
562
+ if (emittedFromSeriesStart > maxCount) {
563
+ break;
564
+ }
565
+
566
+ if (from && startAt < from) {
567
+ continue;
568
+ }
569
+
570
+ const recurrenceDate = localDate.toFormat('yyyy-LL-dd');
571
+ if (emittedDates.has(recurrenceDate)) continue;
572
+ emittedDates.add(recurrenceDate);
573
+ instances.push({
574
+ recurrenceDate,
575
+ startAt,
576
+ endAt: getScheduleOccurrenceEndAt(
577
+ startAt,
578
+ series.durationMinutes,
579
+ zone,
580
+ series.allDay,
581
+ ),
582
+ });
583
+
584
+ if (instances.length >= limit) {
585
+ break;
586
+ }
587
+ }
588
+
589
+ return instances;
590
+ }
591
+
592
+ /**
593
+ * Return the instant the materialization horizon should reach from "now".
594
+ */
595
+
596
+ export function getScheduleMaterializationHorizon(now: Date): Date {
597
+ return new Date(
598
+ now.getTime() + SCHEDULE_MATERIALIZATION_HORIZON_DAYS * 86_400_000,
599
+ );
600
+ }
601
+
602
+ /**
603
+ * Check whether one duration is within the range an occurrence may span.
604
+ */
605
+
606
+ export function isValidScheduleDurationMinutes(
607
+ durationMinutes: unknown,
608
+ ): boolean {
609
+ const minutes = Number(durationMinutes);
610
+
611
+ return (
612
+ Number.isInteger(minutes) &&
613
+ minutes > 0 &&
614
+ minutes <= SCHEDULE_OCCURRENCE_MAX_DURATION_MINUTES
615
+ );
616
+ }