Package org.jdesktop.swingx.calendar
Class DateSpan
- java.lang.Object
-
- org.jdesktop.swingx.calendar.DateSpan
-
public class DateSpan extends java.lang.Object
An immutable representation of a time range. The time range is internally represented as two longs. The methods that take and returnDate
s create theDate
s as needed, so that if you modify returnedDate
s you will not effect theDateSpan
. The end points are inclusive.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DateSpan
add(long start, long end)
Returns a newDateSpan
that is the union of thisDateSpan
and the passed in span.DateSpan
add(DateSpan span)
Returns a newDateSpan
that is the union of thisDateSpan
andspan
.boolean
contains(long time)
Returns whether or not thisDateSpan
contains the specified time.boolean
contains(long start, long end)
Returns whether or not thisDateSpan
contains the specified date span.boolean
contains(DateSpan span)
Returns true if thisDateSpan
contains the specifiedDateSpan
.boolean
equals(java.lang.Object o)
long
getEnd()
Returns the end of the date span.java.util.Date
getEndAsDate()
Returns the end of the date span as aDate
.long
getStart()
Returns the start of the date span.java.util.Date
getStartAsDate()
Returns the start of the date span as aDate
.int
hashCode()
boolean
intersects(long start, long end)
Returns true if the thisDateSpan
intersects with the specified time.boolean
intersects(DateSpan span)
Returns true if the thisDateSpan
intersects with the specifiedDateSpan
.java.lang.String
toString()
-
-
-
Constructor Detail
-
DateSpan
public DateSpan(long start, long end)
Creates aDateSpan
between the two end points.- Parameters:
start
- Beginning dateend
- Ending date- Throws:
java.lang.IllegalArgumentException
- ifstart
is afterend
-
DateSpan
public DateSpan(java.util.Date start, java.util.Date end)
Creates aDateSpan
between the two end points. This is a conveniance constructor that is equivalent tonew Date(start.getTime(), end.getTime());
.- Parameters:
start
- Beginning dateend
- Ending date
-
-
Method Detail
-
getStart
public long getStart()
Returns the start of the date span.- Returns:
- start of the span.
-
getEnd
public long getEnd()
Returns the end of the date span.- Returns:
- end of the span.
-
getStartAsDate
public java.util.Date getStartAsDate()
Returns the start of the date span as aDate
.- Returns:
- start of the span.
-
getEndAsDate
public java.util.Date getEndAsDate()
Returns the end of the date span as aDate
.- Returns:
- end of the span.
-
contains
public boolean contains(DateSpan span)
Returns true if thisDateSpan
contains the specifiedDateSpan
.- Parameters:
span
- Date to check- Returns:
- true if this DateSpan contains
span
.
-
contains
public boolean contains(long time)
Returns whether or not thisDateSpan
contains the specified time.- Parameters:
time
- time check- Returns:
- true if this DateSpan contains
time
.
-
contains
public boolean contains(long start, long end)
Returns whether or not thisDateSpan
contains the specified date span.- Parameters:
start
- Start of time spanend
- End of time- Returns:
- true if this
DateSpan
contains the specified date span.
-
intersects
public boolean intersects(long start, long end)
Returns true if the thisDateSpan
intersects with the specified time.- Parameters:
start
- Start timeend
- End time- Returns:
- true if this
DateSpan
intersects with the specified time.
-
intersects
public boolean intersects(DateSpan span)
Returns true if the thisDateSpan
intersects with the specifiedDateSpan
.- Parameters:
span
- DateSpan to compare to- Returns:
- true if this
DateSpan
intersects with the specified time.
-
add
public DateSpan add(DateSpan span)
Returns a newDateSpan
that is the union of thisDateSpan
andspan
.- Parameters:
span
- DateSpan to add- Returns:
- union of this DateSpan and
span
-
add
public DateSpan add(long start, long end)
Returns a newDateSpan
that is the union of thisDateSpan
and the passed in span.- Parameters:
start
- Start of region to addend
- End of region to end- Returns:
- union of this DateSpan and
start
,end
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-