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

Incorrect WEEK_OF_MONTH after changing First Day Of Week

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.4.0
    • core-libs
    • hopper
    • generic
    • generic



      Name: nt126004 Date: 12/04/2001


      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

        Description of the problem is given below at the start of program.
      Please run following program.

      import java.util.*;

      /**
      04 Nov 2001 falls on a Sunday.
      For this date, GregorianCalendar returns week number as two. This is correct
      because default first day of week is SUNDAY (indicated by 1 in output).
      --Week#1--
      Sun
      Mon
      Tue
      Wed
      Thu 1
      Fri 2
      Sat 3
      --Week#2--
      Sun 4
      :

      If first day of week is changed to MONDAY, it should return week number as one.

      BUT IT STILL RETURNS TWO.

      --Week#1--
      Mon
      Tue
      Wed
      Thu 1
      Fri 2
      Sat 3
      Sun 4
      */

      public class WeekNbr
      {
        public static void main(String[] args) {
          GregorianCalendar day = new GregorianCalendar (2001, Calendar.NOVEMBER, 04);

          printCalDetails(day);
            day.setFirstDayOfWeek(Calendar.MONDAY);
          printCalDetails(day);
        }

        static private void printCalDetails(GregorianCalendar cal) {
          System.out.println( "" + cal.getTime()+ " | MinDays=" + cal.getMinimalDaysInFirstWeek() + " | FirstDOW=" + cal.getFirstDayOfWeek() + " | Week#" +cal.get(Calendar.WEEK_OF_MONTH));
        }
      }
      (Review ID: 136315)
      ======================================================================

            okutsu Masayoshi Okutsu
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: