Skip to content

Commit

Permalink
Resolve timezones for all component properties
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Dec 30, 2018
1 parent 6171692 commit 3043578
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/main/java/net/fortuna/ical4j/data/DefaultContentHandler.java
@@ -1,9 +1,7 @@
package net.fortuna.ical4j.data;

import net.fortuna.ical4j.model.*;
import net.fortuna.ical4j.model.component.CalendarComponent;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.model.component.VTimeZone;
import net.fortuna.ical4j.model.component.*;
import net.fortuna.ical4j.model.parameter.TzId;
import net.fortuna.ical4j.model.property.DateListProperty;
import net.fortuna.ical4j.model.property.DateProperty;
Expand All @@ -27,7 +25,7 @@ public class DefaultContentHandler implements ContentHandler {

private final TimeZoneRegistry tzRegistry;

private List<TzId> datesMissingTimezones;
private List<TzId> propertiesWithTzId;

private final Consumer<Calendar> consumer;

Expand Down Expand Up @@ -59,19 +57,27 @@ public DefaultContentHandler(Consumer<Calendar> consumer, TimeZoneRegistry tzReg
@Override
public void startCalendar() {
calendar = new Calendar();
datesMissingTimezones = new ArrayList<>();
propertiesWithTzId = new ArrayList<>();
}

@Override
public void endCalendar() throws IOException {
if (datesMissingTimezones.size() > 0 && tzRegistry != null) {
if (propertiesWithTzId.size() > 0 && tzRegistry != null) {
for (CalendarComponent component : calendar.getComponents()) {
resolveTimezones(component.getProperties());

if (component instanceof VEvent) {
if (component instanceof VAvailability) {
for (Component available : ((VAvailability) component).getAvailable()) {
resolveTimezones(available.getProperties());
}
} else if (component instanceof VEvent) {
for (Component alarm : ((VEvent) component).getAlarms()) {
resolveTimezones(alarm.getProperties());
}
} else if (component instanceof VToDo) {
for (Component todo : ((VToDo) component).getAlarms()) {
resolveTimezones(todo.getProperties());
}
}
}
}
Expand Down Expand Up @@ -148,15 +154,10 @@ public void parameter(String name, String value) throws URISyntaxException {
.name(name).value(value).build();

if (parameter instanceof TzId && tzRegistry != null) {
// final TimeZone timezone = tzRegistry.getTimeZone(parameter.getValue());
// if (timezone != null) {
// propertyBuilder.timeZone(timezone);
// } else {
// VTIMEZONE may be defined later, so so keep
// track of dates until all components have been
// parsed, and then try again later
datesMissingTimezones.add((TzId) parameter);
// }
// VTIMEZONE may be defined later, so so keep
// track of dates until all components have been
// parsed, and then try again later
propertiesWithTzId.add((TzId) parameter);
}

propertyBuilder.parameter(parameter);
Expand All @@ -177,7 +178,7 @@ private void assertProperty(PropertyBuilder property) {
private void resolveTimezones(List<Property> properties) throws IOException {

// Go through each property and try to resolve the TZID.
for (TzId tzParam : datesMissingTimezones) {
for (TzId tzParam : propertiesWithTzId) {

//lookup timezone
final TimeZone timezone = tzRegistry.getTimeZone(tzParam.getValue());
Expand Down

0 comments on commit 3043578

Please sign in to comment.