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
FieldsModifier and TypeFieldDescriptionfinal Durationprotected static final Patternfinal Periodprotected static final intprotected static final intprotected static final List<TemporalUnit> The set of supported units.static final PeriodAndDurationA constant for a period and duration of zero. -
Constructor Summary
ConstructorsConstructorDescriptionPeriodAndDuration(Duration duration) Constructs aPeriodAndDurationfrom the given duration.PeriodAndDuration(Period period) Constructs aPeriodAndDurationfrom the given period.PeriodAndDuration(Period period, Duration duration) Constructs aPeriodAndDurationfrom the given period and duration. -
Method Summary
Modifier and TypeMethodDescriptionlongget(TemporalUnit unit) getUnits()static PeriodAndDurationObtains aPeriodAndDurationfrom a text string.protected static intparseFraction(String string, int sign, String text) protected static intprotected static longparseNumber(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 aPeriodAndDurationfrom the given period and duration. -
PeriodAndDuration
Constructs aPeriodAndDurationfrom the given period. -
PeriodAndDuration
Constructs aPeriodAndDurationfrom the given duration.
-
-
Method Details
-
getUnits
- Specified by:
getUnitsin interfaceTemporalAmount
-
get
- Specified by:
getin interfaceTemporalAmount
-
addTo
- Specified by:
addToin interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFromin interfaceTemporalAmount
-
parse
Obtains aPeriodAndDurationfrom 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".
-