Commit fa397dda by Bryce McKinlay Committed by Bryce McKinlay

Calendar.java (set): Never recompute fields here.

	* java/util/Calendar.java (set): Never recompute fields here. They
	will already be set if someone set time explicitly, and it can cause
	problems to do so. Don't invalidate AM_PM setting if HOUR is set.
	* java/util/GregorianCalendar.java (computeTime): Don't ignore an
	HOUR setting if AM_PM is set. Don't try to ensure the HOUR value is
	sane.
	* java/text/SimpleDateFormat.java (defaultCentury): New field.
	(readObject): Call set2DigitYearStart if appropriate so that
	defaultCentury is calculated.
	(SimpleDateFormat): Don't bother clearing calendar here. Call
	computeCenturyStart().
	(set2DigitYearStart): Calculate and set defaultCentury.
	(format): Don't clone the calendar. Use "calendar" not "theCalendar"
	everywhere.
	(parse): Likewise. If the pattern is "y" or "yy" and it found exactly
	2 numeric digits, use the 80-20 heuristic to parse the value into a
	default century based on defaultCenturyStart.
	(computeCenturyStart): Rewritten. Call set2DigitYearStart().

From-SVN: r44395
parent 2cf50fd3
2001-07-26 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
* java/util/Calendar.java (set): Never recompute fields here. They
will already be set if someone set time explicitly, and it can cause
problems to do so. Don't invalidate AM_PM setting if HOUR is set.
* java/util/GregorianCalendar.java (computeTime): Don't ignore an
HOUR setting if AM_PM is set. Don't try to ensure the HOUR value is
sane.
* java/text/SimpleDateFormat.java (defaultCentury): New field.
(readObject): Call set2DigitYearStart if appropriate so that
defaultCentury is calculated.
(SimpleDateFormat): Don't bother clearing calendar here. Call
computeCenturyStart().
(set2DigitYearStart): Calculate and set defaultCentury.
(format): Don't clone the calendar. Use "calendar" not "theCalendar"
everywhere.
(parse): Likewise. If the pattern is "y" or "yy" and it found exactly
2 numeric digits, use the 80-20 heuristic to parse the value into a
default century based on defaultCenturyStart.
(computeCenturyStart): Rewritten. Call set2DigitYearStart().
2001-07-25 Tom Tromey <tromey@redhat.com>
* Makefile.in: Rebuilt.
......
......@@ -549,8 +549,6 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public final void set(int field, int value)
{
if (!areFieldsSet)
computeFields();
isTimeSet = false;
fields[field] = value;
isSet[field] = true;
......@@ -573,7 +571,6 @@ public abstract class Calendar implements Serializable, Cloneable
isSet[HOUR] = false;
break;
case HOUR:
isSet[AM_PM] = false;
isSet[HOUR_OF_DAY] = false;
break;
}
......@@ -587,8 +584,6 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public final void set(int year, int month, int date)
{
if (!areFieldsSet)
computeFields();
isTimeSet = false;
fields[YEAR] = year;
fields[MONTH] = month;
......
......@@ -373,9 +373,17 @@ public class GregorianCalendar extends Calendar
year = 1 - year;
int[] daysOfYear = getDayOfYear(year);
int hour = isSet[HOUR_OF_DAY] ? fields[HOUR_OF_DAY]
: (isSet[HOUR] && isSet[AM_PM]
? fields[AM_PM] * 12 + (fields[HOUR] % 12) : 0);
int hour = 0;
if (isSet[HOUR_OF_DAY])
hour = fields[HOUR_OF_DAY];
else if (isSet[HOUR])
{
hour = fields[HOUR];
if (isSet[AM_PM] && fields[AM_PM] == PM)
hour += 12;
}
int minute = isSet[MINUTE] ? fields[MINUTE] : 0;
int second = isSet[SECOND] ? fields[SECOND] : 0;
int millis = isSet[MILLISECOND] ? fields[MILLISECOND] : 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment