Class TimeZones

java.lang.Object
  extended by TimeZones

public class TimeZones
extends Object

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

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

India (IST) 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 we allow a conversion of a time from one time zone to another, and a time of 0 hours GMT is -7 hours PDT (for example), while a time of 23:59 GMT is 29:29 IST.

An instance of the class can show the time using a 24-hour clock or using the AM-PM designation; it is the user's choice.


Field Summary
static String ALL
          Contains all the time zones given above, separated by " "
static String BST
          = "BST", a time zone
static String CDT
          = "CDT", a time zone
static String CST
          = "CST", a time zone
static String EDT
          = "EDT", a time zone
static String EST
          = "EST", a time zone
static String GMT
          = "GMT", a time zone
static String IST
          = "IST", a time zone
static String MDT
          = "MDT", a time zone
static String MST
          = "MST", a time zone
static String PDT
          = "PDT", a time zone
static String PST
          = "PST", a time zone
 
Constructor Summary
TimeZones()
          Constructor: an instance with time 0 GMT and a 24-hour clock
TimeZones(int h, int m, int s, String z, boolean b)
          Constructor: A time of day of h hours, m minutes, s seconds in zone z.
TimeZones(int s, String z, boolean b)
          Constructor: A time of day of s seconds in zone z.
 
Method Summary
 int compare(TimeZones t)
          = -1 if this time < time t, 0 if this time equals time t, and 1 if this time > time t
 boolean getAmPm()
          = am-pm indication: true means display in AM-PM format; false means display in 24-hour format
 int getTime()
           
 String getZone()
          = the time zone
static boolean isLegal(String z)
          = "z is a legal zone" --see class specification.
 void setDisplay(boolean b)
          If b is true, set the display mode to AM-PM; if b is false, set it to "twenty-four hours".
 TimeZones timeInGMT()
          = a new Time that is the same as this time but described in GMT
 TimeZones 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

GMT

public static final String GMT
= "GMT", a time zone

See Also:
Constant Field Values

BST

public static final String BST
= "BST", a time zone

See Also:
Constant Field Values

EST

public static final String EST
= "EST", a time zone

See Also:
Constant Field Values

EDT

public static final String EDT
= "EDT", a time zone

See Also:
Constant Field Values

CST

public static final String CST
= "CST", a time zone

See Also:
Constant Field Values

CDT

public static final String CDT
= "CDT", a time zone

See Also:
Constant Field Values

MST

public static final String MST
= "MST", a time zone

See Also:
Constant Field Values

MDT

public static final String MDT
= "MDT", a time zone

See Also:
Constant Field Values

PST

public static final String PST
= "PST", a time zone

See Also:
Constant Field Values

PDT

public static final String PDT
= "PDT", a time zone

See Also:
Constant Field Values

IST

public static final String IST
= "IST", a time zone

See Also:
Constant Field Values

ALL

public static final String ALL
Contains all the time zones given above, separated by " "

See Also:
Constant Field Values
Constructor Detail

TimeZones

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


TimeZones

public TimeZones(int s,
                 String z,
                 boolean b)
Constructor: A time of day of s seconds in zone z. If z is not a legal zone, make it GMT. Parameter s should be > -24 hours and < 48 hours; if not, use time 0. The time should be displayed as am-pm iff b is true


TimeZones

public TimeZones(int h,
                 int m,
                 int s,
                 String z,
                 boolean b)
Constructor: A time of day of h hours, m minutes, s seconds in zone z. The time should be > -24 hours and < 48 hours; if not, use time 0 is. If z is not a legal zone, make it GMT. The time should be displayed as am-pm iff b is true

Method Detail

getTime

public int getTime()

getZone

public String getZone()
= the time zone


getAmPm

public boolean getAmPm()
= am-pm indication: true means display in AM-PM format; false means display in 24-hour format


setDisplay

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


isLegal

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


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: 06:20:05AM DST or 06:20:05PM DST
In 24-hour mode: 06:20:05 DST or 18:20:05 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. See the assignment handout, section "rules for function toString", for more details.

Overrides:
toString in class Object

timeInGMT

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


timeInZone

public TimeZones 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


compare

public int compare(TimeZones t)
= -1 if this time < time t, 0 if this time equals time t, and 1 if this time > time t