public void testSubDailyFreqs() throws ParseException {
    task.setValue(Task.DUE_DATE, DateUtilities.now() - DateUtilities.ONE_WEEK);
    task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true);

    for (Frequency freq : Frequency.values()) {
      long interval = -1;
      switch (freq) {
        case MINUTELY:
          interval = DateUtilities.ONE_MINUTE;
          break;
        case HOURLY:
          interval = DateUtilities.ONE_HOUR;
          break;
        default:
          continue;
      }

      buildRRule(1, freq);
      nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());

      buildRRule(6, freq);
      nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
      assertDateTimeEquals(freq.toString() + "x6", DateUtilities.now() + 6 * interval, nextDueDate);
      task.setValue(Task.DUE_DATE, nextDueDate);
      assertTrue(task.hasDueTime());
    }
  }
  public void testDailyAndGreaterFreqs() throws ParseException {
    task.setValue(
        Task.DUE_DATE,
        Task.createDueDate(
            Task.URGENCY_SPECIFIC_DAY, DateUtilities.now() - DateUtilities.ONE_WEEK));
    task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true);

    for (int interval = 1; interval < 7; interval++) {
      for (Frequency freq : Frequency.values()) {
        long next = DateUtilities.now();
        switch (freq) {
          case DAILY:
            next += interval * DateUtilities.ONE_DAY;
            break;
          case WEEKLY:
            next += interval * DateUtilities.ONE_WEEK;
            break;
          case MONTHLY:
            next = DateUtilities.addCalendarMonthsToUnixtime(next, interval);
            break;
          case YEARLY:
            next = DateUtilities.addCalendarMonthsToUnixtime(next, interval * 12);
            break;
          default:
            continue;
        }

        buildRRule(interval, freq);
        nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
        assertDateEquals(freq.toString() + "x" + interval, next, nextDueDate);
        task.setValue(Task.DUE_DATE, nextDueDate);
        assertFalse(task.hasDueTime());
      }
    }
  }
  public void testTimeZoneLate() throws ParseException {
    TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
    task.setValue(Task.DUE_DATE, DateUtilities.now() + DateUtilities.ONE_WEEK);
    task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true);
    nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());

    long expected = Task.createDueDate(Task.URGENCY_TOMORROW, 0);
    assertDateEquals("tomorrow", expected, nextDueDate);
  }
  @Test
  public void testDueDateSpecificTime() throws ParseException {
    buildRRule(1, Frequency.DAILY);

    // test specific day & time
    long dayWithTime =
        Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDate(2010, 8, 1, 10, 4, 0).getTime());
    task.setValue(Task.DUE_DATE, dayWithTime);

    long nextDayWithTime = dayWithTime + DateUtilities.ONE_DAY;
    nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal(), false);
    assertDateTimeEquals(nextDayWithTime, nextDueDate);
  }
  @Test
  public void testCompletionDateSpecificTime() throws ParseException {
    buildRRule(1, Frequency.DAILY);

    // test specific day & time
    long dayWithTime =
        Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDate(2010, 8, 1, 10, 4, 0).getTime());
    task.setValue(Task.DUE_DATE, dayWithTime);

    Date todayWithTime = newDate();
    todayWithTime.setHours(10);
    todayWithTime.setMinutes(4);
    todayWithTime.setSeconds(1);
    long nextDayWithTimeLong = todayWithTime.getTime();
    nextDayWithTimeLong += DateUtilities.ONE_DAY;
    nextDayWithTimeLong = nextDayWithTimeLong / 1000L * 1000;

    nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal(), true);
    assertDateTimeEquals(nextDayWithTimeLong, nextDueDate);
  }
 private void computeNextDueDate(boolean fromComplete) throws ParseException {
   nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal(), fromComplete);
 }