Package org.apache.commons.lang3.time
Class DurationUtils
java.lang.Object
org.apache.commons.lang3.time.DurationUtils
Utilities for 
Duration.- Since:
- 3.12.0
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T extends Throwable>
 voidaccept(FailableBiConsumer<Long, Integer, T> consumer, Duration duration) Accepts the function with the duration as a long milliseconds and int nanoseconds.static intgetNanosOfMiili(Duration duration) Deprecated.static intgetNanosOfMilli(Duration duration) Gets the nanosecond part of a Duration converted to milliseconds.static booleanisPositive(Duration duration) Tests whether the given Duration is positive (>0).of(FailableConsumer<Instant, E> consumer) Runs the lambda and returns the duration of its execution.of(FailableRunnable<E> runnable) Runs the lambda and returns the duration of its execution.static DurationComputes the Duration between a start instant and now.static DurationtoDuration(long amount, TimeUnit timeUnit) Converts an amount and TimeUnit into a Duration.static inttoMillisInt(Duration duration) Converts a Duration to milliseconds bound to an int (instead of a long).static DurationzeroIfNull(Duration duration) Returns the given non-null value orDuration.ZEROif null.
- 
Constructor Details- 
DurationUtilsDeprecated.TODO Make private in 4.0.Make private in 4.0.
 
- 
- 
Method Details- 
acceptpublic static <T extends Throwable> void accept(FailableBiConsumer<Long, Integer, throws TT> consumer, Duration duration) Accepts the function with the duration as a long milliseconds and int nanoseconds.- Type Parameters:
- T- The function exception.
- Parameters:
- consumer- Accepting function.
- duration- The duration to pick apart.
- Throws:
- T- See the function signature.
- See Also:
 
- 
getNanosOfMiiliDeprecated.Gets the nanosecond part of a Duration converted to milliseconds.Handy when calling an API that takes a long of milliseconds and an int of nanoseconds. For example, Object.wait(long, int)andThread.sleep(long, int).Note that is this different from Duration.getNano()because a duration are seconds and nanoseconds.- Parameters:
- duration- The duration to query.
- Returns:
- nanoseconds between 0 and 999,999.
 
- 
getNanosOfMilliGets the nanosecond part of a Duration converted to milliseconds.Handy when calling an API that takes a long of milliseconds and an int of nanoseconds. For example, Object.wait(long, int)andThread.sleep(long, int).Note that is this different from Duration.getNano()because a duration are seconds and nanoseconds.- Parameters:
- duration- The duration to query.
- Returns:
- nanoseconds between 0 and 999,999.
- Since:
- 3.13.0
 
- 
isPositiveTests whether the given Duration is positive (>0).- Parameters:
- duration- the value to test
- Returns:
- whether the given Duration is positive (>0).
 
- 
ofRuns the lambda and returns the duration of its execution.- Type Parameters:
- E- The type of exception throw by the lambda.
- Parameters:
- consumer- What to execute.
- Returns:
- The Duration of execution.
- Throws:
- E- thrown by the lambda.
- Since:
- 3.13.0
- See Also:
 
- 
ofRuns the lambda and returns the duration of its execution.- Type Parameters:
- E- The type of exception throw by the lambda.
- Parameters:
- runnable- What to execute.
- Returns:
- The Duration of execution.
- Throws:
- E- thrown by the lambda.
- Since:
- 3.13.0
- See Also:
 
- 
sinceComputes the Duration between a start instant and now.- Parameters:
- startInclusive- the start instant, inclusive, not null.
- Returns:
- a Duration, not null.
- Since:
- 3.13.0
 
- 
toDurationConverts an amount and TimeUnit into a Duration.- Parameters:
- amount- the amount of the duration, measured in terms of the unit, positive or negative
- timeUnit- the unit that the duration is measured in, must have an exact duration, not null
- Returns:
- a Duration.
 
- 
toMillisIntConverts a Duration to milliseconds bound to an int (instead of a long).Handy for low-level APIs that take millisecond timeouts in ints rather than longs. - If the duration milliseconds are greater than Integer.MAX_VALUE, then returnInteger.MAX_VALUE.
- If the duration milliseconds are lesser than Integer.MIN_VALUE, then returnInteger.MIN_VALUE.
 - Parameters:
- duration- The duration to convert, not null.
- Returns:
- int milliseconds.
 
- If the duration milliseconds are greater than 
- 
zeroIfNullReturns the given non-null value orDuration.ZEROif null.- Parameters:
- duration- The duration to test.
- Returns:
- The given duration or Duration.ZERO.
 
 
-