JDK-4267450 : (cal) API: Need public API to calculate, format and parse "year of week"
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.2,6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_7,windows_2000
  • CPU: generic,x86,sparc
  • Submitted: 1999-08-31
  • Updated: 2017-05-16
  • Resolved: 2011-03-07
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 Availability Release.

To download the current JDK release, click here.
7 b112Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Name: bb33257			Date: 08/31/99

There is no way to have a date format string for a correct 
"year and week" date format as it is heavily used in Europe, 
especially in businesses. When you order something that takes 
more than a few days to deliver, then you will get something 
like "yyyy'-W'ww" as a delivery date, where "ww" is the week 
of the year and "yyyy" is the year according to the week 
calculation (and '-W' are two literal characters, the format 
looks like 1999-W31 for the 31st week of 1999).

This year can be different from the year according to some of 
the days of that week.

The ISO standard for dates specifies that the first week of the 
year is the one with the first Thursday of the week, and 
specifies Monday as the first day (in ICU locales, this is 
DateTimeElements { 2, 4 }). This is used all over Europe, 
although almost any other setting leads to the same issue.

Taking the ISO/Europe standard as an example, the first day of 
this year, 1999-jan-01, a Friday, belongs to the last week of 
1998. In other words, 1998-W53 is from 1998-dec-28 (Monday) to 
1999-jan-03 (Sunday). Days of one year can belong to a week of 
the next or previous one.

Our locales do not have a localPatternChar for it, nor does 
especially Calendar::EDateFields have a field constant for it. 
However, we do have code for the calculation: 
GregorianCalendar::getISOYear() . Unfortunately, this is (1) a 
private method that is not used anywhere, and (2) it is a 
misnomer, because this year value is not any more or less 
"ISO-y" than the day's year value. A better name would be 
along the line of "YearOfWeek" or so.

In other words, it is right now not possible to have a 
DateFormat that produces a correct year-week date string 
as is used in many countries, but it would be fairly simple 
to add this to our code (and changing all localPatternChars 
to include a new character for this field).

(Review ID: 94685)


EVALUATION Added the following methods to Calendar/GregorianCalendar: public boolean isWeekDateSupported() public int getWeekYear() public void setWeekDate(int weekYear, int weekOfYear, int dayOfWeek) public int getWeeksInWeekYear() Added the following letters to SimpleDateFormat: Letter Date or Time Component Presentation Examples ------------------------------------------------------------ Y Week year Year 2009; 09 u Day number of week Number 1 (1 = Monday, ..., 7 = Sunday) Note that Calendar uses Calendar's own week numbering (1 = SUNDAY, ..., 7 = SATURDAY), while SimpleDateFormat uses the ISO week numbering (1 = Monday, ..., 7 = Sunday).

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang

EVALUATION Need to add a pattern letter for week-based year (cf. POSIX strftime "%G") and provide a public method in GregorianCalendar for calculating it. masayoshi.okutsu@Eng 1999-09-07 See also 4731296. ###@###.### 2005-03-30 01:52:40 GMT