Class TimeStamp

java.lang.Object
  extended by TimeStamp

public class TimeStamp
extends java.lang.Object

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.

Version:
4/10/2006
Author:
You

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

TimeStamp

public TimeStamp(int hr,
                 int mn)
A constructor to create a new TimeStamp object with the specified hours and minutes.

Parameters:
hr - the hours in military format (00-23).
mn - the minutes (00-60).

TimeStamp

public TimeStamp(java.lang.String s)
A constructor to create a new TimeStamp object with a time specified as a string.

Parameters:
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

compareTo

public int compareTo(TimeStamp ts)
A method to compare two 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.

Parameters:
ts - the second TimeStamp object to be compared to the calling object.
Returns:
returns:
  • +1 if calling object is larger than parameter ts
  • 0 if calling object is larger is the same as parameter ts
  • -1 if calling object is smaller than parameter ts

equals

public boolean equals(TimeStamp ts)
A method to compare two TimeStamp objects for equality.

Parameters:
ts - the second TimeStamp object.
Returns:
true if ts is the same as the calling object, otherwise false.

difference

public TimeStamp difference(TimeStamp ts)
A method to subtract to 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.

Parameters:
ts - the second TimeStamp object which to subtract from the calling object.
Returns:
a new TimeStamp object in hh:mm format where the hh is the difference in hours and the mm is the remaining difference in seconds.

toHours

public double toHours()
A method to convert hh::mm format to an hours format in which the minutes represent fractional hours. For example, 8:15 is returned as 8.25 hours.

Returns:
the hours + fractional minutes in decimal format

toString

public java.lang.String toString()
Returns the time as a string in "hh:mm" format.

Overrides:
toString in class java.lang.Object
Returns:
TimeStamp object in "hh:mm" String format.