From: jrlatala@shell.golden.net (John R. Latala)
Newsgroups: comp.sys.hp48
Subject: Re: countdown clock and converting ticks to/from date/time
Date: 15 Oct 1998 12:27:22 GMT
Organization: Golden Triangle Online
Lines: 172
Message-ID: <704pna$jom$1@cougar.golden.net>
References: <6vug52$oq5$1@cougar.golden.net>
NNTP-Posting-Host: 199.166.210.4
X-Newsreader: TIN [version 1.2 PL2]
Xref: republic.btigate.com comp.sys.hp48:17340

jrlatala@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.

%%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 * 
        @
        @ 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 
        \<< 
          { "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
jrlatala@golden.net