Class BasePeriod
- java.lang.Object
-
- org.joda.time.base.AbstractPeriod
-
- org.joda.time.base.BasePeriod
-
- All Implemented Interfaces:
java.io.Serializable
,ReadablePeriod
- Direct Known Subclasses:
MutablePeriod
,Period
public abstract class BasePeriod extends AbstractPeriod implements ReadablePeriod, java.io.Serializable
BasePeriod is an abstract implementation of ReadablePeriod that stores data in aPeriodType
and anint[]
.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:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PeriodType
getPeriodType()
Gets the period type.int
getValue(int index)
Gets the value at the specified index.Duration
toDurationFrom(ReadableInstant startInstant)
Gets the total millisecond duration of this period relative to a start instant.Duration
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, toString
-
Methods inherited from interface org.joda.time.ReadablePeriod
equals, get, getFieldType, hashCode, isSupported, size, toMutablePeriod, toPeriod, toString
-
-
-
-
Method Detail
-
getPeriodType
public PeriodType getPeriodType()
Gets the period type.- Specified by:
getPeriodType
in interfaceReadablePeriod
- Returns:
- the period type
-
getValue
public int getValue(int index)
Gets the value at the specified index.- Specified by:
getValue
in interfaceReadablePeriod
- Parameters:
index
- the index to retrieve- Returns:
- the value of the field at the specified index
- Throws:
java.lang.IndexOutOfBoundsException
- if the index is invalid
-
toDurationFrom
public Duration toDurationFrom(ReadableInstant startInstant)
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:
java.lang.ArithmeticException
- if the millis exceeds the capacity of the duration
-
toDurationTo
public Duration toDurationTo(ReadableInstant endInstant)
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:
java.lang.ArithmeticException
- if the millis exceeds the capacity of the duration
-
-