Doh
Gary Benson wrote:
> Hi again,
>
> This commit makes GregorianCalendar.computeTime() sometimes update
> the fields. The more weird logic I put in to make us match Sun the
> less happy I am, but I'm hoping that something's suddenly going to
> click and it's all going to become clear. Til then... well, that's
> why I'm working on a branch, no?
>
> Cheers,
> Gary
>
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.9239.2.8
diff -u -r1.9239.2.8 ChangeLog
--- ChangeLog 13 Apr 2007 13:05:39 -0000 1.9239.2.8
+++ ChangeLog 13 Apr 2007 15:39:58 -0000
@@ -1,3 +1,11 @@
+2007-04-13 Gary Benson <[EMAIL PROTECTED]>
+
+ * java/util/GregorianCalendar.java
+ (computeFields): Moved the majority of the logic into...
+ (internalComputeFields): New method.
+ (setDefaultFields): Only set areFieldsSet all fields were set.
+ (computeTime): Sometimes call internalComputeFields.
+
2007-04-13 Gary Benson <[EMAIL PROTECTED]>
* java/util/GregorianCalendar.java
Index: java/util/GregorianCalendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/GregorianCalendar.java,v
retrieving revision 1.49.4.5
diff -u -r1.49.4.5 GregorianCalendar.java
--- java/util/GregorianCalendar.java 13 Apr 2007 13:05:39 -0000 1.49.4.5
+++ java/util/GregorianCalendar.java 13 Apr 2007 15:39:58 -0000
@@ -508,10 +508,14 @@
*/
private void setDefaultFields()
{
+ boolean areAnyFieldsSet = false;
for (int i = 0; i < FIELD_COUNT; i++)
{
if (isSet[i])
- continue;
+ {
+ areAnyFieldsSet = true;
+ continue;
+ }
if (i == DAY_OF_WEEK)
fields[i] = getFirstDayOfWeek();
@@ -521,7 +525,8 @@
// It seems odd that a call to computeTime() should cause
// areFieldsSet to become true, but that's what Sun do...
- areFieldsSet = true;
+ if (!areAnyFieldsSet)
+ areFieldsSet = true;
}
/**
@@ -735,7 +740,10 @@
- zone.getRawOffset());
time -= rawOffset + dstOffset;
- }
+
+ if (!areFieldsSet)
+ internalComputeFields();
+}
/**
* Get the linear day in days since the epoch, using the
@@ -848,6 +856,18 @@
*/
protected synchronized void computeFields()
{
+ internalComputeFields();
+ for (int i = 0; i < FIELD_COUNT; i++)
+ isSet[i] = true;
+ }
+
+ /**
+ * Converts the milliseconds since the epoch UTC
+ * (<code>time</code>) to time fields
+ * (<code>fields</code>).
+ */
+ private void internalComputeFields()
+ {
boolean gregorian = (time >= gregorianCutover);
TimeZone zone = getTimeZone();
@@ -916,7 +936,7 @@
fields[SECOND] = millisInDay / (1000);
fields[MILLISECOND] = millisInDay % 1000;
- areFieldsSet = isSet[ERA] = isSet[YEAR] = isSet[MONTH] =
isSet[WEEK_OF_YEAR] = isSet[WEEK_OF_MONTH] = isSet[DAY_OF_MONTH] =
isSet[DAY_OF_YEAR] = isSet[DAY_OF_WEEK] = isSet[DAY_OF_WEEK_IN_MONTH] =
isSet[AM_PM] = isSet[HOUR] = isSet[HOUR_OF_DAY] = isSet[MINUTE] = isSet[SECOND]
= isSet[MILLISECOND] = isSet[ZONE_OFFSET] = isSet[DST_OFFSET] = true;
+ areFieldsSet = true;
}
/**