use of net.fortuna.ical4j.model.component.VTimeZone in project zm-mailbox by Zimbra.
the class TimeZoneDefinition method addVtimezone.
public void addVtimezone(ContentHandler icalOutput) throws ParserException, URISyntaxException, IOException, ParseException {
if (getTimezoneName() == null) {
return;
}
if (effectiveRule == null) {
return;
}
getTimeZone();
if (theZone == null) {
return;
}
VTimeZone vtz = theZone.getVTimeZone();
icalOutput.startComponent(Component.VTIMEZONE);
for (Object obj : vtz.getProperties()) {
if (obj instanceof Property) {
Property currProp = (Property) obj;
IcalUtil.addProperty(icalOutput, currProp);
}
}
for (Object obj : vtz.getObservances()) {
if (obj instanceof Component) {
Component currComp = (Component) obj;
icalOutput.startComponent(currComp.getName());
for (Object propObj : currComp.getProperties()) {
if (propObj instanceof Property) {
Property obsProp = (Property) propObj;
IcalUtil.addProperty(icalOutput, obsProp);
}
}
icalOutput.endComponent(currComp.getName());
}
}
icalOutput.endComponent(Component.VTIMEZONE);
if (true) {
return;
}
}
use of net.fortuna.ical4j.model.component.VTimeZone in project zm-mailbox by Zimbra.
the class TimeZoneDefinition method getTimeZone.
/**
*
* @return the appropriate iCal4j TimeZone for this TimeZoneDefinition
*/
public TimeZone getTimeZone() {
if (theZone != null) {
return theZone;
}
if (effectiveRule == null) {
theZone = new TimeZone(0, TimeZones.UTC_ID);
return theZone;
}
if (!effectiveRule.hasDaylightSaving()) {
theZone = new TimeZone(effectiveRule.getStandardUtcOffsetMillis(), getTimezoneName());
return theZone;
}
UtcOffset stdOffset = effectiveRule.getStandardUtcOffset();
UtcOffset dlOffset = effectiveRule.getDaylightUtcOffset();
PropertyList vtzProps = new PropertyList();
TzId myTzid = new TzId(getTimezoneName());
vtzProps.add(myTzid);
VTimeZone vtz = new VTimeZone(vtzProps);
Standard stdComp = new Standard();
stdComp.getProperties().add(effectiveRule.getStandardDtStart());
stdComp.getProperties().add(effectiveRule.icalStandardRRule());
TzOffsetFrom offsetFrom = new TzOffsetFrom(dlOffset);
TzOffsetTo offsetTo = new TzOffsetTo(stdOffset);
stdComp.getProperties().add(offsetFrom);
stdComp.getProperties().add(offsetTo);
Daylight dayComp = new Daylight();
dayComp.getProperties().add(effectiveRule.getDaylightDtStart());
dayComp.getProperties().add(effectiveRule.icalDaylightRRule());
offsetFrom = new TzOffsetFrom(stdOffset);
offsetTo = new TzOffsetTo(dlOffset);
dayComp.getProperties().add(offsetFrom);
dayComp.getProperties().add(offsetTo);
vtz.getObservances().add(stdComp);
vtz.getObservances().add(dayComp);
try {
vtz.validate(true);
theZone = new TimeZone(vtz);
} catch (ValidationException e) {
if (sLog.isDebugEnabled()) {
sLog.debug("Problem with property %s - will default to UTC" + this.mpi.toString(), e);
}
theZone = new TimeZone(0, TimeZones.UTC_ID);
}
theZone = new TimeZone(vtz);
return theZone;
}
use of net.fortuna.ical4j.model.component.VTimeZone 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