@Test public void timezone_without_id() throws Exception { StreamReader reader = new StreamReaderImpl() { @Override protected ICalendar _readNext() { ICalendar ical = new ICalendar(); VTimezone timezone = new VTimezone(null); { StandardTime standard = new StandardTime(); standard.setDateStart(new DateTimeComponents(2014, 9, 1, 2, 0, 0, false)); standard.setTimezoneOffsetFrom(new UtcOffset(true, 10, 0)); standard.setTimezoneOffsetTo(new UtcOffset(true, 9, 0)); timezone.addStandardTime(standard); DaylightSavingsTime daylight = new DaylightSavingsTime(); daylight.setDateStart(new DateTimeComponents(2014, 1, 1, 2, 0, 0, false)); daylight.setTimezoneOffsetFrom(new UtcOffset(true, 9, 0)); daylight.setTimezoneOffsetTo(new UtcOffset(true, 10, 0)); timezone.addDaylightSavingsTime(daylight); } ical.addComponent(timezone); return ical; } }; ICalendar ical = reader.readNext(); TimezoneInfo tzinfo = reader.getTimezoneInfo(); assertEquals(0, tzinfo.getComponents().size()); assertEquals(1, ical.getComponents(VTimezone.class).size()); assertWarnings(1, reader); }
@Test public void timezones() throws Exception { StreamReader reader = new StreamReaderImpl() { @Override protected ICalendar _readNext() { ICalendar ical = new ICalendar(); VTimezone timezone = new VTimezone("tz"); { StandardTime standard = new StandardTime(); standard.setDateStart(new DateTimeComponents(2014, 9, 1, 2, 0, 0, false)); standard.setTimezoneOffsetFrom(new UtcOffset(true, 10, 0)); standard.setTimezoneOffsetTo(new UtcOffset(true, 9, 0)); timezone.addStandardTime(standard); DaylightSavingsTime daylight = new DaylightSavingsTime(); daylight.setDateStart(new DateTimeComponents(2014, 1, 1, 2, 0, 0, false)); daylight.setTimezoneOffsetFrom(new UtcOffset(true, 9, 0)); daylight.setTimezoneOffsetTo(new UtcOffset(true, 10, 0)); timezone.addDaylightSavingsTime(daylight); } ical.addComponent(timezone); TestProperty floating = new TestProperty(icalDate("2014-09-21T10:22:00")); context.addFloatingDate(floating, floating.date); ical.addProperty(floating); String tzid = timezone.getTimezoneId().getValue(); TestProperty timezoned = new TestProperty(icalDate("2014-10-01T13:07:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = timezone.getTimezoneId().getValue(); timezoned = new TestProperty(icalDate("2014-08-01T13:07:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = timezone.getTimezoneId().getValue(); timezoned = new TestProperty(icalDate("2013-12-01T13:07:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = "/America/New_York"; timezoned = new TestProperty(icalDate("2014-07-04T09:00:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = "America/New_York"; timezoned = new TestProperty(icalDate("2014-07-04T09:00:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = "foobar"; timezoned = new TestProperty(icalDate("2014-06-11T14:00:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); return ical; } }; ICalendar ical = reader.readNext(); TimezoneInfo tzinfo = reader.getTimezoneInfo(); Collection<VTimezone> components = tzinfo.getComponents(); assertEquals(1, components.size()); assertEquals(0, ical.getComponents(VTimezone.class).size()); VTimezone component = components.iterator().next(); Iterator<TestProperty> it = ical.getProperties(TestProperty.class).iterator(); // floating-time property TestProperty property = it.next(); assertTrue(tzinfo.isFloating(property)); assertNull(tzinfo.getComponent(property)); assertNull(tzinfo.getTimeZone(property)); assertNull(property.getParameters().getTimezoneId()); assertEquals(date("2014-09-21 10:22:00"), property.date); // timezoned property property = it.next(); assertFalse(tzinfo.isFloating(property)); assertEquals(component, tzinfo.getComponent(property)); assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2014-10-01 04:07:00"), property.date); // timezoned property property = it.next(); assertFalse(tzinfo.isFloating(property)); assertEquals(component, tzinfo.getComponent(property)); assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2014-08-01 03:07:00"), property.date); // timezoned property property = it.next(); assertFalse(tzinfo.isFloating(property)); assertEquals(component, tzinfo.getComponent(property)); assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2013-12-01 04:07:00"), property.date); // property with Olsen TZID property = it.next(); assertFalse(tzinfo.isFloating(property)); assertNull(tzinfo.getComponent(property)); assertEquals(TimeZone.getTimeZone("America/New_York"), tzinfo.getTimeZone(property)); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2014-07-04 13:00:00"), property.date); // property with Olsen TZID that doesn't point to a VTIMEZONE component property = it.next(); assertFalse(tzinfo.isFloating(property)); assertNull(tzinfo.getComponent(property)); assertEquals(TimeZone.getTimeZone("America/New_York"), tzinfo.getTimeZone(property)); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2014-07-04 13:00:00"), property.date); // property with TZID that doesn't point to a VTIMEZONE component property = it.next(); assertFalse(tzinfo.isFloating(property)); assertNull(tzinfo.getComponent(property)); assertNull(tzinfo.getTimeZone(property)); assertEquals("foobar", property.getParameters().getTimezoneId()); assertEquals(date("2014-06-11 14:00:00"), property.date); assertFalse(it.hasNext()); assertWarnings(2, reader); }