Index: java/util/Calendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Calendar.java,v
retrieving revision 1.31
diff -u -r1.31 Calendar.java
--- java/util/Calendar.java 31 Oct 2004 20:05:39 -0000 1.31
+++ java/util/Calendar.java 21 Jan 2005 16:24:04 -0000
@@ -51,7 +51,7 @@
* integer fields which represent YEAR
,
* MONTH
, DAY
, etc. The Date
* object represents a time in milliseconds since the Epoch.
- *
+ *
* This class is locale sensitive. To get the Object matching the
* current locale you can use getInstance
. You can even provide
* a locale or a timezone. getInstance
returns currently
@@ -78,13 +78,13 @@
* and for the first line all fields are set, that line is used to
* compute the day.
*
- *
+ *
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- * + * * The hour_of_day-field takes precedence over the ampm and * hour_of_ampm fields.
java.text.DateFormat
class. roll
ing fields (that means increase/decrease a
* specific field by one, propagating overflows), or
@@ -101,7 +101,7 @@
* @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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 @@
* Useful constant for 12-hour clock.
*/
public static final int AM = 0;
+
/**
* Useful constant for 12-hour clock.
*/
@@ -292,21 +329,25 @@
* @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 @@
/**
* 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;
@@ -349,12 +390,12 @@
/**
* 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.
+ * time and the timezone.
*/
private boolean explicitDSTOffset = false;
/**
- * The version of the serialized data on the stream.
+ * The version of the serialized data on the stream.
* time
) to time fields
* (fields
). Override this method if you write your
- * own Calendar.
+ * own Calendar.
*/
protected abstract void computeFields();
@@ -548,7 +591,7 @@
*/
public final Date getTime()
{
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
return new Date(time);
}
@@ -569,7 +612,7 @@
*/
public long getTimeInMillis()
{
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
return time;
}
@@ -600,14 +643,14 @@
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
@@ -658,11 +701,11 @@
isSet[HOUR_OF_DAY] = false;
break;
case DST_OFFSET:
- explicitDSTOffset = true;
+ explicitDSTOffset = true;
}
// May have crossed over a DST boundary.
- if (!explicitDSTOffset && (field != DST_OFFSET && field != ZONE_OFFSET))
+ if (! explicitDSTOffset && (field != DST_OFFSET && field != ZONE_OFFSET))
isSet[DST_OFFSET] = false;
}
@@ -685,8 +728,8 @@
isSet[DAY_OF_WEEK] = false;
isSet[DAY_OF_WEEK_IN_MONTH] = false;
- if (!explicitDSTOffset)
- isSet[DST_OFFSET] = false; // May have crossed a DST boundary.
+ if (! explicitDSTOffset)
+ isSet[DST_OFFSET] = false; // May have crossed a DST boundary.
}
/**
@@ -716,8 +759,8 @@
* @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;
@@ -767,18 +810,18 @@
/**
* 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).
@@ -786,12 +829,12 @@
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
* hashCode()
*/
public int hashCode()
@@ -801,7 +844,7 @@
}
/**
- * 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.
@@ -814,7 +857,7 @@
}
/**
- * 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.
@@ -841,11 +884,11 @@
/**
* 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. FIELD_COUNT
.
@@ -884,7 +927,6 @@
}
}
-
/**
* Sets the time zone to the specified value.
* @param zone the new time zone
@@ -928,7 +970,7 @@
/**
* 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)
@@ -938,7 +980,7 @@
/**
* 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()
@@ -982,7 +1024,6 @@
*/
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.
@@ -994,7 +1035,7 @@
* 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);
@@ -1010,16 +1051,15 @@
*/
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;
}
@@ -1028,7 +1068,7 @@
* 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
* <= FIELD_COUNT
.
@@ -1036,7 +1076,7 @@
*/
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);
@@ -1058,7 +1098,7 @@
{
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)
@@ -1067,16 +1107,19 @@
}
}
- 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
@@ -1119,7 +1162,7 @@
* says, that it could be omitted. */
private void writeObject(ObjectOutputStream stream) throws IOException
{
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
stream.defaultWriteObject();
}
@@ -1131,7 +1174,7 @@
throws IOException, ClassNotFoundException
{
stream.defaultReadObject();
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
if (serialVersionOnStream > 1)
@@ -1140,7 +1183,6 @@
// 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;
Index: java/util/GregorianCalendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/GregorianCalendar.java,v
retrieving revision 1.31
diff -u -r1.31 GregorianCalendar.java
--- java/util/GregorianCalendar.java 14 Jan 2005 16:32:24 -0000 1.31
+++ java/util/GregorianCalendar.java 21 Jan 2005 16:24:04 -0000
@@ -39,6 +39,7 @@
package java.util;
+
/**
* * This class represents the Gregorian calendar, that is used in most @@ -46,7 +47,7 @@ * for dates smaller than the date of the change to the Gregorian calendar. * The Gregorian calendar differs from the Julian calendar by a different * leap year rule (no leap year every 100 years, except if year is divisible - * by 400). + * by 400). *
** This change date is different from country to country, and can be changed with @@ -136,7 +137,7 @@ * Constant representing the era BC (Before Christ). */ public static final int BC = 0; - + /** * Constant representing the era AD (Anno Domini). */ @@ -171,36 +172,36 @@ * @param locale the locale in use for this calendar. * @return A resource bundle for the calendar for the specified locale. */ - private static ResourceBundle getBundle(Locale locale) + private static ResourceBundle getBundle(Locale locale) { return ResourceBundle.getBundle(bundleName, locale, - ClassLoader.getSystemClassLoader()); + ClassLoader.getSystemClassLoader()); } /** * Constructs a new GregorianCalender representing the current - * time, using the default time zone and the default locale. + * time, using the default time zone and the default locale. */ public GregorianCalendar() { this(TimeZone.getDefault(), Locale.getDefault()); } - + /** * Constructs a new GregorianCalender representing the current - * time, using the specified time zone and the default locale. - * + * time, using the specified time zone and the default locale. + * * @param zone a time zone. */ public GregorianCalendar(TimeZone zone) { this(zone, Locale.getDefault()); } - + /** * Constructs a new GregorianCalender representing the current * time, using the default time zone and the specified locale. - * + * * @param locale a locale. */ public GregorianCalendar(Locale locale) @@ -212,8 +213,8 @@ * Constructs a new GregorianCalender representing the current * time with the given time zone and the given locale. * - * @param zone a time zone. - * @param locale a locale. + * @param zone a time zone. + * @param locale a locale. */ public GregorianCalendar(TimeZone zone, Locale locale) { @@ -224,8 +225,8 @@ /** * Common constructor that all constructors should call. - * @param zone a time zone. - * @param locale a locale. + * @param zone a time zone. + * @param locale a locale. * @param unused unused parameter to make the signature differ from * the public constructor (TimeZone, Locale). */ @@ -277,8 +278,8 @@ * @param minute corresponds to the MINUTE time field. * @param second corresponds to the SECOND time field. */ - public GregorianCalendar(int year, int month, int day, - int hour, int minute, int second) + public GregorianCalendar(int year, int month, int day, int hour, int minute, + int second) { this(TimeZone.getDefault(), Locale.getDefault(), false); set(year, month, day, hour, minute, second); @@ -321,7 +322,7 @@ *
* * @param year a year (use a negative value for BC). - * @return true, if the given year is a leap year, false otherwise. + * @return true, if the given year is a leap year, false otherwise. */ public boolean isLeapYear(int year) { @@ -332,9 +333,9 @@ // compute the linear day of the 29. February of that year. // The 13 is the number of days, that were omitted in the Gregorian // Calender until the epoch. - int julianDay = (((year-1) * (365*4+1)) >> 2) + (31+29 - - (((1970-1) * (365*4+1)) / 4 + 1 - 13)); - + int julianDay = (((year - 1) * (365 * 4 + 1)) >> 2) + + (31 + 29 - (((1970 - 1) * (365 * 4 + 1)) / 4 + 1 - 13)); + // If that day is smaller than the gregorianChange the julian // rule applies: This is a leap year since it is divisible by 4. if (julianDay * (24 * 60 * 60 * 1000L) < gregorianCutover) @@ -352,7 +353,7 @@ * @param year the year of the date. * @param dayOfYear the day of year of the date; 1 based. * @param millis the millisecond in that day. - * @return the days since the epoch, may be negative. + * @return the days since the epoch, may be negative. */ private long getLinearTime(int year, int dayOfYear, int millis) { @@ -360,8 +361,8 @@ // Calendar until the epoch. // We shift right by 2 instead of dividing by 4, to get correct // results for negative years (and this is even more efficient). - int julianDay = ((year * (365 * 4 + 1)) >> 2) + dayOfYear - - ((1970 * (365 * 4 + 1)) / 4 + 1 - 13); + int julianDay = ((year * (365 * 4 + 1)) >> 2) + dayOfYear + - ((1970 * (365 * 4 + 1)) / 4 + 1 - 13); long time = julianDay * (24 * 60 * 60 * 1000L) + millis; if (time >= gregorianCutover) @@ -378,7 +379,7 @@ // And on and after the leap day, the leap day has already been // included in dayOfYear. int gregOffset = (year / 400) - (year / 100) + 2; - if (isLeapYear (year, true)) + if (isLeapYear(year, true)) --gregOffset; time += gregOffset * (24 * 60 * 60 * 1000L); } @@ -395,8 +396,7 @@ */ private int getWeekDay(int year, int dayOfYear) { - int day = - (int) (getLinearTime(year, dayOfYear, 0) / (24 * 60 * 60 * 1000L)); + int day = (int) (getLinearTime(year, dayOfYear, 0) / (24 * 60 * 60 * 1000L)); // The epoch was a thursday. int weekday = (day + THURSDAY) % 7; @@ -407,7 +407,7 @@ /** *- * Calculate the dayOfYear from the fields array. + * Calculate the dayOfYear from the fields array. * The relativeDays is used, to account for weeks that begin before * the Gregorian change and end after it. *
@@ -416,13 +416,13 @@ * should use the Gregorian calendar or the Julian calendar, in order * to handle the change year. The second is a relative day after the given * day. This is necessary for week calculation in the year in - * which the Gregorian change occurs. + * which the Gregorian change occurs. * - * + * * @param year the year, negative for BC. * @return an array of two integer values, the first containing a reference * day in the current year, the second a relative count since this reference - * day. + * day. */ private int[] getDayOfYear(int year) { @@ -431,7 +431,6 @@ int dayOfYear; if (fields[MONTH] > FEBRUARY) { - // The months after February are regular: // 9 is an offset found by try and error. dayOfYear = (fields[MONTH] * (31 + 30 + 31 + 30 + 31) - 9) / 5; @@ -439,75 +438,76 @@ dayOfYear++; } else - dayOfYear = 31 * fields[MONTH]; + dayOfYear = 31 * fields[MONTH]; if (isSet[DAY_OF_MONTH]) - { - return new int[] - { - dayOfYear + fields[DAY_OF_MONTH], 0}; - } + return new int[] { dayOfYear + fields[DAY_OF_MONTH], 0 }; if (isSet[WEEK_OF_MONTH] && isSet[DAY_OF_WEEK]) { // the weekday of the first day in that month is: int weekday = getWeekDay(year, ++dayOfYear); return new int[] - { - dayOfYear, - // the day of week in the first week - // (weeks starting on sunday) is: - fields[DAY_OF_WEEK] - weekday + - // Now jump to the right week and correct the possible - // error made by assuming sunday is the first week day. - 7 * (fields[WEEK_OF_MONTH] - + (fields[DAY_OF_WEEK] < getFirstDayOfWeek()? 0 : -1) - + (weekday < getFirstDayOfWeek()? -1 : 0))}; + { + dayOfYear, + // the day of week in the first week + // (weeks starting on sunday) is: + fields[DAY_OF_WEEK] - weekday + + // Now jump to the right week and correct the possible + // error made by assuming sunday is the first week day. + 7 * (fields[WEEK_OF_MONTH] + + (fields[DAY_OF_WEEK] < getFirstDayOfWeek() ? 0 : -1) + + (weekday < getFirstDayOfWeek() ? -1 : 0)) + }; } if (isSet[DAY_OF_WEEK] && isSet[DAY_OF_WEEK_IN_MONTH]) { // the weekday of the first day in that month is: int weekday = getWeekDay(year, ++dayOfYear); - return new int[] { - dayOfYear, - fields[DAY_OF_WEEK] - weekday + - 7 * (fields[DAY_OF_WEEK_IN_MONTH] - + (fields[DAY_OF_WEEK] < weekday ? 0 : -1))}; + return new int[] + { + dayOfYear, + fields[DAY_OF_WEEK] - weekday + + 7 * (fields[DAY_OF_WEEK_IN_MONTH] + + (fields[DAY_OF_WEEK] < weekday ? 0 : -1)) + }; } } // MONTH + something did not succeed. if (isSet[DAY_OF_YEAR]) - { - return new int[] {0, fields[DAY_OF_YEAR]}; - } - + return new int[] { 0, fields[DAY_OF_YEAR] }; + if (isSet[DAY_OF_WEEK] && isSet[WEEK_OF_YEAR]) { int dayOfYear = getMinimalDaysInFirstWeek(); + // the weekday of the day, that begins the first week // in that year is: int weekday = getWeekDay(year, dayOfYear); - return new int[] { - dayOfYear, - // the day of week in the first week - // (weeks starting on sunday) is: - fields[DAY_OF_WEEK] - weekday - // Now jump to the right week and correct the possible - // error made by assuming sunday is the first week day. - + 7 * (fields[WEEK_OF_YEAR] - + (fields[DAY_OF_WEEK] < getFirstDayOfWeek()? 0 : -1) - + (weekday < getFirstDayOfWeek()? -1 : 0))}; + return new int[] + { + dayOfYear, + + // the day of week in the first week + // (weeks starting on sunday) is: + fields[DAY_OF_WEEK] - weekday + // Now jump to the right week and correct the possible + // error made by assuming sunday is the first week day. + + 7 * (fields[WEEK_OF_YEAR] + + (fields[DAY_OF_WEEK] < getFirstDayOfWeek() ? 0 : -1) + + (weekday < getFirstDayOfWeek() ? -1 : 0)) + }; } // As last resort return Jan, 1st. - return new int[] {1, 0}; + return new int[] { 1, 0 }; } /** * Converts the time field values (fields
) to
- * milliseconds since the epoch UTC (time
).
+ * milliseconds since the epoch UTC (time
).
*
* @throws IllegalArgumentException if any calendar fields
* are invalid.
@@ -542,9 +542,9 @@
else if (isSet[HOUR])
{
hour = fields[HOUR];
- if (isSet[AM_PM] && fields[AM_PM] == PM)
+ if (isSet[AM_PM] && fields[AM_PM] == PM)
if (hour != 12) /* not Noon */
- hour += 12;
+ hour += 12;
/* Fix the problem of the status of 12:00 AM (midnight). */
if (isSet[AM_PM] && fields[AM_PM] == AM && hour == 12)
hour = 0;
@@ -559,14 +559,14 @@
{
// prevent overflow
long allMillis = (((hour * 60L) + minute) * 60L + second) * 1000L
- + millis;
+ + millis;
daysOfYear[1] += allMillis / (24 * 60 * 60 * 1000L);
millisInDay = (int) (allMillis % (24 * 60 * 60 * 1000L));
}
else
{
- if (hour < 0 || hour >= 24 || minute < 0 || minute > 59
- || second < 0 || second > 59 || millis < 0 || millis >= 1000)
+ if (hour < 0 || hour >= 24 || minute < 0 || minute > 59 || second < 0
+ || second > 59 || millis < 0 || millis >= 1000)
throw new IllegalArgumentException();
millisInDay = (((hour * 60) + minute) * 60 + second) * 1000 + millis;
}
@@ -576,10 +576,9 @@
// get right behaviour when jumping over the gregorianCutover.
time += daysOfYear[1] * (24 * 60 * 60 * 1000L);
-
TimeZone zone = getTimeZone();
- int rawOffset = isSet[ZONE_OFFSET]
- ? fields[ZONE_OFFSET] : zone.getRawOffset();
+ int rawOffset = isSet[ZONE_OFFSET] ? fields[ZONE_OFFSET]
+ : zone.getRawOffset();
int day = (int) (time / (24 * 60 * 60 * 1000L));
millisInDay = (int) (time % (24 * 60 * 60 * 1000L));
@@ -595,18 +594,20 @@
int month = f[MONTH];
day = f[DAY_OF_MONTH];
int weekday = f[DAY_OF_WEEK];
- int dstOffset = isSet[DST_OFFSET]
- ? fields[DST_OFFSET] : (zone.getOffset((year < 0) ? BC : AD,
- (year < 0) ? 1 - year : year,
- month, day, weekday, millisInDay)
- - zone.getRawOffset());
+ int dstOffset = isSet[DST_OFFSET] ? fields[DST_OFFSET]
+ : (zone.getOffset((year < 0) ? BC : AD,
+ (year < 0) ? 1 - year
+ : year,
+ month, day, weekday,
+ millisInDay)
+ - zone.getRawOffset());
time -= rawOffset + dstOffset;
isTimeSet = true;
}
/**
* - * Determines if the given year is a leap year. + * Determines if the given year is a leap year. *
*
* To specify a year in the BC era, use a negative value calculated
@@ -616,7 +617,7 @@
*
* @param year a year (use a negative value for BC).
* @param gregorian if true, use the gregorian leap year rule.
- * @return true, if the given year is a leap year, false otherwise.
+ * @return true, if the given year is a leap year, false otherwise.
*/
private boolean isLeapYear(int year, boolean gregorian)
{
@@ -624,7 +625,7 @@
// Only years divisible by 4 can be leap years
return false;
- if (!gregorian)
+ if (! gregorian)
return true;
// We rely on AD area here.
@@ -635,12 +636,12 @@
* Get the linear day in days since the epoch, using the
* Julian or Gregorian calendar as specified. If you specify a
* nonpositive year it is interpreted as BC as following: 0 is 1
- * BC, -1 is 2 BC and so on.
+ * BC, -1 is 2 BC and so on.
*
* @param year the year of the date.
* @param dayOfYear the day of year of the date; 1 based.
* @param gregorian true
, if we should use the Gregorian rules.
- * @return the days since the epoch, may be negative.
+ * @return the days since the epoch, may be negative.
*/
private long getLinearDay(int year, int dayOfYear, boolean gregorian)
{
@@ -648,8 +649,8 @@
// Calender until the epoch.
// We shift right by 2 instead of dividing by 4, to get correct
// results for negative years (and this is even more efficient).
- long julianDay = ((year * (365L * 4 + 1)) >> 2) + dayOfYear -
- ((1970 * (365 * 4 + 1)) / 4 + 1 - 13);
+ long julianDay = ((year * (365L * 4 + 1)) >> 2) + dayOfYear
+ - ((1970 * (365 * 4 + 1)) / 4 + 1 - 13);
if (gregorian)
{
@@ -663,7 +664,7 @@
// The additional leap year factor accounts for the fact that
// a leap day is not seen on Jan 1 of the leap year.
int gregOffset = (year / 400) - (year / 100) + 2;
- if (isLeapYear (year, true) && dayOfYear < 31 + 29)
+ if (isLeapYear(year, true) && dayOfYear < 31 + 29)
--gregOffset;
julianDay += gregOffset;
}
@@ -675,22 +676,23 @@
* day_of_year, day_of_month, day_of_week, and writes the result
* into the fields array.
*
- * @param day the linear day.
+ * @param day the linear day.
* @param gregorian true, if we should use Gregorian rules.
*/
private void calculateDay(int[] fields, long day, boolean gregorian)
{
// the epoch is a Thursday.
- int weekday = (int)(day + THURSDAY) % 7;
+ int weekday = (int) (day + THURSDAY) % 7;
if (weekday <= 0)
weekday += 7;
fields[DAY_OF_WEEK] = weekday;
// get a first approximation of the year. This may be one
// year too big.
- int year = 1970 + (int)(gregorian
- ? ((day - 100) * 400) / (365 * 400 + 100 - 4 + 1)
- : ((day - 100) * 4) / (365 * 4 + 1));
+ int year = 1970
+ + (int) (gregorian
+ ? ((day - 100) * 400) / (365 * 400 + 100 - 4 + 1)
+ : ((day - 100) * 4) / (365 * 4 + 1));
if (day >= 0)
year++;
@@ -703,9 +705,9 @@
firstDayOfYear = getLinearDay(year, 1, gregorian);
}
- day -= firstDayOfYear - 1; // day of year, one based.
+ day -= firstDayOfYear - 1; // day of year, one based.
- fields[DAY_OF_YEAR] = (int)day;
+ fields[DAY_OF_YEAR] = (int) day;
if (year <= 0)
{
fields[ERA] = BC;
@@ -720,13 +722,13 @@
int leapday = isLeapYear(year, gregorian) ? 1 : 0;
if (day <= 31 + 28 + leapday)
{
- fields[MONTH] = (int)day / 32; // 31->JANUARY, 32->FEBRUARY
- fields[DAY_OF_MONTH] = (int)day - 31 * fields[MONTH];
+ fields[MONTH] = (int) day / 32; // 31->JANUARY, 32->FEBRUARY
+ fields[DAY_OF_MONTH] = (int) day - 31 * fields[MONTH];
}
else
{
// A few more magic formulas
- int scaledDay = ((int)day - leapday) * 5 + 8;
+ int scaledDay = ((int) day - leapday) * 5 + 8;
fields[MONTH] = scaledDay / (31 + 30 + 31 + 30 + 31);
fields[DAY_OF_MONTH] = (scaledDay % (31 + 30 + 31 + 30 + 31)) / 5 + 1;
}
@@ -754,10 +756,10 @@
}
calculateDay(fields, day, gregorian);
- fields[DST_OFFSET] =
- zone.getOffset(fields[ERA], fields[YEAR], fields[MONTH],
- fields[DAY_OF_MONTH], fields[DAY_OF_WEEK],
- millisInDay) - fields[ZONE_OFFSET];
+ fields[DST_OFFSET] = zone.getOffset(fields[ERA], fields[YEAR],
+ fields[MONTH], fields[DAY_OF_MONTH],
+ fields[DAY_OF_WEEK], millisInDay)
+ - fields[ZONE_OFFSET];
millisInDay += fields[DST_OFFSET];
if (millisInDay >= 24 * 60 * 60 * 1000)
@@ -778,13 +780,12 @@
// Do the Correction: getMinimalDaysInFirstWeek() is always in the
// first week.
int minDays = getMinimalDaysInFirstWeek();
- int firstWeekday =
- (7 + getWeekDay(fields[YEAR], minDays) - getFirstDayOfWeek()) % 7;
+ int firstWeekday = (7 + getWeekDay(fields[YEAR], minDays)
+ - getFirstDayOfWeek()) % 7;
if (minDays - firstWeekday < 1)
weekOfYear++;
fields[WEEK_OF_YEAR] = weekOfYear;
-
int hourOfDay = millisInDay / (60 * 60 * 1000);
fields[AM_PM] = (hourOfDay < 12) ? AM : PM;
int hour = hourOfDay % 12;
@@ -796,14 +797,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 = 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;
}
/**
@@ -811,7 +805,7 @@
* equivalent to this if it is also a GregorianCalendar
* with the same time since the epoch under the same conditions
* (same change date and same time zone).
- *
+ *
* @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 necessarily have the same fields).
@@ -823,7 +817,7 @@
*/
public boolean equals(Object o)
{
- if (!(o instanceof GregorianCalendar))
+ if (! (o instanceof GregorianCalendar))
return false;
GregorianCalendar cal = (GregorianCalendar) o;
@@ -839,11 +833,9 @@
// public boolean before(Object o) {
// if (!(o instanceof GregorianCalendar))
// return false;
-
// GregorianCalendar cal = (GregorianCalendar) o;
// return (cal.getTimeInMillis() < getTimeInMillis());
// }
-
// /**
// * Compares the given calender with this.
// * @param o the object to that we should compare.
@@ -853,7 +845,6 @@
// public boolean after(Object o) {
// if (!(o instanceof GregorianCalendar))
// return false;
-
// GregorianCalendar cal = (GregorianCalendar) o;
// return (cal.getTimeInMillis() > getTimeInMillis());
// }
@@ -864,7 +855,7 @@
* it does what you expect: Jan, 25 + 10 Days is Feb, 4.
* @param field one of the time field constants.
* @param amount the amount of time to add.
- * @exception IllegalArgumentException if field
is
+ * @exception IllegalArgumentException if field
is
* ZONE_OFFSET
, DST_OFFSET
, or invalid; or
* if amount
contains an out-of-range value and the calendar
* is not in lenient mode.
@@ -899,7 +890,7 @@
case DAY_OF_MONTH:
case DAY_OF_YEAR:
case DAY_OF_WEEK:
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
time += amount * (24 * 60 * 60 * 1000L);
areFieldsSet = false;
@@ -907,59 +898,57 @@
case WEEK_OF_YEAR:
case WEEK_OF_MONTH:
case DAY_OF_WEEK_IN_MONTH:
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
time += amount * (7 * 24 * 60 * 60 * 1000L);
areFieldsSet = false;
break;
case AM_PM:
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
time += amount * (12 * 60 * 60 * 1000L);
areFieldsSet = false;
break;
case HOUR:
case HOUR_OF_DAY:
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
time += amount * (60 * 60 * 1000L);
areFieldsSet = false;
break;
case MINUTE:
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
time += amount * (60 * 1000L);
areFieldsSet = false;
break;
case SECOND:
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
time += amount * (1000L);
areFieldsSet = false;
break;
case MILLISECOND:
- if (!isTimeSet)
+ if (! isTimeSet)
computeTime();
time += amount;
areFieldsSet = false;
break;
case ZONE_OFFSET:
- case DST_OFFSET:
- default:
+ case DST_OFFSET:default:
throw new IllegalArgumentException("Invalid or unknown field");
}
}
-
/**
* 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
- * minimum value.
+ * the maximum for this field is reached, start over with the
+ * minimum value.
*
* Note: There may be situation, where the other
- * fields must be changed, e.g rolling the month on May, 31.
- * The date June, 31 is automatically converted to July, 1.
+ * fields must be changed, e.g rolling the month on May, 31.
+ * The date June, 31 is automatically converted to July, 1.
* This requires lenient settings.
*
* @param field the time field. One of the time field constants.
@@ -1001,7 +990,6 @@
isSet[DAY_OF_YEAR] = false;
isSet[WEEK_OF_YEAR] = false;
break;
-
case DAY_OF_MONTH:
isSet[WEEK_OF_MONTH] = false;
isSet[DAY_OF_WEEK] = false;
@@ -1010,7 +998,6 @@
isSet[WEEK_OF_YEAR] = false;
time += delta * (24 * 60 * 60 * 1000L);
break;
-
case WEEK_OF_MONTH:
isSet[DAY_OF_MONTH] = false;
isSet[DAY_OF_WEEK_IN_MONTH] = false;
@@ -1042,7 +1029,6 @@
isSet[DAY_OF_YEAR] = false;
time += delta * (7 * 24 * 60 * 60 * 1000L);
break;
-
case AM_PM:
isSet[HOUR_OF_DAY] = false;
time += delta * (12 * 60 * 60 * 1000L);
@@ -1056,7 +1042,6 @@
isSet[AM_PM] = false;
time += delta * (60 * 60 * 1000L);
break;
-
case MINUTE:
time += delta * (60 * 1000L);
break;
@@ -1076,7 +1061,7 @@
* with the minimum value and vice versa for negative amounts.
*
* Note: 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 corrected to June, 30.
*
* @param field the time field. One of the time field constants.
@@ -1113,16 +1098,23 @@
/**
* The minimum values for the calendar fields.
*/
- private static final int[] minimums =
- { BC, 1, 0, 0, 1, 1, 1, SUNDAY, 1,
- AM, 1, 0, 1, 1, 1, -(12*60*60*1000), 0 };
+ private static final int[] minimums =
+ {
+ BC, 1, 0, 0, 1, 1, 1, SUNDAY, 1, AM,
+ 1, 0, 1, 1, 1, -(12 * 60 * 60 * 1000),
+ 0
+ };
/**
* The maximum values for the calendar fields.
*/
- private static final int[] maximums =
- { AD, 5000000, 11, 53, 5, 31, 366, SATURDAY, 5,
- PM, 12, 23, 59, 59, 999, +(12*60*60*1000), (12*60*60*1000) };
+ private static final int[] maximums =
+ {
+ AD, 5000000, 11, 53, 5, 31, 366,
+ SATURDAY, 5, PM, 12, 23, 59, 59, 999,
+ +(12 * 60 * 60 * 1000),
+ (12 * 60 * 60 * 1000)
+ };
/**
* Gets the smallest value that is allowed for the specified field.
@@ -1146,7 +1138,6 @@
return maximums[field];
}
-
/**
* Gets the greatest minimum value that is allowed for the specified field.
* This is the largest value returned by the getActualMinimum(int)
@@ -1171,7 +1162,7 @@
* 28 days).
*
* @param field the time field. One of the time field constants.
- * @return the least maximum value.
+ * @return the least maximum value.
* @see #getActualMaximum(int)
* @since 1.2
*/
@@ -1211,7 +1202,7 @@
int min = getMinimalDaysInFirstWeek();
if (min == 0)
return 1;
- if (!areFieldsSet || !isSet[ERA] || !isSet[YEAR])
+ if (! areFieldsSet || ! isSet[ERA] || ! isSet[YEAR])
complete();
int year = fields[ERA] == AD ? fields[YEAR] : 1 - fields[YEAR];
@@ -1232,45 +1223,46 @@
* 29, rather than 28.
*
* @param field the time field. One of the time field constants.
- * @return the actual maximum value.
+ * @return the actual maximum value.
*/
public int getActualMaximum(int field)
{
switch (field)
{
case WEEK_OF_YEAR:
- {
- if (!areFieldsSet || !isSet[ERA] || !isSet[YEAR])
+ {
+ if (! areFieldsSet || ! isSet[ERA] || ! isSet[YEAR])
complete();
+
// This is wrong for the year that contains the gregorian change.
// I.e it gives the weeks in the julian year or in the gregorian
// year in that case.
int year = fields[ERA] == AD ? fields[YEAR] : 1 - fields[YEAR];
int lastDay = isLeapYear(year) ? 366 : 365;
int weekday = getWeekDay(year, lastDay);
- int week = (lastDay + 6
- - (7 + weekday - getFirstDayOfWeek()) % 7) / 7;
+ int week = (lastDay + 6 - (7 + weekday - getFirstDayOfWeek()) % 7) / 7;
int minimalDays = getMinimalDaysInFirstWeek();
int firstWeekday = getWeekDay(year, minimalDays);
- /*
+ /*
* Is there a set of days at the beginning of the year, before the
* first day of the week, equal to or greater than the minimum number
* of days required in the first week?
*/
if (minimalDays - (7 + firstWeekday - getFirstDayOfWeek()) % 7 < 1)
return week + 1; /* Add week 1: firstWeekday through to firstDayOfWeek */
- }
- case DAY_OF_MONTH:
- {
- if (!areFieldsSet || !isSet[MONTH])
+ }
+ case DAY_OF_MONTH:
+ {
+ if (! areFieldsSet || ! isSet[MONTH])
complete();
int month = fields[MONTH];
+
// If you change this, you should also change
// SimpleTimeZone.getDaysInMonth();
if (month == FEBRUARY)
{
- if (!isSet[YEAR] || !isSet[ERA])
+ if (! isSet[YEAR] || ! isSet[ERA])
complete();
int year = fields[ERA] == AD ? fields[YEAR] : 1 - fields[YEAR];
return isLeapYear(year) ? 29 : 28;
@@ -1279,33 +1271,31 @@
return 31 - (month & 1);
else
return 30 + (month & 1);
- }
+ }
case DAY_OF_YEAR:
- {
- if (!areFieldsSet || !isSet[ERA] || !isSet[YEAR])
+ {
+ if (! areFieldsSet || ! isSet[ERA] || ! isSet[YEAR])
complete();
int year = fields[ERA] == AD ? fields[YEAR] : 1 - fields[YEAR];
return isLeapYear(year) ? 366 : 365;
- }
+ }
case DAY_OF_WEEK_IN_MONTH:
- {
+ {
// This is wrong for the month that contains the gregorian change.
int daysInMonth = getActualMaximum(DAY_OF_MONTH);
+
// That's black magic, I know
return (daysInMonth - (fields[DAY_OF_MONTH] - 1) % 7 + 6) / 7;
- }
+ }
case WEEK_OF_MONTH:
- {
+ {
int daysInMonth = getActualMaximum(DAY_OF_MONTH);
int weekday = (daysInMonth - fields[DAY_OF_MONTH]
- + fields[DAY_OF_WEEK] - SUNDAY) % 7 + SUNDAY;
- return (daysInMonth + 6
- - (7 + weekday - getFirstDayOfWeek()) % 7) / 7;
- }
+ + fields[DAY_OF_WEEK] - SUNDAY) % 7 + SUNDAY;
+ return (daysInMonth + 6 - (7 + weekday - getFirstDayOfWeek()) % 7) / 7;
+ }
default:
return maximums[field];
}
}
-
-
}
Index: java/util/SimpleTimeZone.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/SimpleTimeZone.java,v
retrieving revision 1.20
diff -u -r1.20 SimpleTimeZone.java
--- java/util/SimpleTimeZone.java 8 Jan 2005 10:39:09 -0000 1.20
+++ java/util/SimpleTimeZone.java 21 Jan 2005 16:24:04 -0000
@@ -38,6 +38,7 @@
package java.util;
+
/**
* This class represents a simple time zone offset and handles
* daylight savings. It can only handle one daylight savings rule, so
@@ -49,14 +50,14 @@
* lying in the AD era.
*
* @see Calendar
- * @see GregorianCalender
+ * @see GregorianCalender
* @author Jochen Hoenicke
*/
public class SimpleTimeZone extends TimeZone
{
/**
* The raw time zone offset in milliseconds to GMT, ignoring
- * daylight savings.
+ * daylight savings.
* @serial
*/
private int rawOffset;
@@ -77,16 +78,15 @@
private int dstSavings = 60 * 60 * 1000;
/**
- * The first year, in which daylight savings rules applies.
+ * The first year, in which daylight savings rules applies.
* @serial
*/
private int startYear;
-
private static final int DOM_MODE = 1;
private static final int DOW_IN_MONTH_MODE = 2;
private static final int DOW_GE_DOM_MODE = 3;
private static final int DOW_LE_DOM_MODE = 4;
-
+
/**
* The mode of the start rule. This takes one of the following values:
*
SimpleTimeZone
with the given time offset
- * from GMT and without daylight savings.
+ * from GMT and without daylight savings.
* @param rawOffset the time offset from GMT in milliseconds.
- * @param id The identifier of this time zone.
+ * @param id The identifier of this time zone.
*/
public SimpleTimeZone(int rawOffset, String id)
{
@@ -273,7 +275,7 @@
* Create a SimpleTimeZone
with the given time offset
* from GMT and with daylight savings. The start/end parameters
* can have different meaning (replace WEEKDAY with a real day of
- * week). Only the first two meanings were supported by earlier
+ * week). Only the first two meanings were supported by earlier
* versions of jdk.
*
* setEndRule
or the result of
@@ -514,14 +507,16 @@
* @since 1.2
* @see SimpleTimeZone
*/
- public void setStartRule(int month, int day, int dayOfWeek, int time, boolean after)
+ public void setStartRule(int month, int day, int dayOfWeek, int time,
+ boolean after)
{
// FIXME: XXX: Validate that checkRule and offset processing work with on
// or before mode.
this.startDay = after ? Math.abs(day) : -Math.abs(day);
this.startDayOfWeek = after ? Math.abs(dayOfWeek) : -Math.abs(dayOfWeek);
- this.startMode = (dayOfWeek != 0) ? (after ? DOW_GE_DOM_MODE : DOW_LE_DOM_MODE)
- : checkRule(month, day, dayOfWeek);
+ this.startMode = (dayOfWeek != 0)
+ ? (after ? DOW_GE_DOM_MODE : DOW_LE_DOM_MODE)
+ : checkRule(month, day, dayOfWeek);
this.startDay = Math.abs(this.startDay);
this.startDayOfWeek = Math.abs(this.startDayOfWeek);
@@ -606,14 +601,16 @@
* @since 1.2
* @see #setStartRule
*/
- public void setEndRule(int month, int day, int dayOfWeek, int time, boolean after)
+ public void setEndRule(int month, int day, int dayOfWeek, int time,
+ boolean after)
{
// FIXME: XXX: Validate that checkRule and offset processing work with on
// or before mode.
this.endDay = after ? Math.abs(day) : -Math.abs(day);
this.endDayOfWeek = after ? Math.abs(dayOfWeek) : -Math.abs(dayOfWeek);
- this.endMode = (dayOfWeek != 0) ? (after ? DOW_GE_DOM_MODE : DOW_LE_DOM_MODE)
- : checkRule(month, day, dayOfWeek);
+ this.endMode = (dayOfWeek != 0)
+ ? (after ? DOW_GE_DOM_MODE : DOW_LE_DOM_MODE)
+ : checkRule(month, day, dayOfWeek);
this.endDay = Math.abs(this.endDay);
this.endDayOfWeek = Math.abs(endDayOfWeek);
@@ -648,7 +645,7 @@
}
/**
- * Gets the time zone offset, for current date, modified in case of
+ * Gets the time zone offset, for current date, modified in case of
* daylight savings. This is the offset to add to UTC to get the local
* time.
*
@@ -674,8 +671,8 @@
* @return the time zone offset in milliseconds.
* @throws IllegalArgumentException if arguments are incorrect.
*/
- public int getOffset(int era, int year, int month,
- int day, int dayOfWeek, int millis)
+ public int getOffset(int era, int year, int month, int day, int dayOfWeek,
+ int millis)
{
int daysInMonth = getDaysInMonth(month, year);
if (day < 1 || day > daysInMonth)
@@ -691,27 +688,21 @@
{
// This does only work for Gregorian calendars :-(
// This is mainly because setStartYear doesn't take an era.
-
- boolean afterStart = !isBefore(year, month, day, dayOfWeek, millis,
- startMode, startMonth,
- startDay, startDayOfWeek, startTime);
+ boolean afterStart = ! isBefore(year, month, day, dayOfWeek, millis,
+ startMode, startMonth, startDay,
+ startDayOfWeek, startTime);
boolean beforeEnd = isBefore(year, month, day, dayOfWeek,
- millis + dstSavings,
- endMode, endMonth,
- endDay, endDayOfWeek, endTime);
+ millis + dstSavings, endMode, endMonth,
+ endDay, endDayOfWeek, endTime);
if (startMonth < endMonth)
- {
- // use daylight savings, if the date is after the start of
- // savings, and before the end of savings.
- daylightSavings = afterStart && beforeEnd ? dstSavings : 0;
- }
+ // use daylight savings, if the date is after the start of
+ // savings, and before the end of savings.
+ daylightSavings = afterStart && beforeEnd ? dstSavings : 0;
else
- {
- // use daylight savings, if the date is before the end of
- // savings, or after the start of savings.
- daylightSavings = beforeEnd || afterStart ? dstSavings : 0;
- }
+ // use daylight savings, if the date is before the end of
+ // savings, or after the start of savings.
+ daylightSavings = beforeEnd || afterStart ? dstSavings : 0;
}
return rawOffset + daylightSavings;
}
@@ -740,7 +731,7 @@
* milliseconds with respect to standard time. Typically this
* is one hour, but for some time zones this may be half an our.
* @return the daylight savings offset in milliseconds.
- *
+ *
* @since 1.2
*/
public int getDSTSavings()
@@ -760,7 +751,7 @@
{
if (dstSavings <= 0)
throw new IllegalArgumentException("illegal value for dstSavings");
-
+
this.dstSavings = dstSavings;
}
@@ -775,7 +766,7 @@
/**
* Returns the number of days in the given month. It does always
- * use the Gregorian leap year rule.
+ * use the Gregorian leap year rule.
* @param month The month, zero based; use one of the Calendar constants.
* @param year The year.
*/
@@ -783,12 +774,9 @@
{
// Most of this is copied from GregorianCalendar.getActualMaximum()
if (month == Calendar.FEBRUARY)
- {
- return ((year & 3) == 0 && (year % 100 != 0 || year % 400 == 0))
- ? 29 : 28;
- }
+ return ((year & 3) == 0 && (year % 100 != 0 || year % 400 == 0)) ? 29 : 28;
else if (month < Calendar.AUGUST)
- return 31 - (month & 1);
+ return 31 - (month & 1);
else
return 30 + (month & 1);
}
@@ -804,23 +792,19 @@
* @param mode the change mode; same semantic as startMode.
* @param month the change month; same semantic as startMonth.
* @param day the change day; same semantic as startDay.
- * @param dayOfWeek the change day of week;
+ * @param dayOfWeek the change day of week;
* @param millis the change time in millis since midnight standard time.
* same semantic as startDayOfWeek.
* @return true, if cal is before the change, false if cal is on
* or after the change.
*/
- private boolean isBefore(int calYear,
- int calMonth, int calDayOfMonth, int calDayOfWeek,
- int calMillis, int mode, int month,
- int day, int dayOfWeek, int millis)
+ private boolean isBefore(int calYear, int calMonth, int calDayOfMonth,
+ int calDayOfWeek, int calMillis, int mode,
+ int month, int day, int dayOfWeek, int millis)
{
-
// This method is called by Calendar, so we mustn't use that class.
// We have to do all calculations by hand.
-
// check the months:
-
// XXX - this is not correct:
// for the DOW_GE_DOM and DOW_LE_DOM modes the change date may
// be in a different month.
@@ -835,7 +819,7 @@
return calDayOfMonth < day;
break;
case DOW_IN_MONTH_MODE:
- {
+ {
// This computes the day of month of the day of type
// "dayOfWeek" that lies in the same (sunday based) week as cal.
calDayOfMonth += (dayOfWeek - calDayOfWeek);
@@ -844,7 +828,6 @@
// after dividing by 7). If we count from the end of the
// month, we get want a -7 based number counting the days from
// the end:
-
if (day < 0)
calDayOfMonth -= getDaysInMonth(calMonth, calYear) + 7;
else
@@ -857,9 +840,9 @@
// 20 21 22 23 24 25 26 -23-22-21-20-19-18-17
// 27 28 29 30 31 32 33 -16-15-14-13-12-11-10
// 34 35 36 -9 -8 -7
-
// Now we calculate the day of week in month:
int week = calDayOfMonth / 7;
+
// day > 0 day < 0
// S M T W T F S S M T W T F S
// 1 1 1 1 1 1 -5 -5 -4 -4 -4 -4
@@ -867,7 +850,6 @@
// 2 3 3 3 3 3 3 -3 -3 -3 -2 -2 -2 -2
// 3 4 4 4 4 4 4 -2 -2 -2 -1 -1 -1 -1
// 4 5 5 -1 -1 -1
-
if (week != day)
return week < day;
@@ -876,26 +858,25 @@
// daylight savings starts/ends on the given day.
break;
- }
-
+ }
case DOW_LE_DOM_MODE:
// The greatest sunday before or equal December, 12
// is the same as smallest sunday after or equal December, 6.
day = Math.abs(day) - 6;
-
case DOW_GE_DOM_MODE:
-
// Calculate the day of month of the day of type
// "dayOfWeek" that lies before (or on) the given date.
- calDayOfMonth -= (calDayOfWeek < dayOfWeek ? 7 : 0)
- + calDayOfWeek - dayOfWeek;
+ calDayOfMonth -= (calDayOfWeek < dayOfWeek ? 7 : 0) + calDayOfWeek
+ - dayOfWeek;
if (calDayOfMonth < day)
return true;
if (calDayOfWeek != dayOfWeek || calDayOfMonth >= day + 7)
return false;
+
// now we have the same day
break;
}
+
// the millis decides:
return (calMillis < millis);
}
@@ -914,40 +895,35 @@
/**
* Generates the hashCode for the SimpleDateFormat object. It is
* the rawOffset, possibly, if useDaylightSavings is true, xored
- * with startYear, startMonth, startDayOfWeekInMonth, ..., endTime.
+ * with startYear, startMonth, startDayOfWeekInMonth, ..., endTime.
*/
public synchronized int hashCode()
{
- return rawOffset ^
- (useDaylight ?
- startMonth ^ startDay ^ startDayOfWeek ^ startTime
- ^ endMonth ^ endDay ^ endDayOfWeek ^ endTime : 0);
+ return rawOffset
+ ^ (useDaylight
+ ? startMonth ^ startDay ^ startDayOfWeek ^ startTime ^ endMonth
+ ^ endDay ^ endDayOfWeek ^ endTime : 0);
}
public synchronized boolean equals(Object o)
{
if (this == o)
return true;
- if (!(o instanceof SimpleTimeZone))
+ if (! (o instanceof SimpleTimeZone))
return false;
SimpleTimeZone zone = (SimpleTimeZone) o;
- if (zone.hashCode() != hashCode()
- || !getID().equals(zone.getID())
- || rawOffset != zone.rawOffset || useDaylight != zone.useDaylight)
+ if (zone.hashCode() != hashCode() || ! getID().equals(zone.getID())
+ || rawOffset != zone.rawOffset || useDaylight != zone.useDaylight)
return false;
- if (!useDaylight)
+ if (! useDaylight)
return true;
- return (startYear == zone.startYear
- && startMonth == zone.startMonth
- && startDay == zone.startDay
- && startDayOfWeek == zone.startDayOfWeek
- && startTime == zone.startTime
- && startTimeMode == zone.startTimeMode
- && endMonth == zone.endMonth
- && endDay == zone.endDay
- && endDayOfWeek == zone.endDayOfWeek
- && endTime == zone.endTime
- && endTimeMode == zone.endTimeMode);
+ return (startYear == zone.startYear && startMonth == zone.startMonth
+ && startDay == zone.startDay
+ && startDayOfWeek == zone.startDayOfWeek
+ && startTime == zone.startTime
+ && startTimeMode == zone.startTimeMode && endMonth == zone.endMonth
+ && endDay == zone.endDay && endDayOfWeek == zone.endDayOfWeek
+ && endTime == zone.endTime && endTimeMode == zone.endTimeMode);
}
/**
@@ -962,25 +938,21 @@
{
if (this == other)
return true;
- if (!(other instanceof SimpleTimeZone))
+ if (! (other instanceof SimpleTimeZone))
return false;
SimpleTimeZone zone = (SimpleTimeZone) other;
- if (zone.hashCode() != hashCode()
- || rawOffset != zone.rawOffset || useDaylight != zone.useDaylight)
+ if (zone.hashCode() != hashCode() || rawOffset != zone.rawOffset
+ || useDaylight != zone.useDaylight)
return false;
- if (!useDaylight)
+ if (! useDaylight)
return true;
- return (startYear == zone.startYear
- && startMonth == zone.startMonth
- && startDay == zone.startDay
- && startDayOfWeek == zone.startDayOfWeek
- && startTime == zone.startTime
- && startTimeMode == zone.startTimeMode
- && endMonth == zone.endMonth
- && endDay == zone.endDay
- && endDayOfWeek == zone.endDayOfWeek
- && endTime == zone.endTime
- && endTimeMode == zone.endTimeMode);
+ return (startYear == zone.startYear && startMonth == zone.startMonth
+ && startDay == zone.startDay
+ && startDayOfWeek == zone.startDayOfWeek
+ && startTime == zone.startTime
+ && startTimeMode == zone.startTimeMode && endMonth == zone.endMonth
+ && endDay == zone.endDay && endDayOfWeek == zone.endDayOfWeek
+ && endTime == zone.endTime && endTimeMode == zone.endTimeMode);
}
/**
@@ -991,26 +963,17 @@
{
// the test for useDaylight is an incompatibility to jdk1.2, but
// I think this shouldn't hurt.
- return getClass().getName() + "["
- + "id=" + getID()
- + ",offset=" + rawOffset
- + ",dstSavings=" + dstSavings
- + ",useDaylight=" + useDaylight
- + (useDaylight ?
- ",startYear=" + startYear
- + ",startMode=" + startMode
- + ",startMonth=" + startMonth
- + ",startDay=" + startDay
- + ",startDayOfWeek=" + startDayOfWeek
- + ",startTime=" + startTime
- + ",startTimeMode=" + startTimeMode
- + ",endMode=" + endMode
- + ",endMonth=" + endMonth
- + ",endDay=" + endDay
- + ",endDayOfWeek=" + endDayOfWeek
- + ",endTime=" + endTime
- + ",endTimeMode=" + endTimeMode
- : "") + "]";
+ return getClass().getName() + "[" + "id=" + getID() + ",offset="
+ + rawOffset + ",dstSavings=" + dstSavings + ",useDaylight="
+ + useDaylight
+ + (useDaylight
+ ? ",startYear=" + startYear + ",startMode=" + startMode
+ + ",startMonth=" + startMonth + ",startDay=" + startDay
+ + ",startDayOfWeek=" + startDayOfWeek + ",startTime="
+ + startTime + ",startTimeMode=" + startTimeMode + ",endMode="
+ + endMode + ",endMonth=" + endMonth + ",endDay=" + endDay
+ + ",endDayOfWeek=" + endDayOfWeek + ",endTime=" + endTime
+ + ",endTimeMode=" + endTimeMode : "") + "]";
}
/**
@@ -1029,7 +992,8 @@
startMode = DOW_IN_MONTH_MODE;
startTimeMode = WALL_TIME;
endTimeMode = WALL_TIME;
- serialVersionOnStream = 2; }
+ serialVersionOnStream = 2;
+ }
else
{
int length = input.readInt();
@@ -1054,29 +1018,31 @@
* start/endDay(OfWeek)
-Fields are written in the
* DOW_IN_MONTH_MODE rule, since this was the only supported rule
* in 1.1.
- *
+ *
* In the optional section, we write first the length of an byte
* array as int and afterwards the byte array itself. The byte
* array contains in this release four elements, namely the real
* startDay, startDayOfWeek endDay, endDayOfWeek in that Order.
* These fields are needed, because for compatibility reasons only
* approximative values are written to the required section, as
- * described above.
+ * described above.
*/
private void writeObject(java.io.ObjectOutputStream output)
throws java.io.IOException
{
byte[] byteArray = new byte[]
- {
- (byte) startDay, (byte) startDayOfWeek,
- (byte) endDay, (byte) endDayOfWeek};
+ {
+ (byte) startDay, (byte) startDayOfWeek, (byte) endDay,
+ (byte) endDayOfWeek
+ };
/* calculate the approximation for JDK 1.1 */
switch (startMode)
{
case DOM_MODE:
- startDayOfWeek = Calendar.SUNDAY; // random day of week
- // fall through
+ startDayOfWeek = Calendar.SUNDAY; // random day of week
+
+ // fall through
case DOW_GE_DOM_MODE:
case DOW_LE_DOM_MODE:
startDay = (startDay + 6) / 7;
@@ -1085,7 +1051,8 @@
{
case DOM_MODE:
endDayOfWeek = Calendar.SUNDAY;
- // fall through
+
+ // fall through
case DOW_GE_DOM_MODE:
case DOW_LE_DOM_MODE:
endDay = (endDay + 6) / 7;