summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2006-05-14 18:56:14 +0000
committerMark Wielaard <mark@klomp.org>2006-05-14 18:56:14 +0000
commita004a295bc2cf92e77cc1b8ee981f6ab99797e23 (patch)
treec2d1b78cae560a5452c2a9be704e8346366fb4c4
parent6e1b79f37e548f0118e724ce6519aec1cbe1358b (diff)
downloadclasspath-a004a295bc2cf92e77cc1b8ee981f6ab99797e23.tar.gz
2006-05-14 Lillian Angel <langel@redhat.com>
* java/util/SimpleTimeZone.java: Reverted patch. (SimpleTimeZone): Throw exception if startMonth == endMonth. (SimpleTimeZone): Likewise. (checkRule): Rewritten to properly check all values (more efficently). This code is now more stable, at least less buggy than before. Fixed API documentation. (setStartRule): Moved checkRule call to end. (setStartRule): Likewise. (setEndRule): Likewise. (setEndRule): Likewise.
-rw-r--r--ChangeLog15
-rw-r--r--java/util/SimpleTimeZone.java102
2 files changed, 68 insertions, 49 deletions
diff --git a/ChangeLog b/ChangeLog
index 0a2a7681b..b6ce8e776 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2006-05-14 Lillian Angel <langel@redhat.com>
+
+ * java/util/SimpleTimeZone.java: Reverted patch.
+ (SimpleTimeZone): Throw exception if startMonth ==
+ endMonth.
+ (SimpleTimeZone): Likewise.
+ (checkRule): Rewritten to properly check all values (more
+ efficently).
+ This code is now more stable, at least less buggy than before.
+ Fixed API documentation.
+ (setStartRule): Moved checkRule call to end.
+ (setStartRule): Likewise.
+ (setEndRule): Likewise.
+ (setEndRule): Likewise.
+
2006-05-14 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* javax/swing/tree/DefaultTreeSelectionModel.java (leadRow):
diff --git a/java/util/SimpleTimeZone.java b/java/util/SimpleTimeZone.java
index 72d61ff19..d94f89ad3 100644
--- a/java/util/SimpleTimeZone.java
+++ b/java/util/SimpleTimeZone.java
@@ -333,6 +333,8 @@ public class SimpleTimeZone extends TimeZone
setStartRule(startMonth, startDayOfWeekInMonth, startDayOfWeek, startTime);
setEndRule(endMonth, endDayOfWeekInMonth, endDayOfWeek, endTime);
+ if (startMonth == endMonth)
+ throw new IllegalArgumentException("startMonth and endMonth must be different");
this.startYear = 0;
}
@@ -391,6 +393,8 @@ public class SimpleTimeZone extends TimeZone
setStartRule(startMonth, startDayOfWeekInMonth, startDayOfWeek, startTime);
setEndRule(endMonth, endDayOfWeekInMonth, endDayOfWeek, endTime);
+ if (startMonth == endMonth)
+ throw new IllegalArgumentException("startMonth and endMonth must be different");
this.startYear = 0;
this.dstSavings = dstSavings;
@@ -409,66 +413,67 @@ public class SimpleTimeZone extends TimeZone
}
/**
- * Checks if the values are in range and
+ * Checks if the month, day, dayOfWeek arguments are in range and
* returns the mode of the rule.
* @param month the month parameter as in the constructor
+ * @param day the day parameter as in the constructor
+ * @param dayOfWeek the day of week parameter as in the constructor
* @return the mode of this rule see startMode.
* @exception IllegalArgumentException if parameters are out of range.
* @see #SimpleTimeZone(int, String, int, int, int, int, int, int, int, int)
* @see #startMode
*/
- private int checkRule(int month)
+ private int checkRule(int month, int day, int dayOfWeek)
{
- if (startDay != 0)
+ if (month < 0 || month > 11)
+ throw new IllegalArgumentException("month out of range");
+
+ int daysInMonth = getDaysInMonth(month, 1);
+ if (dayOfWeek == 0)
+ {
+ if (day <= 0 || day > daysInMonth)
+ throw new IllegalArgumentException("day out of range");
+ return DOM_MODE;
+ }
+ else if (dayOfWeek > 0)
{
- if (startMonth < 0 || startMonth > 11)
- throw new IllegalArgumentException("month out of range");
-
- if (startDayOfWeek == 0)
- startMode = DOM_MODE;
- else
- {
- if (startDayOfWeek > 0)
- startMode = DOW_IN_MONTH_MODE;
- else
- {
- startDayOfWeek = -startDayOfWeek;
- if (startDay < 0)
- {
- startDay = - startDay;
- startMode = DOW_LE_DOM_MODE;
- }
- else
- startMode = DOW_GE_DOM_MODE;
- }
-
- if (startDayOfWeek > Calendar.SATURDAY)
- throw new IllegalArgumentException("day of week out of range");
- }
-
- if (startMode != DOW_IN_MONTH_MODE
- && (startDay <= 0 || startDay > getDaysInMonth(month, 1)))
- throw new IllegalArgumentException("day out of range");
+ if (Math.abs(day) > (daysInMonth + 6) / 7)
+ throw new IllegalArgumentException("dayOfWeekInMonth out of range");
+ if (dayOfWeek > Calendar.SATURDAY)
+ throw new IllegalArgumentException("dayOfWeek out of range");
+ return DOW_IN_MONTH_MODE;
+ }
+ else
+ {
+ if (day == 0 || Math.abs(day) > daysInMonth)
+ throw new IllegalArgumentException("day out of range");
+ if (dayOfWeek < -Calendar.SATURDAY)
+ throw new IllegalArgumentException("dayOfWeek out of range");
+ if (day < 0)
+ return DOW_LE_DOM_MODE;
+ else
+ return DOW_GE_DOM_MODE;
}
- return startMode;
}
/**
- * Sets the daylight savings start rule. You must also set the end rule with
- * <code>setEndRule</code> or the result of getOffset is undefined. For the
- * parameters see the ten-argument constructor above.
- *
- * @param month The month where daylight savings start, zero based. You should
- * use the constants in Calendar.
+ * Sets the daylight savings start rule. You must also set the
+ * end rule with <code>setEndRule</code> or the result of
+ * getOffset is undefined. For the parameters see the ten-argument
+ * constructor above.
+ *
+ * @param month The month where daylight savings start, zero
+ * based. You should use the constants in Calendar.
* @param day A day of month or day of week in month.
* @param dayOfWeek The day of week where daylight savings start.
- * @param time The time in milliseconds standard time where daylight savings
- * start.
+ * @param time The time in milliseconds standard time where daylight
+ * savings start.
* @exception IllegalArgumentException if parameters are out of range.
* @see SimpleTimeZone
*/
public void setStartRule(int month, int day, int dayOfWeek, int time)
{
+ this.startMode = checkRule(month, day, dayOfWeek);
this.startMonth = month;
this.startDay = day;
this.startDayOfWeek = Math.abs(dayOfWeek);
@@ -478,7 +483,6 @@ public class SimpleTimeZone extends TimeZone
// Convert from UTC to STANDARD
this.startTime = time + this.rawOffset;
useDaylight = true;
- this.startMode = checkRule(month);
}
/**
@@ -513,6 +517,9 @@ public class SimpleTimeZone extends TimeZone
// 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.startDay = Math.abs(this.startDay);
this.startDayOfWeek = Math.abs(this.startDayOfWeek);
@@ -524,9 +531,6 @@ public class SimpleTimeZone extends TimeZone
// Convert from UTC to STANDARD
this.startTime = time + this.rawOffset;
useDaylight = true;
- this.startMode = (dayOfWeek != 0)
- ? (after ? DOW_GE_DOM_MODE : DOW_LE_DOM_MODE)
- : checkRule(month);
}
/**
@@ -562,6 +566,7 @@ public class SimpleTimeZone extends TimeZone
*/
public void setEndRule(int month, int day, int dayOfWeek, int time)
{
+ this.endMode = checkRule(month, day, dayOfWeek);
this.endMonth = month;
this.endDay = day;
this.endDayOfWeek = Math.abs(dayOfWeek);
@@ -574,7 +579,6 @@ public class SimpleTimeZone extends TimeZone
// Convert from UTC to DST
this.endTime = time + this.rawOffset + this.dstSavings;
useDaylight = true;
- this.endMode = checkRule(month);
}
/**
@@ -607,6 +611,9 @@ public class SimpleTimeZone extends TimeZone
// 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.endDay = Math.abs(this.endDay);
this.endDayOfWeek = Math.abs(endDayOfWeek);
@@ -621,9 +628,6 @@ public class SimpleTimeZone extends TimeZone
// Convert from UTC to DST
this.endTime = time + this.rawOffset + this.dstSavings;
useDaylight = true;
- this.endMode = (dayOfWeek != 0)
- ? (after ? DOW_GE_DOM_MODE : DOW_LE_DOM_MODE)
- : checkRule(month);
}
/**
@@ -770,7 +774,7 @@ public class SimpleTimeZone extends TimeZone
* @param year The year.
*/
private int getDaysInMonth(int month, int year)
- {
+ {
if (month == Calendar.FEBRUARY)
{
if ((year & 3) != 0)