United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 4267450 (cal) API: Need public API to calculate, format and parse "year of week"
4267450 : (cal) API: Need public API to calculate, format and parse "year of week"

Details
Type:
Bug
Submit Date:
1999-08-31
Status:
Closed
Updated Date:
2010-10-13
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
core-libs
OS:
solaris_7,generic,windows_2000
Sub-Component:
java.util:i18n
CPU:
x86,sparc,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.2,6
Fixed Versions:
7

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

Sub Tasks

Description
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)

======================================================================

                                    

Comments
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).
                                     
2010-09-02
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-08-06
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
                                     
1999-09-07



Hardware and Software, Engineered to Work Together