[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/29690] New: GregorianCalendar implementation disagrees wi
From: |
tamir dot nitzan at medtronic dot com |
Subject: |
[Bug classpath/29690] New: GregorianCalendar implementation disagrees with itself |
Date: |
2 Nov 2006 18:39:46 -0000 |
Symptom: get an IllegalArgumentException when performing this sequence:
/**** symptom ****/
GregorianCalendar calendar = new GregorianCalendar();
calendar.setLenient(false);
calendar.set(java.util.Calendar.YEAR, 2001);
calendar.set(java.util.Calendar.MONTH, 11);
calendar.set(java.util.Calendar.DATE, 30);
calendar.clear(java.util.Calendar.DST_OFFSET);
calendar.clear(java.util.Calendar.ZONE_OFFSET);
java.util.Date d = calendar.getTime();
/**** end symptom ****/
Note that Dec. 31, 2001 is a valid date.
OK, I confess to not understanding all the code in this implementation (some of
the algorithms are a little cryptic), but I did find this out:
/**** snippet from computeTime() ****/
/* this snippet ends up setting the WEEK_OF_YEAR to 53 */
int weekOfYear = (fields[DAY_OF_YEAR] - relativeWeekday + 6) / 7;
// Do the Correction: getMinimalDaysInFirstWeek() is always in the
// first week.
int minDays = getMinimalDaysInFirstWeek();
int firstWeekday = (7 + getWeekDay(fields[YEAR], minDays)
- getFirstDayOfWeek()) % 7;
if (minDays - firstWeekday < 1)
weekOfYear++;
fields[WEEK_OF_YEAR] = weekOfYear;
/**** end snippet from computeTime() ****/
whereas,
/**** snippet from nonLeniencyCheck() ****/
/* this snippet comes back saying there were only 52 weeks in 2001!! */
int daysInYear = 365 + leap;
daysInYear += (getFirstDayOfMonth(year, 0) - 1); // pad first week
int last = getFirstDayOfMonth(year, 11) + 4;
if (last > 7)
last -= 7;
daysInYear += 7 - last;
int weeks = daysInYear / 7;
if (fields[WEEK_OF_YEAR] < 1 || fields[WEEK_OF_YEAR] > weeks)
throw new IllegalArgumentException("Illegal WEEK_OF_YEAR.");
/**** end snippet from nonLeniencyCheck() ****/
It seems something is wrong in one of these calculations, but honestly this is
so abstract I can't figure out which one is correct :)
Thanks for the help,
Tamir Nitzan
--
Summary: GregorianCalendar implementation disagrees with itself
Product: classpath
Version: 0.92
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: classpath
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tamir dot nitzan at medtronic dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29690
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug classpath/29690] New: GregorianCalendar implementation disagrees with itself,
tamir dot nitzan at medtronic dot com <=