Skip to content

Commit

Permalink
fix: add start date for vJournal
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrigore committed Sep 11, 2024
1 parent 9bd8695 commit 156752c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public Calendar getCalendar(boolean allowCalendarWithMethod) throws CosmoDavExce

try {
Calendar c = CalendarUtils.parseCalendar(getInputStream());
ValidationUtils.addRequired(c);
ValidationUtils.verifyResult(c.validate(true));

if (CalendarUtils.hasMultipleComponentTypes(c)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.unitedinternet.cosmo.util;

import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.Date;
import net.fortuna.ical4j.model.component.VJournal;
import net.fortuna.ical4j.model.property.DtStart;
import net.fortuna.ical4j.validate.ValidationException;
import net.fortuna.ical4j.validate.ValidationResult;

Expand All @@ -15,4 +20,22 @@ public static void verifyResult(ValidationResult result) throws ValidationExcept
throw new ValidationException("there are validation error in result");
}
}

public static void addRequired(Calendar calendar) {
addRequiredVjournal(calendar);
}

private static void addRequiredVjournal(Calendar calendar) {
if (calendar == null) {
return;
}
VJournal vJournal = calendar.getComponent(Component.VJOURNAL);
if (vJournal == null) {
return;
}
// See: https://github.com/orgs/ical4j/discussions/710
if (vJournal.getStartDate() == null) {
vJournal.getProperties().add(new DtStart(new Date(System.currentTimeMillis())));
}
}
}

0 comments on commit 156752c

Please sign in to comment.