Class DateDuration


  • public class DateDuration
    extends Object
    This class specifies a duration that spans one or more days. It consists of a number and a date unit. For example: 5 days or 3 months.
    • Constructor Detail

      • DateDuration

        public DateDuration​(int count,
                            DateUnit unit)
        Constructs a new date duration.
        Parameters:
        count - the number of date units
        unit - the date unit
    • Method Detail

      • getCount

        public int getCount()
        Returns the number of date units that defines this duration. The date unit is obtained with getUnit().
        Returns:
        the number of date units
      • getUnit

        public DateUnit getUnit()
        Returns the date unit that, together with the number returned by getCount(), defines this duration.
        Returns:
        the date unit
      • getCountBetween

        public int getCountBetween​(org.joda.time.ReadableInstant start,
                                   org.joda.time.ReadableInstant end)
        Returns the number of times this date duration completely fits between the two specified times.
        Parameters:
        start - the start time
        end - the end time
        Returns:
        the number of durations between the start and end time
      • getCountBetween

        public int getCountBetween​(org.joda.time.ReadablePartial start,
                                   org.joda.time.ReadablePartial end)
        Returns the number of times this date duration completely fits between the two specified times.
        Parameters:
        start - the start time
        end - the end time
        Returns:
        the number of durations between the start and end time
      • toReadablePeriod

        public org.joda.time.ReadablePeriod toReadablePeriod()
        Returns this date duration as a ReadablePeriod.
        Returns:
        the readable period
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • parse

        public static DateDuration parse​(String s,
                                         DateUnit min,
                                         DateUnit max)
                                  throws ParseException
        Parses a date duration from a string. The string should consist of a number and a date unit, separated by white space. You can specify the smallest and largest allowed date unit.
        Parameters:
        s - the string
        min - the smallest allowed date unit. You can set this to null for the smallest known date unit.
        max - the largest allowed date unit. You can set this to null for the largest known date unit.
        Returns:
        the date duration
        Throws:
        ParseException - if the string is invalid