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
12 changes: 8 additions & 4 deletions src/pat/recurrence/recurrence.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,21 @@ function widgetSaveToRfc5545(form, RDATE, EXDATE, conf, tz) {

for (let rdate of RDATE) {
if (rdate !== "") {
// RDATE values are "YYYY-MM-DD"
// The values from the input field are ISO8601 "YYYY-MM-DD"
// RFC5545 expects a date or date-time format of e.g.
// "YYYYMMDD". See:‌
// https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.5.2
rdate = rdate.replaceAll("-", "");
// by adding "T000000" the recurrence sequence generator of
// plone.event.recurrence adds the current start time correctly
rdate += rdate.length === 10 ? "T000000" : "";
rdate += rdate.length === 8 ? "T000000" : "";
rdate += tz ? "Z" : "";
tmp_dates.push(rdate);

// human readable RDATE
year = parseInt(rdate.substring(0, 4), 10);
month = parseInt(rdate.substring(5, 7), 10) - 1;
day = parseInt(rdate.substring(8, 10), 10);
month = parseInt(rdate.substring(4, 6), 10) - 1; // js month.
day = parseInt(rdate.substring(6, 8), 10);
tmp_human.push(
format(
new Date(year, month, day),
Expand Down
42 changes: 42 additions & 0 deletions src/pat/recurrence/recurrence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,46 @@ describe("Recurrence", function () {
const add_occurrence = document.querySelector(".modal .riaddoccurrence");
expect(add_occurrence).toBeTruthy();
});

it("Adds EXDATES as expected by RFC5545.", async function () {
// This fixes a problem described in
// https://github.com/plone/plone.formwidget.recurrence/issues/48
// A RDATE needs to follow RFC5545 date or date-time format. See:
// https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.5.2
document.body.innerHTML = `
<input name="start" type="date" value="2026-01-01" />
<textarea class="pat-recurrence"
data-pat-recurrence='{
"startField": "[name=start]",
"allowAdditionalDates": true
}'
></textarea>
`;

registry.scan(document.body);
await utils.timeout(1);

const edit_btn = document.querySelector("[name=riedit]");
edit_btn.click();

const add_date = document.querySelector(".modal #adddate");
add_date.value = "2026-01-14";
const add_date_btn = document.querySelector(".modal #addaction");
add_date_btn.click();

const jq = (await import("jquery")).default;
jq.fn.ajaxSubmit = () => {};

// Save
const save_btn = document.querySelector(".modal .risavebutton");
save_btn.click();

// modal is closed now.
const modal = document.querySelector(".modal");
expect(modal).toBeFalsy();

const recurrence = document.querySelector(".pat-recurrence");
expect(recurrence.value).toContain("RRULE:FREQ=DAILY");
expect(recurrence.value).toContain("RDATE:20260114T000000");
});
});