stevencaswell 2004/07/05 10:54:48 Modified: lang/src/java/org/apache/commons/lang/time DateUtils.java Log: changed modify method to calculate the field offset and use the set method, rather than adding the offset and letting Calendar perform the calculation - this fixes http://issues.apache.org/bugzilla/show_bug.cgi?id=25560; updated javadocs on round method to explain how rounding across daylight saving time is handled Revision Changes Path 1.20 +38 -2 jakarta-commons/lang/src/java/org/apache/commons/lang/time/DateUtils.java Index: DateUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/time/DateUtils.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- DateUtils.java 27 Jun 2004 06:29:29 -0000 1.19 +++ DateUtils.java 5 Jul 2004 17:54:48 -0000 1.20 @@ -123,6 +123,18 @@ * 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it * would return 1 April 2002 0:00:00.000.</p> * + * <p>For a date in a timezone that handles the change to daylight + * saving time, roudning to Calendar.HOUR_OF_DAY will behave as follows. + * Suppose daylight saving time begins at 02:00 on March 30. Rounding a + * date that crosses this time would produce the following values: + * <ul> + * <li>March 30, 2003 01:10 rounds to March 30, 2003 01:00</li> + * <li>March 30, 2003 01:40 rounds to March 30, 2003 03:00</li> + * <li>March 30, 2003 02:10 rounds to March 30, 2003 03:00</li> + * <li>March 30, 2003 02:40 rounds to March 30, 2003 04:00</li> + * </ul> + * </p> + * * @param date the date to work with * @param field the field from <code>Calendar</code> * or <code>SEMI_MONTH</code> @@ -148,6 +160,18 @@ * 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it * would return 1 April 2002 0:00:00.000.</p> * + * <p>For a date in a timezone that handles the change to daylight + * saving time, roudning to Calendar.HOUR_OF_DAY will behave as follows. + * Suppose daylight saving time begins at 02:00 on March 30. Rounding a + * date that crosses this time would produce the following values: + * <ul> + * <li>March 30, 2003 01:10 rounds to March 30, 2003 01:00</li> + * <li>March 30, 2003 01:40 rounds to March 30, 2003 03:00</li> + * <li>March 30, 2003 02:10 rounds to March 30, 2003 03:00</li> + * <li>March 30, 2003 02:40 rounds to March 30, 2003 04:00</li> + * </ul> + * </p> + * * @param date the date to work with * @param field the field from <code>Calendar</code> * or <code>SEMI_MONTH</code> @@ -172,6 +196,18 @@ * 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it * would return 1 April 2002 0:00:00.000.</p> * + * <p>For a date in a timezone that handles the change to daylight + * saving time, roudning to Calendar.HOUR_OF_DAY will behave as follows. + * Suppose daylight saving time begins at 02:00 on March 30. Rounding a + * date that crosses this time would produce the following values: + * <ul> + * <li>March 30, 2003 01:10 rounds to March 30, 2003 01:00</li> + * <li>March 30, 2003 01:40 rounds to March 30, 2003 03:00</li> + * <li>March 30, 2003 02:10 rounds to March 30, 2003 03:00</li> + * <li>March 30, 2003 02:40 rounds to March 30, 2003 04:00</li> + * </ul> + * </p> + * * @param date the date to work with, either Date or Calendar * @param field the field from <code>Calendar</code> * or <code>SEMI_MONTH</code> @@ -352,7 +388,7 @@ roundUp = offset > ((max - min) / 2); } //We need to remove this field - val.add(fields[i][0], -offset); + val.set(fields[i][0], val.get(fields[i][0]) - offset); } throw new IllegalArgumentException("The field " + field + " is not supported");
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]