[multiple changes]

2005-02-21  Mark Wielaard  <mark@klomp.org>

	* gnu/java/locale/LocaleInformation_en.java: Extend
	localPatternChars to "GyMdkHmsSEDFwWahKzYeugAZ".

2005-02-21  Mark Wielaard  <mark@klomp.org>

	* java/text/SimpleDateFormat.java
	(SimpleDateFormat(String, DateFormatSymbols)): Throw
	NullPointerException when formatData is null.

2005-02-21  Mark Wielaard  <mark@klomp.org>

	* java/util/SimpleTimeZone.java (getOffset): Calculate beforeEnd by
	taking dstSavings into account.

2005-02-21  Sven de Marothy <sven@physto.se>

	* java/text/SimpleDateFormat.java,
	(parse): Set correct DST_OFFSET to the correct value.

2005-02-21  Mark Wielaard  <mark@klomp.org>

	* java/util/SimpleTimeZone.java (checkRule): Throw
	IllegalArgumentException when month out of range.

2005-02-21  Sven de Marothy  <sven@physto.se>

	* java/util/GregorianCalendar.java,
	(add): Don't set fields directly anymore. Use set()

2005-02-21  Mark Wielaard  <mark@klomp.org>

	* java/text/SimpleDateFormat.java (CompiledField.toString):
	Use StringBuffer, not StringBuilder.
	(toString): Likewise.

2005-02-21  Sven de Marothy  <sven@physto.se>

	* java/util/Calendar.java
	(clear): Dates should clear to local time.
	* java/util/GregorianCalendar.java
	(computeTime): Fix priority problem with DAY_OF_WEEK,
	Handle non-sunday-startig weeks and minimumDaysInFirstWeek.

2005-02-21  Sven de Marothy  <sven@physto.se>

	* java/util/Calendar.java
	(Calendar): Constructor should clear fields.

2005-02-21  Sven de Marothy  <sven@physto.se>

	* java/text/SimpleDateFormat.java
	(parse): Tweak handling of 2-year dates
	* java/util/Calendar.java
	(clear): Clear fields to correct value.
	* java/util/GregorianCalendar.java
	(computeTime): Correct handling of time zones.
	Correct field minimum values.

2005-02-21  Sven de Marothy  <sven@physto.se>

	* java/util/Calendar.java
	(set) Invalidate all fields on first call to set().

2005-02-21  Sven de Marothy  <sven@physto.se>

	* java/util/GregorianCalendar.java
	(computeTime): Fixed handling of time zones.

2005-02-21  Sven de Marothy  <sven@physto.se>

	* java/util/Calendar.java
	(clear): Set values to Epoch instead of zero.
	(set): Set isSet to the relevant field pattern instead of just
	the field.
	* java/util/GregorianCalendar.java
	(getBundle): Removed.
	(getDayOfYear): Removed.
	(getFirstDayOfMonth): New private method.
	(nonLeniencyCheck): New private method.
	(computeTime): Correct handling of insufficient data.

2005-02-21  Sven de Marothy <sven@physto.se>

	* java/util/Calendar.java: Invalidate ERA field on setting
	the YEAR.
	* java/util/SimpleTimeZone.java:
	(getDaysInMonth): Reimplemented.
	* java/util/GregorianCalendar.java:
	(getLinearTime): Removed.
	(isLeapYear(int,boolean)): Removed.
	(before(), after()): Removed.
	(computeTime): Reimplemented.

2005-02-21  Sven de Marothy <sven@physto.se>

	* java/util/Calendar.java: Reformatted.
	* java/util/GregorianCalendar.java: Reformatted.
	* java/util/SimpleTimeZone.java: Reformatted.

2005-02-21  Sven de Marothy <sven@physto.se>

        * java/util/GregorianCalendar.java
        (GregorianCalendar): Update fields in the constructor

2005-02-21  Noa Resare  <noa@resare.com>

        * java/util/Calendar.java (explicitDSTOffset): New instance field.
        (set(int,int)): Set and use new field.
        (set(int,int,int)): Check new field.

2005-02-21  Noa Resare  <address@hidden>

	* java/util/Calendar.java(set):
	Fix for DST related regression.

