Maintenance Notice

The bugs.java.com site will be undergoing maintenance on 15th Dec 2017 21:00 PST to 16th Dec 2017 1:00 AM PST.
JDK-4103271 : Calendar Week Nos. 0, 54 invalid
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.1.3,1.1.4
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.5.1
  • CPU: generic,sparc
  • Submitted: 1998-01-12
  • Updated: 1999-07-20
  • Resolved: 1999-07-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other
1.1.8 1.1.8Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
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