thredds.datatype
Class DateRange

java.lang.Object
  extended by thredds.datatype.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".

Version:
$Revision:63 $ $Date:2006-07-12 21:50:51Z $
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 units)
          Create DateRange from another DateRange, with a different units ofr the 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, if needed.
 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.
 boolean intersect(java.util.Date start_want, java.util.Date end_want)
          Determine if the given range intersects this date range.
 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
clone, finalize, 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 units)
          throws java.lang.Exception
Create DateRange from another DateRange, with a different units ofr the Resolution.

Parameters:
range - sopy start and end from here
units - make resolution using new TimeDuration( units)
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

intersect

public boolean intersect(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

getStart

public DateType getStart()

setStart

public void setStart(DateType start)

getEnd

public DateType getEnd()

setEnd

public void setEnd(DateType end)

extend

public void extend(DateRange dr)
Extend this date range by the given one, if needed.

Parameters:
dr - given DateRange

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

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