2005-02-21  Jeroen Frijters  <jeroen@frijters.net>

	* java/util/Calendar.java
	(setTimeInMillis): Added call to clear, removed computeFields call.
	* java/util/Date.java
	(Date(int,int,int,int,int,int)): Removed workaround for
	GregorianCalendar bug.
	* java/util/GregorianCalendar.java
	(GregorianCalendar): Chained all constructors to a (new)
	common constructor.
	(computeTime): Fixed support for lenient month treatment.
	(getLinearDay): Return long instead of int.
	(calculateDay): Added fields argument and changed day argument
	to long.

2005-02-21  Andrew John Hughes  <gnu_andrew@member.fsf.org>

	* java/text/SimpleDateFormat.java
	Lots of documentation updates.
	(readObject(java.io.ObjectInputStream)): Wraps
	IllegalArgumentException as specified.
	(compileFormat(String)): Uses standardChars
	rather than the local pattern characters.
	Throws IllegalArgumentException rather than
	storing a -1 field.
	(toString()): Extended to include all variables
	in a better format.
	(translateLocalizedPattern(String, String, String)):
	Renamed to better define the use of this method.

2005-02-21  Andrew John Hughes  <gnu_andrew@member.fsf.org>

	* java/text/DateFormat.java:
	Documented pattern character offset constants and
	added new ones.
	(Field): Added new static fields for new pattern chars.
	* java/text/SimpleDateFormat.java:
	(CompiledField): Changed name of FieldSizePair class
	to CompiledField after adding the character as an
	attribute.  Changed fields to private and added
	accessors to give encapsulation.
	(CompiledField.CompiledField(int,int,char)): Extended
	with character field.
	(CompiledField.getField()): New accessor method.
	(CompiledField.getSize()): New acceessor method.
	(CompiledField.getCharacter()): New accessor method.
	(CompiledField.toString()): Added primarily for debugging.
	(standardChars): Now uses extended 24 character sequence.
	(compileFormat(String)): Changed to use CompiledField.
	(formatWithAttribute(java.util.Date, gnu.java.text.FormatBuffer,
	java.text.FieldPosition)): Changed to use CompiledField.
	New handler for RFC 822 timezones added.

2005-02-21  Andrew John Hughes  <gnu_andrew@member.fsf.org>

	* java/text/SimpleDateFormat.java:
	(parse(String, java.text.ParsePosition)):
	Changed 'E' and 'M' cases to use both
	short and long names.  Extended 'z'
	case to also handle 'Z', and deal
	with simple GMT offsets such as +0100.
	(computeOffset(String)): New private method,
	which converts a GMT offset specification,
	such as GMT-0500 to a numeric offset in
	milliseconds.
	* java/util/TimeZone.java:
	(timezones()): Added "CEST", the daylight
	savings time version of "CET", or Central
	European Time.

2005-02-21  Ito Kazumitsu  <kaz@maczuka.gcd.org>

	* java/text/SimpleDateFormat.java:
	(parse): Set the DST offset to 0 when parsing
	GMT offset timezones.

2005-02-21  Ito Kazumitsu  <kaz@maczuka.gcd.org>

	* java/text/SimpleDateFormat.java:
	(parse): Use offset to set ZONE_OFFSET
	rather than the DST_OFFSET, so that
	GMT offset timezones change the right
	one.

2005-02-21  Andrew John Hughes  <gnu_andrew@member.fsf.org>

	* java/text/SimpleDateFormat.java:
	(getDateFormatSymbols()): return a copy
	(setDateFormatSymbols(java.text.DateFormatSymbols)):
	throw exception on null input
	(clone()): implemented to clone
	internal fields

2005-02-21  Sven de Marothy <sven@physto.se>

	* java/text/SimpleDateFormat.java
	(parse): comparison should be case-insensitive, ignore null
	strings.

From-SVN: r95368
This commit is contained in:
Mark Wielaard 2005-02-22 00:58:36 +00:00
parent 665794a6c4
commit 933e5b284a
8 changed files with 1853 additions and 917 deletions

View file

