Package ucar.nc2.units
Class DateRange
- java.lang.Object
-
- 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".
-
-
Constructor Summary
Constructors Constructor Description DateRange()
default ConstructorDateRange(Date start, Date end)
Create Date Range from a start and end dateDateRange(Date start, TimeDuration duration)
Create Date Range from a start date and durationDateRange(CalendarDateRange cdr)
DateRange(DateRange range, String timeUnits)
Create DateRange from another DateRange, with a different units of resolution.DateRange(DateType start, DateType end, TimeDuration duration, TimeDuration resolution)
Encapsulates a range of dates, using DateType start/end, and/or a TimeDuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 intervalDateType
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 rangeboolean
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 emptyboolean
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.
-
-
-
Constructor Detail
-
DateRange
public DateRange() throws ParseException
default Constructor- Throws:
ParseException
- artifact, cant happen
-
DateRange
public DateRange(CalendarDateRange cdr)
-
DateRange
public DateRange(Date start, Date end)
Create Date Range from a start and end date- Parameters:
start
- start of rangeend
- end of range
-
DateRange
public DateRange(Date start, TimeDuration duration)
Create Date Range from a start date and duration- Parameters:
start
- start of rangeduration
- 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 heretimeUnits
- 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:- a start date and end date
- a start date and duration
- an end date and duration
- Parameters:
start
- starting dateend
- ending dateduration
- time duration; may be nullresolution
- 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 hereend_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
-
-