Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6452848

(cal) Conflict resolution doesn't work as specified in Calendar API doc

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 1.2.2
    • core-libs
    • 1.1
    • b08
    • generic
    • generic
    • Verified

      After the Calendar fields have been normalized, changing a date by setting DAY_OF_WEEK and DAY_OF_WEEK_IN_MONTH doesn't work if DAY_OF_WEEK_IN_MONTH is set before DAY_OF_WEEK.

      Test case:

          public static Date nextNthDayOf(int nth, int dayOfWeek, int hour, int minute, int second) {
      Calendar cal = new GregorianCalendar();
      int nthWeek = cal.get(cal.DAY_OF_WEEK_IN_MONTH);
      System.out.println("dowim=" + nthWeek + ", nth=" + nth);
      if (nthWeek > nth) {
      cal.add(cal.MONTH, +1);
      } else if (nthWeek == nth) {
      int dow = cal.get(cal.DAY_OF_WEEK);
      if (dow >= dayOfWeek) {
      cal.add(cal.MONTH, +1);
      }
      }
      cal.set(cal.DAY_OF_WEEK_IN_MONTH, nth);
      cal.set(cal.DAY_OF_WEEK, dayOfWeek);
      cal.set(cal.HOUR_OF_DAY, hour);
      cal.set(cal.MINUTE, minute);
      cal.set(cal.SECOND, second);
      cal.set(cal.MILLISECOND, 0);
      return cal.getTime();
          }

            okutsu Masayoshi Okutsu
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: