Package com.google.ical.util

Examples of com.google.ical.util.DTBuilder


      int hour = Integer.parseInt(m.group(4)),
        minute = Integer.parseInt(m.group(5)),
        second = Integer.parseInt(m.group(6));
      boolean utc = null != m.group(7);

      DateValue dv = new DTBuilder(
          year, month, day, hour, minute, second).toDateTime();
      if (!utc && null != tzid) {
        dv = TimeUtils.toUtc(dv, tzid);
      }
      return dv;
    } else {
      return new DTBuilder(year, month, day).toDate();
    }
  }
View Full Code Here


    return goldenDateRange(dateStr, 1);
  }

  public String goldenDateRange(String dateStr, int interval) throws Exception {
    PeriodValue period = IcalParseUtil.parsePeriodValue(dateStr);
    DTBuilder b = new DTBuilder(period.start());
    StringBuilder out = new StringBuilder();
    while (true) {
      DateValue d = b.toDate();
      if (d.compareTo(period.end()) > 0) { break; }
      if (0 != out.length()) { out.append(','); }
      out.append(d);
      b.day += interval;
    }
View Full Code Here

  protected void setUp() throws Exception {
    super.setUp();
    seed = null != rnd ? rnd.nextLong() : System.currentTimeMillis();
    System.out.println("RANDOM SEED " + seed + " : " + getName());
    rnd = new Random(seed);
    refDate = new DTBuilder(1900 + rnd.nextInt(200), 1, rnd.nextInt(366) + 1)
        .toDate();
  }
View Full Code Here

  public void testByYearDayGenerator() throws Exception {
    runGeneratorTests(
        Generators.byYearDayGenerator(new int[] { 1, 5, -1, 100 },
                                      IcalParseUtil.parseDateValue("20060101")),
        new DTBuilder(2006, 1, 1), "day", "1, 5");
    runGeneratorTests(
        Generators.byYearDayGenerator(new int[] { 1, 5, -1, 100 },
                                      IcalParseUtil.parseDateValue("20060102")),
        new DTBuilder(2006, 1, 2), "day", "1, 5");
    runGeneratorTests(
        Generators.byYearDayGenerator(new int[] { 100 },
                                      IcalParseUtil.parseDateValue("20060106")),
        new DTBuilder(2006, 1, 6), "day", "");
    runGeneratorTests(
        Generators.byYearDayGenerator(new int[] {  },
                                      IcalParseUtil.parseDateValue("20060106")),
        new DTBuilder(2006, 1, 6), "day", "");
    runGeneratorTests(
        Generators.byYearDayGenerator(new int[] { 1, 5, -1, 100 },
                                      IcalParseUtil.parseDateValue("20060201")),
        new DTBuilder(2006, 2, 1), "day", "");
    runGeneratorTests(
        Generators.byYearDayGenerator(new int[] { 1, 5, -1, 100 },
                                      IcalParseUtil.parseDateValue("20061201")),
        new DTBuilder(2006, 12, 1), "day", "31");
    runGeneratorTests(
        Generators.byYearDayGenerator(new int[] { 1, 5, -1, 100 },
                                      IcalParseUtil.parseDateValue("20060401")),
        new DTBuilder(2006, 4, 1), "day", "10");
  }
View Full Code Here

  }

  public void testByWeekNoGenerator() throws Exception {
    Generator g = Generators.byWeekNoGenerator(
        new int[] { 22 }, Weekday.SU, IcalParseUtil.parseDateValue("20060101"));
    runGeneratorTests(g, new DTBuilder(2006, 1, 1), "day", "");
    runGeneratorTests(g, new DTBuilder(2006, 2, 1), "day", "");
    runGeneratorTests(g, new DTBuilder(2006, 3, 1), "day", "");
    runGeneratorTests(g, new DTBuilder(2006, 4, 1), "day", "");
    runGeneratorTests(g, new DTBuilder(2006, 5, 1), "day", "28, 29, 30, 31");
    runGeneratorTests(g, new DTBuilder(2006, 6, 1), "day", "1, 2, 3");
    runGeneratorTests(g, new DTBuilder(2006, 7, 1), "day", "");

    // weekstart of monday shifts each week forward by one
    Generator g2 = Generators.byWeekNoGenerator(
        new int[] { 22 }, Weekday.MO, IcalParseUtil.parseDateValue("20060101"));
    runGeneratorTests(g2, new DTBuilder(2006, 1, 1), "day", "");
    runGeneratorTests(g2, new DTBuilder(2006, 2, 1), "day", "");
    runGeneratorTests(g2, new DTBuilder(2006, 3, 1), "day", "");
    runGeneratorTests(g2, new DTBuilder(2006, 4, 1), "day", "");
    runGeneratorTests(g2, new DTBuilder(2006, 5, 1), "day", "29, 30, 31");
    runGeneratorTests(g2, new DTBuilder(2006, 6, 1), "day", "1, 2, 3, 4");
    runGeneratorTests(g2, new DTBuilder(2006, 7, 1), "day", "");

    // 2004 with a week start of monday has no orphaned days.
    // 2004-01-01 falls on Thursday
    Generator g3 = Generators.byWeekNoGenerator(
        new int[] { 14 }, Weekday.MO, IcalParseUtil.parseDateValue("20040101"));
    runGeneratorTests(g3, new DTBuilder(2004, 1, 1), "day", "");
    runGeneratorTests(g3, new DTBuilder(2004, 2, 1), "day", "");
    runGeneratorTests(g3, new DTBuilder(2004, 3, 1), "day", "29, 30, 31");
    runGeneratorTests(g3, new DTBuilder(2004, 4, 1), "day", "1, 2, 3, 4");
    runGeneratorTests(g3, new DTBuilder(2004, 5, 1), "day", "");
  }
