United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4103271 : Calendar Week Nos. 0, 54 invalid

Details
Type:
Bug
Submit Date:
1998-01-12
Status:
Closed
Updated Date:
1999-07-20
Project Name:
JDK
Resolved Date:
1999-07-20
Component:
core-libs
OS:
solaris_2.5.1,generic
Sub-Component:
java.util:i18n
CPU:
sparc,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.1.3,1.1.4
Fixed Versions:
1.1.8 (1.1.8)

Related Reports
Backport:
Duplicate:
Relates:
Relates:
Relates:

Sub Tasks

Description
Name: mf23781			Date: 01/12/98

Calendar Week Numbers sometimes have value 0(zero) or 54.
While testing for Year2000 problems, the Week Number value
from aCalendar.get(Calendar.WEEK_OF_YEAR) was checked and found
to have values 0 or 54 for certain Calendar/date values.
The Java API specification makes no mention of possible values
but the values of zero and 54 are confusing to the
programmer/API user.  The week number 54s appear to have just
one day in them, and I think the week zeros ought to be
week 52/53 from the previous year.
The ISO standard 8601 suggests that week numbers should be in the
range 1-53.  There is a summary of the standard at the following
internet address:
  http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html
The results vary according to the Calendar setting of the
FirstDayOfWeek and MinimalDaysInFirstWeek.  The program attached below
attempts to cycle through the variations and display the week
number for various calendar/date values around the end/start of
each year.
Here is a sample of the output with values of 0 and 54:
Test11 indicates that the FirstDayOfWeek and MinimalDaysInWeek
are both set to 1 and so on.
Test11 - 31 Dec 2000            54
Test11 - 31 Dec 2028            54
Test21 - 31 Dec 2012            54
Test12 - 1 Jan 2000             0
Test12 - 1 Jan 2005             0
Test12 - 1 Jan 2011             0
Test12 - 1 Jan 2022             0
Test12 - 1 Jan 2028             0
Test12 - 1 Jan 2033             0
Test13 - 1 Jan 1999             0
Test13 - 2 Jan 1999             0
Test13 - 1 Jan 2000             0
Test13 - 1 Jan 2005             0
Test13 - 1 Jan 2010             0
Test13 - 2 Jan 2010             0
Test13 - 1 Jan 2011             0
Test13 - 1 Jan 2016             0
Test13 - 2 Jan 2016             0
Test13 - 1 Jan 2021             0
Test13 - 2 Jan 2021             0
Test13 - 1 Jan 2022             0
Test13 - 1 Jan 2027             0
Test13 - 2 Jan 2027             0
Test13 - 1 Jan 2028             0
Test13 - 1 Jan 2033             0
Test13 - 1 Jan 2038             0
Test13 - 2 Jan 2038             0
Test14 - 1 Jan 1998             0
Test14 - 2 Jan 1998             0
Test14 - 3 Jan 1998             0
Test14 - 1 Jan 1999             0
Test14 - 2 Jan 1999             0
Test14 - 1 Jan 2000             0
Sample test program follows:
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
import java.text.SimpleDateFormat;
public class TestWeekNo
{
  private static SimpleDateFormat sdf  = new SimpleDateFormat();
  public static void main(String args[])
  {
    int numYears=40, startYear=1997, numDays=15;
    String output, testDesc;
    GregorianCalendar testCal = (GregorianCalendar)Calendar.getInstance();
    for (int firstDay=1; firstDay<=2; firstDay++)
    {
      for (int minDays=1; minDays<=7; minDays++)
      {
        testCal.setMinimalDaysInFirstWeek(minDays);
        testCal.setFirstDayOfWeek(firstDay);
        System.out.println();
        testDesc = ("Test"
                          +String.valueOf(firstDay)
                          +String.valueOf(minDays));
        System.out.println(testDesc + " => 1st day of week="
                          +String.valueOf(firstDay)
                          +", minimum days in first week="
                          +String.valueOf(minDays));
        for (int j=startYear; j<=startYear+numYears; j++)
        {
          testCal.set(j,11,25);
          for(int i=0; i<numDays; i++)
          {
            testCal.add(Calendar.DATE,1);
            output = testDesc + " - " + checkCalendar(testCal);
            System.out.println(output);
          }
        }
      }
    }
  }
  private static String checkCalendar(GregorianCalendar date)
  {
    String output,calWOY;
    int actWOY = date.get(Calendar.WEEK_OF_YEAR);
    Date d = date.getTime();
    calWOY = String.valueOf(actWOY);
    sdf.setCalendar(date);
    sdf.applyPattern("d MMM yyyy");
    output = sdf.format(d) + "\t";
    output = output + "\t" + calWOY;
    return output;
  }
}
======================================================================

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.1.8
1.2beta4

FIXED IN:
1.1.8
1.2beta4

INTEGRATED IN:
1.1.8
1.2beta4

VERIFIED IN:
1.1.8


                                     
2004-06-14
WORK AROUND

Name: mf23781			Date: 01/12/98
======================================================================
                                     
2004-06-11
EVALUATION

Disallow week of year values 0, 54; fix roll (WEEK_OF_YEAR)
helena.shih@eng 1998-03-10

-----------------------------------------------------------------------
This bug was verified by the i18n testing team.
al.smith@eng 1999-03-17
                                     
1998-03-10



Hardware and Software, Engineered to Work Together