Search in sources :

Example 61 with ParsedDateTime

use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.

the class Recurrence method getReferencedTZIDs.

// Get the set of TZIDs referenced in a recurrence.  RDATE and EXDATE can use TZID parameter.
public static Set<String> getReferencedTZIDs(IRecurrence recur) {
    Set<String> tzids = new HashSet<String>();
    // RDATE
    for (Iterator iter = recur.addRulesIterator(); iter != null && iter.hasNext(); ) {
        IRecurrence cur = (IRecurrence) iter.next();
        if (cur.getType() == Recurrence.TYPE_SINGLE_DATES) {
            Recurrence.SingleDates sd = (Recurrence.SingleDates) cur;
            RdateExdate rdate = sd.getRdateExdate();
            ICalTimeZone tz = rdate.getTimeZone();
            if (tz != null)
                tzids.add(tz.getID());
        }
    }
    // EXDATE
    for (Iterator iter = recur.subRulesIterator(); iter != null && iter.hasNext(); ) {
        IRecurrence cur = (IRecurrence) iter.next();
        if (cur.getType() == Recurrence.TYPE_SINGLE_DATES) {
            Recurrence.SingleDates sd = (Recurrence.SingleDates) cur;
            RdateExdate exdate = sd.getRdateExdate();
            ICalTimeZone tz = exdate.getTimeZone();
            if (tz != null)
                tzids.add(tz.getID());
        }
    }
    ParsedDateTime recurStart = recur.getStartTime();
    if (recurStart != null) {
        ICalTimeZone tz = recurStart.getTimeZone();
        if (tz != null)
            tzids.add(tz.getID());
    }
    return tzids;
}
Also used : Iterator(java.util.Iterator) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) HashSet(java.util.HashSet)

Example 62 with ParsedDateTime

use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.

the class InviteChanges method diffInvites.

private void diffInvites(Invite inv1, Invite inv2) {
    // Subject
    if (!StringUtil.equal(inv1.getName(), inv2.getName()))
        mChanges |= SUBJECT;
    // LOCATION
    if (!StringUtil.equal(inv1.getLocation(), inv2.getLocation()))
        mChanges |= LOCATION;
    // DTSTART
    boolean dtStartChanged;
    ParsedDateTime dtStart1 = inv1.getStartTime();
    ParsedDateTime dtStart2 = inv2.getStartTime();
    if (dtStart1 == null || dtStart2 == null)
        dtStartChanged = dtStart1 != dtStart2;
    else
        dtStartChanged = !StringUtil.equal(dtStart1.getDateTimePartString(false), dtStart2.getDateTimePartString(false));
    if (dtStartChanged) {
        mChanges |= TIME;
    } else {
        // DTEND
        boolean dtEndChanged;
        ParsedDateTime dtEnd1 = inv1.getEndTime();
        ParsedDateTime dtEnd2 = inv2.getEndTime();
        if (dtEnd1 == null || dtEnd2 == null)
            dtEndChanged = dtEnd1 != dtEnd2;
        else
            dtEndChanged = !StringUtil.equal(dtEnd1.getDateTimePartString(false), dtEnd2.getDateTimePartString(false));
        if (dtEndChanged) {
            mChanges |= TIME;
        } else {
            boolean durationChanged;
            ParsedDuration dur1 = inv1.getDuration();
            ParsedDuration dur2 = inv2.getDuration();
            if (dur1 == null || dur2 == null)
                durationChanged = dur1 != dur2;
            else
                durationChanged = !dur1.equals(dur2);
            if (durationChanged)
                mChanges |= TIME;
        }
    }
    // Recurrence
    boolean recurChanged;
    IRecurrence recur1 = inv1.getRecurrence();
    IRecurrence recur2 = inv2.getRecurrence();
    if (recur1 == null || recur2 == null) {
        recurChanged = recur1 != recur2;
    } else {
        recurChanged = !Recurrence.sameSeriesRules(recur1, recur2);
    }
    if (recurChanged)
        mChanges |= RECURRENCE;
}
Also used : IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) ParsedDuration(com.zimbra.common.calendar.ParsedDuration) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Example 63 with ParsedDateTime

