ucar.nc2.units
Class DateRange

java.lang.Object
  extended by ucar.nc2.units.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".

Author:
john caron

Constructor Summary
DateRange()
          default Constructor
DateRange(Date start, Date end)
          Create Date Range from a start and end date
DateRange(DateRange range, String timeUnits)
          Create DateRange from another DateRange, with a different units of resolution.
DateRange(Date start, TimeDuration duration)
          Create Date Range from a start date and duration
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 contains(Date d)
          Same as included()
 boolean equals(Object o)
           
 void extend(Date d)
          Extend this date range by the given Date.
 void extend(DateRange dr)
          Extend this date range by the given one.
 TimeDuration getDuration()
          Get the duration of the interval
 DateType getEnd()
          Get the ending Date.
 TimeDuration getResolution()
          Get the time resolution.
 DateType getStart()
          Get the starting Date.
 int hashCode()
          Override Object.hashCode() to implement equals.
 boolean included(Date d)
          Determine if the given date is included in this date range.
 DateRange intersect(DateRange clip)
          Intersect with another date range
 boolean intersects(Date start_want, Date end_want)
          Determine if the given range intersects this date range.
 boolean intersects(DateRange other)
          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)
          Set the duration of the interval.
 void setEnd(DateType end)
          Set the ending Date.
 void setResolution(TimeDuration resolution)
          Set the time resolution.
 void setStart(DateType start)
          Set the starting Date.
 String toString()
           
 boolean useDuration()
          Get if the duration is fixed.
 boolean useEnd()
          Get if the end is fixed.
 boolean useResolution()
          Get if the resolution is set.
 boolean useStart()
          Get if the start is fixed.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateRange

public DateRange()
          throws ParseException
default Constructor

Throws:
ParseException - artifact, cant happen

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 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:
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(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

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

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

Overrides:
hashCode in class Object


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.