View Full Code Here

      new WeekdayNum(-2, Weekday.TU) // second to last tuesday
    };
    Generator g = Generators.byDayGenerator(
        days, false, IcalParseUtil.parseDateValue("20060101"));
    runGeneratorTests(
        g, new DTBuilder(2006, 1, 1), "day", "1, 2, 8, 15, 22, 24, 29, 30");
    runGeneratorTests(
        g, new DTBuilder(2006, 2, 1), "day", "5, 6, 12, 19, 21, 26");
  }
View Full Code Here

  public void testByMonthDayGenerator() throws Exception {
    int[] monthDays = new int[] { 1, 15, 29 };
    runGeneratorTests(Generators.byMonthDayGenerator(
                          monthDays, IcalParseUtil.parseDateValue("20060101")),
                      new DTBuilder(2006, 1, 1), "day", "1, 15, 29");
    runGeneratorTests(Generators.byMonthDayGenerator(
                          monthDays, IcalParseUtil.parseDateValue("20060115")),
                      new DTBuilder(2006, 1, 15), "day", "1, 15, 29");
    runGeneratorTests(Generators.byMonthDayGenerator(
                          monthDays, IcalParseUtil.parseDateValue("20060201")),
                      new DTBuilder(2006, 2, 1), "day", "1, 15");
    runGeneratorTests(Generators.byMonthDayGenerator(
                          monthDays, IcalParseUtil.parseDateValue("20060216")),
                      new DTBuilder(2006, 2, 16), "day", "1, 15");

    monthDays = new int[] { 1, -30, 30 };
    Generator g2 = Generators.byMonthDayGenerator(
        monthDays, IcalParseUtil.parseDateValue("20060101"));
    runGeneratorTests(g2,
                      new DTBuilder(2006, 1, 1), "day", "1, 2, 30");
    runGeneratorTests(g2,
                      new DTBuilder(2006, 2, 1), "day", "1");
    runGeneratorTests(g2,
                      new DTBuilder(2006, 3, 1), "day", "1, 2, 30");
    runGeneratorTests(g2,
                      new DTBuilder(2006, 4, 1), "day", "1, 30");
  }