@ -51,7 +51,7 @@ import java.lang.reflect.InvocationTargetException;
* integer fields which represent <code>YEAR</code>,
* <code>MONTH</code>, <code>DAY</code>, etc. The <code>Date</code>
* object represents a time in milliseconds since the Epoch. <br>
*
*
* This class is locale sensitive. To get the Object matching the
* current locale you can use <code>getInstance</code>. You can even provide
* a locale or a timezone. <code>getInstance</code> returns currently
@ -78,13 +78,13 @@ import java.lang.reflect.InvocationTargetException;
* and for the first line all fields are set, that line is used to
* compute the day. <br>
*
*
*
<pre>month + day_of_month
month + week_of_month + day_of_week
month + day_of_week_of_month + day_of_week
day_of_year
day_of_week + week_of_year</pre>
*
*
* The hour_of_day-field takes precedence over the ampm and
* hour_of_ampm fields. <br>
*
@ -92,7 +92,7 @@ day_of_week + week_of_year</pre>
*
* To convert a calendar to a human readable form and vice versa, use
* the <code>java.text.DateFormat</code> class. <br>
*
*
* Other useful things you can do with an calendar, is
* <code>roll</code>ing fields (that means increase/decrease a
* specific field by one, propagating overflows), or
@ -101,7 +101,7 @@ day_of_week + week_of_year</pre>
* @see Date
* @see GregorianCalendar
* @see TimeZone
* @see java.text.DateFormat
* @see java.text.DateFormat
*/
public abstract class Calendar implements Serializable, Cloneable
{
@ -109,43 +109,52 @@ public abstract class Calendar implements Serializable, Cloneable
* Constant representing the era time field.
*/
public static final int ERA = 0;
/**
* Constant representing the year time field.
*/
public static final int YEAR = 1;
/**
* Constant representing the month time field. This field
* should contain one of the JANUARY,...,DECEMBER constants below.
*/
public static final int MONTH = 2;
/**
* Constant representing the week of the year field.
* @see #setFirstDayOfWeek(int)
*/
public static final int WEEK_OF_YEAR = 3;
/**
* Constant representing the week of the month time field.
* @see #setFirstDayOfWeek(int)
*/
public static final int WEEK_OF_MONTH = 4;
/**
* Constant representing the day time field, synonym for DAY_OF_MONTH.
*/
public static final int DATE = 5;
/**
* Constant representing the day time field.
*/
public static final int DAY_OF_MONTH = 5;
/**
* Constant representing the day of year time field. This is
* 1 for the first day in month.
*/
public static final int DAY_OF_YEAR = 6;
/**
* Constant representing the day of week time field. This field
* should contain one of the SUNDAY,...,SATURDAY constants below.
*/
public static final int DAY_OF_WEEK = 7;
/**
* Constant representing the day-of-week-in-month field. For
* instance this field contains 2 for the second thursday in a
@ -153,42 +162,51 @@ public abstract class Calendar implements Serializable, Cloneable
* from the end of the month.
*/
public static final int DAY_OF_WEEK_IN_MONTH = 8;
/**
* Constant representing the part of the day for 12-hour clock. This
* should be one of AM or PM.
*/
public static final int AM_PM = 9;
/**
* Constant representing the hour time field for 12-hour clock.
*/
public static final int HOUR = 10;
/**
* Constant representing the hour of day time field for 24-hour clock.
*/
public static final int HOUR_OF_DAY = 11;
/**
* Constant representing the minute of hour time field.
*/
public static final int MINUTE = 12;
/**
* Constant representing the second time field.
*/
public static final int SECOND = 13;
/**
* Constant representing the millisecond time field.
*/
public static final int MILLISECOND = 14;
/**
* Constant representing the time zone offset time field for the
* time given in the other fields. It is measured in
* milliseconds. The default is the offset of the time zone.
* milliseconds. The default is the offset of the time zone.
*/
public static final int ZONE_OFFSET = 15;
/**
* Constant representing the daylight saving time offset in
* milliseconds. The default is the value given by the time zone.
* milliseconds. The default is the value given by the time zone.
*/
public static final int DST_OFFSET = 16;
/**
* Number of time fields.
*/
@ -198,26 +216,32 @@ public abstract class Calendar implements Serializable, Cloneable
* Constant representing Sunday.
*/
public static final int SUNDAY = 1;
/**
* Constant representing Monday.
*/
public static final int MONDAY = 2;
/**
* Constant representing Tuesday.
*/
public static final int TUESDAY = 3;
/**
* Constant representing Wednesday.
*/
public static final int WEDNESDAY = 4;
/**
* Constant representing Thursday.
*/
public static final int THURSDAY = 5;
/**
* Constant representing Friday.
*/
public static final int FRIDAY = 6;
/**
* Constant representing Saturday.
*/
@ -227,50 +251,62 @@ public abstract class Calendar implements Serializable, Cloneable
* Constant representing January.
*/
public static final int JANUARY = 0;
/**
* Constant representing February.
*/
public static final int FEBRUARY = 1;
/**
* Constant representing March.
*/
public static final int MARCH = 2;
/**
* Constant representing April.
*/
public static final int APRIL = 3;
/**
* Constant representing May.
*/
public static final int MAY = 4;
/**
* Constant representing June.
*/
public static final int JUNE = 5;
/**
* Constant representing July.
*/
public static final int JULY = 6;
/**
* Constant representing August.
*/
public static final int AUGUST = 7;
/**
* Constant representing September.
*/
public static final int SEPTEMBER = 8;
/**
* Constant representing October.
*/
public static final int OCTOBER = 9;
/**
* Constant representing November.
*/
public static final int NOVEMBER = 10;
/**
* Constant representing December.
*/
public static final int DECEMBER = 11;
/**
* Constant representing Undecimber. This is an artificial name useful
* for lunar calendars.
@ -281,6 +317,7 @@ public abstract class Calendar implements Serializable, Cloneable
* Useful constant for 12-hour clock.
*/
public static final int AM = 0;
/**
* Useful constant for 12-hour clock.
*/
@ -292,21 +329,25 @@ public abstract class Calendar implements Serializable, Cloneable
* @serial
*/
protected int[] fields = new int[FIELD_COUNT];
/**
* The flags which tell if the fields above have a value.
* @serial
*/
protected boolean[] isSet = new boolean[FIELD_COUNT];
/**
* The time in milliseconds since the epoch.
* @serial
*/
protected long time;
/**
* Tells if the above field has a valid value.
* @serial
*/
protected boolean isTimeSet;
/**
* Tells if the fields have a valid value. This superseeds the isSet
* array.
@ -332,7 +373,7 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Sets what the first day of week is. This is used for
* WEEK_OF_MONTH and WEEK_OF_YEAR fields.
* WEEK_OF_MONTH and WEEK_OF_YEAR fields.
* @serial
*/
private int firstDayOfWeek;
@ -347,7 +388,14 @@ public abstract class Calendar implements Serializable, Cloneable
private int minimalDaysInFirstWeek;
/**
* The version of the serialized data on the stream.
* Is set to true if DST_OFFSET is explicitly set. In that case
* it's value overrides the value computed from the current
* time and the timezone.
*/
private boolean explicitDSTOffset = false;
/**
* The version of the serialized data on the stream.
* <dl><dt>0 or not present</dt>
* <dd> JDK 1.1.5 or later.</dd>
* <dl><dt>1</dt>
@ -371,14 +419,14 @@ public abstract class Calendar implements Serializable, Cloneable
private static final String bundleName = "gnu.java.locale.Calendar";
/**
* get resource bundle:
* get resource bundle:
* The resources should be loaded via this method only. Iff an application
* uses this method, the resourcebundle is required.
* uses this method, the resourcebundle is required.
*/
private static ResourceBundle getBundle(Locale locale)
private static ResourceBundle getBundle(Locale locale)
{
return ResourceBundle.getBundle(bundleName, locale,
ClassLoader.getSystemClassLoader());
ClassLoader.getSystemClassLoader());
}
/**
@ -404,8 +452,9 @@ public abstract class Calendar implements Serializable, Cloneable
ResourceBundle rb = getBundle(locale);
firstDayOfWeek = ((Integer) rb.getObject("firstDayOfWeek")).intValue();
minimalDaysInFirstWeek =
((Integer) rb.getObject("minimalDaysInFirstWeek")).intValue();
minimalDaysInFirstWeek = ((Integer) rb.getObject("minimalDaysInFirstWeek"))
.intValue();
clear();
}
/**
@ -437,15 +486,17 @@ public abstract class Calendar implements Serializable, Cloneable
return getInstance(TimeZone.getDefault(), locale);
}
/**
/**
* Cache of locale->calendar-class mappings. This avoids having to do a ResourceBundle
* lookup for every getInstance call.
* lookup for every getInstance call.
*/
private static HashMap cache = new HashMap();
/** Preset argument types for calendar-class constructor lookup. */
private static Class[] ctorArgTypes
= new Class[] {TimeZone.class, Locale.class};
private static Class[] ctorArgTypes = new Class[]
{
TimeZone.class, Locale.class
};
/**
* Creates a calendar representing the actual time, using the given
@ -473,7 +524,7 @@ public abstract class Calendar implements Serializable, Cloneable
}
}
// GregorianCalendar is by far the most common case. Optimize by
// GregorianCalendar is by far the most common case. Optimize by
// avoiding reflection.
if (calendarClass == GregorianCalendar.class)
return new GregorianCalendar(zone, locale);
@ -481,7 +532,7 @@ public abstract class Calendar implements Serializable, Cloneable
if (Calendar.class.isAssignableFrom(calendarClass))
{
Constructor ctor = calendarClass.getConstructor(ctorArgTypes);
return (Calendar) ctor.newInstance(new Object[] {zone, locale});
return (Calendar) ctor.newInstance(new Object[] { zone, locale });
}
}
catch (ClassNotFoundException ex)
@ -504,9 +555,9 @@ public abstract class Calendar implements Serializable, Cloneable
{
exception = ex;
}
throw new RuntimeException("Error instantiating calendar for locale " +
locale, exception);
throw new RuntimeException("Error instantiating calendar for locale "
+ locale, exception);
}
/**
@ -530,7 +581,7 @@ public abstract class Calendar implements Serializable, Cloneable
* Converts the milliseconds since the epoch UTC
* (<code>time</code>) to time fields
* (<code>fields</code>). Override this method if you write your
* own Calendar.
* own Calendar.
*/
protected abstract void computeFields();
@ -541,7 +592,7 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public final Date getTime()
{
if (!isTimeSet)
if (! isTimeSet)
computeTime();
return new Date(time);
}
@ -562,7 +613,7 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public long getTimeInMillis()
{
if (!isTimeSet)
if (! isTimeSet)
computeTime();
return time;
}
@ -575,9 +626,9 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public void setTimeInMillis(long time)
{
clear();
this.time = time;
isTimeSet = true;
computeFields();
}
/**
@ -593,14 +644,14 @@ public abstract class Calendar implements Serializable, Cloneable
public int get(int field)
{
// If the requested field is invalid, force all fields to be recomputed.
if (!isSet[field])
if (! isSet[field])
areFieldsSet = false;
complete();
return fields[field];
}
/**
* Gets the value of the specified field. This method doesn't
* Gets the value of the specified field. This method doesn't
* recompute the fields, if they are invalid.
* @param field the time field. One of the time field constants.
* @return the value of the specified field, undefined if
@ -626,21 +677,72 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public void set(int field, int value)
{
if (isTimeSet)
for (int i = 0; i < FIELD_COUNT; i++)
isSet[i] = false;
isTimeSet = false;
fields[field] = value;
isSet[field] = true;
// The five valid date patterns, in order of priority
// 1 YEAR + MONTH + DAY_OF_MONTH
// 2 YEAR + MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
// 3 YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
// 4 YEAR + DAY_OF_YEAR
// 5 YEAR + DAY_OF_WEEK + WEEK_OF_YEAR
switch (field)
{
case YEAR:
case MONTH:
case DATE:
isSet[WEEK_OF_YEAR] = false;
case MONTH: // pattern 1,2 or 3
isSet[DAY_OF_YEAR] = false;
isSet[WEEK_OF_MONTH] = false;
isSet[WEEK_OF_YEAR] = false;
break;
case DAY_OF_MONTH: // pattern 1
isSet[YEAR] = true;
isSet[MONTH] = true;
isSet[WEEK_OF_MONTH] = true;
isSet[DAY_OF_WEEK] = false;
isSet[DAY_OF_WEEK_IN_MONTH] = false;
isSet[DAY_OF_YEAR] = false;
isSet[WEEK_OF_YEAR] = false;
break;
case WEEK_OF_MONTH: // pattern 2
isSet[YEAR] = true;
isSet[MONTH] = true;
isSet[DAY_OF_WEEK] = true;
isSet[DAY_OF_MONTH] = false;
isSet[DAY_OF_WEEK_IN_MONTH] = false;
isSet[DAY_OF_YEAR] = false;
isSet[WEEK_OF_YEAR] = false;
break;
case DAY_OF_WEEK_IN_MONTH: // pattern 3
isSet[YEAR] = true;
isSet[MONTH] = true;
isSet[DAY_OF_WEEK] = true;
isSet[DAY_OF_YEAR] = false;
isSet[DAY_OF_MONTH] = false;
isSet[WEEK_OF_MONTH] = false;
isSet[WEEK_OF_YEAR] = false;
break;
case DAY_OF_YEAR: // pattern 4
isSet[YEAR] = true;
isSet[MONTH] = false;
isSet[WEEK_OF_MONTH] = false;
isSet[DAY_OF_MONTH] = false;
isSet[DAY_OF_WEEK] = false;
isSet[WEEK_OF_YEAR] = false;
isSet[DAY_OF_WEEK_IN_MONTH] = false;
break;
case WEEK_OF_YEAR: // pattern 5
isSet[YEAR] = true;
isSet[DAY_OF_WEEK] = true;
isSet[MONTH] = false;
isSet[DAY_OF_MONTH] = false;
isSet[WEEK_OF_MONTH] = false;
isSet[DAY_OF_YEAR] = false;
isSet[DAY_OF_WEEK_IN_MONTH] = false;
break;
case AM_PM:
isSet[HOUR] = true;
isSet[HOUR_OF_DAY] = false;
break;
case HOUR_OF_DAY:
@ -648,12 +750,15 @@ public abstract class Calendar implements Serializable, Cloneable
isSet[HOUR] = false;
break;
case HOUR:
isSet[AM_PM] = true;
isSet[HOUR_OF_DAY] = false;
break;
case DST_OFFSET:
explicitDSTOffset = true;
}
// May have crossed over a DST boundary.
if (field != DST_OFFSET && field != ZONE_OFFSET)
if (! explicitDSTOffset && (field != DST_OFFSET && field != ZONE_OFFSET))
isSet[DST_OFFSET] = false;
}
@ -675,8 +780,10 @@ 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[ERA] = false;
isSet[DST_OFFSET] = false; // May have crossed a DST boundary.
if (! explicitDSTOffset)
isSet[DST_OFFSET] = false; // May have crossed a DST boundary.
}
/**
@ -706,8 +813,8 @@ public abstract class Calendar implements Serializable, Cloneable
* @param minute the minute.
* @param second the second.
*/
public final void set(int year, int month, int date,
int hour, int minute, int second)
public final void set(int year, int month, int date, int hour, int minute,
int second)
{
set(year, month, date, hour, minute);
fields[SECOND] = second;
@ -721,11 +828,15 @@ public abstract class Calendar implements Serializable, Cloneable
{
isTimeSet = false;
areFieldsSet = false;
int zoneOffs = zone.getRawOffset();
int[] tempFields =
{
1, 1970, JANUARY, 1, 1, 1, 1, THURSDAY, 1, AM, 0, 0, 0,
0, 0, zoneOffs, 0
};
fields = tempFields;
for (int i = 0; i < FIELD_COUNT; i++)
{
isSet[i] = false;
fields[i] = 0;
}
isSet[i] = false;
}
/**
@ -737,10 +848,15 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public final void clear(int field)
{
int[] tempFields =
{
1, 1970, JANUARY, 1, 1, 1, 1, THURSDAY, 1, AM, 0, 0, 0,
0, 0, zone.getRawOffset(), 0
};
isTimeSet = false;
areFieldsSet = false;
isSet[field] = false;
fields[field] = 0;
fields[field] = tempFields[field];
}
/**
@ -757,18 +873,18 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Fills any unset fields in the time field list
* @return true if the specified field has a value.
* @return true if the specified field has a value.
*/
protected void complete()
{
if (!isTimeSet)
if (! isTimeSet)
computeTime();
if (!areFieldsSet)
if (! areFieldsSet)
computeFields();
}
/**
* Compares the given calendar with this.
* Compares the given calendar with this.
* @param o the object to that we should compare.
* @return true, if the given object is a calendar, that represents
* the same time (but doesn't necessary have the same fields).
@ -776,12 +892,12 @@ public abstract class Calendar implements Serializable, Cloneable
public boolean equals(Object o)
{
return (o instanceof Calendar)
&& getTimeInMillis() == ((Calendar) o).getTimeInMillis();
&& getTimeInMillis() == ((Calendar) o).getTimeInMillis();
}
/**
* Returns a hash code for this calendar.
* @return a hash code, which fullfits the general contract of
* @return a hash code, which fullfits the general contract of
* <code>hashCode()</code>
*/
public int hashCode()
@ -791,7 +907,7 @@ public abstract class Calendar implements Serializable, Cloneable
}
/**
* Compares the given calendar with this.
* Compares the given calendar with this.
* @param o the object to that we should compare.
* @return true, if the given object is a calendar, and this calendar
* represents a smaller time than the calendar o.
@ -804,7 +920,7 @@ public abstract class Calendar implements Serializable, Cloneable
}
/**
* Compares the given calendar with this.
* Compares the given calendar with this.
* @param o the object to that we should compare.
* @return true, if the given object is a calendar, and this calendar
* represents a bigger time than the calendar o.
@ -831,11 +947,11 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Rolls the specified time field up or down. This means add one
* to the specified field, but don't change the other fields. If
* the maximum for this field is reached, start over with the
* the maximum for this field is reached, start over with the
* minimum value. <br>
*
* <strong>Note:</strong> There may be situation, where the other
* fields must be changed, e.g rolling the month on May, 31.
* fields must be changed, e.g rolling the month on May, 31.
* The date June, 31 is automatically converted to July, 1.
* @param field the time field. One of the time field constants.
* @param up the direction, true for up, false for down.
@ -854,7 +970,7 @@ public abstract class Calendar implements Serializable, Cloneable
*
* @param field the time field. One of the time field constants.
* @param amount the amount to roll by, positive for rolling up,
* negative for rolling down.
* negative for rolling down.
* @throws ArrayIndexOutOfBoundsException if the field is outside
* the valid range. The value of field must be >= 0 and
* <= <code>FIELD_COUNT</code>.
@ -874,7 +990,6 @@ public abstract class Calendar implements Serializable, Cloneable
}
}
/**
* Sets the time zone to the specified value.
* @param zone the new time zone
@ -918,7 +1033,7 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Sets what the first day of week is. This is used for
* WEEK_OF_MONTH and WEEK_OF_YEAR fields.
* WEEK_OF_MONTH and WEEK_OF_YEAR fields.
* @param value the first day of week. One of SUNDAY to SATURDAY.
*/
public void setFirstDayOfWeek(int value)
@ -928,7 +1043,7 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Gets what the first day of week is. This is used for
* WEEK_OF_MONTH and WEEK_OF_YEAR fields.
* WEEK_OF_MONTH and WEEK_OF_YEAR fields.
* @return the first day of week. One of SUNDAY to SATURDAY.
*/
public int getFirstDayOfWeek()
@ -972,7 +1087,6 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public abstract int getMaximum(int field);
/**
* Gets the greatest minimum value that is allowed for the specified field.
* @param field the time field. One of the time field constants.
@ -984,7 +1098,7 @@ public abstract class Calendar implements Serializable, Cloneable
* Gets the smallest maximum value that is allowed for the
* specified field. For example this is 28 for DAY_OF_MONTH.
* @param field the time field. One of the time field constants.
* @return the least maximum value.
* @return the least maximum value.
*/
public abstract int getLeastMaximum(int field);
@ -1000,16 +1114,15 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public int getActualMinimum(int field)
{
Calendar tmp = (Calendar)clone(); // To avoid restoring state
Calendar tmp = (Calendar) clone(); // To avoid restoring state
int min = tmp.getGreatestMinimum(field);
int end = tmp.getMinimum(field);
tmp.set(field, min);
for (; min > end; min--)
{
tmp.add(field, -1); // Try to get smaller
tmp.add(field, -1); // Try to get smaller
if (tmp.get(field) != min - 1)
break; // Done if not successful
break; // Done if not successful
}
return min;
}
@ -1018,7 +1131,7 @@ public abstract class Calendar implements Serializable, Cloneable
* Gets the actual maximum value that is allowed for the specified field.
* This value is dependent on the values of the other fields.
* @param field the time field. One of the time field constants.
* @return the actual maximum value.
* @return the actual maximum value.
* @throws ArrayIndexOutOfBoundsException if the field is outside
* the valid range. The value of field must be >= 0 and
* <= <code>FIELD_COUNT</code>.
@ -1026,7 +1139,7 @@ public abstract class Calendar implements Serializable, Cloneable
*/
public int getActualMaximum(int field)
{
Calendar tmp = (Calendar)clone(); // To avoid restoring state
Calendar tmp = (Calendar) clone(); // To avoid restoring state
int max = tmp.getLeastMaximum(field);
int end = tmp.getMaximum(field);
tmp.set(field, max);
@ -1048,7 +1161,7 @@ public abstract class Calendar implements Serializable, Cloneable
{
Calendar cal = (Calendar) super.clone();
cal.fields = (int[]) fields.clone();
cal.isSet = (boolean[])isSet.clone();
cal.isSet = (boolean[]) isSet.clone();
return cal;
}
catch (CloneNotSupportedException ex)
@ -1057,16 +1170,19 @@ public abstract class Calendar implements Serializable, Cloneable
}
}
private static final String[] fieldNames = {
",ERA=", ",YEAR=", ",MONTH=",
",WEEK_OF_YEAR=", ",WEEK_OF_MONTH=",
",DAY_OF_MONTH=", ",DAY_OF_YEAR=", ",DAY_OF_WEEK=",
",DAY_OF_WEEK_IN_MONTH=",
",AM_PM=", ",HOUR=", ",HOUR_OF_DAY=",
",MINUTE=", ",SECOND=", ",MILLISECOND=",
",ZONE_OFFSET=", ",DST_OFFSET="
};
private static final String[] fieldNames =
{
",ERA=", ",YEAR=", ",MONTH=",
",WEEK_OF_YEAR=",
",WEEK_OF_MONTH=",
",DAY_OF_MONTH=",
",DAY_OF_YEAR=", ",DAY_OF_WEEK=",
",DAY_OF_WEEK_IN_MONTH=",
",AM_PM=", ",HOUR=",
",HOUR_OF_DAY=", ",MINUTE=",
",SECOND=", ",MILLISECOND=",
",ZONE_OFFSET=", ",DST_OFFSET="
};
/**
* Returns a string representation of this object. It is mainly
@ -1109,7 +1225,7 @@ public abstract class Calendar implements Serializable, Cloneable
* says, that it could be omitted. */
private void writeObject(ObjectOutputStream stream) throws IOException
{
if (!isTimeSet)
if (! isTimeSet)
computeTime();
stream.defaultWriteObject();
}
@ -1121,7 +1237,7 @@ public abstract class Calendar implements Serializable, Cloneable
throws IOException, ClassNotFoundException
{
stream.defaultReadObject();
if (!isTimeSet)
if (! isTimeSet)
computeTime();
if (serialVersionOnStream > 1)
@ -1130,7 +1246,6 @@ public abstract class Calendar implements Serializable, Cloneable
// Sun wants to remove all fields from the stream someday
// and will then increase the serialVersion number again.
// We prepare to be compatible.
fields = new int[FIELD_COUNT];
isSet = new boolean[FIELD_COUNT];
areFieldsSet = false;