Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

countdown clock and converting ticks to/from date/time

6 views
Skip to first unread message

jrla...@shell.golden.net

unread,
Oct 13, 1998, 3:00:00 AM10/13/98
to
I call this a countdown clock but it'll count in either direction depending
on whether the moment specified by the date/time is in the past or the
future.

You call the CDC program by passing it the specified date, time and a short
message. It'll then tell you how many days and h/m/s it is to that moment
in time.

There are two handy support routines called ->TICK and TICK->. They will
convert a date (mm.ddyyyy) and a time (hh.mmss) into a large binary number.
The binary number is of the same form as used by the HP and returned by the
TICKS command.

I use this quite a bit in many programs when I need the current date and
time. Doing the two commands:

DATE TIME

together doesn't guarantee that you'll have the right date and time
especially if there is a midnight rollover between the two commands. This
isn't a real problem with most people who use their calculator during the
day but I use it quite a bit when I'm helping a friend with his telescope.
The telescope is much more useful when it's dark and there's this problem
where the date changes right in the middle of the dark.

For these cases the program fragment:

TICKS TICK\->

will get you a date and time that is guaranteed to be correct.

If anybody has any questions drop me a line ...

Here's the commented program listing

%%HP: T(3)A(D)F(.);
DIR
@
@ Count Down Clock
@
@ mm.ddyyyy hh.mmss "message" ->
@
@ displays the message as well as a running count of the remaining
@ days/hours/minutes/seconds to/from the specified date/time.
@
@ Any keystroke stops the program
@
@ If the time given is negative it is not displayed and the time
@ difference is computed from noon of that day.
@
CDC
\<<
0
@ save the flags because we want to ensure that the binary word
@ size is set to 64.
RCLF
\<<
DUP IP SWAP FP 100 * DUP IP SWAP FP 100 * IP
\-> h m s
\<<
h DUP 9 \<= "0" "" IFTE SWAP + ":" +
m DUP 9 \<= "0" "" IFTE SWAP + + ":" +
s DUP 9 \<= "0" "" IFTE SWAP + +
\>>
\>>
\-> date time msg done flag ahms
\<<
@ all calculations with ticks are done with 64 bit binaries
64 STWS
CLLCD
@ display the message
" Msg: " msg + 1 DISP
@ display the date in a nice format
"Date: " date DUP IP SWAP FP 100 * DUP IP SWAP FP 10000 *
\-> m d y
\<<
{ "Jan" "Feb" "Mar" "Apr" "May" "Jun"
"Jul" "Aug" "Sep" "Oct" "Nov" "Dec" } m GET " " + d \->STR +
", " + y \->STR +
\>>
+ 2 DISP
@ display the time only if it's not negative
IF time 0 \>= THEN
"Time: " time ahms EVAL + 3 DISP
END
date
@ if the time is negative use noon
time 0 < 12 time IFTE
@ convert date/time into clock ticks
\->TICK
\-> t0
\<<
WHILE done NOT REPEAT
@ how many ticks since the user supplied moment?
TICKS t0 -
\-> \GDt
\<<
@ display the ticks time difference as days/hr/min/sec
"\GDT: "
@ if the difference is negative adjust for that
IF \GDt # 8000000000000000h AND # 0h \=/ THEN
\GDt NEG '\GDt' STO
"-" +
END
@ how many days in the ticks?
\GDt 707788800 / B\->R
@ what's the h/m/s left after the days is taken care of?
\GDt OVER 707788800 * -
@ convert ticks to hh.mmss
B\->R 29491200 / \->HMS
@ convert hh.mmss into a string "hh:mm:ss"
ahms EVAL
@ add the days to the front and display it
SWAP \->STR "d " + SWAP + + 5 DISP
\>>
@ if a key was pressed then pack it in
IF KEY THEN
DROP 1 'done' STO
END
END
\>>
@ retore the users flags
flag STOF
\>>
\>>
@
@ convert a binary tick count into it's date/time
@
@ # xd -> mm.ddyyyy hh.mmss
@
TICK\->
\<<
RCLF
\-> t f
\<<
64 STWS
@ extract the number of days from the binary
t 707788800 /
@ convert it to a julian day as needed by the HP
B\->R 584388 -
@ find out what day it is
1.0116 SWAP DATE+
@
@ extract the time into the day
t # 2A300000h DUP2 / * -
@ truncate it to seconds
# 1FFFh NOT AND
@ convert it to hh.mmss
B\->R 29491200 / \->HMS
f STOF
\>>
\>>
@
@ convert a date/time into it's binary tick count
@
@ date time -> # xxxxd
@
\->TICK
\<<
RCLF
\-> d t f
\<<
64 STWS
@ convert the day into a julian day number as needed by the HP
d 1.0116 SWAP DDAYS 584388 +
@ convert that into ticks
R\->B 707788800 *
@ convert the time into ticks and add it to the date ticks
t HMS\-> 29491200 * +
f STOF
\>>
\>>
CST
{
{ "Y2K" \<< 1.012 0 "Y2K" CDC \>> }
}
END


