You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2007/08/09 02:25:02 UTC
svn commit: r564053 - in /commons/proper/lang/trunk/src:
java/org/apache/commons/lang/time/DateUtils.java
test/org/apache/commons/lang/time/DateUtilsTest.java
Author: bayard
Date: Wed Aug 8 17:24:59 2007
New Revision: 564053
URL: http://svn.apache.org/viewvc?view=rev&rev=564053
Log:
Applying the fix and the test patches from LANG-346 - fixes bugs in DateUtils.round() for minutes and seconds. Patch from Dave Meikle
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/DateUtilsTest.java
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java?view=diff&rev=564053&r1=564052&r2=564053
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java Wed Aug 8 17:24:59 2007
@@ -640,18 +640,18 @@
int millisecs = val.get(Calendar.MILLISECOND);
if (!round || millisecs < 500) {
time = time - millisecs;
- if (field == Calendar.SECOND) {
- done = true;
- }
+ }
+ if (field == Calendar.SECOND) {
+ done = true;
}
// truncate seconds
int seconds = val.get(Calendar.SECOND);
if (!done && (!round || seconds < 30)) {
time = time - (seconds * 1000L);
- if (field == Calendar.MINUTE) {
- done = true;
- }
+ }
+ if (field == Calendar.MINUTE) {
+ done = true;
}
// truncate minutes
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/DateUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/DateUtilsTest.java?view=diff&rev=564053&r1=564052&r2=564053
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/DateUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/DateUtilsTest.java Wed Aug 8 17:24:59 2007
@@ -693,6 +693,69 @@
}
/**
+ * Tests the Changes Made by LANG-346 to the DateUtils.modify() private method invoked
+ * by DateUtils.round().
+ */
+ public void testRoundLang346() throws Exception
+ {
+ TimeZone.setDefault(defaultZone);
+ dateTimeParser.setTimeZone(defaultZone);
+ Calendar testCalendar = Calendar.getInstance();
+ testCalendar.set(2007, 6, 2, 8, 8, 50);
+ Date date = testCalendar.getTime();
+ assertEquals("Minute Round Up Failed",
+ dateTimeParser.parse("July 2, 2007 08:09:00.000"),
+ DateUtils.round(date, Calendar.MINUTE));
+
+ testCalendar.set(2007, 6, 2, 8, 8, 20);
+ date = testCalendar.getTime();
+ assertEquals("Minute No Round Failed",
+ dateTimeParser.parse("July 2, 2007 08:08:00.000"),
+ DateUtils.round(date, Calendar.MINUTE));
+
+ testCalendar.set(2007, 6, 2, 8, 8, 50);
+ testCalendar.set(Calendar.MILLISECOND, 600);
+ date = testCalendar.getTime();
+
+ assertEquals("Second Round Up with 600 Milli Seconds Failed",
+ dateTimeParser.parse("July 2, 2007 08:08:51.000"),
+ DateUtils.round(date, Calendar.SECOND));
+
+ testCalendar.set(2007, 6, 2, 8, 8, 50);
+ testCalendar.set(Calendar.MILLISECOND, 200);
+ date = testCalendar.getTime();
+ assertEquals("Second Round Down with 200 Milli Seconds Failed",
+ dateTimeParser.parse("July 2, 2007 08:08:50.000"),
+ DateUtils.round(date, Calendar.SECOND));
+
+ testCalendar.set(2007, 6, 2, 8, 8, 20);
+ testCalendar.set(Calendar.MILLISECOND, 600);
+ date = testCalendar.getTime();
+ assertEquals("Second Round Up with 200 Milli Seconds Failed",
+ dateTimeParser.parse("July 2, 2007 08:08:21.000"),
+ DateUtils.round(date, Calendar.SECOND));
+
+ testCalendar.set(2007, 6, 2, 8, 8, 20);
+ testCalendar.set(Calendar.MILLISECOND, 200);
+ date = testCalendar.getTime();
+ assertEquals("Second Round Down with 200 Milli Seconds Failed",
+ dateTimeParser.parse("July 2, 2007 08:08:20.000"),
+ DateUtils.round(date, Calendar.SECOND));
+
+ testCalendar.set(2007, 6, 2, 8, 8, 50);
+ date = testCalendar.getTime();
+ assertEquals("Hour Round Down Failed",
+ dateTimeParser.parse("July 2, 2007 08:00:00.000"),
+ DateUtils.round(date, Calendar.HOUR));
+
+ testCalendar.set(2007, 6, 2, 8, 31, 50);
+ date = testCalendar.getTime();
+ assertEquals("Hour Round Up Failed",
+ dateTimeParser.parse("July 2, 2007 09:00:00.000"),
+ DateUtils.round(date, Calendar.HOUR));
+ }
+
+ /**
* Tests various values with the trunc method
*/
public void testTruncate() throws Exception {