JDK-4746307 : API: Date reports wrong week in the end of year 2002
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-09-12
  • Updated: 2002-09-13
  • Resolved: 2002-09-13
Related Reports
Duplicate :  
Description

Name: nt126004			Date: 09/12/2002


FULL PRODUCT VERSION :
C:\trunc\project\planit>java -version
java version "1.3.1_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_04-b02)
Java HotSpot(TM) Client VM (build 1.3.1_04-b02, mixed mode)

and

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

FULL OPERATING SYSTEM VERSION :
5.0.2195 Service Pack 2 Build 2195

ADDITIONAL OPERATING SYSTEMS :
None



A DESCRIPTION OF THE PROBLEM :
When week 52 is used and you are supposed to cycle to week
01 again, year does not follow.

So for instance 31.12.2002 renders to week 2002 01, it
should be 2003 01 if I am not mistaken, and this occurs for
other years aswell... The code to reproduce is within
Reproducibility box.'

I got the same error in build 1.3.1_02 aswell...

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the code belove...
2. Run it...
3. Scratch your head and get anoyed :)


EXPECTED VERSUS ACTUAL BEHAVIOR :
Here is the output from the little code piece above:
*****************************************************
C:\>java Foo
Date initiated: Tue Dec 31 00:00:00 CET 2002
Week expected is 2003-01
Rendered week : 2002-01
*****************************************************
I could live with 2002-53 because then dataretrieval would
still work properly from the datawarehouse... But when it
rolls the year back by one (or forgets to roll the year) it
is impossible.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
//**********************************
//Testcode to demonstrate
//wrong yearhandling in
//java.util.Date or SimpleDateFormat
//**********************************
//filename: Foo.java
//**********************************
import java.util.*;
import java.text.*;

public class Foo {
  public static void main(String args[]) {
    DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
    Date date = null;
    try {
      date = df.parse("31.12.2002");
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("Date initiated: "+date.toString());
    df = new SimpleDateFormat("yyyy-ww");
    System.out.println("Week expected is 2003-01");
    System.out.println("Rendered week : "+df.format(date));
  }
}
---------- END SOURCE ----------
(Review ID: 160347) 
======================================================================

Comments
EVALUATION GregorianCalendar uses the ISO 8601-style week numbering with Gregorian (or Julian) years, which creats the reported problem. ###@###.### 2002-09-13
13-09-2002