GregorianCalendar.java (computeTime): Skip buggy formulae when we already know the answer.

2004-06-11  Jerry Quinn  <jlquinn@optonline.net>

	* java/util/GregorianCalendar.java (computeTime):  Skip buggy formulae
	when we already know the answer.
	* java/util/SimpleTimeZone.java (serialVersionOnStream): Bump to 2.
	(setStartRule,setEndRule): Don't take abs of day number.
	(getOffset): Clarify docs.  Add argument checks.
	(isBefore): Take abs of day number in DOW_LE_DOM_MODE.
	(equals,hasSameRules,toString,readObject): Use startTimeMode and
	endTimeMode.

From-SVN: r82962
This commit is contained in:
Jerry Quinn
2004-06-11 05:54:02 +00:00
committed by Jerry Quinn
parent afeebbc08e
commit b092552d60
3 changed files with 58 additions and 22 deletions
+11 -3
View File
@@ -1,5 +1,6 @@
/* java.util.GregorianCalendar
Copyright (C) 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -441,8 +442,15 @@ public class GregorianCalendar extends Calendar
? fields[ZONE_OFFSET] : zone.getRawOffset();
int dayOfYear = daysOfYear[0] + daysOfYear[1];
int month = (dayOfYear * 5 + 3) / (31 + 30 + 31 + 30 + 31);
int day = (6 + (dayOfYear * 5 + 3) % (31 + 30 + 31 + 30 + 31)) / 5;
// This formula isn't right, so check for month as a quick fix.
// It doesn't compensate for leap years and puts day 30 in month 1
// instead of month 0.
int month = isSet[MONTH]
? fields[MONTH] : (dayOfYear * 5 + 3) / (31 + 30 + 31 + 30 + 31);
// This formula isn't right, so check for day as a quick fix. It
// doesn't compensate for leap years, either.
int day = isSet[DAY_OF_MONTH] ? fields[DAY_OF_MONTH]
: (6 + (dayOfYear * 5 + 3) % (31 + 30 + 31 + 30 + 31)) / 5;
int weekday = ((int) (time / (24 * 60 * 60 * 1000L)) + THURSDAY) % 7;
if (weekday <= 0)
weekday += 7;