java.lang.ObjectTimeStamp
public class TimeStamp
TimeStamp implements basic time keeping operations. Times are
kept in hours
and minutes only; seconds are not recorded. Hours are recorded in military
time, thus 2:30pm is kept as 14:30. The user should not use am/pm notation
and should enter all hours in 0-23 military format.
The TimeStamp objects are intended only to measure differences
during the course of one day (00:00 to 23:59). You should not subtract
or compare differences across day boundaries.
| Constructor Summary | |
|---|---|
TimeStamp(int hr,
int mn)
A constructor to create a new TimeStamp object with
the specified hours and minutes. |
|
TimeStamp(java.lang.String s)
A constructor to create a new TimeStamp object
with a time specified as a string. |
|
| Method Summary | |
|---|---|
int |
compareTo(TimeStamp ts)
A method to compare two TimeStamp objects. |
TimeStamp |
difference(TimeStamp ts)
A method to subtract to TimeStamp objects and return the
different in hh:mm format. |
boolean |
equals(TimeStamp ts)
A method to compare two TimeStamp objects for equality. |
double |
toHours()
A method to convert hh::mm format to an hours format in which the minutes represent fractional hours. |
java.lang.String |
toString()
Returns the time as a string in "hh:mm" format. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TimeStamp(int hr,
int mn)
TimeStamp object with
the specified hours and minutes.
hr - the hours in military format (00-23).mn - the minutes (00-60).public TimeStamp(java.lang.String s)
TimeStamp object
with a time specified as a string.
s - the input string must be of the form "hh:mm" where
hh is the hours (00-23) in 24hr military form and "mm" is the
minutes (00-60).| Method Detail |
|---|
public int compareTo(TimeStamp ts)
TimeStamp objects.
The calling object is compared to the input parameter to generate
the following return values: +1 if calling object is bigger,
0 if they are the same, -1 if the calling object is smaller.
ts - the second TimeStamp object to be compared
to the calling object.
ts
ts
tspublic boolean equals(TimeStamp ts)
TimeStamp objects for equality.
ts - the second TimeStamp object.
true if ts is the same as the calling
object, otherwise false.public TimeStamp difference(TimeStamp ts)
TimeStamp objects and return the
different in hh:mm format. The subtraction is performed as
calling TimeStamp object - ts object.
This method should be used only when the calling object is larger than
the parameter. If the parameter is larger (or the same value), then
a zero will be returned (00:00) as we do not represent negative
values for times.
ts - the second TimeStamp object which to subtract
from the calling object.
TimeStamp object in hh:mm format where
the hh is the difference in hours and the mm is the remaining difference
in seconds.public double toHours()
public java.lang.String toString()
toString in class java.lang.ObjectTimeStamp object in "hh:mm" String format.