@forcecalendar/core 2.1.45 → 2.1.46
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.
|
@@ -319,9 +319,41 @@ export class RecurrenceEngineV2 {
|
|
|
319
319
|
next.setMonth(next.getMonth() + rule.interval);
|
|
320
320
|
this.setToNthWeekdayOfMonth(next, weekday, nthOccurrence);
|
|
321
321
|
} else if (rule.bySetPos && rule.bySetPos.length > 0) {
|
|
322
|
-
// BYSETPOS
|
|
322
|
+
// BYSETPOS selects from the set of candidates generated by other BY* rules
|
|
323
323
|
next.setMonth(next.getMonth() + rule.interval);
|
|
324
|
-
|
|
324
|
+
next.setDate(1);
|
|
325
|
+
|
|
326
|
+
const dayMap = { SU: 0, MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6 };
|
|
327
|
+
const candidates = [];
|
|
328
|
+
|
|
329
|
+
if (rule.byDay && rule.byDay.length > 0) {
|
|
330
|
+
// Generate all matching weekday occurrences in the month
|
|
331
|
+
const lastDay = new Date(next.getFullYear(), next.getMonth() + 1, 0).getDate();
|
|
332
|
+
for (let d = 1; d <= lastDay; d++) {
|
|
333
|
+
const date = new Date(next.getFullYear(), next.getMonth(), d);
|
|
334
|
+
const dayOfWeek = date.getDay();
|
|
335
|
+
for (const byDay of rule.byDay) {
|
|
336
|
+
const dayStr = typeof byDay === 'string' ? byDay.replace(/^-?\d+/, '') : byDay.weekday;
|
|
337
|
+
if (dayMap[dayStr] === dayOfWeek) {
|
|
338
|
+
candidates.push(d);
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Apply BYSETPOS indices (1-based, negative from end)
|
|
346
|
+
const selectedDays = [];
|
|
347
|
+
for (const pos of rule.bySetPos) {
|
|
348
|
+
const index = pos > 0 ? pos - 1 : candidates.length + pos;
|
|
349
|
+
if (index >= 0 && index < candidates.length) {
|
|
350
|
+
selectedDays.push(candidates[index]);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (selectedDays.length > 0) {
|
|
355
|
+
next.setDate(selectedDays[0]);
|
|
356
|
+
}
|
|
325
357
|
} else {
|
|
326
358
|
// Same day of next month
|
|
327
359
|
const currentDay = next.getDate();
|