Class DateRange


  • public class DateRange
    extends Object
    Implements a range of dates, using DateType and/or TimeDuration. You can use a DateType = "present" and a time duration to specify "real time" intervals, eg "last 3 days" uses endDate = "present" and duration = "3 days".
    • Constructor Detail

      • DateRange

        public DateRange​(Date start,
                         Date end)
        Create Date Range from a start and end date
        Parameters:
        start - start of range
        end - end of range
      • DateRange

        public DateRange​(Date start,
                         TimeDuration duration)
        Create Date Range from a start date and duration
        Parameters:
        start - start of range
        duration - duration of range
      • DateRange

        public DateRange​(DateRange range,
                         String timeUnits)
                  throws ParseException
        Create DateRange from another DateRange, with a different units of resolution.
        Parameters:
        range - copy start and end from here
        timeUnits - make resolution using new TimeDuration( timeUnits)
        Throws:
        ParseException - is units are not valid time units
      • DateRange

        public DateRange​(DateType start,
                         DateType end,
                         TimeDuration duration,
                         TimeDuration resolution)
        Encapsulates a range of dates, using DateType start/end, and/or a TimeDuration. A DateRange can be specified in any of the following ways:
        1. a start date and end date
        2. a start date and duration
        3. an end date and duration
        Parameters:
        start - starting date
        end - ending date
        duration - time duration; may be null
        resolution - time resolution; may be null
    • Method Detail

      • included

        public boolean included​(Date d)
        Determine if the given date is included in this date range. The date range includes the start and end dates.
        Parameters:
        d - date to check
        Returns:
        true if date in inside this range
      • contains

        public boolean contains​(Date d)
        Same as included()
        Parameters:
        d - date to check
        Returns:
        true if date in inside this range
      • intersects

        public boolean intersects​(Date start_want,
                                  Date end_want)
        Determine if the given range intersects this date range.
        Parameters:
        start_want - range starts here
        end_want - range ends here
        Returns:
        true if ranges intersect
      • intersects

        public boolean intersects​(DateRange other)
        Determine if the given range intersects this date range.
        Parameters:
        other - date range
        Returns:
        true if ranges intersect
      • intersect

        public DateRange intersect​(DateRange clip)
        Intersect with another date range
        Parameters:
        clip - intersect with this date range
        Returns:
        new date range that is the intersection
      • extend

        public void extend​(DateRange dr)
        Extend this date range by the given one.
        Parameters:
        dr - given DateRange
      • extend

        public void extend​(Date d)
        Extend this date range by the given Date.
        Parameters:
        d - given Date
      • getStart

        public DateType getStart()
        Get the starting Date.
        Returns:
        starting Date
      • setStart

        public void setStart​(DateType start)
        Set the starting Date. Makes useStart true. If useEnd, recalculate the duration, else recalculate end.
        Parameters:
        start - starting Date
      • getEnd

        public DateType getEnd()
        Get the ending Date.
        Returns:
        ending Date
      • setEnd

        public void setEnd​(DateType end)
        Set the ending Date. Makes useEnd true. If useStart, recalculate the duration, else recalculate start.
        Parameters:
        end - ending Date
      • getDuration

        public TimeDuration getDuration()
        Get the duration of the interval
        Returns:
        duration of the interval
      • setDuration

        public void setDuration​(TimeDuration duration)
        Set the duration of the interval. Makes useDuration true. If useStart, recalculate end, else recalculate start.
        Parameters:
        duration - duration of the interval
      • getResolution

        public TimeDuration getResolution()
        Get the time resolution.
        Returns:
        time resolution as a duration
      • setResolution

        public void setResolution​(TimeDuration resolution)
        Set the time resolution.
        Parameters:
        resolution - the time resolution
      • useStart

        public boolean useStart()
        Get if the start is fixed.
        Returns:
        if start is fixed
      • useEnd

        public boolean useEnd()
        Get if the end is fixed.
        Returns:
        if end is fixed
      • useDuration

        public boolean useDuration()
        Get if the duration is fixed.
        Returns:
        if duration is fixed
      • useResolution

        public boolean useResolution()
        Get if the resolution is set.
        Returns:
        if resolution is fixed
      • isPoint

        public boolean isPoint()
        Return true if start date equals end date, so date range is a point.
        Returns:
        true if start = end
      • isEmpty

        public boolean isEmpty()
        If the range is empty
        Returns:
        if the range is empty
      • hashCode

        public int hashCode()
        Override Object.hashCode() to implement equals.
        Overrides:
        hashCode in class Object