Beispiel #1
0
  private MSRecurrence getRecurrence(EventRecurrence recurrence) {
    if (recurrence.getKind() == RecurrenceKind.none) {
      return null;
    }

    MSRecurrence r = new MSRecurrence();
    switch (recurrence.getKind()) {
      case daily:
        r.setType(RecurrenceType.DAILY);
        break;
      case monthlybydate:
        r.setType(RecurrenceType.MONTHLY);
        break;
      case monthlybyday:
        r.setType(RecurrenceType.MONTHLY_NDAY);
        break;
      case weekly:
        r.setType(RecurrenceType.WEEKLY);
        r.setDayOfWeek(RecurrenceDayOfWeekConverter.fromRecurrenceDays(recurrence.getDays()));
        break;
      case yearly:
        r.setType(RecurrenceType.YEARLY);
        break;
      case yearlybyday:
        r.setType(RecurrenceType.YEARLY_NDAY);
        break;
      case none:
        r.setType(null);
        break;
    }
    r.setUntil(recurrence.getEnd());

    r.setInterval(recurrence.getFrequence());

    return r;
  }
Beispiel #2
0
  private EventRecurrence getRecurrence(MSTask mst) {
    if (mst.getRecurrence() == null) {
      return null;
    }
    MSRecurrence pr = mst.getRecurrence();
    EventRecurrence or = new EventRecurrence();
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

    int multiply = 0;
    switch (pr.getType()) {
      case DAILY:
        or.setKind(RecurrenceKind.daily);
        or.setDays(RecurrenceDayOfWeekConverter.toRecurrenceDays(pr.getDayOfWeek()));
        multiply = Calendar.DAY_OF_MONTH;
        break;
      case MONTHLY:
        or.setKind(RecurrenceKind.monthlybydate);
        multiply = Calendar.MONTH;
        break;
      case MONTHLY_NDAY:
        or.setKind(RecurrenceKind.monthlybyday);
        multiply = Calendar.MONTH;
        break;
      case WEEKLY:
        or.setKind(RecurrenceKind.weekly);
        or.setDays(RecurrenceDayOfWeekConverter.toRecurrenceDays(pr.getDayOfWeek()));
        multiply = Calendar.WEEK_OF_YEAR;
        break;
      case YEARLY:
        or.setKind(RecurrenceKind.yearly);
        cal.setTimeInMillis(mst.getUtcStartDate().getTime());
        cal.set(Calendar.DAY_OF_MONTH, pr.getDayOfMonth());
        cal.set(Calendar.MONTH, pr.getMonthOfYear() - 1);
        mst.setUtcStartDate(cal.getTime());
        or.setFrequence(1);
        multiply = Calendar.YEAR;
        break;
      case YEARLY_NDAY:
        or.setKind(RecurrenceKind.yearly);
        multiply = Calendar.YEAR;
        break;
    }

    // interval
    if (pr.getInterval() != null) {
      or.setFrequence(pr.getInterval());
    }

    // occurence or end date
    Date endDate = null;
    if (pr.getOccurrences() != null && pr.getOccurrences() > 0) {
      cal.setTimeInMillis(pr.getStart().getTime());
      cal.add(multiply, pr.getOccurrences() - 1);
      endDate = new Date(cal.getTimeInMillis());
    } else {
      endDate = pr.getUntil();
    }
    or.setEnd(endDate);

    return or;
  }