Search in sources :

Example 1 with TzName

use of net.fortuna.ical4j.model.property.TzName in project zm-mailbox by Zimbra.

the class ZoneInfo2iCalendar method toStandardComp.

private static Standard toStandardComp(Time gmtOffset, String tznameFormat) {
    PropertyList props = new PropertyList();
    if (tznameFormat != null && tznameFormat.length() > 0 && !tznameFormat.contains("%")) {
        props.add(new TzName(iCalEscape(tznameFormat)));
    }
    props.add(getMsOutlookStyleDtstart());
    String offset = getUtcOffset(gmtOffset);
    UtcOffset utcOffset = new UtcOffset(offset);
    props.add(new TzOffsetTo(utcOffset));
    props.add(new TzOffsetFrom(utcOffset));
    return new Standard(props);
}
Also used : UtcOffset(net.fortuna.ical4j.model.UtcOffset) TzName(net.fortuna.ical4j.model.property.TzName) PropertyList(net.fortuna.ical4j.model.PropertyList) TzOffsetTo(net.fortuna.ical4j.model.property.TzOffsetTo) TzOffsetFrom(net.fortuna.ical4j.model.property.TzOffsetFrom) Standard(net.fortuna.ical4j.model.component.Standard)

Example 2 with TzName

use of net.fortuna.ical4j.model.property.TzName 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);
    }
}
Also used : TzName(net.fortuna.ical4j.model.property.TzName) RRule(net.fortuna.ical4j.model.property.RRule) DateTime(net.fortuna.ical4j.model.DateTime) Time(com.zimbra.common.calendar.ZoneInfoParser.Time) Standard(net.fortuna.ical4j.model.component.Standard) UtcOffset(net.fortuna.ical4j.model.UtcOffset) PropertyList(net.fortuna.ical4j.model.PropertyList) Daylight(net.fortuna.ical4j.model.component.Daylight) TzOffsetTo(net.fortuna.ical4j.model.property.TzOffsetTo) TzOffsetFrom(net.fortuna.ical4j.model.property.TzOffsetFrom) ParameterList(net.fortuna.ical4j.model.ParameterList) ParseException(java.text.ParseException) TZDataParseException(com.zimbra.common.calendar.ZoneInfoParser.TZDataParseException)

Aggregations

PropertyList (net.fortuna.ical4j.model.PropertyList)2 UtcOffset (net.fortuna.ical4j.model.UtcOffset)2 Standard (net.fortuna.ical4j.model.component.Standard)2 TzName (net.fortuna.ical4j.model.property.TzName)2 TzOffsetFrom (net.fortuna.ical4j.model.property.TzOffsetFrom)2 TzOffsetTo (net.fortuna.ical4j.model.property.TzOffsetTo)2 TZDataParseException (com.zimbra.common.calendar.ZoneInfoParser.TZDataParseException)1 Time (com.zimbra.common.calendar.ZoneInfoParser.Time)1 ParseException (java.text.ParseException)1 DateTime (net.fortuna.ical4j.model.DateTime)1 ParameterList (net.fortuna.ical4j.model.ParameterList)1 Daylight (net.fortuna.ical4j.model.component.Daylight)1 RRule (net.fortuna.ical4j.model.property.RRule)1