You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2014/05/04 10:49:28 UTC
svn commit: r1592324 -
/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
Author: britter
Date: Sun May 4 08:49:27 2014
New Revision: 1592324
URL: http://svn.apache.org/r1592324
Log:
LANG-1003: DurationFormatUtils are not able to handle negative duration/periods. Document new behavior for negative inputs.
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java?rev=1592324&r1=1592323&r2=1592324&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java Sun May 4 08:49:27 2014
@@ -77,6 +77,7 @@ public class DurationFormatUtils {
*
* @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");
@@ -92,6 +93,7 @@ public class DurationFormatUtils {
*
* @param durationMillis the duration to format
* @return the formatted duration, not null
+ * @throws java.lang.IllegalArgumentException if durationMillis is negative
*/
public static String formatDurationISO(final long durationMillis) {
return formatDuration(durationMillis, ISO_EXTENDED_FORMAT_PATTERN, false);
@@ -106,6 +108,7 @@ public class DurationFormatUtils {
* @param durationMillis the duration to format
* @param format the way in which to format the duration, not null
* @return the formatted duration, not null
+ * @throws java.lang.IllegalArgumentException if durationMillis is negative
*/
public static String formatDuration(final long durationMillis, final String format) {
return formatDuration(durationMillis, format, true);
@@ -122,10 +125,11 @@ public class DurationFormatUtils {
* @param format the way in which to format the duration, not null
* @param padWithZeros whether to pad the left hand side of numbers with 0's
* @return the formatted duration, not null
+ * @throws java.lang.IllegalArgumentException if durationMillis is negative
*/
public static String formatDuration(final long durationMillis, final String format, final boolean padWithZeros) {
if(durationMillis < 0) {
- throw new IllegalArgumentException("Duration must not be less than 0");
+ throw new IllegalArgumentException("durationMillis must not be negative");
}
final Token[] tokens = lexx(format);
@@ -166,6 +170,7 @@ public class DurationFormatUtils {
* @param suppressLeadingZeroElements suppresses leading 0 elements
* @param suppressTrailingZeroElements suppresses trailing 0 elements
* @return the formatted text in days/hours/minutes/seconds, not null
+ * @throws java.lang.IllegalArgumentException if durationMillis is negative
*/
public static String formatDurationWords(
final long durationMillis,
@@ -229,6 +234,7 @@ public class DurationFormatUtils {
* @param startMillis the start of the duration to format
* @param endMillis the end of the duration to format
* @return the formatted duration, not null
+ * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis
*/
public static String formatPeriodISO(final long startMillis, final long endMillis) {
return formatPeriod(startMillis, endMillis, ISO_EXTENDED_FORMAT_PATTERN, false, TimeZone.getDefault());
@@ -242,6 +248,7 @@ public class DurationFormatUtils {
* @param endMillis the end of the duration
* @param format the way in which to format the duration, not null
* @return the formatted duration, not null
+ * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis
*/
public static String formatPeriod(final long startMillis, final long endMillis, final String format) {
return formatPeriod(startMillis, endMillis, format, true, TimeZone.getDefault());
@@ -269,11 +276,12 @@ public class DurationFormatUtils {
* @param padWithZeros whether to pad the left hand side of numbers with 0's
* @param timezone the millis are defined in
* @return the formatted duration, not null
+ * @throws java.lang.IllegalArgumentException if startMillis is greater than endMillis
*/
public static String formatPeriod(final long startMillis, final long endMillis, final String format, final boolean padWithZeros,
final TimeZone timezone) {
if(startMillis > endMillis) {
- throw new IllegalArgumentException("endMillis must be greater than startMillis");
+ throw new IllegalArgumentException("startMillis must not be greater than endMillis");
}
// Used to optimise for differences under 28 days and