Package org.nuxeo.common.utils
Class PeriodAndDuration
- java.lang.Object
-
- org.nuxeo.common.utils.PeriodAndDuration
-
- All Implemented Interfaces:
TemporalAmount
public final class PeriodAndDuration extends Object implements TemporalAmount
The combination of aPeriodand aDuration.This allows the representation of ISO 8601 "durations", which comprise a nominal duration (Java
Period, i.e., years, months, days), and an accurate duration (JavaDuration, i.e., hours, minutes, seconds).- Since:
- 11.1
-
-
Field Summary
Fields Modifier and Type Field Description Durationdurationprotected static PatternPATTERNPeriodperiodprotected static intSECONDS_PER_HOURprotected static intSECONDS_PER_MINUTEprotected static List<TemporalUnit>UNITSThe set of supported units.static PeriodAndDurationZEROA constant for a period and duration of zero.
-
Constructor Summary
Constructors Constructor Description PeriodAndDuration(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TemporaladdTo(Temporal temporal)longget(TemporalUnit unit)List<TemporalUnit>getUnits()static PeriodAndDurationparse(String text)Obtains aPeriodAndDurationfrom a text string.protected static intparseFraction(String string, int sign, String text)protected static intparseInt(String string, String text, String errorText)protected static longparseNumber(String string, int multiplier, String text, String errorText)TemporalsubtractFrom(Temporal temporal)StringtoString()Outputs this period and duration as aString, such asP6Y3M1DT4H12M5.636224S.
-
-
-
Field Detail
-
ZERO
public static final PeriodAndDuration ZERO
A constant for a period and duration of zero.
-
UNITS
protected static final List<TemporalUnit> UNITS
-
PATTERN
protected static final Pattern PATTERN
-
SECONDS_PER_MINUTE
protected static final int SECONDS_PER_MINUTE
- See Also:
- Constant Field Values
-
SECONDS_PER_HOUR
protected static final int SECONDS_PER_HOUR
- See Also:
- Constant Field Values
-
period
public final Period period
-
duration
public final Duration duration
-
-
Constructor Detail
-
PeriodAndDuration
public PeriodAndDuration(Period period, Duration duration)
Constructs aPeriodAndDurationfrom the given period and duration.
-
PeriodAndDuration
public PeriodAndDuration(Period period)
Constructs aPeriodAndDurationfrom the given period.
-
PeriodAndDuration
public PeriodAndDuration(Duration duration)
Constructs aPeriodAndDurationfrom the given duration.
-
-
Method Detail
-
getUnits
public List<TemporalUnit> getUnits()
- Specified by:
getUnitsin interfaceTemporalAmount
-
get
public long get(TemporalUnit unit)
- Specified by:
getin interfaceTemporalAmount
-
addTo
public Temporal addTo(Temporal temporal)
- Specified by:
addToin interfaceTemporalAmount
-
subtractFrom
public Temporal subtractFrom(Temporal temporal)
- Specified by:
subtractFromin interfaceTemporalAmount
-
parse
public static PeriodAndDuration parse(String text)
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:
toString()
-
parseNumber
protected static long parseNumber(String string, int multiplier, String text, String errorText)
-
toString
public String 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".
- Overrides:
toStringin classObject- Returns:
- a string representation of this period, not
null - See Also:
parse(java.lang.String)
-
-