Skip to content

Commit

Permalink
SAK-50276 Calendar correct the end date for all day events (sakaiproj…
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored Jul 29, 2024
1 parent d5b2d2e commit acad917
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
4 changes: 4 additions & 0 deletions calendar/calendar-api/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-component-manager</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.util.Collection;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.time.api.TimeRange;

public interface ExternalCalendarSubscriptionService
{

Expand Down Expand Up @@ -116,4 +119,31 @@ public void setSubscriptionsForChannel(String reference,
/** Check if reference references a institutional external calendar */
public boolean isInstitutionalCalendar(String reference);

/**
* Creates an id encoding the recurrence info into the id
*
* @param id the event id
* @param range the recurrence range
* @param sequence the sequence
* @return an id
*/
static String encodeRecurrenceWithId(String id, TimeRange range, int sequence) {
return '!' + range.toString() + '!' + sequence + '!' + id;
}

/**
* Detects if id has been encoded with recurrence info and decodes it
* returning the original event id.
* If the id is not encoded it simple returns the supplied id.
*
* @param encodedId an id
* @return the original event id
*/
static String decodeIdFromRecurrence(String encodedId) {
if (StringUtils.countMatches(encodedId, '!') == 3) {
return StringUtils.split(encodedId, '!')[2];
}
return encodedId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,7 @@ public ExternalCalendarEvent(CalendarEvent other, RecurrenceInstance ri)
m_calendar_id = ((ExternalCalendarEvent) other).m_calendar_id;

// encode the instance and the other's id into my id
m_id = '!' + ri.getRange().toString() + '!' + ri.getSequence() + '!'
+ ((ExternalCalendarEvent) other).m_id;
m_id = ExternalCalendarSubscriptionService.encodeRecurrenceWithId(((ExternalCalendarEvent) other).m_id, ri.getRange(), ri.getSequence());

// use the new range
m_range = (TimeRange) ri.getRange().clone();
Expand Down Expand Up @@ -1576,6 +1575,6 @@ public String getSiteName()

return calendarName;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,28 @@ public String importStreamFromDelimitedFile(InputStream stream, ReaderImportRowH

CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(stream);
// SAK-33451: READ TIME ZONE OF ICALENDAR

ZoneId calendarZone = null;
try {
Component vTimeZone = calendar.getComponent(Component.VTIMEZONE);
if (vTimeZone != null) {
Property tzProperty = vTimeZone.getProperty(Property.TZID);
if (tzProperty != null) {
calendarTzid = tzProperty.getValue();
ZoneId zone = ZoneId.of(calendarTzid);
log.debug("Calendar time zone is valid [{}]", zone);
calendarZone = ZoneId.of(calendarTzid);
log.debug("Calendar time zone is valid [{}]", calendarZone);
}
} else {
log.debug("Calendar time zone not found");
}
log.debug("Calendar time zone not found");
} catch (Exception e) {
log.warn("Error reading VTIMEZONE component/TZID property: [{}]", e.toString());
calendarTzid = null;
}

if (calendarZone == null) {
calendarZone = timeService.getLocalTimeZone().toZoneId();
}

int lineNumber = 1;
for (Component event : calendar.getComponents(Component.VEVENT)) {
Property summary = event.getProperty(Property.SUMMARY);
Expand All @@ -129,12 +132,13 @@ public String importStreamFromDelimitedFile(InputStream stream, ReaderImportRowH
// all day event
Date startDate = Date.from(LocalDate
.parse(start.getValue(), DateTimeFormatter.BASIC_ISO_DATE)
.atStartOfDay(ZoneId.systemDefault())
.atStartOfDay(calendarZone)
.toInstant());
Date endDate = Date.from(LocalDate
.parse(end.getValue(), DateTimeFormatter.BASIC_ISO_DATE)
.atTime(LocalTime.MAX)
.atZone(ZoneId.systemDefault())
.atZone(calendarZone)
.minusDays(1)
.toInstant());
Period period = new Period(new DateTime(startDate), new DateTime(endDate));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3600,7 +3600,7 @@ public void doDescription(RunData data, Context context)
// "crack" the reference (a.k.a dereference, i.e. make a Reference)
// and get the event id and calendar reference
Reference ref = EntityManager.newReference(data.getParameters().getString(EVENT_REFERENCE_PARAMETER));
String eventId = ref.getId();
String eventId = ExternalCalendarSubscriptionService.decodeIdFromRecurrence(ref.getId());
String calId = null;
if(CalendarService.REF_TYPE_EVENT_SUBSCRIPTION.equals(ref.getSubType()))
calId = CalendarService.calendarSubscriptionReference(ref.getContext(), ref.getContainer());
Expand Down

0 comments on commit acad917

Please sign in to comment.