Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,15 @@ const normalizeICSDateStr = (value: string | null | undefined): string | null =>
return null;
}

if (value.length === 8) {
return `${value}T000000Z`;
// For VALUE=PERIOD, compare against the period start date only.
// The end value is not relevant for the now/max window checks here.
const normalizedValue: string = value.split("/")[0] ?? value;

if (normalizedValue.length === 8) {
return `${normalizedValue}T000000Z`;
}

return value;
return normalizedValue;
};

const toICSDateString = (date: Date): string => {
Expand Down
11 changes: 11 additions & 0 deletions src/tests/rdate-support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@ describe("icsFilter on ics content with RDATE properties and max limit", () => {
assert.ok(!filteredMaxContent.includes("rdate-value-date@test"), "Event with RDATE;VALUE=DATE dates beyond max should be dropped");
assert.ok(!filteredMaxContent.includes("rdate-period@test"), "Event with RDATE;VALUE=PERIOD dates beyond max should be dropped");
});

test("should keep RDATE;VALUE=PERIOD when the start date is within max", () => {
const now = new Date("2025-01-01T00:00:00.000Z");
const max = new Date("2030-06-01T10:00:00.000Z");
const periodContent =
"BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nUID:period-within-max@test\nDTSTART:20200601T100000Z\nDTEND:20200601T120000Z\nRDATE;VALUE=PERIOD:20300601T100000Z/20300601T120000Z\nEND:VEVENT\nEND:VCALENDAR";

const filtered = icsFilter(periodContent, now, max);

assert.ok(filtered.includes("period-within-max@test"), "Event with PERIOD RDATE starting at max should be kept");
});
});