Package com.google.ical.values

Examples of com.google.ical.values.RRule


  private void runRecurrenceIteratorTest(
      String rruleText, DateValue dtStart, int limit, String golden,
      DateValue advanceTo, TimeZone tz)
  throws Exception {
    RecurrenceIterator ri = RecurrenceIteratorFactory.createRecurrenceIterator(
        new RRule(rruleText), dtStart, tz);
    if (null != advanceTo) {
      ri.advanceTo(advanceTo);
    }
    StringBuilder sb = new StringBuilder();
    int k = 0, n = limit;
View Full Code Here


    }
  }

  public void testFrequencyLimits() throws Exception {
    RecurrenceIteratorFactory.createRecurrenceIterator(
        new RRule(
            "RRULE:FREQ=SECONDLY;BYSECOND=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,"
            + "15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,"
            + "30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,"
            + "45,46,47,48,49,50,51,52,53,54,55,56,57,58,59"),
            IcalParseUtil.parseDateValue("20000101"), TimeUtils.utcTimezone());
View Full Code Here

  }

  public void testNextCalledWithoutHasNext() throws Exception {
    RecurrenceIterator riter =
      RecurrenceIteratorFactory.createRecurrenceIterator(
        new RRule("RRULE:FREQ=DAILY"),
        IcalParseUtil.parseDateValue("20000101"), TimeUtils.utcTimezone());
    assertEquals(IcalParseUtil.parseDateValue("20000101"), riter.next());
    assertEquals(IcalParseUtil.parseDateValue("20000102"), riter.next());
    assertEquals(IcalParseUtil.parseDateValue("20000103"), riter.next());
  }
View Full Code Here

  }

  public void testNoInstancesGenerated() throws Exception {
    RecurrenceIterator riter =
      RecurrenceIteratorFactory.createRecurrenceIterator(
        new RRule("RRULE:FREQ=DAILY;UNTIL=19990101"),
        IcalParseUtil.parseDateValue("20000101"), TimeUtils.utcTimezone());
    assertTrue(!riter.hasNext());

    assertNull(riter.next());
    assertNull(riter.next());
View Full Code Here

  }

  public void testNoInstancesGenerated2() throws Exception {
    RecurrenceIterator riter =
      RecurrenceIteratorFactory.createRecurrenceIterator(
        new RRule("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30"),
        IcalParseUtil.parseDateValue("20000101"), TimeUtils.utcTimezone());
    assertTrue(!riter.hasNext());
  }
View Full Code Here

  }

  public void testNoInstancesGenerated3() throws Exception {
    RecurrenceIterator riter =
      RecurrenceIteratorFactory.createRecurrenceIterator(
        new RRule("RRULE:FREQ=YEARLY;INTERVAL=4;BYYEARDAY=366"),
        IcalParseUtil.parseDateValue("20010101"), TimeUtils.utcTimezone());
    assertTrue(!riter.hasNext());
  }
View Full Code Here

    for (int i = 0; i < 1000; ++i) {
      System.err.print("<");
      DumpStackTask task = dumpStackIfRunsTooLong();

      boolean timed = rnd.nextBoolean();
      RRule rrule = monkeySeeRRule(timed, false);
      task.rrule = rrule;
      boolean needsTime = rrule.getFreq().compareTo(Frequency.DAILY) < 0
          || rrule.getByHour().length != 0
          || rrule.getByMinute().length != 0
          || rrule.getBySecond().length != 0;
      DateValue dtStart = monkeySeeDateValue(needsTime || maybeNot(timed));
      task.dtStart = task.dtStart;

      RecurrenceIterator it;
      try {
        it = RecurrenceIteratorFactory.createRecurrenceIterator(
            rrule, dtStart, PST);
      } catch (Throwable th) {
        // if we can't create it, don't worry.  This is only testing order of
        // results.
        task.cancel();
        continue;
      }

      try {
        int tries = 200;
        DateValue last = null;
        while (it.hasNext() && --tries >= 0) {
          DateValue dv = it.next();
          assertTrue("last=" + last + ", current=" + dv,
                     null == last || last.compareTo(dv) < 0);
          last = dv;
        }
      } catch (Throwable th) {
        task.cancel();
        System.err.println("\n" + rrule.toIcal() + " / " + dtStart);
        throw th;
      }
      task.cancel();
      System.err.print(">");
    }
View Full Code Here

    Histogram histogram = new Histogram(nRuns);
    for (int i = 0; i < nRuns; ++i) {
      System.err.print("<");
      DumpStackTask task = dumpStackIfRunsTooLong();
      boolean timed = rnd.nextBoolean();
      RRule rrule = monkeySeeRRule(timed, true);
      task.rrule = rrule;
      DateValue dtStart = monkeySeeDateValue(maybeNot(timed));
      task.dtStart = dtStart;
      try {
        RecurrenceIterator it = RecurrenceIteratorFactory
            .createRecurrenceIterator(rrule, dtStart, PST);
        int tries = countLimit;
        long t0 = System.nanoTime();
        while (it.hasNext() && --tries >= 0) {
          it.next();
        }
        long dt = System.nanoTime() - t0;
        histogram.addSample(dt / 1000)// nanoseconds -> microseconds
        totalGened += countLimit - tries;
      } catch (Throwable th) {
        task.cancel();
        System.err.println("\n" + rrule.toIcal() + " / " + dtStart);
        throw th;
      }
      task.cancel();
      System.err.print(">");
    }
