Time Since and Remaining

 More Timing Issues.  Now we want to work with timing events some more to deal with determining something like how many days:hours:minutes:seconds it has been since the semester started and how many days:hours:minutes:seconds it remain until the semester ends. This is essentially equivalent to Thau's developments for the NASA clocks that relate to how long the space station has been in orbit and how long until the next mission is launched. What makes this problem interesting, in addition to what we have previously developed, is the necessity of converting milliseconds into actual days, hours, minutes and seconds and then displaying them. The problem is started by setting the start and end of the semester semester_start = Date.parse("Monday 30 Aug 2004 08:00:00 EST"); and the end of the semester. semester_end = Date.parse("Friday 17 Dec 2004 17:00:00 EST"); Then you obtain the current time and date and determine how many milliseconds have elapsed since the beginning of the semester and how many milliseconds remain until the end of the semester.  This needs to be done in milliseconds since it is the most robust measure.  Then these durations need to be converted back into days, hours, minutes and seconds.  This leads to some interesting and worthwhile problem solving. The following code should be copied into a file called TimeInClass.html.

 How Long Must This Go On?

How much longer will this class go on?

It has been days hours minutes seconds since this semester started

There remain days hours minutes seconds until this semester is over

 When this is uploaded you should get something like the following.

 Remember, sine everything is in milliseconds, all of the conversion factors are 1000 times larger than you would normally expect to see.   The conversion factors are in the following table.

 Time Unit Conversion seconds 1000 milliseconds/second minutes 60000 milliseconds/minute hours 3600000 milliseconds/hour days 86400000 milliseconds/day

 So to get each of these amounts within the milliseconds since or remaining you need to divide it by the appropriate conversion factor.  For example, to determine time remaining first divide out the timeLeft by 86400000 to get how many days there are left then modulo timeLeft by 86400000 to get how many milliseconds are left that aren't accounted for by days then divide out this remaining timeLeft by 3600000 to get how many hours that remain in the semester then modulo timeLeft by 3600000 to get how many milliseconds aren't accounted for by hours then divide this timeLeft by 60000 to get how many minutes remain in the semester then modulo timeLeft by 60000 to get how many milliseconds aren't accounted for by minutes then divide this timeLeft by 1000 to get how many seconds remain in the semester It is important to do this in this order so that you do not do something analogous to giving someone \$0.90 change in 18 nickels.  You would want to first figure out how many quarters you should give them which is 90/25 = 3 quarters then modulo 90 % 25 = 15 to see how many cents you have left then divide 15/10 = 1 dime to get how many dimes you should give them. then modulo 15 % 10 = 5 to get how much more change you need to give them. then divide 5/5 = 1 to determine they need a nickel Thus there change would be 3 quarters, 1 dime and 1 nickel.  This needs to be done in this sequence from greater parts to smaller parts. Most of the rest of the processing has to do with placing the output into the form.