private TimeZone extractCalendarTimeZoneComponent(Calendar cal,TimeZone calTz) { try { for(Component component : cal.getComponents().getComponents("VTIMEZONE")) { VTimeZone v = (VTimeZone) component; v.getTimeZoneId(); if(calTz==null) { calTz = TimeZone.getTimeZone(v.getTimeZoneId().getValue()); } } } catch (Exception e) { log.warn("Unable to determine ical timezone", e); } return null; }
log.warn("Unable to retrieve updates for timezone: " + vTimeZone.getTimeZoneId().getValue(), e);
log.warn("Unable to retrieve updates for timezone: " + vTimeZone.getTimeZoneId().getValue(), e);
/** * @param vTimeZone * @return */ private VTimeZone updateDefinition(VTimeZone vTimeZone) { final TzUrl tzUrl = vTimeZone.getTimeZoneUrl(); if (tzUrl != null) { try { final CalendarBuilder builder = new CalendarBuilder(); final Calendar calendar = builder.build(tzUrl.getUri().toURL().openStream()); final VTimeZone updatedVTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE); if (updatedVTimeZone != null) { return updatedVTimeZone; } } catch (Exception e) { log.warn("Unable to retrieve updates for timezone: " + vTimeZone.getTimeZoneId().getValue(), e); } } return vTimeZone; } }
public VEvent convertVEvent(final TeamEventDO event) { final ICalConverterStore store = ICalConverterStore.getInstance(); // create vEvent final VEvent vEvent = new VEvent(false); // set time zone if (this.timeZone != null) { final net.fortuna.ical4j.model.TimeZone timezone = TIMEZONE_REGISTRY.getTimeZone(this.timeZone.getID()); vEvent.getProperties().add(timezone.getVTimeZone().getTimeZoneId()); } for (String export : this.exportsVEvent) { VEventComponentConverter converter = store.getVEventConverter(export); if (converter == null) { log.warn(String.format("No converter found for '%s', converter is skipped", export)); continue; } converter.toVEvent(event, vEvent); } return vEvent; }
/** * Compact timezones. * @param calendar The calendar. */ private void compactTimezones(Calendar calendar) { if (calendar==null) { return; } // Get list of timezones in master calendar and remove all timezone // definitions that are in the registry. The idea is to not store // extra data. Instead, the timezones will be added to the calendar // by the getCalendar() api. ComponentList<VTimeZone> timezones = calendar.getComponents(Component.VTIMEZONE); List<VTimeZone> toRemove = new ArrayList<>(); for(VTimeZone vtz : timezones) { String tzid = vtz.getTimeZoneId().getValue(); TimeZone tz = TIMEZONE_REGISTRY.getTimeZone(tzid); // Remove timezone iff it matches the one in the registry if(tz!=null && vtz.equals(tz.getVTimeZone())) { toRemove.add(vtz); } } // remove known timezones from master calendar calendar.getComponents().removeAll(toRemove); }
/** * Compact timezones. * @param calendar The calendar. */ private void compactTimezones(Calendar calendar) { if (calendar==null) { return; } // Get list of timezones in master calendar and remove all timezone // definitions that are in the registry. The idea is to not store // extra data. Instead, the timezones will be added to the calendar // by the getCalendar() api. ComponentList<VTimeZone> timezones = calendar.getComponents(Component.VTIMEZONE); List<VTimeZone> toRemove = new ArrayList<>(); for(VTimeZone vtz : timezones) { String tzid = vtz.getTimeZoneId().getValue(); TimeZone tz = TIMEZONE_REGISTRY.getTimeZone(tzid); // Remove timezone iff it matches the one in the registry if(tz!=null && vtz.equals(tz.getVTimeZone())) { toRemove.add(vtz); } } // remove known timezones from master calendar calendar.getComponents().removeAll(toRemove); }
private TimeZoneInfo doTimeZone(final VTimeZone vtz) throws CalFacadeException { TzId tzid = vtz.getTimeZoneId(); if (tzid == null) { throw new CalFacadeException("Missing tzid property"); } String id = tzid.getValue(); //if (debug()) { // debug("Got timezone: \n" + vtz.toString() + " with id " + id); //} try { TimeZone tz = Timezones.getTz(id); String tzSpec = null; if (tz == null) { tz = new TimeZone(vtz); tzSpec = vtz.toString(); } return new TimeZoneInfo(id, tz, tzSpec); } catch (Throwable t) { throw new CalFacadeException(t); } }
public static VEvent createVEvent(final Date startDate, final Date endDate, final String uid, final String summary, final boolean allDay, final TimeZone timezone) { VEvent vEvent; if (allDay == true) { final Date startUtc = CalendarUtils.getUTCMidnightDate(startDate); final Date endUtc = CalendarUtils.getUTCMidnightDate(endDate); final net.fortuna.ical4j.model.Date fortunaStartDate = new net.fortuna.ical4j.model.Date(startUtc); final org.joda.time.DateTime jodaTime = new org.joda.time.DateTime(endUtc); // requires plus 1 because one day will be omitted by calendar. final net.fortuna.ical4j.model.Date fortunaEndDate = new net.fortuna.ical4j.model.Date( jodaTime.plusDays(1).toDate()); vEvent = new VEvent(fortunaStartDate, fortunaEndDate, summary); } else { final net.fortuna.ical4j.model.DateTime fortunaStartDate = new net.fortuna.ical4j.model.DateTime(startDate); fortunaStartDate.setTimeZone(timezone); final net.fortuna.ical4j.model.DateTime fortunaEndDate = new net.fortuna.ical4j.model.DateTime(endDate); fortunaEndDate.setTimeZone(timezone); vEvent = new VEvent(fortunaStartDate, fortunaEndDate, summary); vEvent.getProperties().add(timezone.getVTimeZone().getTimeZoneId()); } vEvent.getProperties().add(new Uid(uid)); return vEvent; }
public VEvent convertVEvent(final Date startDate, final Date endDate, final boolean allDay, final String summary, final String uid) { VEvent vEvent = new VEvent(false); final net.fortuna.ical4j.model.TimeZone timezone = TIMEZONE_REGISTRY.getTimeZone(timeZone.getID()); final net.fortuna.ical4j.model.Date fortunaStartDate, fortunaEndDate; if (allDay == true) { final Date startUtc = CalendarUtils.getUTCMidnightDate(startDate); final Date endUtc = CalendarUtils.getUTCMidnightDate(endDate); fortunaStartDate = new net.fortuna.ical4j.model.Date(startUtc); // TODO should not be done final org.joda.time.DateTime jodaTime = new org.joda.time.DateTime(endUtc); // requires plus 1 because one day will be omitted by calendar. fortunaEndDate = new net.fortuna.ical4j.model.Date(jodaTime.plusDays(1).toDate()); } else { fortunaStartDate = new net.fortuna.ical4j.model.DateTime(startDate); ((net.fortuna.ical4j.model.DateTime) fortunaStartDate).setTimeZone(timezone); fortunaEndDate = new net.fortuna.ical4j.model.DateTime(endDate); ((net.fortuna.ical4j.model.DateTime) fortunaEndDate).setTimeZone(timezone); } vEvent.getProperties().add(timezone.getVTimeZone().getTimeZoneId()); vEvent.getProperties().add(new DtStart(fortunaStartDate)); vEvent.getProperties().add(new DtEnd(fortunaEndDate)); vEvent.getProperties().add(new Summary(summary)); vEvent.getProperties().add(new Uid(uid)); return vEvent; }
vevent.getProperties().add(tz.getTimeZoneId());
HashMap<String, VTimeZone> tzMap = new HashMap<String, VTimeZone>(); for(VTimeZone vtz : timezones) { tzMap.put(vtz.getTimeZoneId().getValue(), vtz);
final TzId timeZoneId = vTimeZone.getTimeZoneId();
HashMap<String, VTimeZone> tzMap = new HashMap<String, VTimeZone>(); for(VTimeZone vtz : timezones) { tzMap.put(vtz.getTimeZoneId().getValue(), vtz);