|
Description
|
A DESCRIPTION OF THE PROBLEM :
Problems with formatting dates in conjunction with
datawarehouse data retrieval.
I would suggest another formatting option Y for weeks year.
This way datawarehouse problems concerning the 53rd week
would be possible to handle without extending the
functionability of the current formatting utilities.
By weeks year i mean for instance 31.12.2003 when formatted
using yyyyww will be 200301. This will result in two week
01 in year 2003. If you have an option for weeks year ie
YYYYww you will get 200401 when formatted.
Another option I would love to see in the formatting
classes, is the possibility to use the Calendar class
instead of the Date class... It seems the Date class is
locked to the ISO date standard while you can create an
instance of the GregorianCalendar... In the case above the
yyyyww formatting string would render to 200353 which is
the Gregorian way of handling the extra week in a year.
I reported a bug against simple date format earlier, but
after reading some I found that the formatting classes
don't support the Gregorian version of the calendar, or it
atleast seem that way, so my previous bug report is
invalid, since the ISO way of formatting week is correct in
the SimpleDateFormat class.
(Review ID: 160455)
======================================================================
|
|
Comments
|
Submitted On 29-JAN-2003
myrseth
This is allso a case in 1.3.1, when i tested for the bug in
1.4.1 I allso found this to be true for 1.2.x and 1.3.x aswell.
Submitted On 14-DEC-2007
I have also struck this problem.
One odd effect of the currently incomplete week-of-year support in SimpleDateFormat is that there is no way to "round-trip" a week-based date.
Date d = new Date(2000-1900, 00, 01);
SimpleDateFormat df = new
SimpleDateFormat("ww/yyyy");
Str s1 = df.format(d);
Date d2 = df.parse(s1);
d1 is 2000-01-01
s1 is "52/2000" (wrong: should be 52/1999)
d2 is 2000-12-25 (should be 1999-12-25)
Note that when round-tripping a week date, a few days difference is expected as the date gets rounded to the start-of-week. But the above is a whole year off..
I agree with the original poster that the best solution is probably to introduce a new format option that outputs the "weekYear". The JODA library (www.joda.org) provides an "xxxx" format option to do exactly that.
Having "yyyy" behaviour change depending on whether a "ww" option is present is also possible, but much uglier, and makes this kind of output impossible:
"xxxx-ww yyyy/MM/dd"
If implementing this, then it would be nice to add a "numeric day in week" option too, perhaps as "e" so that a date format could be fully specified as "yyyy-ww-ee". That raises the question about how to number the days of the week; I would recommend ISO-8601 numbering, ie Monday=1, Sunday=7
Request against: Java 1.6.0
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|