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:
parent
00dc479f6a
commit
fd54d42f78
|
@ -22,6 +22,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="3.4" date="tba" description="tba">
|
<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-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-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>
|
<action issue="LANG-994" type="add" dev="britter" due-to="Mikhail Mazursky">Add zero copy read method to StrBuilder</action>
|
||||||
|
|
|
@ -72,15 +72,14 @@ public class DurationFormatUtils {
|
||||||
/**
|
/**
|
||||||
* <p>Formats the time gap as a string.</p>
|
* <p>Formats the time gap as a string.</p>
|
||||||
*
|
*
|
||||||
* <p>The format used is ISO 8601-like:
|
* <p>The format used is ISO 8601-like: {@code HH:mm:ss.SSS}.</p>
|
||||||
* <i>H</i>:<i>m</i>:<i>s</i>.<i>S</i>.</p>
|
*
|
||||||
*
|
|
||||||
* @param durationMillis the duration to format
|
* @param durationMillis the duration to format
|
||||||
* @return the formatted duration, not null
|
* @return the formatted duration, not null
|
||||||
* @throws java.lang.IllegalArgumentException if durationMillis is negative
|
* @throws java.lang.IllegalArgumentException if durationMillis is negative
|
||||||
*/
|
*/
|
||||||
public static String formatDurationHMS(final long durationMillis) {
|
public static String formatDurationHMS(final long durationMillis) {
|
||||||
return formatDuration(durationMillis, "H:mm:ss.SSS");
|
return formatDuration(durationMillis, "HH:mm:ss.SSS");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -165,31 +165,31 @@ public class DurationFormatUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFormatDurationHMS() {
|
public void testFormatDurationHMS() {
|
||||||
long time = 0;
|
long time = 0;
|
||||||
assertEquals("0:00:00.000", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("00:00:00.000", DurationFormatUtils.formatDurationHMS(time));
|
||||||
|
|
||||||
time = 1;
|
time = 1;
|
||||||
assertEquals("0:00:00.001", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("00:00:00.001", DurationFormatUtils.formatDurationHMS(time));
|
||||||
|
|
||||||
time = 15;
|
time = 15;
|
||||||
assertEquals("0:00:00.015", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("00:00:00.015", DurationFormatUtils.formatDurationHMS(time));
|
||||||
|
|
||||||
time = 165;
|
time = 165;
|
||||||
assertEquals("0:00:00.165", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("00:00:00.165", DurationFormatUtils.formatDurationHMS(time));
|
||||||
|
|
||||||
time = 1675;
|
time = 1675;
|
||||||
assertEquals("0:00:01.675", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("00:00:01.675", DurationFormatUtils.formatDurationHMS(time));
|
||||||
|
|
||||||
time = 13465;
|
time = 13465;
|
||||||
assertEquals("0:00:13.465", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("00:00:13.465", DurationFormatUtils.formatDurationHMS(time));
|
||||||
|
|
||||||
time = 72789;
|
time = 72789;
|
||||||
assertEquals("0:01:12.789", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("00:01:12.789", DurationFormatUtils.formatDurationHMS(time));
|
||||||
|
|
||||||
time = 12789 + 32 * 60000;
|
time = 12789 + 32 * 60000;
|
||||||
assertEquals("0:32:12.789", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("00:32:12.789", DurationFormatUtils.formatDurationHMS(time));
|
||||||
|
|
||||||
time = 12789 + 62 * 60000;
|
time = 12789 + 62 * 60000;
|
||||||
assertEquals("1:02:12.789", DurationFormatUtils.formatDurationHMS(time));
|
assertEquals("01:02:12.789", DurationFormatUtils.formatDurationHMS(time));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
@ -367,13 +367,13 @@ public class DurationFormatUtilsTest {
|
||||||
|
|
||||||
// tests the ISO 8601-like
|
// tests the ISO 8601-like
|
||||||
assertArrayEquals(new DurationFormatUtils.Token[]{
|
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(new StringBuilder(":"), 1),
|
||||||
new DurationFormatUtils.Token(DurationFormatUtils.m, 2),
|
new DurationFormatUtils.Token(DurationFormatUtils.m, 2),
|
||||||
new DurationFormatUtils.Token(new StringBuilder(":"), 1),
|
new DurationFormatUtils.Token(new StringBuilder(":"), 1),
|
||||||
new DurationFormatUtils.Token(DurationFormatUtils.s, 2),
|
new DurationFormatUtils.Token(DurationFormatUtils.s, 2),
|
||||||
new DurationFormatUtils.Token(new StringBuilder("."), 1),
|
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
|
// test the iso extended format
|
||||||
assertArrayEquals(new DurationFormatUtils.Token[]{
|
assertArrayEquals(new DurationFormatUtils.Token[]{
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class StopWatchTest {
|
||||||
public void testStopWatchSimpleGet(){
|
public void testStopWatchSimpleGet(){
|
||||||
final StopWatch watch = new StopWatch();
|
final StopWatch watch = new StopWatch();
|
||||||
assertEquals(0, watch.getTime());
|
assertEquals(0, watch.getTime());
|
||||||
assertEquals("0:00:00.000", watch.toString());
|
assertEquals("00:00:00.000", watch.toString());
|
||||||
|
|
||||||
watch.start();
|
watch.start();
|
||||||
try {Thread.sleep(500);} catch (final InterruptedException ex) {}
|
try {Thread.sleep(500);} catch (final InterruptedException ex) {}
|
||||||
|
@ -74,7 +74,7 @@ public class StopWatchTest {
|
||||||
final long totalTime = watch.getTime();
|
final long totalTime = watch.getTime();
|
||||||
|
|
||||||
assertEquals("Formatted split string not the correct length",
|
assertEquals("Formatted split string not the correct length",
|
||||||
splitStr.length(), 11);
|
splitStr.length(), 12);
|
||||||
assertTrue(splitTime >= 500);
|
assertTrue(splitTime >= 500);
|
||||||
assertTrue(splitTime < 700);
|
assertTrue(splitTime < 700);
|
||||||
assertTrue(totalTime >= 1500);
|
assertTrue(totalTime >= 1500);
|
||||||
|
|
Loading…
Reference in New Issue