This page contains some explanatory notes on assignment A3. Some people had questions, and this page attempts to explain them. This page was last updated on 27 September.

1. Restriction on times. Any time that is given in a new expression will be greater than -24 hours (- 1 day) and less than 48 hours (2 days) ---or else 0 is used instead. This restriction applies only to values given as arguments in constructor calls. That is the only place restrictions are given in the specification. An internal time may get out of that range. For example, if you create a folder with time 47 hours GMT and then convert it to India time, the India time will be 53 hours and 30 minutes. However, the restriction does imply that any hour of a time to be printed takes at most two digits.

2. About the arguments h, m, and s in the constructor that you have to write.

(a) No restriction is given on these parameters individually, so there is no need to do any checking of them individually. The only restriction is that when the given time is translated to seconds, the result be greater than -24 hours (ie. -1 day, or whatever that is in seconds) and less than 48 hours (i.e. 2 days, or whatever that is in seconds).

(b) The obvious way to translate h hours, m minutes, s seconds to a time in seconds is to convert all three values to seconds and add them together. That is what you should do. This implies that h = 48, m = 0, and s = 1 is an illegal time, because it is greater than 2 days. Also, h = 48, m = 0, s = -1 is a legal time, since it is 1 second less than 2 days.

3. No capitalization in giving time zones. For example, one time zone is "GMT", but "gmT" is not a time zone. This should be clear from the specification of the class, which lists what time zones are allowed.

4. Extra (private) methods. You are allowed to write any private methods that ou wish. Whenever you are given a program to write, as you proceed, you may find it helpful to add new methods in order to keep other methods simple and understandable. You saw this in the program to anglicize integers, which we developed in class on Tuesday, 23 September.

5. Rules for function toString. We will attempt to define things so that several different interpretations of the assignment can be used, whichever you prefer.

(a) If the time is negative, then a 24 hour clock is to be used. Further, only ONE - sign is to appear. For example, here are two times and how they should be displayed:

- 48370 seconds, i.e. (-13 hours, -26 minutes, -10 seconds) in GMT :    "-13:26:10 GMT"

- 36970 seconds, i.e. (-10 hours, -16 minutes, -10 seconds in GMT :    "-10:16:10 GMT"

(b) You may, if you wish, precede a positive time by a blank. But you don't have to. Here is a positive time printed two ways followed by a negative time:

36970 seconds, i.e. (10 hours, 16 minutes, 10 seconds in GMT :          "10:16:10 GMT"

36970 seconds, i.e. (10 hours, 16 minutes, 10 seconds in GMT :          " 10:16:10 GMT"

- 36970 seconds, i.e. (-10 hours, -16 minutes, -10 seconds in GMT :    "-10:16:10 GMT"

(c) The hours MUST be two digits. The minutes may be 1 or 2 digits. The seconds may be 1 or 2 digits. It's your choice. Examples:

0 hours, 5 minutes, 16 seconds in GMT :          "00:5:16 GMT" or "00:05:16 GMT"

6 hours, 15 minutes, 6 seconds in GMT :          "06:15:6 GMT" or "00:15:06 GMT"

(d) The time 0 is midnight. It is usually thought of as AM, so print time 0 in 12-hour time with an AM indication. Similarly, noon is the beginning of PM, so it should be printed in 12-hour time with a PM indication.

Note: If the time is between -0 hours and -10 hours, prepending a leading 0 can be tricky. Be careful.

Note: It may be advantageous to write an auxiliary private function that, given a string that contains an unsigned integer, returns a string that represents the same unsigned integer but has length at least two (it prepends a leading 0 if necessary). You can then call this function in several different places.