use of com.zimbra.common.calendar.ZoneInfoParser.ZoneLine 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 com.zimbra.common.calendar.ZoneInfoParser.ZoneLine in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method getZoneLinesFromDate.
private static List<ZoneLine> getZoneLinesFromDate(Zone zone, Calendar referenceDate) {
Until referenceUntil = new Until(referenceDate);
Set<ZoneLine> zlines = zone.getZoneLines();
List<ZoneLine> zoneLines = Lists.newArrayList();
for (ZoneLine zline : zlines) {
Until until = zline.getUntil();
if (until != null) {
if (until.compareTo(referenceUntil) < 0) {
continue;
}
}
zoneLines.add(zline);
}
return zoneLines;
}
use of com.zimbra.common.calendar.ZoneInfoParser.ZoneLine in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method toVTimeZoneComp.
/**
* @param zoneLines - Only the zoneLines related to a time zone that might be relevant from the reference date.
*/
private static VTimeZone toVTimeZoneComp(Calendar referenceDate, List<ZoneLine> zoneLines, LastModified lastModified, Set<String> tzAliases, boolean isPrimary, Integer matchScore) {
int hintYear = referenceDate.get(Calendar.YEAR);
ZoneLine zline1 = zoneLines.get(0);
PropertyList vtzProps = toVTimeZonePropertyList(zline1, lastModified, tzAliases, isPrimary, matchScore);
if (zoneLines.size() == 1) {
return toVTimeZoneComp(hintYear, toObservances(hintYear, zline1), vtzProps);
}
boolean suppressWarning = false;
// Rare to get here - generally happens for some new timezone changes in the near future.
ZoneLine zline2 = zoneLines.get(1);
Observances obs1 = toObservances(hintYear, zline1);
if (zline1.hasRule()) {
if ((null != obs1.std) && (null != obs1.daylight)) {
VTimeZone vtz = null;
vtz = toVTimeZoneComp(referenceDate, zline1, zline2, obs1, vtzProps, obs1.inDaylightTimeOnDate(referenceDate));
if (vtz != null) {
return vtz;
}
}
} else {
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
String fmtRefDate = format1.format(referenceDate.getTime());
if ((null != obs1.std) && (null == obs1.daylight)) {
// At reference date, only using STANDARD time
Observances obs2 = toObservances(hintYear, zline2);
if ((null != obs2.std) && (null != obs2.daylight)) {
if (obs2.inDaylightTimeOnDate(referenceDate)) {
System.err.println(String.format("1st zoneLine '%s' for '%s' only has STANDARD time.", zline1.toString(), zline1.getName()));
System.err.println(String.format("Reference date %s would be in DAYLIGHT time by rules of 2nd zoneLine '%s'", fmtRefDate, zline2.toString()));
System.err.println("Therefore, Ignoring 2nd zoneLine.");
suppressWarning = true;
} else {
TzOffsetTo oldOffsetTo = (TzOffsetTo) obs1.std.getProperties().getProperty(Property.TZOFFSETTO);
TzOffsetTo newOffsetTo = (TzOffsetTo) obs2.std.getProperties().getProperty(Property.TZOFFSETTO);
if (oldOffsetTo.equals(newOffsetTo)) {
// Standard time same by current rules and new rules - can ignore 1st zoneLine going forward
return toVTimeZoneComp(hintYear, toObservances(hintYear, zline2), vtzProps);
}
System.err.println(String.format("1st zoneLine '%s' for '%s' only has STANDARD time.", zline1.toString(), zline1.getName()));
System.err.println(String.format("Reference date %s would also be in STANDARD time by rules of 2nd zoneLine '%s'", fmtRefDate, zline2.toString()));
System.err.println(String.format("BUT OLD STANDARD has TZOFFSETTO=%s which differs from new TZOFFSETTO=%s.", oldOffsetTo.toString(), newOffsetTo.toString()));
System.err.println("Therefore, Ignoring 2nd zoneLine.");
suppressWarning = true;
}
}
}
}
if (!suppressWarning) {
System.err.println(String.format("More than 1 zoneLine for zone '%s' but unknown scenario. Using only zoneLine:\n %s", zline1.getName(), zline1.toString()));
}
return toVTimeZoneComp(hintYear, toObservances(hintYear, zline1), vtzProps);
}
Aggregations