Calendar.java (set): Invalidate DST_OFFSET field as a DST boundary may have been crossed.

2004-10-08  Bryce McKinlay  <mckinlay@redhat.com>

	* java/util/Calendar.java (set): Invalidate DST_OFFSET
	field as a DST boundary may have been crossed.
	* java/util/GregorianCalendar.java (add): Throw
	IllegalArgumentException on attempt to add to DST_OFFSET or
	ZONE_OFFSET fields. Update javadoc.

From-SVN: r88847
This commit is contained in:
Bryce McKinlay 2004-10-10 16:19:37 +00:00 committed by Bryce McKinlay
parent 711f836923
commit 0ba09d8fc6
3 changed files with 20 additions and 11 deletions

View File

@ -1,3 +1,11 @@
2004-10-08 Bryce McKinlay <mckinlay@redhat.com>
* java/util/Calendar.java (set): Invalidate DST_OFFSET
field as a DST boundary may have been crossed.
* java/util/GregorianCalendar.java (add): Throw
IllegalArgumentException on attempt to add to DST_OFFSET or
ZONE_OFFSET fields. Update javadoc.
2004-10-09 Michael Koch <konqueror@gmx.de>
* java/io/CharArrayWriter.java

View File

@ -651,6 +651,10 @@ public abstract class Calendar implements Serializable, Cloneable
isSet[HOUR_OF_DAY] = false;
break;
}
// May have crossed over a DST boundary.
if (field != DST_OFFSET && field != ZONE_OFFSET)
isSet[DST_OFFSET] = false;
}
/**
@ -671,6 +675,8 @@ public abstract class Calendar implements Serializable, Cloneable
isSet[WEEK_OF_MONTH] = false;
isSet[DAY_OF_WEEK] = false;
isSet[DAY_OF_WEEK_IN_MONTH] = false;
isSet[DST_OFFSET] = false; // May have crossed a DST boundary.
}
/**

View File

@ -540,7 +540,7 @@ public class GregorianCalendar extends Calendar
fields[DAY_OF_WEEK] = weekday;
// get a first approximation of the year. This may be one
// year to big.
// year too big.
int year = 1970 + (gregorian
? ((day - 100) * 400) / (365 * 400 + 100 - 4 + 1)
: ((day - 100) * 4) / (365 * 4 + 1));
@ -709,6 +709,10 @@ public class GregorianCalendar extends Calendar
* it does what you expect: Jan, 25 + 10 Days is Feb, 4.
* @param field the time field. One of the time field constants.
* @param amount the amount of time.
* @exception IllegalArgumentException if <code>field</code> is
* <code>ZONE_OFFSET</code>, <code>DST_OFFSET</code>, or invalid; or
* if <code>amount</code> contains an out-of-range value and the calendar
* is not in lenient mode.
*/
public void add(int field, int amount)
{
@ -785,18 +789,9 @@ public class GregorianCalendar extends Calendar
areFieldsSet = false;
break;
case ZONE_OFFSET:
complete();
fields[ZONE_OFFSET] += amount;
time -= amount;
break;
case DST_OFFSET:
complete();
fields[DST_OFFSET] += amount;
isTimeSet = false;
break;
default:
throw new IllegalArgumentException
("Unknown Calendar field: " + field);
throw new IllegalArgumentException("Invalid or unknown field");
}
}