View Full Code Here

  public void testByMonthGenerator() throws Exception {
    runGeneratorTests(Generators.byMonthGenerator(
                          new int[] { 2, 8, 6, 10 },
                          IcalParseUtil.parseDateValue("20060101")),
                      new DTBuilder(2006, 1, 1), "month", "2, 6, 8, 10");
    Generator g = Generators.byMonthGenerator(
        new int[] { 2, 8, 6, 10 }, IcalParseUtil.parseDateValue("20060401"));
    runGeneratorTests(g, new DTBuilder(2006, 4, 1), "month", "2, 6, 8, 10");
    runGeneratorTests(g, new DTBuilder(2007, 11, 1), "month", "2, 6, 8, 10");
  }
View Full Code Here

  public void testByYearGenerator() throws Exception {
    runGeneratorTests(
        Generators.byYearGenerator(new int[] { 1066, 1492, 1876, 1975, 2006 },
                                   IcalParseUtil.parseDateValue("20060101")),
        new DTBuilder(2006, 1, 1), "year", "2006");
    runGeneratorTests(
        Generators.byYearGenerator(new int[] { 1066, 1492, 1876, 1975, 2006 },
                                   IcalParseUtil.parseDateValue("20070101")),
        new DTBuilder(2007, 1, 1), "year", "");
    runGeneratorTests(
        Generators.byYearGenerator(new int[] { 1066, 1492, 1876, 1975, 2006 },
                                   IcalParseUtil.parseDateValue("10660701")),
        new DTBuilder(1066, 7, 1), "year", "1066, 1492, 1876, 1975, 2006");
    runGeneratorTests(
        Generators.byYearGenerator(new int[] { 1066, 1492, 1876, 1975, 2006 },
                                   IcalParseUtil.parseDateValue("19000701")),
        new DTBuilder(1900, 7, 1), "year", "1975, 2006");
  }
View Full Code Here

  public void testSerialDayGenerator() throws Exception {
    runGeneratorTests(
        Generators.serialDayGenerator(
            1, IcalParseUtil.parseDateValue("20060115")),
        new DTBuilder(2006, 1, 15), "day",
          "15, 16, 17, 18, 19, 20, 21, 22, 23, 24, "
          + "25, 26, 27, 28, 29, 30, 31");
    runGeneratorTests(Generators.serialDayGenerator(
                          1, IcalParseUtil.parseDateValue("20060101")),
                      new DTBuilder(2006, 1, 1), "day",
                      "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");
    Generator g = Generators.serialDayGenerator(
        2, IcalParseUtil.parseDateValue("20060101"));
    runGeneratorTests(
        g, new DTBuilder(2006, 1, 1), "day",
        "1, 3, 5, 7, 9, "
        + "11, 13, 15, 17, 19, "
        + "21, 23, 25, 27, 29, "
        + "31");
    // now g should start on the second of February
    runGeneratorTests(
        g, new DTBuilder(2006, 2, 1), "day",
        "2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28");
    // and if we skip way ahead to June, it should start on the 1st
    // This test is limited to one output value
    runGeneratorTests(g,
                      new DTBuilder(2006, 4, 1), "day", "1", 1);
    // test with intervals longer than 30 days
    Generator g2 = Generators.serialDayGenerator(
        45, IcalParseUtil.parseDateValue("20060101"));
    runGeneratorTests(g2, new DTBuilder(2006, 1, 1), "day", "1");
    runGeneratorTests(g2, new DTBuilder(2006, 2, 1), "day", "15");
    runGeneratorTests(g2, new DTBuilder(2006, 3, 1), "day", "");
    runGeneratorTests(g2, new DTBuilder(2006, 4, 1), "day", "1");
    runGeneratorTests(g2, new DTBuilder(2006, 5, 1), "day", "16");
  }
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.