JDK-4238740 : java.util.Calendar gives different WEEK_OF_YEAR:s for different days of week
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.2.1
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic,windows_98
  • CPU: generic,x86
  • Submitted: 1999-05-17
  • Updated: 1999-07-30
  • Resolved: 1999-07-30
Description

Name: skT88420			Date: 05/17/99


The following program demonstrates that java.util.Calendar
incorrectly gives different WEEK_OF_YEAR:s for different
days of the same week. This occurs (at least) when using 
configuration for Finnish calendar (week begins on Monday 
and first week of year must contain at least 4 days).

Source code:

import java.util.*;

public class CalendarBug
{
    public static void main( String args[] )
    {
        Calendar cal = Calendar.getInstance();

        cal.setFirstDayOfWeek( Calendar.MONDAY );
        cal.setMinimalDaysInFirstWeek( 4 );
		
        cal.set( 1999, Calendar.DECEMBER, 27 );
		
        for( int i=0; i<7; i++ ) {
            System.out.println("Day: "
                +cal.get(Calendar.DAY_OF_MONTH)
                +" Dow: "
                +cal.get(Calendar.DAY_OF_WEEK)
                +" Week: "
                +cal.get(Calendar.WEEK_OF_YEAR) );
            cal.add( Calendar.DATE, 1 );
        }
    }
}

Output:

Day: 27 Dow: 2 Week: 52
Day: 28 Dow: 3 Week: 52
Day: 29 Dow: 4 Week: 52
Day: 30 Dow: 5 Week: 52
Day: 31 Dow: 6 Week: 52
Day: 1 Dow: 7 Week: 53
Day: 2 Dow: 1 Week: 53

While the correct output should be:

Day: 27 Dow: 2 Week: 52
Day: 28 Dow: 3 Week: 52
Day: 29 Dow: 4 Week: 52
Day: 30 Dow: 5 Week: 52
Day: 31 Dow: 6 Week: 52
Day: 1 Dow: 7 Week: 52
Day: 2 Dow: 1 Week: 52

Java version:

java version "1.2.1"
HotSpot VM (1.0fcs, mixed mode, build E)

java full version "JDK-1.2.1-A"
(Review ID: 83145) 
======================================================================

Name: skT88420			Date: 05/17/99


GregorianCalendar "says" that WEEK_OF_YEAR for 1999.12.31 is 52
(which is correct), and that WEEK_OF_YEAR for 2000.01.01 is 53.
That is not correct since the two dates are in the same week.


Her is some source code to demonstrate:

import java.util.*;
public class T {
  public static void main(String[] args) {
    Calendar cal = Calendar.getInstance();
    cal.set(1999, 11, 31);
    System.out.println("Week of year for dec. 31st 1999: " + cal.get(Calendar.WEEK_OF_YEAR));
    System.out.println(cal.toString());
    cal.set(2000, 0, 1);
    System.out.println("Week of year for jan. 1st 2000: " + cal.get(Calendar.WEEK_OF_YEAR));
    System.out.println(cal.toString());
  }
}


And here's the output thatI get:

Week of year for dec. 31st 1999: 52
java.util.GregorianCalendar[time=946653317950,areFieldsSet=true,areAllFieldsSet=
true,lenient=true,zone=java.util.SimpleTimeZone[id=Europe/Copenhagen,offset=3600
000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,sta
rtDay=-1,startDayOfWeek=1,startTime=7200000,endMode=2,endMonth=9,endDay=-1,endDa
yOfWeek=1,endTime=7200000],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=
1999,MONTH=11,WEEK_OF_YEAR=52,WEEK_OF_MONTH=5,DAY_OF_MONTH=31,DAY_OF_YEAR=365,DA
Y_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=5,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=15,SECON
D=17,MILLISECOND=950,ZONE_OFFSET=3600000,DST_OFFSET=0]
Week of year for jan. 1st 2000: 53
java.util.GregorianCalendar[time=946739717950,areFieldsSet=true,areAllFieldsSet=
true,lenient=true,zone=java.util.SimpleTimeZone[id=Europe/Copenhagen,offset=3600
000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,sta
rtDay=-1,startDayOfWeek=1,startTime=7200000,endMode=2,endMonth=9,endDay=-1,endDa
yOfWeek=1,endTime=7200000],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=
2000,MONTH=0,WEEK_OF_YEAR=53,WEEK_OF_MONTH=0,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF
_WEEK=7,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=15,SECOND=17
,MILLISECOND=950,ZONE_OFFSET=3600000,DST_OFFSET=0]


And finally some java version info:

c:\javaapps\w2>java -version
java version "1.2.1"
Classic VM (build JDK-1.2.1-A, native threads)

c:\javaapps\w2>java -fullversion
JAVA.EXE full version "JDK-1.2.1-A"
(Review ID: 83112)
======================================================================

Comments
PUBLIC COMMENTS java.util.Calendar gives wrong WEEK_OF_YEARS for certain day. The problem has been fixed already on 1.2.2.
10-06-2004

EVALUATION The problem no longer happened with 1.2.2 FCS (or Kestrel), though 1.2.1 had it. This has been fixed already. koushi.takahashi@japan 1999-07-30
30-07-1999