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
|
name: Library/sstent/icalendar
|
||||||
version: "0.3.27"
|
version: "0.3.28"
|
||||||
tags: meta/library
|
tags: meta/library
|
||||||
files:
|
files:
|
||||||
- icalendar.plug.js
|
- icalendar.plug.js
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "icalendar-plug",
|
"name": "icalendar-plug",
|
||||||
"version": "0.3.27",
|
"version": "0.3.28",
|
||||||
"nodeModulesDir": "auto",
|
"nodeModulesDir": "auto",
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"sync-version": "deno run -A scripts/sync-version.ts",
|
"sync-version": "deno run -A scripts/sync-version.ts",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: icalendar
|
name: icalendar
|
||||||
version: 0.3.27
|
version: 0.3.28
|
||||||
author: sstent
|
author: sstent
|
||||||
index: icalendar.ts
|
index: icalendar.ts
|
||||||
# Legacy SilverBullet permission name
|
# 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 { RRule, RRuleSet } from "rrule";
|
||||||
import { getUtcOffsetMs, resolveIanaName } from "./timezones.ts";
|
import { getUtcOffsetMs, resolveIanaName } from "./timezones.ts";
|
||||||
|
|
||||||
const VERSION = "0.3.27";
|
const VERSION = "0.3.28";
|
||||||
const CACHE_KEY = "icalendar:lastSync";
|
const CACHE_KEY = "icalendar:lastSync";
|
||||||
|
|
||||||
console.log(`[iCalendar] Plug script executing at top level (Version ${VERSION})`);
|
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();
|
const now = new Date();
|
||||||
// Start the window 7 days ago to catch recent past events
|
// Start our visible window 7 days ago to catch recent past events
|
||||||
const windowStart = new Date(now.getTime() - 7 * 86400000);
|
const filterStart = new Date(now.getTime() - 7 * 86400000);
|
||||||
const windowEnd = new Date(now.getTime() + windowDays * 86400000);
|
const windowEnd = new Date(now.getTime() + windowDays * 86400000);
|
||||||
|
|
||||||
// Expand from the start of our window
|
// Expand from the event's actual start date to ensure all recurrences are calculated correctly
|
||||||
const occurrences = set.between(windowStart, windowEnd, true);
|
// 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
|
||||||
|
.filter(occurrenceDate => occurrenceDate >= filterStart)
|
||||||
return occurrences.map(occurrenceDate => {
|
.map(occurrenceDate => {
|
||||||
const localIso = localDateString(occurrenceDate);
|
const localIso = localDateString(occurrenceDate);
|
||||||
return {
|
return {
|
||||||
...icsEvent,
|
...icsEvent,
|
||||||
start: localIso,
|
start: localIso,
|
||||||
recurrent: true,
|
recurrent: true,
|
||||||
rrule: undefined,
|
rrule: undefined,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[iCalendar] Error expanding recurrence for ${icsEvent.summary}:`, err);
|
console.error(`[iCalendar] Error expanding recurrence for ${icsEvent.summary}:`, err);
|
||||||
return [icsEvent];
|
return [icsEvent];
|
||||||
|
|||||||
Reference in New Issue
Block a user