Date and time routines by:

Eric Stuyvesant
undergrad, Metallurgical Engineering & Materials Science, Carnegie Mellon U.

ARPA:  es2a+hp@andrew.cmu.edu

Home (before May 14):            Home (after May 14):
     1060 Morewood Ave.          2890 Fowler Road
     Box 1193                    Springfield, OH 45502
     Pittsburgh, PA 15213        (513) 323 9243
     (412) 268 8644


YEAR:
    [ 0 31 59 90 120 151 181 212 243 273 304 334 365 ]
LYEAR:
    [ 0 31 60 91 121 152 182 213 244 274 305 335 366 ]

LNYR:
    << IF 2 FS? THEN LYEAR ELSE YEAR END >>

LEAP:
    << IF baseyear 4 MOD 0 SAME THEN 2 SF ELSE 2 CF END >>

GETDATE:
    << # 11CAh SYSEVAL B->R 707788800 / >>
         ^^^^^
         |||||
          this is for 28S's; use #123E (in HEX mode) for HP-28C's.
         |||||
GETTIME: vvvvv
    << # 11CAh SYSEVAL B->R 29491200 / >>

SETDATE:
    << ->STR IF DUP SIZE 5 SAME THEN "0" SWAP + END 'da' STO da 1 2 SUB
       da 3 4 SUB da 5 6 SUB STR-> 3 ROLLD STR-> 3 ROLLD STR-> 3 ROLLD
       'baseyear' STO SWAP LEAP LNYR SWAP 1 ->LIST GET + GETTIME basetime
       + 24 MOD 24 / + GETDATE - 'basedate' STO 'da' PURGE >>
SETTIME:
    << HMS-> GETTIME - 'basetime' STO >>

DATE:
    << STD GETDATE basedate + 'dys' STO LEAP IF 2 FS? THEN 366 ELSE 365 END
       -> o << WHILE o dys < REPEAT basedate o - 'basedate' STO dys o -
       'dys' STO 1 'baseyear' STO+ END >> 0 'p' STO DO 'p' 1 STO+ UNTIL
       LNYR p 1 ->LIST GET dys > END 'p' 1 STO- dys LNYR p 1 ->LIST
       GET - IP p ->STR "/" + SWAP ->STR "/" + + baseyear ->STR +
       { dys p } PURGE >>

TIME:
    << STD GETTIME basetime + 24 MOD IF DUP 0 SAME THEN 2 SF END IF DUP 12
       DIV 1 SAME THEN 1 SF ELSE 1 CF END 12 MOD ->HMS 10000 * IP .1 +
       1000000 / ->STR 58 CHR -> ti c << ti 2 3 SUB IF DUP STR-> 0 SAME
       THEN DROP "12" END c + ti 4 5 SUB + c + ti 6 7 SUB + >> IF 1 FC?
       THEN " AM" + ELSE "PM" + END >>

CLOCK:
    << CLLCD DATE 2 DISP "Hit any key (not [ON])" 4 DISP DO TIME 1 DISP
       UNTIL KEY END DROP CLMF >>

DIV:
    << -> yy zz << if zz 0 == THEN MAXR ELSE yy zz / IP END >> >>

Notes:
1)  I originally got some of the DATE code from elsewhere.  I think that
I have modified it some since then.

2)  Note that this DATE/TIME suite requires user flags 1 and 2 for its own
consumption (even when it is not running)

3)  Make sure that you get the correct SYSEVAL location in GETDATE and GETTIME.

4)  ALWAYS SET THE TIME BEFORE SETTING THE DATE!!!!!!!!!
5)  STACK DIAGRAMS for SETDATE and SETTIME:

SETDATE          Set the Date                 Utility

____________________________Level_1_____|____________________
                                        |
                               n        |
                                        |
________________________________________|____________________

n=MMddYY, MM=month, dd=day, YY=year
SETTIME           Set the Time               Utility

___________________________Level_1______|____________________
                                        |
                             hms        |
                                        |
________________________________________|____________________

hms=HH.MMSSss, HH=hour in 24-hour, military format, MM=minutes,
               SS=seconds, ss=decimal seconds

6) With the exception of some of the TIME programming and some of the
   CLOCK programming, I am the author of these programs.

7) I am going home for the summer on Sunday, May 14.  I do not have
   access to ARPA over the summer, but I will read mail when I get
   back after summer break.

8) No warranty comes with this software.  It works on a 28S I wrote it on,
   and I see no reason why it wouldn't work on a 28C (aside from memory
   limits), but you takes you chances!!!
9) This software is public domain (I hereby make the parts written by me so,
   and I believe the rest also is.)
10)For those of you with 28S's FAST is very appropriately added to these
   programs (DATE is ungodly slow)


11)Bugs:

-CLOCK only calls DATE once, so if you are watching the clock when the day
  changes, don't expect the day to change as you watch.
-Both TIME and DATE (and thus, CLOCK) force STD mode, and leave it changed.


GOOD LUCK!!!!

