Hi all,
This commit reorders the parts of GregorianCalendar.computeTime() that
decide which fields to use into the priority order outlined in
http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#date_resolution.
The previous incarnation was in an odd order and had some fun fallback
cases. It's not correct yet -- it's not so much a question of which
fields are set as it is a question of which fields were most recently
set -- and this commit breaks a couple of things that relied on the
previous, ordering. So it's on a branch :)
Cheers,
Gary
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.9239
diff -u -r1.9239 ChangeLog
--- ChangeLog 12 Apr 2007 15:09:31 -0000 1.9239
+++ ChangeLog 12 Apr 2007 15:27:00 -0000
@@ -1,3 +1,8 @@
+2007-04-12 Gary Benson <[EMAIL PROTECTED]>
+
+ * java/util/GregorianCalendar.java
+ (computeTime): Reorder the cases into priority order.
+
2007-04-12 Christian Thalinger <[EMAIL PROTECTED]>
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c
Index: java/util/GregorianCalendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/GregorianCalendar.java,v
retrieving revision 1.49
diff -u -r1.49 GregorianCalendar.java
--- java/util/GregorianCalendar.java 5 Apr 2007 12:52:44 -0000 1.49
+++ java/util/GregorianCalendar.java 12 Apr 2007 15:27:00 -0000
@@ -510,71 +510,78 @@
int month = fields[MONTH];
int day = fields[DAY_OF_MONTH];
+ int hour = fields[HOUR_OF_DAY];
int minute = fields[MINUTE];
int second = fields[SECOND];
int millis = fields[MILLISECOND];
int[] month_days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int[] dayCount = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
- int hour = 0;
if (! isLenient())
nonLeniencyCheck();
- if (! isSet[MONTH] && (! isSet[DAY_OF_WEEK] || isSet[WEEK_OF_YEAR]))
+ if (isSet[YEAR])
{
- // 5: YEAR + DAY_OF_WEEK + WEEK_OF_YEAR
- if (isSet[WEEK_OF_YEAR])
+ if (isSet[MONTH])
{
- int first = getFirstDayOfMonth(year, 0);
- int offs = 1;
- int daysInFirstWeek = getFirstDayOfWeek() - first;
- if (daysInFirstWeek <= 0)
- daysInFirstWeek += 7;
-
- if (daysInFirstWeek < getMinimalDaysInFirstWeek())
- offs += daysInFirstWeek;
- else
- offs -= 7 - daysInFirstWeek;
- month = 0;
- day = offs + 7 * (fields[WEEK_OF_YEAR] - 1);
- offs = fields[DAY_OF_WEEK] - getFirstDayOfWeek();
-
- if (offs < 0)
- offs += 7;
- day += offs;
+ if (isSet[DAY_OF_MONTH])
+ {
+ // 1: YEAR + MONTH + DAY_OF_MONTH
+ }
+ else if (isSet[DAY_OF_WEEK])
+ {
+ int first = getFirstDayOfMonth(year, month);
+
+ if (isSet[WEEK_OF_MONTH])
+ {
+ // 2: YEAR + MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
+ int offs = 1;
+ int daysInFirstWeek = getFirstDayOfWeek() - first;
+ if (daysInFirstWeek <= 0)
+ daysInFirstWeek += 7;
+
+ if (daysInFirstWeek < getMinimalDaysInFirstWeek())
+ offs += daysInFirstWeek;
+ else
+ offs -= 7 - daysInFirstWeek;
+
+ day = offs + 7 * (fields[WEEK_OF_MONTH] - 1);
+ offs = fields[DAY_OF_WEEK] - getFirstDayOfWeek();
+ if (offs < 0)
+ offs += 7;
+ day += offs;
+ }
+ else if (isSet[DAY_OF_WEEK_IN_MONTH])
+ {
+ // 3: YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
+ if (fields[DAY_OF_WEEK_IN_MONTH] < 0)
+ {
+ month++;
+ first = getFirstDayOfMonth(year, month);
+ day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH]);
+ }
+ else
+ day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH] - 1);
+
+ int offs = fields[DAY_OF_WEEK] - first;
+ if (offs < 0)
+ offs += 7;
+ day += offs;
+ }
+ }
}
else
{
- // 4: YEAR + DAY_OF_YEAR
- month = 0;
- day = fields[DAY_OF_YEAR];
- }
- }
- else
- {
- if (isSet[DAY_OF_WEEK])
- {
- int first = getFirstDayOfMonth(year, month);
-
- // 3: YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
- if (isSet[DAY_OF_WEEK_IN_MONTH])
+ if (isSet[DAY_OF_YEAR])
{
- if (fields[DAY_OF_WEEK_IN_MONTH] < 0)
- {
- month++;
- first = getFirstDayOfMonth(year, month);
- day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH]);
- }
- else
- day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH] - 1);
-
- int offs = fields[DAY_OF_WEEK] - first;
- if (offs < 0)
- offs += 7;
- day += offs;
+ // 4: YEAR + DAY_OF_YEAR
+ month = 0;
+ day = fields[DAY_OF_YEAR];
}
- else
- { // 2: YEAR + MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
+ else if (isSet[DAY_OF_WEEK] && isSet[WEEK_OF_YEAR])
+ {
+ // 5: YEAR + DAY_OF_WEEK + WEEK_OF_YEAR
+ int first = getFirstDayOfMonth(year, 0);
int offs = 1;
int daysInFirstWeek = getFirstDayOfWeek() - first;
if (daysInFirstWeek <= 0)
@@ -584,31 +591,34 @@
offs += daysInFirstWeek;
else
offs -= 7 - daysInFirstWeek;
-
- day = offs + 7 * (fields[WEEK_OF_MONTH] - 1);
+ month = 0;
+ day = offs + 7 * (fields[WEEK_OF_YEAR] - 1);
offs = fields[DAY_OF_WEEK] - getFirstDayOfWeek();
+
if (offs < 0)
offs += 7;
day += offs;
}
}
-
- // 1: YEAR + MONTH + DAY_OF_MONTH
}
if (era == BC && year > 0)
year = 1 - year;
// rest of code assumes day/month/year set
// should negative BC years be AD?
+
// get the hour (but no check for validity)
- if (isSet[HOUR])
+ if (isSet[HOUR_OF_DAY])
{
+ // 1. HOUR_OF_DAY
+ }
+ else if (isSet[HOUR] && isSet[AM_PM])
+ {
+ // 2. AM_PM + HOUR
hour = fields[HOUR];
if (fields[AM_PM] == PM)
hour += 12;
}
- else
- hour = fields[HOUR_OF_DAY];
// Read the era,year,month,day fields and convert as appropriate.
// Calculate number of milliseconds into the day