--
john R. Latala
jrla...@golden.net

John H Meyers

unread,
Oct 13, 1998, 3:00:00 AM10/13/98
to
In article <6vug52$oq5$1...@cougar.golden.net>,
jrla...@shell.golden.net () writes:

> Doing the two commands:
> DATE TIME
> together doesn't guarantee that you'll have
> the right date and time especially if there is
> a midnight rollover between the two commands.

The following does guarantee correct date and time,
even at a midnight rollover:

WHILE DATE TIME OVER DATE \=/ REPEAT DROP2 END

(where \=/ means the "notequal" symbol)

The same principle can be used with any operating system
which does not have a single, uninterruptible call
for retrieving both the date and the time.

"I could climb the very highest Himalayas,
be one of the greatest ever tennis players,
or even the world's greatest mime;
there's no limit to my genius, but
I just don't have the time." - Michael Flanders ("The Sloth")

-----------------------------------------------------------
With best wishes from: John H Meyers <jhme...@mum.edu>

Diego Berge

unread,
Oct 14, 1998, 3:00:00 AM10/14/98
to
(mail, usenet reply)

In article <6vug52$oq5$1...@cougar.golden.net>, jrla...@shell.golden.net says...
>

> @ mm.ddyyyy hh.mmss "message" ->

Just tought I'd let you know you should test flag -42 (date format). Make
sure its clear (factory default, but a lot of us here in Europe change it).

Regards,
Diego Berge.


jrla...@shell.golden.net

unread,
Oct 14, 1998, 3:00:00 AM10/14/98
to
Diego Berge (dberg...@geocities.com) wrote:

: In article <6vug52$oq5$1...@cougar.golden.net>, jrla...@shell.golden.net says...
: >

: > @ mm.ddyyyy hh.mmss "message" ->

: Just tought I'd let you know you should test flag -42 (date format). Make

: sure its clear (factory default, but a lot of us here in Europe change it).

The version I posted isn't actually the version I use. The version I use
calles a lot of helper routines I keep in my HOME directory. I thought the
program would be more useful if it didn't need fifteen or twenty support
routines to function ...

Diego Berge

unread,
Oct 14, 1998, 3:00:00 AM10/14/98
to
(mail, usenet reply)

In article <701i9v$p9p$1...@cougar.golden.net>, jrla...@shell.golden.net says...

Unfortunately I don't have your source code handy right now to illustrate,
but it only takes either one or two more instructions to make it more robust.
Just before you process the date data, add:
-42 FS? SWAP
But since you're code saves and later restores the flags state, you might
simply do:
-42 CF

Just a tought. :)
Regards,
Diego Berge.


Diego Berge

unread,
Oct 15, 1998, 3:00:00 AM10/15/98
to
(me again, mail, usenet :)

In article <703dcc$7pf$2...@diana.bcn.ibernet.es>, dberg...@geocities.com
says...


>
> Unfortunately I don't have your source code handy right now to illustrate,
>but it only takes either one or two more instructions to make it more robust.
>Just before you process the date data, add:
> -42 FS? SWAP

Forgot to say, this expects the month in level 2 and date on level 1. The
whole thing's like:

DATE DUP DUP IP SWAP FP 100 * IP -42 FS? SWAP ROT 100 * FP 100 *
^^^^^^^^^^^^

( date -> mm dd yyyy)

Regards,
Diego Berge.


jrla...@shell.golden.net

unread,
Oct 15, 1998, 3:00:00 AM10/15/98
to
jrla...@shell.golden.net wrote:
: I call this a countdown clock but it'll count in either direction depending

: on whether the moment specified by the date/time is in the past or the
: future.

Sigh ... just got mail saying my posting of an updated version of my
countdown clock didn't go through ... let's try this again.

Here's an updated version of my countdown clock that takes the date
flag into account. The ->TICK and TICK-> routines didn't need any changes
just the CDC routine.

See the CST variable for an example of how to call it.

@
@ this is the change for the date format flag. At this point we
@ have the month, day and year on the stack, we change that to
@ the year, month and day with the ROLLD and then swap the month
@ and day if the date format flag is set.
@
3 ROLLD
IF -42 FS? THEN
SWAP
END
@ instead of passing in m, d and year we're now passing in the
@ year, month, day
\-> y m d

0 new messages