Package com.google.ical.values

Examples of com.google.ical.values.Weekday


    WeekdayNum[] wdays = new WeekdayNum[n];
    for (int i = n; --i >= 0;) {
      int num = numRange != 0 && rnd.nextInt(10) < 2
                ? rnd.nextInt(numRange)
                : 0;
      Weekday wday = WDAYS[rnd.nextInt(7)];
      wdays[i] = new WeekdayNum(num, wday);
    }
    return wdays;
  }
View Full Code Here


    //           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
    Weekday dow0 = Weekday.WE;
    int nDays = 31;
    int d0 = 0;

    assertEquals(1, Util.dayNumToDate(dow0, nDays, 1, Weekday.WE, d0, nDays));
    assertEquals(8, Util.dayNumToDate(dow0, nDays, 2, Weekday.WE, d0, nDays));
View Full Code Here

    // 10  5  6  7  8  9 10 11
    // 11 12 13 14 15 16 17 18
    // 12 19 20 21 22 23 24 25
    // 13 26 27 28 29 30 31

    Weekday dow0 = Weekday.SU;
    int nInMonth = 31;
    int nDays = 365;
    int d0 = 59;

    // TODO(msamuel): check that these answers are right
View Full Code Here

          while (i < dates.length && dates[i] < day) { ++i; }
        }

        void generateDates() {
          int nDays;
          Weekday dow0;
          int nDaysInMonth = TimeUtils.monthLength(year, month);
          // index of the first day of the month in the month or year
          int d0;

          if (weeksInYear) {
View Full Code Here

        void checkYear() {
          // if the first day of jan is wkst, then there are 7.
          // if the first day of jan is wkst + 1, then there are 6
          // if the first day of jan is wkst + 6, then there is 1
          Weekday dowJan1 = Weekday.firstDayOfWeekInMonth(year, 1);
          int nDaysInFirstWeek =
            7 - ((7 + dowJan1.javaDayNum - wkst.javaDayNum) % 7);
          // number of days not in any week
          int nOrphanedDays = 0;
          // according to RFC 2445
View Full Code Here

   */
  static Predicate<DateValue> byDayFilter(
      final WeekdayNum[] days, final boolean weeksInYear, final Weekday wkst) {
    return new Predicate<DateValue>() {
        public boolean apply(DateValue date) {
          Weekday dow = Weekday.valueOf(date);

          int nDays;
          // first day of the week in the given year or month
          Weekday dow0;
          // where does date appear in the year or month?
          // in [0, lengthOfMonthOrYear - 1]
          int instance;
          if (weeksInYear) {
            nDays = TimeUtils.yearLength(date.year());
View Full Code Here

      RRule rrule, DateValue dtStart, TimeZone tzid) {
    assert null != tzid;
    assert null != dtStart;

    Frequency freq = rrule.getFreq();
    Weekday wkst = rrule.getWkSt();
    DateValue untilUtc = rrule.getUntil();
    int count = rrule.getCount();
    int interval = rrule.getInterval();
    WeekdayNum[] byDay = rrule.getByDay().toArray(new WeekdayNum[0]);
    int[] byMonth = rrule.getByMonth();
    int[] byMonthDay = rrule.getByMonthDay();
    int[] byWeekNo = rrule.getByWeekNo();
    int[] byYearDay = rrule.getByYearDay();
    int[] bySetPos = rrule.getBySetPos();
    int[] byHour = rrule.getByHour();
    int[] byMinute = rrule.getByMinute();
    int[] bySecond = rrule.getBySecond();

    if (interval <= 0) {  interval = 1; }

    if (null == wkst) {
      wkst = Weekday.MO;
    }

    // Optimize out BYSETPOS where possible.
    if (bySetPos.length != 0) {
      switch (freq) {
        case HOURLY:
          // ;BYHOUR=3,6,9;BYSETPOS=-1,1
          //     is equivalent to
          // ;BYHOUR=3,9
          if (byHour.length != 0 && byMinute.length <= 1
              && bySecond.length <= 1) {
            byHour = filterBySetPos(byHour, bySetPos);
          }
          // Handling bySetPos for rules that are more frequent than daily
          // tends to lead to large amounts of processor being used before other
          // work limiting features can kick in since there many seconds between
          // dtStart and where the year limit kicks in.
          // There are no known use cases for the use of bySetPos with hourly
          // minutely and secondly rules so we just ignore it.
          bySetPos = NO_INTS;
          break;
        case MINUTELY:
          // ;BYHOUR=3,6,9;BYSETPOS=-1,1
          //     is equivalent to
          // ;BYHOUR=3,9
          if (byMinute.length != 0 && bySecond.length <= 1) {
            byMinute = filterBySetPos(byMinute, bySetPos);
          }
          // See bySetPos handling comment above.
          bySetPos = NO_INTS;
          break;
        case SECONDLY:
          // ;BYHOUR=3,6,9;BYSETPOS=-1,1
          //     is equivalent to
          // ;BYHOUR=3,9
          if (bySecond.length != 0) {
            bySecond = filterBySetPos(bySecond, bySetPos);
          }
          // See bySetPos handling comment above.
          bySetPos = NO_INTS;
          break;
        default:
      }
    }

    DateValue start = dtStart;
    if (bySetPos.length != 0) {
      // Roll back till the beginning of the period to make sure that any
      // positive indices are indexed properly.
      // The actual iterator implementation is responsible for anything
      // < dtStart.
      switch (freq) {
        case YEARLY:
          start = dtStart instanceof TimeValue
              ? new DateTimeValueImpl(start.year(), 1, 1, 0, 0, 0)
              : new DateValueImpl(start.year(), 1, 1);
          break;
        case MONTHLY:
          start = dtStart instanceof TimeValue
              ? new DateTimeValueImpl(start.year(), start.month(), 1, 0, 0, 0)
              : new DateValueImpl(start.year(), start.month(), 1);
          break;
        case WEEKLY:
          int d = (7 + wkst.ordinal() - Weekday.valueOf(dtStart).ordinal()) % 7;
          start = TimeUtils.add(dtStart, new DateValueImpl(0, 0, -d));
          break;
        default: break;
      }
    }
View Full Code Here

TOP

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

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.