use of net.fortuna.ical4j.model.PropertyList in project openhab1-addons by openhab.
the class EventReloaderJob method readCategory.
/**
* Returns a list of categories or an empty list if none found.
*
* @param vEvent
* @return
*/
private List<String> readCategory(VEvent vEvent) {
PropertyList propertyCategoryList = vEvent.getProperties(Property.CATEGORIES);
ArrayList<String> splittedCategoriesToReturn = new ArrayList<String>();
if (propertyCategoryList != null) {
for (int categoriesLineNum = 0; categoriesLineNum < propertyCategoryList.size(); categoriesLineNum++) {
Property propertyCategory = propertyCategoryList.get(categoriesLineNum);
String categories = propertyCategory.getValue();
if (categories != null) {
String[] categoriesSplit = StringUtils.split(categories, ",");
for (String category : categoriesSplit) {
if (!splittedCategoriesToReturn.contains(category)) {
splittedCategoriesToReturn.add(category);
}
}
}
}
}
return splittedCategoriesToReturn;
}
use of net.fortuna.ical4j.model.PropertyList 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);
}
use of net.fortuna.ical4j.model.PropertyList in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method toObservanceComp.
private static Observance toObservanceComp(int hintYear, RuleLine rline, boolean isStandard, Time standardOffset, Time daylightOffset, String tznameFormat) {
PropertyList props = new PropertyList();
String tzname = getObservanceName(tznameFormat, rline);
if (tzname != null) {
props.add(new TzName(tzname));
}
Time at = rline.getAt();
Time onset;
switch(at.getType()) {
case STANDARD_TIME:
if (isStandard) {
// We're moving from daylight time to standard time. In iCalendar we want hh:mm:ss in
// wall clock in the pre-transition time, so it's daylight time.
// daylight = utc + daylight offset = (standard - standard offset) + daylight offset
onset = addTimes(subtractTimes(at, standardOffset), daylightOffset);
} else {
// We're moving from standard time to daylight time. In iCalendar we want hh:mm:ss in
// wall clock in the pre-transition time, so it's standard time. at is already in
// standard time.
onset = at;
}
break;
case UTC_TIME:
if (isStandard) {
// We're moving from daylight time to standard time. In iCalendar we want hh:mm:ss in
// wall clock in the pre-transition time, so it's daylight time.
// daylight = utc + daylightOffset.
onset = addTimes(at, daylightOffset);
} else {
// We're moving from standard time to daylight time. In iCalendar we want hh:mm:ss in
// wall clock in the pre-transition time, so it's standard time.
// standard = utc + standard offset.
onset = addTimes(at, standardOffset);
}
break;
default:
// WALL_TIME
// at is already in the iCalendar style.
onset = at;
break;
}
int hh = onset.getHour();
int mm = onset.getMinute();
int ss = onset.getSecond();
if (hh >= 24) {
// Hour should be between 0 and 23, but sometimes we can get 24:00:00 from the zoneinfo source.
// Since hour part in iCalendar only allows 0-23, let's approximate any time with hour >= 24 to
// 23:59:59.
hh = 23;
mm = 59;
ss = 59;
}
// YYYYMMDD fixed to 16010101 (MS Outlook style)
props.add(getDtStart(String.format("16010101T%02d%02d%02d", hh, mm, ss)));
Time toOffset, fromOffset;
if (isStandard) {
toOffset = standardOffset;
fromOffset = daylightOffset;
} else {
toOffset = daylightOffset;
fromOffset = standardOffset;
}
props.add(new TzOffsetTo(new UtcOffset(getUtcOffset(toOffset))));
props.add(new TzOffsetFrom(new UtcOffset(getUtcOffset(fromOffset))));
int month = rline.getIn();
StringBuilder rruleVal = new StringBuilder();
rruleVal.append("FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=").append(month).append(";");
rruleVal.append(dayToICalRRulePart(hintYear, month, rline.getOn()));
try {
RRule rrule = new RRule(new ParameterList(), rruleVal.toString());
props.add(rrule);
} catch (ParseException e) {
}
if (isStandard) {
return new Standard(props);
} else {
return new Daylight(props);
}
}
Aggregations