forked from GitHubMirrors/silverbullet-icalendar
Fix: Add 7-day lookback window for recurring events expansion and iterate to 0.3.26
This commit is contained in:
13
icalendar.ts
13
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.25";
|
||||
const VERSION = "0.3.26";
|
||||
const CACHE_KEY = "icalendar:lastSync";
|
||||
|
||||
console.log(`[iCalendar] Plug script executing at top level (Version ${VERSION})`);
|
||||
@@ -23,7 +23,7 @@ async function sha256Hash(str: string): Promise<string> {
|
||||
return hashArray.map(b => b.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
|
||||
function localDateString(date: Date): string {
|
||||
export function localDateString(date: Date): string {
|
||||
const pad = (n: number) => String(n).padStart(2, "0");
|
||||
return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + "T" + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds());
|
||||
}
|
||||
@@ -175,10 +175,13 @@ export function expandRecurrences(icsEvent: any, windowDays = 365): any[] {
|
||||
set.exdate(new Date(exdate.includes("Z") ? exdate : exdate + "Z"));
|
||||
}
|
||||
|
||||
const windowEnd = new Date(dtstart.getTime() + windowDays * 86400000);
|
||||
const now = new Date();
|
||||
// Start the window 7 days ago to catch recent past events
|
||||
const windowStart = new Date(now.getTime() - 7 * 86400000);
|
||||
const windowEnd = new Date(now.getTime() + windowDays * 86400000);
|
||||
|
||||
// Expand from the event's start date, not from 'now', to ensure tests and past events work
|
||||
const occurrences = set.between(dtstart, windowEnd, true);
|
||||
// Expand from the start of our window
|
||||
const occurrences = set.between(windowStart, windowEnd, true);
|
||||
|
||||
if (occurrences.length === 0) return [icsEvent];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user