use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.

the class Period method parse.

public static Period parse(String value, ICalTimeZone tz, TimeZoneMap tzmap) throws ServiceException, ParseException {
    String[] parsed = value.split("\\/", 2);
    if (parsed.length != 2 || parsed[0].length() == 0 || parsed[1].length() == 1)
        throw ServiceException.INVALID_REQUEST("Invalid PERIOD value \"" + value + "\"", null);
    ParsedDateTime startTime;
    startTime = ParsedDateTime.parse(parsed[0], tzmap, tz, tzmap.getLocalTimeZone());
    char ch = parsed[1].charAt(0);
    if (ch == 'P' || ch == '+' || ch == '-') {
        ParsedDuration duration = ParsedDuration.parse(parsed[1]);
        return new Period(startTime, duration);
    } else {
        ParsedDateTime endTime = ParsedDateTime.parse(parsed[1], tzmap, tz, tzmap.getLocalTimeZone());
        return new Period(startTime, endTime);
    }
}
Also used : ParsedDuration(com.zimbra.common.calendar.ParsedDuration) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Example 64 with ParsedDateTime

use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.

the class RdateExdate method getDatesCSV.

private String getDatesCSV() {
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Object value : mValues) {
        if (first)
            first = false;
        else
            sb.append(",");
        if (value instanceof ParsedDateTime) {
            ParsedDateTime t = (ParsedDateTime) value;
            sb.append(t.getDateTimePartString(false));
        } else if (value instanceof Period)
            sb.append(value.toString());
    }
    return sb.toString();
}
Also used : ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Example 65 with ParsedDateTime

use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.

the class RdateExdate method toXml.

public Element toXml(Element parent) {
    if (isRDATE() && !DebugConfig.enableRdate) {
        return null;
    }
    Element dateElem = parent.addElement(MailConstants.E_CAL_DATES);
    if (mTimeZone != null)
        dateElem.addAttribute(MailConstants.A_CAL_TIMEZONE, mTimeZone.getID());
    for (Object val : mValues) {
        Element dtvalElem = dateElem.addElement(MailConstants.E_CAL_DATE_VAL);
        if (val instanceof ParsedDateTime) {
            ParsedDateTime dt = (ParsedDateTime) val;
            Element startElem = dtvalElem.addElement(MailConstants.E_CAL_START_TIME);
            startElem.addAttribute(MailConstants.A_CAL_DATETIME, dt.getDateTimePartString(false));
        } else if (val instanceof Period) {
            Period p = (Period) val;
            Element startElem = dtvalElem.addElement(MailConstants.E_CAL_START_TIME);
            startElem.addAttribute(MailConstants.A_CAL_DATETIME, p.getStart().getDateTimePartString(false));
            if (p.hasEnd()) {
                Element endElem = dtvalElem.addElement(MailConstants.E_CAL_END_TIME);
                endElem.addAttribute(MailConstants.A_CAL_DATETIME, p.getEnd().getDateTimePartString(false));
            } else {
                p.getDuration().toXml(dtvalElem);
            }
        }
    }
    return dateElem;
}
Also used : Element(com.zimbra.common.soap.Element) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Aggregations

ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)66 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)23 Invite (com.zimbra.cs.mailbox.calendar.Invite)20 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)18 ParseException (java.text.ParseException)16 ArrayList (java.util.ArrayList)16 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)15 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)14 Element (com.zimbra.common.soap.Element)13 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)11 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)10 Account (com.zimbra.cs.account.Account)10 ZOrganizer (com.zimbra.cs.mailbox.calendar.ZOrganizer)10 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)9 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)8 ZAttendee (com.zimbra.cs.mailbox.calendar.ZAttendee)8 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)7 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)7 ServiceException (com.zimbra.common.service.ServiceException)7 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)7