Lukas Aichbauer - 2014-03-18

Hi!
At first, this is a wonderfull library thanks for that!

I am the developer of iCal Import/Export and my app would not have been possible without your library.

I am expiriencing crazy daylight behaviour, not in generally but on certain dates near the daylight toggle, but only on Android system. The same code on Desktop works.

I have three events all with timezone Europe/Vienna:
(UTC offset default +1 hours
UTC offset daylight saving starting on 30 March 0200 till 26 October 0300, +2 hours)
1st 20140329T180000
2nd 20140330T180000
3rd 20140401T180000

To retrieve UTC time I use event.getStartDate().getDate().getTime()
As stated before on Desktop environment all Events have correct UTC time:
1st 1396112400000L
2nd 1396195200000L
3rd 1396368000000L

But on Android I get the following, which is really weird.
1st 1396112400000L
2nd 1396198800000L (This is wrong, exactly 1 hour ahead)
3rd 1396368000000L

Here the code to reproduce:

Android (JUnit 3 android):

import java.io.InputStream;
import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.component.VEvent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import tk.drlue.ical.InsertActivity;
import android.test.ActivityInstrumentationTestCase2;

/*
 * TimeZone test
 */
public class TimeZoneBasicTest extends ActivityInstrumentationTestCase2<InsertActivity> {
    private static final Logger LOGGER = LoggerFactory.getLogger(TimeZoneBasicTest.class);

    public TimeZoneBasicTest() {
        super(InsertActivity.class);
    }

    public void testEvents() throws Exception {
        Calendar calendar = new CalendarBuilder().build(openFile("mixed_dst_vienna.ics"));
        for (Object obj : calendar.getComponents(Component.VEVENT)) {
            VEvent event = (VEvent) obj;

            if (event.getSummary().getValue().equals("vienna3:29")) {
                assertEquals(event.getStartDate().getDate().getTime(), 1396112400000L);
            } else if (event.getSummary().getValue().equals("vienna3:30")) {
                assertEquals(event.getStartDate().getDate().getTime(), 1396195200000L);
            } else if (event.getSummary().getValue().equals("vienna4:1")) {
                assertEquals(event.getStartDate().getDate().getTime(), 1396368000000L);
            }
        }
    }

    protected InputStream openFile(String file) throws Exception {
        return getInstrumentation().getContext().getResources().getAssets().open(file);
    }
}



Java Desktop VM (JUnit 3 test):

import junit.framework.TestCase;
import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.component.VEvent;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParseException;

public class UTCTest extends TestCase {
    public void testEvents() throws ParseException, FileNotFoundException, IOException, ParserException {
        CalendarBuilder builder = new CalendarBuilder();
        Calendar calendar = builder.build(new FileInputStream("mixed_dst_vienna.ics"));
        for (Object obj : calendar.getComponents(Component.VEVENT)) {
            VEvent event = (VEvent)obj;
            if (event.getSummary().getValue().equals("vienna3:29")) {
                assertEquals(event.getStartDate().getDate().getTime(), 1396112400000L);
            } else if (event.getSummary().getValue().equals("vienna3:30")) {
                assertEquals(event.getStartDate().getDate().getTime(), 1396195200000L);
            } else if (event.getSummary().getValue().equals("vienna4:1")) {
                assertEquals(event.getStartDate().getDate().getTime(), 1396368000000L);
            }
        }
    }
}

The iCalendar file


http://www.drlue.tk/kdw/mixed_dst_vienna.ics


I made a hotifx which prevents this error, but it is not generally applicable, also because it works without fix on Destkop.


If you need any help or further information please let me know.


Thanks in advance and thanks again for your great library.
Lukas