com.ibm.clock
Class Time

java.lang.Object
  extended by com.ibm.clock.Time

public class Time
extends java.lang.Object

Class to represent time of the day. The time of the hour is represented by three fields -- hour, minute and second.


Field Summary
static int HOURS_IN_DAY
          Hours in a day.
protected static long MILLISECONDS_IN_DAY
           
protected static long MILLISECONDS_IN_HOUR
           
protected static long MILLISECONDS_IN_MINUTE
           
protected static long MILLISECONDS_IN_SECOND
           
static int MINUTES_IN_HOUR
          Minutes in a hour.
static int SECONDS_IN_MINUTE
          Seconds in a minute.
 
Constructor Summary
  Time()
          Default constructor.
  Time(int hour, int minute, int second)
          Construct a time field given the hour, minute and second fields.
protected Time(long time)
          Construct a time object with the specified time.
 
Method Summary
 int getHour()
          Get the hour of the day.
 long getInMillis()
          Get the time of the day in milliseconds.
 int getMinute()
          Get the minute field.
 int getSecond()
          Get the second field.
 void setHour(int hour)
          Set the hour field.
protected  void setInMillis(long time)
          Set the time of the day in millis.
 void setMinute(int minute)
          Set the minute field.
 void setSecond(int second)
          Set the second field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOURS_IN_DAY

public static final int HOURS_IN_DAY
Hours in a day.

See Also:
Constant Field Values

MINUTES_IN_HOUR

public static final int MINUTES_IN_HOUR
Minutes in a hour.

See Also:
Constant Field Values

SECONDS_IN_MINUTE

public static final int SECONDS_IN_MINUTE
Seconds in a minute.

See Also:
Constant Field Values

MILLISECONDS_IN_DAY

protected static final long MILLISECONDS_IN_DAY
See Also:
Constant Field Values

MILLISECONDS_IN_HOUR

protected static final long MILLISECONDS_IN_HOUR
See Also:
Constant Field Values

MILLISECONDS_IN_MINUTE

protected static final long MILLISECONDS_IN_MINUTE
See Also:
Constant Field Values

MILLISECONDS_IN_SECOND

protected static final long MILLISECONDS_IN_SECOND
See Also:
Constant Field Values
Constructor Detail

Time

public Time()
Default constructor. The default time is taken to be zero hour, zero minute, zero second.


Time

protected Time(long time)
        throws java.lang.IllegalArgumentException
Construct a time object with the specified time.

Parameters:
time - The time in milliseconds. Must lie between 0 and 86399999.
Throws:
java.lang.IllegalArgumentException - If the argument is not proper.

Time

public Time(int hour,
            int minute,
            int second)
Construct a time field given the hour, minute and second fields.

Parameters:
hour - The hour of the day. Must be between 0 and 23.
minute - The minute of the hour. Must be between 0 and 59.
second - The second of the minute. Must be between 0 and 59.
Throws:
java.lang.IllegalArgumentException - If any of the arguments is improper.
Method Detail

setInMillis

protected void setInMillis(long time)
                    throws java.lang.IllegalArgumentException
Set the time of the day in millis.

Parameters:
time - The time of the day in milli seconds. The time must lie between 0 and 86399999.
Throws:
java.lang.IllegalArgumentException - If the argument is not proper.

getInMillis

public long getInMillis()
Get the time of the day in milliseconds. This returns the time in milli seconds from the begining of the day.

Returns:
The time of the day in milliseconds.

getHour

public int getHour()
Get the hour of the day.

Returns:
The hour of the day as an integer lying between 0 and 23.

setHour

public void setHour(int hour)
             throws java.lang.IllegalArgumentException
Set the hour field.

Parameters:
hour - The hour of the day. Must lie between 0 and 23.
Throws:
java.lang.IllegalArgumentException - If the argument is illegal.

getMinute

public int getMinute()
Get the minute field.

Returns:
The minute field as an integer between 0 and 59.

setMinute

public void setMinute(int minute)
Set the minute field.

Parameters:
minute - The minute of the hour. Must lie between 0 and 59.
Throws:
java.lang.IllegalArgumentException - If the argument is illegal.

getSecond

public int getSecond()
Get the second field.

Returns:
The second field as an integer between 0 and 59.

setSecond

public void setSecond(int second)
Set the second field.

Parameters:
second - The second of the hour. Must lie between 0 and 59.
Throws:
java.lang.IllegalArgumentException - If the argument is illegal.