Skip to content

Commit 5d5e30f

Browse files
committed
fix(pat-recurrence): Fix the RRULE date format for additional RDATE dates.
Fixes: plone/plone.formwidget.recurrence#48
1 parent e52bcc2 commit 5d5e30f

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/pat/recurrence/recurrence.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,21 @@ function widgetSaveToRfc5545(form, RDATE, EXDATE, conf, tz) {
218218

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

228232
// human readable RDATE
229233
year = parseInt(rdate.substring(0, 4), 10);
230-
month = parseInt(rdate.substring(5, 7), 10) - 1;
231-
day = parseInt(rdate.substring(8, 10), 10);
234+
month = parseInt(rdate.substring(4, 6), 10) - 1; // js month.
235+
day = parseInt(rdate.substring(6, 8), 10);
232236
tmp_human.push(
233237
format(
234238
new Date(year, month, day),

src/pat/recurrence/recurrence.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,45 @@ describe("Recurrence", function () {
9595
const add_occurrence = document.querySelector(".modal .riaddoccurrence");
9696
expect(add_occurrence).toBeTruthy();
9797
});
98+
99+
it("Adds EXDATES as expected by RFC5545.", async function () {
100+
// This fixes a problem described in
101+
// https://github.com/plone/plone.formwidget.recurrence/issues/48
102+
// A RDATE needs to follow RFC5545 date or date-time format. See:
103+
// https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.5.2
104+
document.body.innerHTML = `
105+
<input name="start" type="date" value="2026-01-01" />
106+
<textarea class="pat-recurrence"
107+
data-pat-recurrence='{
108+
"startField": "[name=start]",
109+
"hasAdditionalDates": true
110+
}'
111+
></textarea>
112+
`;
113+
114+
registry.scan(document.body);
115+
await utils.timeout(1);
116+
117+
const edit_btn = document.querySelector("[name=riedit]");
118+
edit_btn.click();
119+
120+
const add_date = document.querySelector(".modal #adddate");
121+
add_date.value = "2026-01-14";
122+
const add_date_btn = document.querySelector(".modal #addaction");
123+
add_date_btn.click();
124+
125+
const jq = (await import("jquery")).default;
126+
jq(".modal form").$ajaxSubmit = () => {};
127+
128+
// Save
129+
const save_btn = document.querySelector(".modal .risavebutton");
130+
save_btn.click();
131+
132+
// modal is closed now.
133+
const modal = document.querySelector(".modal");
134+
expect(modal).toBeFalsy();
135+
136+
const recurrence = document.querySelector(".pat-recurrence");
137+
console.log(recurrence.value);
138+
});
98139
});

0 commit comments

Comments
 (0)