View Full Code Here

   * @param timed should any date values have times associated with them.
   * @param wellFormed should the numeric values all be in the appropriate
   *   ranges, and other constraints specified in the spec hold?
   */
  RRule monkeySeeRRule(boolean timed, boolean wellFormed) {
    RRule rrule = new RRule();
    rrule.setName(rnd.nextInt(4) < 1 ? "EXRULE" : "RRULE");
    // pick a frequency
    // This is stretching the definition of well formed, but we don't do
    // more frequently than daily.
    // TODO: allow more frequently than DAILY. BEFORE SUBMIT
    Frequency freq = FREQS[rnd.nextInt(FREQS.length)];
    rrule.setFreq(freq);

    if (rnd.nextBoolean()) {
      // biased towards the beginning of the week
      rrule.setWkSt(WDAYS[((int) Math.abs(rnd.nextGaussian() / 3) * 7) % 7]);
    }

    if (rnd.nextBoolean()) {
      if (rnd.nextBoolean()) {
        rrule.setCount(1 + ((int) (Math.abs(rnd.nextGaussian() * 10))));
      } else {
        rrule.setUntil(monkeySeeDateValue(maybeNot(timed)));
      }
    }

    rrule.setInterval(
        (int) Math.min(0, Math.abs(rnd.nextGaussian() - .5) * 3) + 1);

    int sparsity = 2 + rnd.nextInt(6);

    boolean allowsByDay = freq.compareTo(Frequency.WEEKLY) >= 0;
    if (0 == rnd.nextInt(sparsity) && maybeNot(allowsByDay)) {
      rrule.setByDay(Arrays.asList(monkeySeeWeekdayNumList(freq)));
    }

    if (0 == rnd.nextInt(sparsity)) {
      rrule.setByMonth(monkeySeeIntArray(1, 12, 3, false));
    }

    if (0 == rnd.nextInt(sparsity)) {
      rrule.setByMonthDay(monkeySeeIntArray(-31, 31, 6, false));
    }

    boolean allowWeekNo = maybeNot(Frequency.MONTHLY.compareTo(freq) <= 0);
    if (allowWeekNo && 0 == rnd.nextInt(sparsity)) {
      boolean useYearly = Frequency.YEARLY == freq;
      if (!wellFormed) { useYearly = maybeNot(useYearly); }
      int mag = useYearly ? 52 : 5;
      rrule.setByWeekNo(monkeySeeIntArray(-mag, mag, 1, false));
    }

    if (0 == rnd.nextInt(sparsity)) {
      rrule.setByYearDay(monkeySeeIntArray(-366, 366, 6, false));
    }

    if (0 == rnd.nextInt(sparsity * 2)) {
      rrule.setByHour(monkeySeeIntArray(0, 23, 3, true));
    }

    if (0 == rnd.nextInt(sparsity * 2)) {
      rrule.setByMinute(monkeySeeIntArray(0, 60, 3, true));
    }

    if (0 == rnd.nextInt(sparsity * 2)) {
      rrule.setBySecond(monkeySeeIntArray(0, 60, 3, true));
    }

    boolean largestSetPlural = false;
    int setMag = 10;
    if (0 != rrule.getByMonth().length) {
      largestSetPlural = rrule.getByMonth().length > 1;
    } else if (0 != rrule.getByWeekNo().length) {
      largestSetPlural = rrule.getByWeekNo().length > 1;
    } else if (0 != rrule.getByYearDay().length) {
      largestSetPlural = rrule.getByYearDay().length > 1;
    } else if (0 != rrule.getByMonthDay().length) {
      largestSetPlural = rrule.getByMonthDay().length > 1;
    } else if (0 != rrule.getByDay().size()) {
      List<WeekdayNum> days = rrule.getByDay();
      largestSetPlural = days.size() > 1 || 0 == days.get(0).num;
    } else if (0 != rrule.getByHour().length) {
      largestSetPlural = rrule.getByHour().length > 1;
    } else if (0 != rrule.getByMinute().length) {
      largestSetPlural = rrule.getByMinute().length > 1;
    } else if (0 != rrule.getBySecond().length) {
      largestSetPlural = rrule.getBySecond().length > 1;
    }

    boolean allowSetPos =
      wellFormed ? largestSetPlural : maybeNot(largestSetPlural);
    if (allowSetPos && 0 == rnd.nextInt(4)) {
      rrule.setBySetPos(monkeySeeIntArray(-setMag, setMag, 3, false));
    }

    return rrule;
  }
View Full Code Here

  public static void main(String[] args) throws Exception {
    MonkeyKeyboardTest mkt = new MonkeyKeyboardTest();
    mkt.setUp();
    for (int i = 0; i < 10000; ++i) {
      boolean timed = mkt.rnd.nextBoolean();
      RRule rrule = mkt.monkeySeeRRule(timed, false);
      DateValue dtstart = mkt.monkeySeeDateValue(timed);
      System.out.println("BEGIN:VEVENT\nDTSTART:" + dtstart
                         + "\n" + rrule.toIcal() + "\nEND:VEVENT\n");
    }
  }
View Full Code Here

TOP

Related Classes of com.google.ical.values.RRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.