Package org.nuxeo.common.utils
Class PeriodAndDuration
java.lang.Object
org.nuxeo.common.utils.PeriodAndDuration
- All Implemented Interfaces:
TemporalAmount
The combination of a
Period
and a Duration
.
This allows the representation of ISO 8601 "durations", which comprise a nominal duration (Java Period
, i.e.,
years, months, days), and an accurate duration (Java Duration
, i.e., hours, minutes, seconds).
- Since:
- 11.1
-
Field Summary
Modifier and TypeFieldDescriptionfinal Duration
protected static final Pattern
final Period
protected static final int
protected static final int
protected static final List<TemporalUnit>
The set of supported units.static final PeriodAndDuration
A constant for a period and duration of zero. -
Constructor Summary
ConstructorDescriptionPeriodAndDuration
(Duration duration) Constructs aPeriodAndDuration
from the given duration.PeriodAndDuration
(Period period) Constructs aPeriodAndDuration
from the given period.PeriodAndDuration
(Period period, Duration duration) Constructs aPeriodAndDuration
from the given period and duration. -
Method Summary
Modifier and TypeMethodDescriptionlong
get
(TemporalUnit unit) getUnits()
static PeriodAndDuration
Obtains aPeriodAndDuration
from a text string.protected static int
parseFraction
(String string, int sign, String text) protected static int
protected static long
parseNumber
(String string, int multiplier, String text, String errorText) subtractFrom
(Temporal temporal) toString()
Outputs this period and duration as aString
, such asP6Y3M1DT4H12M5.636224S
.
-
Field Details
-
ZERO
A constant for a period and duration of zero. -
UNITS
-
PATTERN
-
SECONDS_PER_MINUTE
protected static final int SECONDS_PER_MINUTE- See Also:
-
SECONDS_PER_HOUR
protected static final int SECONDS_PER_HOUR- See Also:
-
period
-
duration
-
-
Constructor Details
-
PeriodAndDuration
Constructs aPeriodAndDuration
from the given period and duration. -
PeriodAndDuration
Constructs aPeriodAndDuration
from the given period. -
PeriodAndDuration
Constructs aPeriodAndDuration
from the given duration.
-
-
Method Details
-
getUnits
- Specified by:
getUnits
in interfaceTemporalAmount
-
get
- Specified by:
get
in interfaceTemporalAmount
-
addTo
- Specified by:
addTo
in interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFrom
in interfaceTemporalAmount
-
parse
Obtains aPeriodAndDuration
from a text string.This will parse the string based on the ISO-8601 period format
PnYnMnDTnHnMnS
. A leading minus sign, and negative values for the units, are allowed.- Parameters:
text
- the text to parse, notnull
- Returns:
- the period and duration (never
null
) - Throws:
DateTimeParseException
- if the text cannot be parsed to a period and duration- See Also:
-
parseInt
-
parseNumber
-
parseFraction
-
toString
Outputs this period and duration as aString
, such asP6Y3M1DT4H12M5.636224S
.The output will be in the ISO-8601 period format. A zero period will be represented as zero seconds, "PT0S".
-