Package org.joda.time

Interface ReadableDuration

  • All Superinterfaces:
    java.lang.Comparable<ReadableDuration>
    All Known Implementing Classes:
    AbstractDuration, BaseDuration, Duration

    public interface ReadableDuration
    extends java.lang.Comparable<ReadableDuration>
    Defines an exact duration of time in milliseconds.

    The implementation of this interface may be mutable or immutable. This interface only gives access to retrieve data, never to change it.

    Methods that are passed a duration as a parameter will treat null as a zero length duration.

    The compareTo method is no longer defined in this class in version 2.0. Instead, the definition is simply inherited from the Comparable interface. This approach is necessary to preserve binary compatibility. The definition of the comparison is ascending order by millisecond duration. Implementors are recommended to extend AbstractInstant instead of this interface.

    Since:
    1.0
    See Also:
    ReadableInterval, ReadablePeriod
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object readableDuration)
      Compares this object with the specified object for equality based on the millisecond length.
      long getMillis()
      Gets the total length of this duration in milliseconds.
      int hashCode()
      Gets a hash code for the duration that is compatible with the equals method.
      boolean isEqual​(ReadableDuration duration)
      Is the length of this duration equal to the duration passed in.
      boolean isLongerThan​(ReadableDuration duration)
      Is the length of this duration longer than the duration passed in.
      boolean isShorterThan​(ReadableDuration duration)
      Is the length of this duration shorter than the duration passed in.
      Duration toDuration()
      Get this duration as an immutable Duration object.
      Period toPeriod()
      Converts this duration to a Period instance using the standard period type and the ISO chronology.
      java.lang.String toString()
      Gets the value as a String in the ISO8601 duration format using hours, minutes and seconds (including fractional milliseconds).
      • Methods inherited from interface java.lang.Comparable

        compareTo
    • Method Detail

      • getMillis

        long getMillis()
        Gets the total length of this duration in milliseconds.
        Returns:
        the total length of the time duration in milliseconds.
      • toDuration

        Duration toDuration()
        Get this duration as an immutable Duration object.

        This will either typecast this instance, or create a new Duration.

        Returns:
        a Duration created using the millisecond duration from this instance
      • toPeriod

        Period toPeriod()
        Converts this duration to a Period instance using the standard period type and the ISO chronology.

        Only precise fields in the period type will be used. Thus, only the hour, minute, second and millisecond fields on the period will be used. The year, month, week and day fields will not be populated.

        If the duration is small, less than one day, then this method will perform as you might expect and split the fields evenly. If the duration is larger than one day then all the remaining duration will be stored in the largest available field, hours in this case.

        For example, a duration effectively equal to (365 + 60 + 5) days will be converted to ((365 + 60 + 5) * 24) hours by this constructor.

        For more control over the conversion process, you must pair the duration with an instant, see Period(ReadableInstant,ReadableDuration).

        Returns:
        a Period created using the millisecond duration from this instance
      • isEqual

        boolean isEqual​(ReadableDuration duration)
        Is the length of this duration equal to the duration passed in.
        Parameters:
        duration - another duration to compare to, null means zero milliseconds
        Returns:
        true if this duration is equal to the duration passed in
      • isLongerThan

        boolean isLongerThan​(ReadableDuration duration)
        Is the length of this duration longer than the duration passed in.
        Parameters:
        duration - another duration to compare to, null means zero milliseconds
        Returns:
        true if this duration is greater than the duration passed in
      • isShorterThan

        boolean isShorterThan​(ReadableDuration duration)
        Is the length of this duration shorter than the duration passed in.
        Parameters:
        duration - another duration to compare to, null means zero milliseconds
        Returns:
        true if this duration is less than the duration passed in
      • equals

        boolean equals​(java.lang.Object readableDuration)
        Compares this object with the specified object for equality based on the millisecond length. All ReadableDuration instances are accepted.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        readableDuration - a readable duration to check against
        Returns:
        true if the length of the duration is equal
      • hashCode

        int hashCode()
        Gets a hash code for the duration that is compatible with the equals method. The following formula must be used:
          long len = getMillis();
          return (int) (len ^ (len >>> 32));
         
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code
      • toString

        java.lang.String toString()
        Gets the value as a String in the ISO8601 duration format using hours, minutes and seconds (including fractional milliseconds).

        For example, "PT6H3M7S" represents 6 hours, 3 minutes, 7 seconds.

        Overrides:
        toString in class java.lang.Object
        Returns:
        the value as an ISO8601 string