LANG-1004: DurationFormatUtils#formatDurationHMS implementation does not correspond to Javadoc and vice versa. Thanks to Michael Osipov

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1592360 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benedikt Ritter 2014-05-04 15:40:59 +00:00
parent 00dc479f6a
commit fd54d42f78
4 changed files with 17 additions and 17 deletions

View File

@ -22,6 +22,7 @@
<body>
<release version="3.4" date="tba" description="tba">
<action issue="LANG-1004" type="update" dev="britter" due-to="Michael Osipov">DurationFormatUtils#formatDurationHMS implementation does not correspond to Javadoc and vice versa</action>
<action issue="LANG-1003" type="update" dev="britter">DurationFormatUtils are not able to handle negative durations/periods</action>
<action issue="LANG-1001" type="fix" dev="ggregory" due-to="Michael Osipov">ISO 8601 misspelled throughout the Javadocs</action>
<action issue="LANG-994" type="add" dev="britter" due-to="Mikhail Mazursky">Add zero copy read method to StrBuilder</action>

View File

@ -72,15 +72,14 @@ public class DurationFormatUtils {
/**
* <p>Formats the time gap as a string.</p>
*
* <p>The format used is ISO 8601-like:
* <i>H</i>:<i>m</i>:<i>s</i>.<i>S</i>.</p>
*
* <p>The format used is ISO 8601-like: {@code HH:mm:ss.SSS}.</p>
*
* @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");
}
/**

View File

@ -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[]{

View File

@ -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);