Class 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 a 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:
    Serialized Form
    • Method Detail

      • getValue

        public int getValue​(int index)
        Gets the value at the specified index.
        Specified by:
        getValue in interface ReadablePeriod
        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