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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
      1.1
    • Resolved In Build:
      b08
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      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();
          }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: