use of net.fortuna.ical4j.model.property.LastModified in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method getTimeZoneForZoneLines.
/**
* @param zoneLines - Only the zoneLines related to a time zone that might be relevant from the reference date.
*/
private static String getTimeZoneForZoneLines(String tzid, Set<String> aliases, List<ZoneLine> zoneLines, Params params, Set<String> zoneIDs, Map<String, VTimeZone> oldTimeZones) {
if ((zoneLines == null) || (zoneLines.isEmpty())) {
return "";
}
boolean isPrimary = sPrimaryTZIDs.contains(tzid);
Integer matchScore = sMatchScores.get(tzid);
if (matchScore == null) {
if (isPrimary) {
matchScore = Integer.valueOf(TZIDMapper.DEFAULT_MATCH_SCORE_PRIMARY);
} else {
matchScore = Integer.valueOf(TZIDMapper.DEFAULT_MATCH_SCORE_NON_PRIMARY);
}
}
Iterator<String> aliasesIter = aliases.iterator();
while (aliasesIter.hasNext()) {
String curr = aliasesIter.next();
if (zoneIDs.contains(curr)) {
aliasesIter.remove();
}
}
ZoneLine zline = zoneLines.get(0);
VTimeZone oldVtz = oldTimeZones.get(zline.getName());
Property oldLastModProp = null;
if (null != oldVtz) {
oldLastModProp = oldVtz.getProperties().getProperty(Property.LAST_MODIFIED);
}
LastModified newLastModified = getLastModified(params.lastModified);
LastModified trialLastModified;
if (null != oldLastModProp && oldLastModProp instanceof LastModified) {
trialLastModified = (LastModified) oldLastModProp;
} else {
trialLastModified = newLastModified;
}
VTimeZone vtz = toVTimeZoneComp(params.referenceDate, zoneLines, trialLastModified, aliases, isPrimary, matchScore);
String asText = vtz.toString();
if ((null != oldVtz) && (trialLastModified != newLastModified)) {
String oldText = oldVtz.toString();
if (!asText.equals(oldText)) {
/* Work around non-round tripped entries where the original source has:
* X-ZIMBRA-TZ-ALIAS:(GMT+12.00) Anadyr\, Petropavlovsk-Kamchatsky (RTZ 11)
* but in this we have:
* X-ZIMBRA-TZ-ALIAS:(GMT+12.00) Anadyr\\\, Petropavlovsk-Kamchatsky (RTZ 11)
* suspect that is a bug in libical which may be fixed in a later revision
*/
String oldText2 = oldText.replace("\\\\\\,", "\\,");
if (!asText.equals(oldText2)) {
LastModified lastModProp = (LastModified) vtz.getProperties().getProperty(Property.LAST_MODIFIED);
try {
lastModProp.setValue(newLastModified.getValue());
asText = vtz.toString();
} catch (ParseException e) {
System.err.println("Problem assigning LAST-MODIFIED - " + e.getMessage());
}
}
}
}
return asText;
}
use of net.fortuna.ical4j.model.property.LastModified in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method getLastModified.
private static LastModified getLastModified(String lastModified) {
LastModified lMod = null;
DateTime dt;
try {
dt = new DateTime(lastModified);
lMod = new LastModified(dt);
} catch (ParseException e) {
System.err.println(e.getMessage());
System.err.println("String turning into LAST-MODIFIED: " + lastModified);
e.printStackTrace();
System.exit(1);
}
return lMod;
}
use of net.fortuna.ical4j.model.property.LastModified in project openhab1-addons by openhab.
the class Util method createCalendar.
public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) {
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone(timeZone.getID());
Calendar calendar = new Calendar();
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(new ProdId("openHAB"));
VEvent vEvent = new VEvent();
vEvent.getProperties().add(new Summary(calDavEvent.getName()));
vEvent.getProperties().add(new Description(calDavEvent.getContent()));
final DtStart dtStart = new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate()));
dtStart.setTimeZone(timezone);
vEvent.getProperties().add(dtStart);
final DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate()));
dtEnd.setTimeZone(timezone);
vEvent.getProperties().add(dtEnd);
vEvent.getProperties().add(new Uid(calDavEvent.getId()));
vEvent.getProperties().add(Clazz.PUBLIC);
vEvent.getProperties().add(new LastModified(new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate())));
calendar.getComponents().add(vEvent);
return calendar;
}
Aggregations