ucar.nc2.units
Class DateRange

java.lang.Object
  extended by ucar.nc2.units.DateRange

public class DateRange
extends java.lang.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".

Author:
john caron

Constructor Summary
DateRange()
          default Constructor
DateRange(java.util.Date start, java.util.Date end)
          Create Date Range from a start and end date
DateRange(DateRange range, java.lang.String timeUnits)
          Create DateRange from another DateRange, with a different units of resolution.
DateRange(DateType start, DateType end, TimeDuration duration, TimeDuration resolution)
          Encapsolates a range of dates, using DateType start/end, and/or a TimeDuration.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 void extend(DateRange dr)
          Extend this date range by the given one.
 TimeDuration getDuration()
           
 DateType getEnd()
           
 TimeDuration getResolution()
           
 DateType getStart()
           
 int hashCode()
          Override Object.hashCode() to implement equals.
 boolean included(java.util.Date d)
          Determine if the given date is included in this date range.
 DateRange intersect(DateRange clip)
          Intersect with another date range
 boolean intersects(java.util.Date start_want, java.util.Date end_want)
          Determine if the given range intersects this date range.
 boolean isEmpty()
          If the range is empty
 boolean isPoint()
          Return true if start date equals end date, so date range is a point.
 void setDuration(TimeDuration duration)
           
 void setEnd(DateType end)
           
 void setResolution(TimeDuration resolution)
           
 void setStart(DateType start)
           
 java.lang.String toString()
           
 boolean useDuration()
           
 boolean useEnd()
           
 boolean useResolution()
           
 boolean useStart()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateRange

public DateRange()
          throws java.text.ParseException
default Constructor

Throws:
java.text.ParseException - artifact, cant happen

DateRange

public DateRange(java.util.Date start,
                 java.util.Date end)
Create Date Range from a start and end date

Parameters:
start - start of range
end - end of range

DateRange

public DateRange(DateRange range,
                 java.lang.String timeUnits)
          throws java.lang.Exception
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:
java.lang.Exception - is units are not valid time units

DateRange

public DateRange(DateType start,
                 DateType end,
                 TimeDuration duration,
                 TimeDuration resolution)
Encapsolates 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
resolution - time resolution; optional
Method Detail

included

public boolean included(java.util.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

intersects

public boolean intersects(java.util.Date start_want,
                          java.util.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

intersect

public DateRange intersect(DateRange clip)
Intersect with another date range

Parameters:
clip - interset 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

getStart

public DateType getStart()

setStart

public void setStart(DateType start)

getEnd

public DateType getEnd()

setEnd

public void setEnd(DateType end)

getDuration

public TimeDuration getDuration()

setDuration

public void setDuration(TimeDuration duration)

getResolution

public TimeDuration getResolution()

setResolution

public void setResolution(TimeDuration resolution)

useStart

public boolean useStart()

useEnd

public boolean useEnd()

useDuration

public boolean useDuration()

useResolution

public boolean useResolution()

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Override Object.hashCode() to implement equals.

Overrides:
hashCode in class java.lang.Object