Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4267450
Votes 50
Synopsis (cal) API: Need public API to calculate, format and parse "year of week"
Category java:classes_util_i18n
Reported Against 1.4 , 1.2.2 , 1.4.2 , tiger-beta2
Release Fixed
State 7-Fix in Progress, bug
Priority: 4-Low
Related Bugs 4103271 , 4731296 , 4746307 , 4862638 , 4966499 , 4985363 , 6900597 , 4977067 , 4962427 , 6218127
Submit Date 31-AUG-1999
Description


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)

======================================================================
Posted Date : 2006-11-15 05:04:41.0
Work Around
N/A
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.
  xxxxx@xxxxx   1999-09-07

See also 4731296.
  xxxxx@xxxxx   2005-03-30 01:52:40 GMT
Comments
  
  Include a link with my name & email   

Submitted On 10-NOV-2002
mgrev
Come on now, fix this!

It's not that hard...


Submitted On 04-JAN-2003
mgrev
I'm using this at the moment, as a quick & dirty fix. No 
guarantees though...

public final static int getYear_WeekBased(GregorianCalendar 
cal)
{
   int year = cal.get(Calendar.YEAR);	
   int week = cal.get(Calendar.WEEK_OF_YEAR);
   int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);

   if (week == 1 && dayOfMonth > 20)
      return year + 1;

   if (week >= 52 && dayOfMonth < 10)
      return year - 1;

   return year;
}


Submitted On 01-JAN-2005
mhdfi6
I ran into this bug today and just want to take the opportunity to congratulate it on now being more than 5 years old!


Submitted On 19-JAN-2005
mgrev
Ok, now I have gotten three updates that this bug has changed the last couple of days. What


Submitted On 19-JAN-2005
mgrev
And it cuts comments!

So darn amaturish!!


Submitted On 07-OCT-2006
sj_colebourne
There is a solution in Java, and that is to use the Joda-Time library - http://joda-time.sourceforge.net - where 'weekyear' is fully supported, along with the ISO week based formats such as 2006-W12-5.

For reference, Joda-Time uses the letter 'x' to represent 'weekyear' in our SimpleDateFormat equivalent.


Submitted On 28-OCT-2006
s690716
Why a bug database, if errors are unhandled for more than 7 year?


Submitted On 18-JAN-2007
Sheepy
Because there are more urgent, show-stopper bugs and rfe to fix/do.  At least you can get arond this with a custom function.

But be patient.  It has already made its way to Top 25, showing that the bug database is truely making/allowing progress. =)


Submitted On 04-JAN-2008
Bruno_Cardoso
I also had this problem recently as I describe it here:
http://bmcardoso.blogspot.com/2008/01/javautilgregoriancalendar.html

However, I don't really see this as a bug. I see this as a lack of functionality. Calendar doesn't have a way to directly give you the year of a certain week so you have to do this yourself. 

I do agree however that creating a Calendar.YEAR_OF_WEEK constant would prevent people for using the Calendar.YEAR by mistake believing that this gives you the YEAR for the week you want.



PLEASE NOTE: JDK6 is formerly known as Project Mustang