From 9a16b763d9c51b788415c5f83b6e9221a3cf5d0d Mon Sep 17 00:00:00 2001 From: Duncan Jones Date: Tue, 13 May 2014 20:31:02 +0000 Subject: [PATCH] Using Validate where possible in time package. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1594373 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/lang3/time/DurationFormatUtils.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 b9db1f666..ddbec62fc 100644 --- a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java +++ b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java @@ -23,6 +23,7 @@ import java.util.GregorianCalendar; import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; /** *

Duration formatting utilities and constants. The following table describes the tokens @@ -127,9 +128,7 @@ public class DurationFormatUtils { * @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("durationMillis must not be negative"); - } + Validate.inclusiveBetween(0, Long.MAX_VALUE, durationMillis, "durationMillis must not be negative"); final Token[] tokens = lexx(format); @@ -279,9 +278,8 @@ public class DurationFormatUtils { */ 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("startMillis must not be greater than endMillis"); - } + Validate.isTrue(startMillis <= endMillis, "startMillis must not be greater than endMillis"); + // Used to optimise for differences under 28 days and // called formatDuration(millis, format); however this did not work