forked from GitHubMirrors/silverbullet-icalendar
Fix: Expand recurrences from event start but filter to last 7 days and iterate to 0.3.28
All checks were successful
Build SilverBullet Plug / build (push) Successful in 44s
All checks were successful
Build SilverBullet Plug / build (push) Successful in 44s
This commit is contained in:
2
PLUG.md
2
PLUG.md
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: Library/sstent/icalendar
|
||||
version: "0.3.27"
|
||||
version: "0.3.28"
|
||||
tags: meta/library
|
||||
files:
|
||||
- icalendar.plug.js
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "icalendar-plug",
|
||||
"version": "0.3.27",
|
||||
"version": "0.3.28",
|
||||
"nodeModulesDir": "auto",
|
||||
"tasks": {
|
||||
"sync-version": "deno run -A scripts/sync-version.ts",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: icalendar
|
||||
version: 0.3.27
|
||||
version: 0.3.28
|
||||
author: sstent
|
||||
index: icalendar.ts
|
||||
# Legacy SilverBullet permission name
|
||||
|
||||
33
icalendar.ts
33
icalendar.ts
@@ -3,7 +3,7 @@ import { convertIcsCalendar } from "https://esm.sh/ts-ics@2.4.0";
|
||||
import { RRule, RRuleSet } from "rrule";
|
||||
import { getUtcOffsetMs, resolveIanaName } from "./timezones.ts";
|
||||
|
||||
const VERSION = "0.3.27";
|
||||
const VERSION = "0.3.28";
|
||||
const CACHE_KEY = "icalendar:lastSync";
|
||||
|
||||
console.log(`[iCalendar] Plug script executing at top level (Version ${VERSION})`);
|
||||
@@ -176,24 +176,25 @@ export function expandRecurrences(icsEvent: any, windowDays = 365): any[] {
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
// Start the window 7 days ago to catch recent past events
|
||||
const windowStart = new Date(now.getTime() - 7 * 86400000);
|
||||
// Start our visible window 7 days ago to catch recent past events
|
||||
const filterStart = new Date(now.getTime() - 7 * 86400000);
|
||||
const windowEnd = new Date(now.getTime() + windowDays * 86400000);
|
||||
|
||||
// Expand from the start of our window
|
||||
const occurrences = set.between(windowStart, windowEnd, true);
|
||||
// Expand from the event's actual start date to ensure all recurrences are calculated correctly
|
||||
// but only take occurrences between (now - 7 days) and (now + windowDays)
|
||||
const occurrences = set.between(dtstart, windowEnd, true);
|
||||
|
||||
if (occurrences.length === 0) return [icsEvent];
|
||||
|
||||
return occurrences.map(occurrenceDate => {
|
||||
const localIso = localDateString(occurrenceDate);
|
||||
return {
|
||||
...icsEvent,
|
||||
start: localIso,
|
||||
recurrent: true,
|
||||
rrule: undefined,
|
||||
};
|
||||
});
|
||||
return occurrences
|
||||
.filter(occurrenceDate => occurrenceDate >= filterStart)
|
||||
.map(occurrenceDate => {
|
||||
const localIso = localDateString(occurrenceDate);
|
||||
return {
|
||||
...icsEvent,
|
||||
start: localIso,
|
||||
recurrent: true,
|
||||
rrule: undefined,
|
||||
};
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`[iCalendar] Error expanding recurrence for ${icsEvent.summary}:`, err);
|
||||
return [icsEvent];
|
||||
|
||||
Reference in New Issue
Block a user