#138 wrong observance on DST starting/ending hours (report 2)

Release
open
Ben Fortuna
Parsing (53)
5
2011-11-14
2011-11-14
sebl29
No

Hello *,

Below is a JUnit-test that fails. Tested with 1.0.2 from the maven-repo (plz see http://wiki.modularity.net.au/ical4j/index.php?title=Maven2 ).

The test-code was adapted to the one of the report "wrong observance on DST starting/ending hours - ID: 3019385" from Michael WANG (thx!) (https://sourceforge.net/tracker/?func=detail&aid=3019385&group_id=107024&atid=646395).
The difference between the code of Michael WANG and mine is the RRULE in the VTIMEZONE-definition: In my one the string "BYMINUTE=0;BYHOUR=2;" is missing.
Best regards and thanks for this cool lib!
Sebl

@Test
public void testObservance() {
try {
String s = "BEGIN%3AVCALENDAR%0D%0AVERSION%3A2.0%0D%0AMETHOD%3AREQUEST%0D%0ABEGIN%3AVTIMEZONE%0D%0ATZID%3ACentral%20Europe%0D%0ABEGIN%3ASTANDARD%0D%0ADTSTART%3A19501029T020000%0D%0ATZOFFSETFROM%3A%2B0200%0D%0ATZOFFSETTO%3A%2B0100%0D%0ARRULE%3AFREQ%3DYEARLY%3BBYDAY%3D-1SU%3BBYMONTH%3D10%0D%0AEND%3ASTANDARD%0D%0ABEGIN%3ADAYLIGHT%0D%0ADTSTART%3A19500326T020000%0D%0ATZOFFSETFROM%3A%2B0100%0D%0ATZOFFSETTO%3A%2B0200%0D%0ARRULE%3AFREQ%3DYEARLY%3BBYDAY%3D-1SU%3BBYMONTH%3D3%0D%0AEND%3ADAYLIGHT%0D%0AEND%3AVTIMEZONE%0D%0ABEGIN%3AVEVENT%0D%0ADTSTART%3BTZID%3D%22Central%20Europe%22%3A20100623T150000%0D%0ADTEND%3BTZID%3D%22Central%20Europe%22%3A20100623T160000%0D%0ATRANSP%3AOPAQUE%0D%0ADTSTAMP%3A20100621T081348Z%0D%0ASEQUENCE%3A0%0D%0ACLASS%3APUBLIC%0D%0ASUMMARY%3A1613%0D%0AUID%3A981A707A9129772548257749002D257C%0D%0AEND%3AVEVENT%0D%0AEND%3AVCALENDAR%0D%0A";
/*
BEGIN:VTIMEZONE
TZID:Central Europe
BEGIN:STANDARD
DTSTART:19501029T020000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:19500326T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
*/
s = URLDecoder.decode(s, "UTF-8").trim();
Calendar c = ICalUtil.getCalendar(s);
if(c == null) {fail("failed to parse ICS");}

vtz = (VTimeZone) c.getComponent(Component.VTIMEZONE);

cal.set(2011, 9, 29, 18, 0, 0); // 20111029T190000 local time
observance = vtz.getApplicableObservance(new DateTime(cal.getTime()));
assertTrue(observance.getName().equals("DAYLIGHT"));

cal.set(2011, 9, 30, 18, 0, 0); // 20111030T190000 local time //sunday of daylight switching
observance = vtz.getApplicableObservance(new DateTime(cal.getTime()));
assertTrue(observance.getName().equals("STANDART"));

cal.set(2011, 9, 31, 18, 0, 0); // 20111031T190000 local time
observance = vtz.getApplicableObservance(new DateTime(cal.getTime()));
assertTrue(observance.getName().equals("STANDART"));

cal.set(2011, 10, 1, 18, 0, 0); // 20111101T190000 local time
observance = vtz.getApplicableObservance(new DateTime(cal.getTime()));
assertTrue(observance.getName().equals("STANDART"));
}
catch (Exception e) {
fail(e.getMessage());
}
}

###############################################
##### ICalUtil ################################
###############################################
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
</dependency>
###############################################
import java.io.IOException;
import java.io.InputStream;

import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.Calendar;

import org.apache.commons.io.IOUtils;

public class ICalUtil {

public static Calendar getCalendar(String s)
{
CalendarBuilder builder = new CalendarBuilder();
InputStream inputStream = IOUtils.toInputStream(s);
try {
Calendar cal = builder.build(inputStream);
return cal;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ParserException e) {
throw new RuntimeException(e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}
###############################################

Discussion