|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.util.TimeSpan
public class TimeSpan
Class used to represent a span of time. This class provides some convience functions for representing a span of time (to the millisecond resolution). This is a serializable class that can be saved and restored.
| Field Summary | |
|---|---|
static int |
FROM_END
Constant used when setting a duration. |
static int |
FROM_START
Constant used when setting a duration. |
| Constructor Summary | |
|---|---|
TimeSpan()
Create a new TimeSpan object which doesn't span any time. |
|
TimeSpan(Date start,
Date end)
Create a TimeSpan object with a specific start/end time. |
|
TimeSpan(long start,
long end)
Create a TimeSpan object with a specific start/end time. |
|
| Method Summary | |
|---|---|
boolean |
containsTime(Date time)
Determines if this time span contains another point in time. |
boolean |
containsTimeMillis(long time)
Determines if this time span contains another point in time. |
boolean |
containsTimeSpan(TimeSpan span)
Determines if this time span contains another TimeSpan object. |
String |
format(String fmtString)
Format the TimeSpan in a configurable manner. |
double |
getDurationDays()
Get the time spanned for the time span entry. |
double |
getDurationHours()
Get the time spanned for the time span entry. |
long |
getDurationMillis()
Get the time spanned for the time span entry. |
double |
getDurationMinutes()
Get the time spanned for the time span entry. |
double |
getDurationSeconds()
Get the time spanned for the time span entry in seconds. |
Date |
getEndTime()
Get the ending point of the time span entry. |
long |
getEndTimeMillis()
Get the end point of the time span entry as a millisecond count. |
Date |
getStartTime()
Get the starting point of the time span entry. |
long |
getStartTimeMillis()
Get the start point of the time span entry as a millisecond count. |
void |
intersect(TimeSpan with)
Create the intersection between this object and another TimeSpan. |
boolean |
intersectsTimeSpan(TimeSpan span)
Determines if this time span intersects with another TimeSpan object. |
boolean |
isEmpty()
Determine if time spanned is empty (negative time spanned). |
void |
setDurationDays(double days,
int mode)
Set the time spanned for the time span entry in day units. |
void |
setDurationHours(double hours,
int mode)
Set the time spanned for the time span entry in hour units. |
void |
setDurationMillis(long millis,
int mode)
Set the time spanned for the time span entry. |
void |
setDurationMinutes(double minutes,
int mode)
Set the time spanned for the time span entry in minute units. |
void |
setEndTime(Date d)
Set the ending point of the time span entry. |
void |
setEndTimeMillis(long millis)
Set the ending point in time to the specified millisecond count. |
void |
setStartTime(Date d)
Set the starting point of the time span entry. |
void |
setStartTimeMillis(long millis)
Set the starting point in time to the specified millisecond count. |
void |
shiftDays(double amount)
Shift the time span a specified number of days. |
void |
shiftHours(double amount)
Shift the time span a specified number of hours. |
void |
shiftMillis(long millis)
Shift the time span a specified number of milliseconds. |
void |
shiftMinutes(double minutes)
Shift the time span a specified number of minutes. |
void |
shiftSeconds(double seconds)
Shift the time span a specified number of seconds. |
String |
toString()
Get the string representation of the time spanned. |
void |
union(Date d)
Create the union between this object and a Date. |
void |
union(long milliTime)
Create the union between this object and a point in time. |
void |
union(TimeSpan with)
Create the union between this object and another TimeSpan. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int FROM_START
FROM_END,
setDurationMillis(long, int),
Constant Field Valuespublic static final int FROM_END
FROM_START,
setDurationMillis(long, int),
Constant Field Values| Constructor Detail |
|---|
public TimeSpan()
empty state. Objects created in this manner will not be
of much use until you use one or more of the "set" members to
adjust the start/end times.
TimeSpan(long,long),
TimeSpan(java.util.Date,java.util.Date)
public TimeSpan(long start,
long end)
start - Standard java millisecond time count to associate with the
start of the time span.end - Standard java millisecond time count to associate with the
end of the time span.TimeSpan(java.util.Date,java.util.Date)
public TimeSpan(Date start,
Date end)
start - Time to set the start of the time span to (pass null to use
the current time).end - Time to set the end of the time span to (pass null to use
the current time).TimeSpan(long,long)| Method Detail |
|---|
public void setStartTimeMillis(long millis)
millis - Millisecond count from 1970-Jan-1 00:00:00 GMTsetEndTimeMillis(long),
setStartTime(java.util.Date)public void setStartTime(Date d)
date - Standard Java date object (or null if you want the current time);setEndTime(java.util.Date),
setStartTimeMillis(long)public long getStartTimeMillis()
getEndTimeMillis(),
getStartTime()public Date getStartTime()
getEndTime(),
getStartTimeMillis()public void setEndTimeMillis(long millis)
millis - Millisecond count from 1970-Jan-1 00:00:00 GMTsetStartTimeMillis(long),
setEndTime(java.util.Date)public void setEndTime(Date d)
date - Standard Java date object (or null if you want the current time);setStartTime(java.util.Date),
setEndTimeMillis(long)public long getEndTimeMillis()
getStartTimeMillis(),
getEndTime()public Date getEndTime()
getStartTime(),
getEndTimeMillis()
public void setDurationMillis(long millis,
int mode)
start time or end time
associated with the time span entry. To use this function, you must
specify the length of the duration, and whether the duration
spans FROM_START (forwards from the current
start time), or FROM_END (backwards from the
current end time).
millis - Length of duration in milliseconds.mode - If set to FROM_END, then the duration will be assumed
to be measured backwards from the current end point in
time. Otherwise the duration will be assumed to be measured
forward from the current start point in time.setStartTime(java.util.Date),
setEndTime(java.util.Date),
setDurationHours(double, int)
public final void setDurationMinutes(double minutes,
int mode)
start time or end time
associated with the time span entry. To use this function, you must
specify the length of the duration, and whether the duration
spans FROM_START (forwards from the current
start time), or FROM_END (backwards from the
current end time).
minutes - Length of duration in minutes.mode - If set to FROM_END, then the duration will be assumed
to be measured backwards from the current end point in
time. Otherwise the duration will be assumed to be measured
forward from the current start point in time.setStartTime(java.util.Date),
setEndTime(java.util.Date),
setDurationMillis(long, int)
public final void setDurationHours(double hours,
int mode)
start time or end time
associated with the time span entry. To use this function, you must
specify the length of the duration, and whether the duration
spans FROM_START (forwards from the current
start time), or FROM_END (backwards from the
current end time).
hours - Length of duration in hours.mode - If set to FROM_END, then the duration will be assumed
to be measured backwards from the current end point in
time. Otherwise the duration will be assumed to be measured
forward from the current start point in time.setStartTime(java.util.Date),
setEndTime(java.util.Date),
setDurationMillis(long, int)
public final void setDurationDays(double days,
int mode)
start time or end time
associated with the time span entry. To use this function, you must
specify the length of the duration, and whether the duration
spans FROM_START (forwards from the current
start time), or FROM_END (backwards from the
current end time).
days - Length of duration in days.mode - If set to FROM_END, then the duration will be assumed
to be measured backwards from the current end point in
time. Otherwise the duration will be assumed to be measured
forward from the current start point in time.setStartTime(java.util.Date),
setEndTime(java.util.Date),
setDurationMillis(long, int)public long getDurationMillis()
getStartTime(),
getEndTime(),
getDurationHours()public final double getDurationSeconds()
getStartTime(),
getEndTime(),
getDurationMillis()public final double getDurationMinutes()
getStartTime(),
getEndTime(),
getDurationHours()public final double getDurationHours()
getStartTime(),
getEndTime(),
getDurationDays()public final double getDurationDays()
getStartTime(),
getEndTime(),
getDurationMillis()public boolean containsTimeMillis(long time)
time - Time to check.
containsTimeSpan(com.ccg.util.TimeSpan),
containsTime(java.util.Date)public boolean containsTime(Date time)
time - Time to check (if you pass null, the current system time will
be checked).
containsTimeSpan(com.ccg.util.TimeSpan),
containsTimeMillis(long)public boolean containsTimeSpan(TimeSpan span)
span - TimeSpan object to check (must not be null).
containsTime(java.util.Date),
containsTimeMillis(long),
intersectsTimeSpan(com.ccg.util.TimeSpan)public boolean intersectsTimeSpan(TimeSpan span)
span - TimeSpan object to check for intersection (must not be null).
containsTimeSpan(com.ccg.util.TimeSpan)public void intersect(TimeSpan with)
TimeSpan.
This method allows one to create the intersection between the
time spanned by this object and the time spanned by another
TimeSpan object. The results of the intersection
will be stored in this object. The other time span passed as a
parameter will be unaffected. It is possible that the two objects
don't actually intersect. You can use the isEmpty() method
to check for this condition (it will return true if the two time
spans didn't overlap).
NOTE: If the result is empty, then the
duration spanned will be negative for this object and any use of
the "contains" methods will return false for all points in time
and non-negative time spans. In other words, a empty time span will behave as one would expect (or hope for).
with - Another TimeSpan object to form the
intersection with (it will remain unchanged). Must not be
null.union(com.ccg.util.TimeSpan),
intersectsTimeSpan(com.ccg.util.TimeSpan),
isEmpty()public void union(TimeSpan with)
TimeSpan.
This method allows one to create the union between the time
spanned by this object and the time spanned by another TimeSpan object. The results of the union will be
stored in this object and the time spanned will be just large
enough to contain both of the two original time spans. The other
time span passed as a parameter will be unaffected.
with - Another TimeSpan object to form the union
with (it will remain unchanged). Must not be null.intersect(com.ccg.util.TimeSpan),
isEmpty()public void union(Date d)
Date.
This method expands the time span (if necessary) such that the
Date object specified will be
contained. This may move the end or start time of the time
span. The resulting duration of time spanned after invoking this
method will be larger than or equal to its prior duration (the
time span will never shrink).
d - A Date object to form the union with
(null is OK - just results in nothing being done). Time
spanned will be enlarged (if necessary) to include this
specified point in time.union(TimeSpan)public void union(long milliTime)
This method expands the time span (if necessary) such that the point in time specified will be contained. This may move the end or start time of the time span. The resulting duration of time spanned after invoking this method will be larger than or equal to its prior duration (the time span will never shrink).
timeMilli - A standard Java millisecond count which represents a point in
time. The time spanned will be enlarged (if necessary) to
include this specified point in time.union(TimeSpan)public boolean isEmpty()
intersecting one TimeSpan object with another, one may want to use this method to
check and see if the resulting intersection was empty (ie the two
time spans which the intersection was performed on didn't have
any common area). Any TimeSpan object which is empty will
always return false when you check to see if it contains a single
point in time or a non-empty TimeSpan object.
intersection.intersect(com.ccg.util.TimeSpan)public String format(String fmtString)
toString() method. You pass this
function a string (or null) in a standard java.text.MessageFormat
style. The subsitution fields defined are:
formatString - A specific format string, or null if you want the default of
"[START,END]" where the times are formatted in the ISO
standard fashion.
toString()public String toString()
toString in class Objectformat(java.lang.String)public void shiftMillis(long millis)
amount - Millisecond duration (positive to shift forward in time,
negative to shift backwards) to adjust your time span by.shiftSeconds(double),
shiftMinutes(double),
shiftHours(double),
shiftDays(double)public void shiftSeconds(double seconds)
amount - Duration, in seconds, to adjust your time span by. Positive to
shift forward in time, negative to shift backwards.shiftMillis(long)public void shiftMinutes(double minutes)
amount - Duration, in minutes, to adjust your time span by. Positive to
shift forward in time, negative to shift backwards.shiftMillis(long)public void shiftHours(double amount)
amount - Duration, in hours, to adjust your time span by. Positive to
shift forward in time, negative to shift backwards.shiftMillis(long)public void shiftDays(double amount)
amount - Duration, in days, to adjust your time span by. Positive to
shift forward in time, negative to shift backwards.shiftMillis(long)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||