Class Time

java.lang.Object
  extended by Time

public class Time
extends Object

An instance represents the time of day in a time zone, in terms of hours, minutes, and seconds. The implemented time zones are:

PST: Pacific Standard Time, GMT-8 hours (LA)
PDT: Pacific Daylight Saving Time, GMT-7 hours (LA)
MST: Mountain Standard Time, GMT-7 hours (Phoenix)
MDT: Mountain Daylight Savings Time, GMT-6 (Phoenix)
CST: Central Standard Time, GMT-6 hours (Chicago)
CDT: Central Daylight Savings Time, GMT-5 hours (Chicago)
EST: Eastern Standard Time, GMT-5 hours (NY)
EDT: Eastern Daylight Savings Time, GMT-4 hours (NY)
GMT: Greenwich Mean Time, GMT
BST: British Summer Time, GMT+1
IND: India time, GMT+5:30 hours (New Delhi)

India (IND) is included to show that times are not always on hourly boundaries from GMT.

A time may appear negative or greater than 24 hours. This is because of possible conversions of a time from one time zone to another, e.g. time of 0 hours GMT is -7 hours PDT, while a time of 23:59 GMT is 29:29 IND.

The user can decide to show the time using a 24-hour clock or a AM-PM designation.


Field Summary
static String ALL
          A string consisting of the 3-letter time zone names, separated by blanks.
static String BST
          The following constants contain the eleven time zones, as Strings.
static String CDT
           
static String CST
           
static String EDT
           
static String EST
           
static String GMT
           
static String IND
           
static String MDT
           
static String MST
           
static String PDT
           
static String PST
           
static String[] zones
           
 
Constructor Summary
Time()
          Constructor: an instance with time 0 in GMT and a 24-hour clock.
Time(int h, int m, int s, String z, boolean b)
          Constructor: A time of day of h hours, m minutes, and s seconds in zone z.
Time(int s, String z, boolean b)
          Constructor: A time of day of s seconds in zone z.
 
Method Summary
 int compareTo(Time t)
          = -1 if this time < time t, 0 if this time equals time t, and 1 if this time > time t.
 boolean getDisplayMode()
          = the 24-hour clock indication --true means display in 24-hour format; false means display in am-pm format.
 int getTime()
           
 String getZone()
          = the time zone.
 boolean isLegal()
          = "this time is legal." A time is legal if it is > -24 hours and < +48 hours.
static boolean isLegal(String z)
          = "z is a legal zone" --see class specification.
 String objectName()
          = the name of this object
static String prepend0(int i)
          = i as a string, using at least two chars (prepend 0 if necessary).
 void setDisplay(boolean b)
          If b is true, set it to "twenty-four hours"; if b is false, set the display mode to AM-PM.
 Time timeInGMT()
          = a new Time that is the same as this time but described in GMT.
 Time timeInZone(String z)
          = a new Time that is the same as this time but described in zone z.
 String toString()
          = a string representation of the time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

zones

public static final String[] zones

BST

public static final String BST
The following constants contain the eleven time zones, as Strings.

See Also:
Constant Field Values

GMT

public static final String GMT
See Also:
Constant Field Values

EST

public static final String EST
See Also:
Constant Field Values

EDT

public static final String EDT
See Also:
Constant Field Values

CST

public static final String CST
See Also:
Constant Field Values

CDT

public static final String CDT
See Also:
Constant Field Values

MST

public static final String MST
See Also:
Constant Field Values

MDT

public static final String MDT
See Also:
Constant Field Values

PST

public static final String PST
See Also:
Constant Field Values

PDT

public static final String PDT
See Also:
Constant Field Values

IND

public static final String IND
See Also:
Constant Field Values

ALL

public static final String ALL
A string consisting of the 3-letter time zone names, separated by blanks.

See Also:
Constant Field Values
Constructor Detail

Time

public Time()
Constructor: an instance with time 0 in GMT and a 24-hour clock.


Time

public Time(int s,
            String z,
            boolean b)
Constructor: A time of day of s seconds in zone z. Note: s should greater than -24 hours and less than +48 hours; if not, the time 0 is used. If z is not a legal zone, GMT will be used. The time should be displayed in 24-hour mode if iff b is true and am-pm mode if false.


Time

public Time(int h,
            int m,
            int s,
            String z,
            boolean b)
Constructor: A time of day of h hours, m minutes, and s seconds in zone z. The time should be greater than -24 hours and less than +48 hours; if not, the time 0 is used. If z is not a legal zone, make it GMT. The time should be displayed in 24-hour mode if iff b is true and am-pm mode if false.

Method Detail

objectName

public String objectName()
= the name of this object


getTime

public int getTime()

getZone

public String getZone()
= the time zone.


getDisplayMode

public boolean getDisplayMode()
= the 24-hour clock indication --true means display in 24-hour format; false means display in am-pm format.


isLegal

public static boolean isLegal(String z)
= "z is a legal zone" --see class specification.


isLegal

public boolean isLegal()
= "this time is legal." A time is legal if it is > -24 hours and < +48 hours.


setDisplay

public void setDisplay(boolean b)
If b is true, set it to "twenty-four hours"; if b is false, set the display mode to AM-PM.


toString

public String toString()
= a string representation of the time. This is basically in the form "hours:minutes:seconds zone", but it differs depending on whether a 12- or 24-hour clock is wanted. We describe the difference with examples:

In AM-PM mode, output could be: 06:20:5AM DST or 06:20:5PM DST
In 24-hour mode output could be: 06:20:5 DST or 18:20:5 DST

If the time is negative or at least 24 hours, print it using the 24-hour mode, even if 12-hour mode is indicated.

Overrides:
toString in class Object

prepend0

public static String prepend0(int i)
= i as a string, using at least two chars (prepend 0 if necessary). Precondition: i >= 0.


timeInGMT

public Time timeInGMT()
= a new Time that is the same as this time but described in GMT.


timeInZone

public Time timeInZone(String z)
= a new Time that is the same as this time but described in zone z. If z is not a legal zone, the new zone is taken to be GMT.


compareTo

public int compareTo(Time t)
= -1 if this time < time t, 0 if this time equals time t, and 1 if this time > time t.