Package org.forgerock.util.time
Class Duration
java.lang.Object
org.forgerock.util.time.Duration
- All Implemented Interfaces:
Comparable<Duration>
Represents a duration in english. Cases is not important, plurals units are accepted.
Notice that negative durations are not supported.
6 days
59 minutes and 1 millisecond
1 minute and 10 seconds
42 millis
unlimited
none
zero
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Convert the current duration to a givenTimeUnit
.static Duration
Provides aDuration
, given a number and time unit.static Duration
Provides aDuration
that represents the given duration expressed in english.boolean
getUnit()
Returns theTimeUnit
this duration is expressed in.long
getValue()
Returns the number ofTimeUnit
this duration represents.int
hashCode()
boolean
Returns true if this Duration represents an unlimited (or indefinite) duration.boolean
isZero()
Returns true if this Duration represents a zero-length duration.long
Convert the current duration to a number of givenTimeUnit
.Returns this duration as a JavaDuration
.toString()
-
Field Details
-
UNLIMITED
Special duration that represents an unlimited duration (or indefinite). -
ZERO
Special duration that represents a zero-length duration.
-
-
Constructor Details
-
Duration
Deprecated.Prefer the use ofduration(long, TimeUnit)
.Builds a newDuration
.- Parameters:
number
- number of time unit (cannot be null).unit
- TimeUnit to express the duration in (cannot be null).
-
-
Method Details
-
duration
Provides aDuration
, given a number and time unit.- Parameters:
number
- number of time unit.unit
- TimeUnit to express the duration in (cannot be null).- Returns:
Duration
instance
-
duration
Provides aDuration
that represents the given duration expressed in english.- Parameters:
value
- natural speech duration- Returns:
Duration
instance- Throws:
IllegalArgumentException
- if the input string is incorrectly formatted.
-
getValue
public long getValue()Returns the number ofTimeUnit
this duration represents.- Returns:
- the number of
TimeUnit
this duration represents.
-
toJavaDuration
Returns this duration as a JavaDuration
.- Returns:
- a new equivalent Java Duration
-
getUnit
Returns theTimeUnit
this duration is expressed in.- Returns:
- the
TimeUnit
this duration is expressed in.
-
convertTo
Convert the current duration to a givenTimeUnit
. Conversions from finer to coarser granularities truncate, so loose precision.- Parameters:
targetUnit
- target unit of the conversion.- Returns:
- converted duration
- See Also:
-
to
Convert the current duration to a number of givenTimeUnit
. Conversions from finer to coarser granularities truncate, so loose precision.- Parameters:
targetUnit
- target unit of the conversion.- Returns:
- converted duration value
- See Also:
-
isUnlimited
public boolean isUnlimited()Returns true if this Duration represents an unlimited (or indefinite) duration.- Returns:
- true if this Duration represents an unlimited duration.
-
isZero
public boolean isZero()Returns true if this Duration represents a zero-length duration.- Returns:
- true if this Duration represents a zero-length duration.
-
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Duration>
-
equals
-
hashCode
public int hashCode()
-
duration(long, TimeUnit)
.