Skip to content

Commit

Permalink
SAK-32668 - Add VTIMEZONE component to calendar (sakaiproject#4583)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonespm authored and ottenhoff committed Jul 10, 2017
1 parent bd86a19 commit 89fecd1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public interface ExternalCalendaringService {

/**
* Creates an iCal calendar from a list of VEvents.
* timeIsLocal is set to true so it returns a local timezone element
*
* @param events iCal VEvents
* @return the Calendar for the given events or null if there was an error
Expand All @@ -126,7 +127,7 @@ public interface ExternalCalendaringService {
* @param method the ITIP method for the calendar, e.g. "REQUEST"
* @return the Calendar for the given events or null if there was an error
*/
public Calendar createCalendar(List<VEvent> events, String method);
public Calendar createCalendar(List<VEvent> events, String method, boolean timeIsLocal);

/**
* Write an iCal calendar out to a file in the filesystem and return the path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,7 @@ public VEvent createEvent(CalendarEvent event, Set<User> attendees) {
return createEvent(event, null, false);
}


/**
* {@inheritDoc}
*/
public VEvent createEvent(CalendarEvent event, Set<User> attendees, boolean timeIsLocal) {

if(!isIcsEnabled()) {
log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
return null;
}

public VTimeZone getTimeZone(boolean timeIsLocal) {
//timezone. All dates are in GMT so we need to explicitly set that
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();

Expand All @@ -106,7 +96,21 @@ public VEvent createEvent(CalendarEvent event, Set<User> attendees, boolean time
//This is guaranteed to return timezone if timeIsLocal == false or it fails and returns null
timezone = registry.getTimeZone("GMT");
}
VTimeZone tz = timezone.getVTimeZone();
return timezone.getVTimeZone();
}


/**
* {@inheritDoc}
*/
public VEvent createEvent(CalendarEvent event, Set<User> attendees, boolean timeIsLocal) {

if(!isIcsEnabled()) {
log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
return null;
}

VTimeZone tz = getTimeZone(timeIsLocal);

//start and end date
DateTime start = new DateTime(getStartDate(event.getRange()).getTime());
Expand Down Expand Up @@ -260,13 +264,13 @@ public VEvent cancelEvent(VEvent vevent) {
* {@inheritDoc}
*/
public Calendar createCalendar(List<VEvent> events) {
return createCalendar(events, null);
return createCalendar(events, null, true);
}

/**
* {@inheritDoc}
*/
public Calendar createCalendar(List<VEvent> events, String method) {
public Calendar createCalendar(List<VEvent> events, String method, boolean timeIsLocal) {

if(!isIcsEnabled()) {
log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
Expand All @@ -285,6 +289,11 @@ public Calendar createCalendar(List<VEvent> events, String method) {
//add vevents to calendar
calendar.getComponents().addAll(events);

//add vtimezone
VTimeZone tz = getTimeZone(timeIsLocal);

calendar.getComponents().add(tz);

//validate
try {
calendar.validate(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public String createCalendarFile(List<VEvent> vevents) {
@Override
public String createCalendarFile(List<VEvent> vevents, String method) {
//create calendar
net.fortuna.ical4j.model.Calendar cal = externalCalendaringService.createCalendar(vevents, method);
net.fortuna.ical4j.model.Calendar cal = externalCalendaringService.createCalendar(vevents, method, true);

//get path to file
return externalCalendaringService.toFile(cal);
Expand Down

0 comments on commit 89fecd1

Please sign in to comment.