diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 1f73bcd5a..059eae60b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ + DurationFormatUtils#formatDurationHMS implementation does not correspond to Javadoc and vice versa DurationFormatUtils are not able to handle negative durations/periods ISO 8601 misspelled throughout the Javadocs Add zero copy read method to StrBuilder diff --git a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java index e9fd007dd..554cef5c9 100644 --- a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java +++ b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java @@ -72,15 +72,14 @@ public class DurationFormatUtils { /** *

Formats the time gap as a string.

* - *

The format used is ISO 8601-like: - * H:m:s.S.

- * + *

The format used is ISO 8601-like: {@code HH:mm:ss.SSS}.

+ * * @param durationMillis the duration to format * @return the formatted duration, not null * @throws java.lang.IllegalArgumentException if durationMillis is negative */ public static String formatDurationHMS(final long durationMillis) { - return formatDuration(durationMillis, "H:mm:ss.SSS"); + return formatDuration(durationMillis, "HH:mm:ss.SSS"); } /** diff --git a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java index 21e11dc65..8f92d52c4 100644 --- a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java @@ -165,31 +165,31 @@ public class DurationFormatUtilsTest { @Test public void testFormatDurationHMS() { long time = 0; - assertEquals("0:00:00.000", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("00:00:00.000", DurationFormatUtils.formatDurationHMS(time)); time = 1; - assertEquals("0:00:00.001", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("00:00:00.001", DurationFormatUtils.formatDurationHMS(time)); time = 15; - assertEquals("0:00:00.015", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("00:00:00.015", DurationFormatUtils.formatDurationHMS(time)); time = 165; - assertEquals("0:00:00.165", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("00:00:00.165", DurationFormatUtils.formatDurationHMS(time)); time = 1675; - assertEquals("0:00:01.675", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("00:00:01.675", DurationFormatUtils.formatDurationHMS(time)); time = 13465; - assertEquals("0:00:13.465", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("00:00:13.465", DurationFormatUtils.formatDurationHMS(time)); time = 72789; - assertEquals("0:01:12.789", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("00:01:12.789", DurationFormatUtils.formatDurationHMS(time)); time = 12789 + 32 * 60000; - assertEquals("0:32:12.789", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("00:32:12.789", DurationFormatUtils.formatDurationHMS(time)); time = 12789 + 62 * 60000; - assertEquals("1:02:12.789", DurationFormatUtils.formatDurationHMS(time)); + assertEquals("01:02:12.789", DurationFormatUtils.formatDurationHMS(time)); } @Test(expected = IllegalArgumentException.class) @@ -367,13 +367,13 @@ public class DurationFormatUtilsTest { // tests the ISO 8601-like assertArrayEquals(new DurationFormatUtils.Token[]{ - new DurationFormatUtils.Token(DurationFormatUtils.H, 1), + new DurationFormatUtils.Token(DurationFormatUtils.H, 2), new DurationFormatUtils.Token(new StringBuilder(":"), 1), new DurationFormatUtils.Token(DurationFormatUtils.m, 2), new DurationFormatUtils.Token(new StringBuilder(":"), 1), new DurationFormatUtils.Token(DurationFormatUtils.s, 2), new DurationFormatUtils.Token(new StringBuilder("."), 1), - new DurationFormatUtils.Token(DurationFormatUtils.S, 3)}, DurationFormatUtils.lexx("H:mm:ss.SSS")); + new DurationFormatUtils.Token(DurationFormatUtils.S, 3)}, DurationFormatUtils.lexx("HH:mm:ss.SSS")); // test the iso extended format assertArrayEquals(new DurationFormatUtils.Token[]{ diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java index f0404edfd..3e464cb66 100644 --- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java +++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java @@ -52,7 +52,7 @@ public class StopWatchTest { public void testStopWatchSimpleGet(){ final StopWatch watch = new StopWatch(); assertEquals(0, watch.getTime()); - assertEquals("0:00:00.000", watch.toString()); + assertEquals("00:00:00.000", watch.toString()); watch.start(); try {Thread.sleep(500);} catch (final InterruptedException ex) {} @@ -74,7 +74,7 @@ public class StopWatchTest { final long totalTime = watch.getTime(); assertEquals("Formatted split string not the correct length", - splitStr.length(), 11); + splitStr.length(), 12); assertTrue(splitTime >= 500); assertTrue(splitTime < 700); assertTrue(totalTime >= 1500);