Package org.nuxeo.common.utils
Class DurationUtils
- java.lang.Object
-
- org.nuxeo.common.utils.DurationUtils
-
public final class DurationUtils extends Object
- Since:
- 11.1
-
-
Field Summary
Fields Modifier and Type Field Description static Pattern
DURATION_SIMPLE_FORMAT
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Duration
parse(String value)
Obtains aDuration
from a text string such asPnDTnHnMn.nS
or_d_h_m_s_ms
.static Duration
parsePositive(String value, Duration defaultDuration)
Obtains aDuration
from a text string according toparse(String)
, but in case of invalid, zero or negative duration returns a default.
-
-
-
Field Detail
-
DURATION_SIMPLE_FORMAT
public static final Pattern DURATION_SIMPLE_FORMAT
-
-
Method Detail
-
parse
public static Duration parse(String value)
Obtains aDuration
from a text string such asPnDTnHnMn.nS
or_d_h_m_s_ms
.See
Duration.parse(CharSequence)
forPnDTnHnMn.nS
format.For
_d_h_m_s_ms
, there are five sections, each consisting of a number and a suffix. The suffixes are "d", "h", "m", "s" and "ms" for days, hours, minutes, seconds and milliseconds. The suffixes must occur in order and at least one of them must be present.- Throws:
DateTimeParseException
- if the text cannot be parsed to a duration- See Also:
Duration.parse(CharSequence)
-
parsePositive
public static Duration parsePositive(String value, Duration defaultDuration)
Obtains aDuration
from a text string according toparse(String)
, but in case of invalid, zero or negative duration returns a default.- Parameters:
value
- the value to parsedefaultDuration
- the default duration to return for invalid, zero or negative duration- Returns:
- the parsed duration (positive), or the default
- Since:
- 11.1
-
-