Class BasePeriod
- All Implemented Interfaces:
Serializable,ReadablePeriod
- Direct Known Subclasses:
MutablePeriod,Period
PeriodType and an int[].
This class should generally not be used directly by API users.
The ReadablePeriod interface should be used when different
kinds of period objects are to be referenced.
BasePeriod subclasses may be mutable and not thread-safe.
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGets the period type.intgetValue(int index) Gets the value at the specified index.toDurationFrom(ReadableInstant startInstant) Gets the total millisecond duration of this period relative to a start instant.toDurationTo(ReadableInstant endInstant) Gets the total millisecond duration of this period relative to an end instant.Methods inherited from class org.joda.time.base.AbstractPeriod
equals, get, getFieldType, getFieldTypes, getValues, hashCode, indexOf, isSupported, size, toMutablePeriod, toPeriod, toString, toStringMethods inherited from interface org.joda.time.ReadablePeriod
equals, get, getFieldType, hashCode, isSupported, size, toMutablePeriod, toPeriod, toString
-
Method Details
-
getPeriodType
Gets the period type.- Specified by:
getPeriodTypein interfaceReadablePeriod- Returns:
- the period type
-
getValue
public int getValue(int index) Gets the value at the specified index.- Specified by:
getValuein interfaceReadablePeriod- Parameters:
index- the index to retrieve- Returns:
- the value of the field at the specified index
- Throws:
IndexOutOfBoundsException- if the index is invalid
-
toDurationFrom
Gets the total millisecond duration of this period relative to a start instant.This method adds the period to the specified instant in order to calculate the duration.
An instant must be supplied as the duration of a period varies. For example, a period of 1 month could vary between the equivalent of 28 and 31 days in milliseconds due to different length months. Similarly, a day can vary at Daylight Savings cutover, typically between 23 and 25 hours.
- Parameters:
startInstant- the instant to add the period to, thus obtaining the duration- Returns:
- the total length of the period as a duration relative to the start instant
- Throws:
ArithmeticException- if the millis exceeds the capacity of the duration
-
toDurationTo
Gets the total millisecond duration of this period relative to an end instant.This method subtracts the period from the specified instant in order to calculate the duration.
An instant must be supplied as the duration of a period varies. For example, a period of 1 month could vary between the equivalent of 28 and 31 days in milliseconds due to different length months. Similarly, a day can vary at Daylight Savings cutover, typically between 23 and 25 hours.
- Parameters:
endInstant- the instant to subtract the period from, thus obtaining the duration- Returns:
- the total length of the period as a duration relative to the end instant
- Throws:
ArithmeticException- if the millis exceeds the capacity of the duration
-