FUNCTION MickeyMouse$() to Convert TIME$()

Welopez

I spent many years in the military and working with a 24-hour clock is second nature to me. There were those, however, who experienced some difficulties when Mickey's little hand was on 4, or 7, or any time after the noon hour. For them, we always had to convert to Mickey Mouse Time.

Just like the military, computers work with a 24-hour format. You, or the user of your program, may use the TIME$() function frequently or only occasionally. Function MickeyMouse$() will convert the 24-hour format to Mickey Mouse Time for you, and conveniently add "a.m." or "p.m" in case you are locked in a dungeon and can't tell whether the sun is shining.




'Convert 24-hour time format to 12-hour format
'Written by Welo


now$=TIME$() 'Get current computer time (24-hour format)
now$=MickeyMouse$(simple$) 'Call function to use simple time format
PRINT "The time is now "; simple$ 'Print Mickey Mouse Time


END


FUNCTION MickeyMouse$(byref simple$)
now$=TIME$()
now$=LEFT$(now$,5)
h$=LEFT$(now$,2)
m$=RIGHT$(now$,2)
tod$ = " a.m."
hh=VAL(h$)
IF hh >=12 THEN tod$= " p.m."
IF hh >= 13 THEN hh = (hh - 12)
h$ = STR$(hh)
simple$ = h$ + ":" + m$ + tod$
END FUNCTION
>

The value returned by TIME$() is a string, hh:mm:ss, which is why we resort to manipulating the string within the function. now$ is passed to the function 'byref' because we want to change the string value and get simple$ for use in the program. The first thing we do is extract only the leading 5 characters of now$, hh:mm, because we don't really care about the seconds.

Next we extract the left two characters, h$ for the hours, and the right two characters, m$ for the minutes. By default, we assign time of day as tod$=" a.m.". The minutes will remain unchanged, but we must do math with the hours, so we assign VAL(h$) to hh (hours).

Then we check to see to which hour Mickey is pointing. If hh >= 12, we set tod$ to " p.m.", but we don't do arithmetic yet. We wait until hh >=13 before subtracting 12 from hh, otherwise hh would equal 0 hours which does not exist in Mickey Mouse Time. (Okay, the military uses 0 hours for that period between midnight and 0100 hours, but the military does not use a.m. and p.m., so we don't want a value of zero for hh.)

After subtracting 12 from hh, it must be converted to a string again to concatenate simple$ for printing when the function returns to the main program.

This little function was constructed without the aid of Worbles because they are enjoying a little R&R at a winter resort in Argentina. I've alerted Homeland Security to be on the lookout for suspected terrorists when they try to return to my computer!