diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 88784197b..8ec9e9d86 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -24,7 +24,8 @@ DurationFormatUtils does not handle large durations correctly DurationFormatUtils.formatDuration(61999, "s.SSSS") - ms field size should be 4 digits - + Failing tests with Java 8 b128 + ReflectionToStringBuilder.toString does not debug 3rd party object fields within 3rd party object 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 f8b9d92d2..57c637379 100644 --- a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java +++ b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java @@ -442,12 +442,10 @@ public class DurationFormatUtils { buffer.append(paddedValue(seconds, padWithZeros, count)); lastOutputSeconds = true; } else if (value == S) { - if (lastOutputSeconds) { - milliseconds += 1000; - final String str = padWithZeros - ? StringUtils.leftPad(Long.toString(milliseconds), count, '0') - : Long.toString(milliseconds); - buffer.append(str.substring(1)); + if (lastOutputSeconds) { + // ensure at least 3 digits are displayed even if padding is not selected + int width = padWithZeros ? Math.max(3, count) : 3; + buffer.append(paddedValue(milliseconds, true, width)); } else { buffer.append(paddedValue(milliseconds, padWithZeros, count)); }