Hour to minute conversions.

One of the tools I use at work is a stopwatch program I use to keep track of my break times. I also use the stopwatch’s countdown feature to count down the time remaining to those rare moments of freedom, such as my lunch break or the end of my shift. It can display this time remaining in either seconds, minutes or hours. I choose to have the countdown displayed in hours since the numbers change less frequently and are less distracting than the other formats. This does leave me trying to decipher numbers such as .585 or .666. I have to use the calculator program to convert that number into minutes to give me a better idea of how much time is left until lunch.

In helping me better interpret the hour equivalents of the countdown in progress I created an Excel spreadsheet in the form of a reference table to convert hours to minutes. I reprint the table here.

0.975 58.50 0.650 39.00 0.325 19.50
0.950 57.00 0.625 37.50 0.300 18.00
0.925 55.50 0.600 36.00 0.275 16.50
0.900 54.00 0.575 34.50 0.250 15.00
0.875 52.50 0.550 33.00 0.225 13.50
0.850 51.00 0.525 31.50 0.200 12.00
0.825 49.50 0.500 30.00 0.175 10.50
0.800 48.00 0.475 28.50 0.150 9.00
0.775 46.50 0.450 27.00 0.125 7.50
0.750 45.00 0.425 25.50 0.100 6.00
0.725 43.50 0.400 24.00 0.075 4.50
0.700 42.00 0.375 22.50 0.050 3.00
0.675 40.50 0.350 21.00 0.025 1.50

So if the display on the timer reads .975, it would mean 58 minutes and 30 seconds left in the countdown. Simple.

I know, this is the second consecutive blog post on countdowns.  Nothing wrong with helping people better anticipate the end of their shifts.

Javascript countdown to 6pm.

My working hours were recently changed to a more accommodating  schedule in which I now leave at 6pm as opposed to 11pm before. As a result I modified my Javascript countdown script to reflect my new departure time and while I was at it I changed the format to appear as a clock showing the hours and minutes remaining until 6pm. While I was at it I worked in a border around the numbers to make it look nice and pretty, like this:

1020

That means as I type this post, there are 10 hours and 20 minutes until 6pm.

Here’s the modified script.

<html>
<head>
<title>Countdown Clock</title>
</head>
<body>
<script type=”text/javascript”>
// From: http://www.webdeveloper.com/forum/showthread.php?t=215504
// Modified for: http://www.webdeveloper.com/forum/showthread.php?t=220174
var definedTime = new Date(’23:00′); // military time to countdown TO
function ShowTimes() {
var now = new Date();
var hrs = 17-now.getHours();
if (hrs < 0) { hrs += 24; }
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
var str = ”;
str += ‘<center><table border=”5″><tr><td><p style=”font-size:xx-large;”>’+hrs+’:’+mins+'</p></td></tr></table></center>’;
document.getElementById(‘countdownToMidnight’).innerHTML = str;
}

var _cntDown;
function StopTimes() { clearInterval(_cntDown); }
</script>
</head>
<body onload=”_cntDown=setInterval(‘ShowTimes()’,1000)”>
<div id=”countdownToMidnight”></div>
</body>
</html>

If you want the countdown clock to count down to 5pm instead, you would change the 17 (highlighted in red) to 16.

Counting down to 11pm using Javascript.

Once again I found myself pondering another use for Javascript to help make my work more easier and to address what is perhaps my biggest concern during my shift. How much longer before I can go home?

I have seen tons of sample scripts that count down to a specific date, which is nice but I wanted to create a script that counts down to a specific time instead. In my case I wanted the script to count down to 11pm, which marks the end of my shift. I also wanted to be able to run this same script each day without having to change anything in the code, as I noticed in the date countdown scripts I saw.

So. Off I went to find the script. After some searching and sweating I came across this discussion forum in which a fellow Javascript novice needed some help creating a countdown script similar to what I was looking for. The moderator responded by posting a countdown script, one that I tried out and liked well enough for me to experiment with to get it to do my bidding.

Here’s my variation on the forum moderator’s script which counts down to 11pm:

<html>
<head>
<title>End of Shift Countdown</title>
</head>
<body>
<script type=”text/javascript”>
// From: http://www.webdeveloper.com/forum/showthread.php?t=215504
// Modified for: http://www.webdeveloper.com/forum/showthread.php?t=220174
var definedTime = new Date(’23:00′); // military time to countdown TO
function ShowTimes() {
var now = new Date();
var hrs = 22-now.getHours();
if (hrs < 0) { hrs += 24; }
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
var str = ”;
str += ‘<center><font size=”7″><br>’+hrs+’ hours, ‘+mins+’ minutes to go</font></center>’;
document.getElementById(‘countdownToMidnight’).innerHTML = str;
}

var _cntDown;
function StopTimes() { clearInterval(_cntDown); }
</script>
</head>
<body onload=”_cntDown=setInterval(‘ShowTimes()’,1000)”>
<div id=”countdownToMidnight”></div>
</body>
</html>

The biggest change I made to the script was modifying the “var hrs” line to subtract 22 from the getHours() variable. I cleaned up the output and did away with displaying the seconds as all I really wanted to do was just count down the hours and minutes to 11pm.

I still consider myself a total novice when it comes to Javascript but it’s nice to know the web is full of sample scripts to help me along.