Package com.google.ical.util

Examples of com.google.ical.util.DTBuilder


  public void testByMinuteGenerator() throws Exception {
    DateValue dtStart = new DateTimeValueImpl(2011, 8, 8, 5, 0, 17);
    Generator g = Generators.byMinuteGenerator(
        new int[] { 3, 57, 20, 3 }, dtStart);
    DTBuilder b = new DTBuilder(dtStart);
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 5:3:17", b.toString());
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 5:20:17", b.toString());
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 5:57:17", b.toString());
    assertFalse(g.generate(b));
    ++b.hour;
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 6:3:17", b.toString());
  }
View Full Code Here


  }

  public void testSingleByMinuteGenerator() throws Exception {
    DateValue dtStart = new DateTimeValueImpl(2011, 8, 8, 5, 30, 17);
    Generator g = Generators.byMinuteGenerator(new int[0], dtStart);
    DTBuilder b = new DTBuilder(dtStart);
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 5:30:17", b.toString());
    assertFalse(g.generate(b));
    ++b.hour;
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 6:30:17", b.toString());
    assertFalse(g.generate(b));
    b.day += 1;
    assertTrue(g.generate(b));
    assertEquals("2011-8-9 6:30:17", b.toString());
    assertFalse(g.generate(b));
  }
View Full Code Here

  }

  public void testSerialSecondGenerator() throws Exception {
    DateValue dtStart = new DateTimeValueImpl(2011, 8, 8, 19, 1, 23);
    Generator g = Generators.serialSecondGenerator(25, dtStart);
    DTBuilder b = new DTBuilder(dtStart);
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:1:23", b.toString());
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:1:48", b.toString());
    assertFalse(g.generate(b));
    b.minute += 1;
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:2:13", b.toString());
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:2:38", b.toString());
    assertFalse(g.generate(b));
    b.minute += 1;
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:3:3", b.toString());
    b.minute += 1;
    // skipped 2:28, 2:53
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:4:18", b.toString());
  }
View Full Code Here

  public void testBySecondGenerator() throws Exception {
    DateValue dtStart = new DateTimeValueImpl(2011, 8, 8, 19, 1, 23);
    Generator g = Generators.bySecondGenerator(
        new int[] { 25, 48, 2 }, dtStart);
    DTBuilder b = new DTBuilder(dtStart);
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:1:25", b.toString());
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:1:48", b.toString());
    assertFalse(g.generate(b));
    ++b.minute;
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:2:2", b.toString());
  }
View Full Code Here

  }

  public void testSingleBySecondGenerator() throws Exception {
    DateValue dtStart = new DateTimeValueImpl(2011, 8, 8, 19, 1, 23);
    Generator g = Generators.bySecondGenerator(new int[0], dtStart);
    DTBuilder b = new DTBuilder(dtStart);
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:1:23", b.toString());
    assertFalse(g.generate(b));
    ++b.minute;
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:2:23", b.toString());
    assertFalse(g.generate(b));
    ++b.minute;
    assertTrue(g.generate(b));
    assertEquals("2011-8-8 19:3:23", b.toString());
  }
View Full Code Here

    ints = Util.uniquify(ints);
    assertEquals("0,1,2,3,4,7,8", arrToString(ints));
  }

  public void testRollToNextWeekStart() throws Exception {
    DTBuilder builder;

    builder = new DTBuilder(2006, 1, 23);
    Util.rollToNextWeekStart(builder, Weekday.TU);
    assertEquals("20060124", builder.toDate().toString());

    builder = new DTBuilder(2006, 1, 24);
    Util.rollToNextWeekStart(builder, Weekday.TU);
    assertEquals("20060124", builder.toDate().toString());

    builder = new DTBuilder(2006, 1, 25);
    Util.rollToNextWeekStart(builder, Weekday.TU);
    assertEquals("20060131", builder.toDate().toString());

    builder = new DTBuilder(2006, 1, 23);
    Util.rollToNextWeekStart(builder, Weekday.MO);
    assertEquals("20060123", builder.toDate().toString());

    builder = new DTBuilder(2006, 1, 24);
    Util.rollToNextWeekStart(builder, Weekday.MO);
    assertEquals("20060130", builder.toDate().toString());

    builder = new DTBuilder(2006, 1, 25);
    Util.rollToNextWeekStart(builder, Weekday.MO);
    assertEquals("20060130", builder.toDate().toString());

    builder = new DTBuilder(2006, 1, 31);
    Util.rollToNextWeekStart(builder, Weekday.MO);
    assertEquals("20060206", builder.toDate().toString());
  }
View Full Code Here

        /** ndays in the last month encountered */
        int nDays;

        {
          // step back one interval
          DTBuilder dtStartMinus1B = new DTBuilder(dtStart);
          dtStartMinus1B.day -= interval;
          DateValue dtStartMinus1 = dtStartMinus1B.toDate();
          year = dtStartMinus1.year();
          month = dtStartMinus1.month();
          date = dtStartMinus1.day();
          nDays = TimeUtils.monthLength(year, month);
        }
View Full Code Here

      final int interval, final Weekday wkst, final DateValue dtStart) {
    return new Predicate<DateValue>() {
      DateValue wkStart;
      {
        // the latest day with day of week wkst on or before dtStart
        DTBuilder wkStartB = new DTBuilder(dtStart);
        wkStartB.day -=
          (7 + Weekday.valueOf(dtStart).javaDayNum - wkst.javaDayNum) % 7;
        wkStart = wkStartB.toDate();
      }

      public boolean apply(DateValue date) {
        int daysBetween = TimeUtils.daysBetween(date, wkStart);
        if (daysBetween < 0) {
View Full Code Here

  /**
   * the earliest day on or after d that falls on wkst.
   * @param wkst the day of the week that the week starts on
   */
  static DateValue nextWeekStart(DateValue d, Weekday wkst) {
    DTBuilder builder = new DTBuilder(d);
    builder.day += (7 - ((7 + (Weekday.valueOf(d).javaDayNum
                               - wkst.javaDayNum)) % 7))
                   % 7;
    return builder.toDate();
  }
View Full Code Here

    this.canShortcutAdvance_ = canShortcutAdvance;

    int initWorkLimit = 1000;

    // Initialize the builder and skip over any extraneous start instances
    DTBuilder builder = new DTBuilder(dtStart);
    this.builder_ = builder;
    // Apply the generators from largest field to smallest so we can start by
    // applying the smallest field iterator when asked to generate a date.
    try {
      Generator[] toInitialize;
View Full Code Here

TOP

Related Classes of com.google.ical.util.DTBuilder

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.