Package ucar.nc2.units
Class DateRange
java.lang.Object
ucar.nc2.units.DateRange
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
ConstructorsConstructorDescriptiondefault ConstructorCreate Date Range from a start and end dateDateRange(Date start, TimeDuration duration) Create Date Range from a start date and durationCreate 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
Modifier and TypeMethodDescriptionbooleanSame as included()booleanvoidExtend this date range by the given Date.voidExtend this date range by the given one.Get the duration of the intervalgetEnd()Get the ending Date.Get the time resolution.getStart()Get the starting Date.inthashCode()Override Object.hashCode() to implement equals.booleanDetermine if the given date is included in this date range.Intersect with another date rangebooleanintersects(Date start_want, Date end_want) Determine if the given range intersects this date range.booleanintersects(DateRange other) Determine if the given range intersects this date range.booleanisEmpty()If the range is emptybooleanisPoint()Return true if start date equals end date, so date range is a point.voidsetDuration(TimeDuration duration) Set the duration of the interval.voidSet the ending Date.voidsetResolution(TimeDuration resolution) Set the time resolution.voidSet the starting Date.toString()booleanGet if the duration is fixed.booleanuseEnd()Get if the end is fixed.booleanGet if the resolution is set.booleanuseStart()Get if the start is fixed.
-
Constructor Details
-
DateRange
default Constructor- Throws:
ParseException- artifact, cant happen
-
DateRange
-
DateRange
Create Date Range from a start and end date- Parameters:
start- start of rangeend- end of range
-
DateRange
Create Date Range from a start date and duration- Parameters:
start- start of rangeduration- duration of range
-
DateRange
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
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 Details
-
included
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
Same as included()- Parameters:
d- date to check- Returns:
- true if date in inside this range
-
intersects
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
Determine if the given range intersects this date range.- Parameters:
other- date range- Returns:
- true if ranges intersect
-
intersect
Intersect with another date range- Parameters:
clip- intersect with this date range- Returns:
- new date range that is the intersection
-
extend
Extend this date range by the given one.- Parameters:
dr- given DateRange
-
extend
Extend this date range by the given Date.- Parameters:
d- given Date
-
getStart
Get the starting Date.- Returns:
- starting Date
-
setStart
Set the starting Date. Makes useStart true. If useEnd, recalculate the duration, else recalculate end.- Parameters:
start- starting Date
-
getEnd
Get the ending Date.- Returns:
- ending Date
-
setEnd
Set the ending Date. Makes useEnd true. If useStart, recalculate the duration, else recalculate start.- Parameters:
end- ending Date
-
getDuration
Get the duration of the interval- Returns:
- duration of the interval
-
setDuration
Set the duration of the interval. Makes useDuration true. If useStart, recalculate end, else recalculate start.- Parameters:
duration- duration of the interval
-
getResolution
Get the time resolution.- Returns:
- time resolution as a duration
-
setResolution
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
-
equals
-
hashCode
public int hashCode()Override Object.hashCode() to implement equals.
-