The Museum of HP Calculators

HP Forum Archive 21

 Date/time programs for the HP 35sMessage #1 Posted by R. Pienne on 3 Oct 2013, 2:37 p.m. Hello everybody. Here are a few date/time calculation programs for the HP 35s, which some people might find useful. Various formats can be converted to the date/time format used by most spreadsheet programs (days since 31.12.1899) to simplify further calculations, and converted back again. Programming principles: (1) Input is not needlessly validated; GIGO applies. (2) X gets replaced with the result, and LastX gets set. (3) Variables I and J and indirect registers 0..4 are not preserved. (4) Other stack levels and variables are preserved, except where stated. Instructions are grouped here to illustrate the logical structure of the programs. I'm sure the code could be made more efficient in places; that's left as an exercise for the reader :-). Any problems, let us know. R. -------------------------------------------------------------------------------------------------------------------------------------------------------- ```C ##### time (D.HHMMSSs) -> days ##### LN=53 CK=BC05 LBL C XEQ Z002 save stack STO J FP 100 x HMS-> 24 ÷ RCL J IP + STO J XEQ Z031 x<>J restore stack RTN M ##### days -> time (D.HHMMSSs) ##### LN=53 CK=B214 LBL M XEQ Z002 save stack STO J FP 24 x ->HMS 100 ÷ RCL J IP + STO J XEQ Z031 x<>J restore stack RTN T ##### Spreadsheet time -> UTC time (YYYYMMDD.HHMM) ##### LN=560 CK=869E (writes vars R,X) LBL T XEQ Z002 STO X save stack 20000101 STO R init calculated time to 2000 start 36526 STO-X ,, T008 RCL X x>=0? GTO T021 if 2000 or later, skip 10000 STO-R 365 STO+X RCL R 10000 INT÷ XEQ Z052 STO+X add days to X, take years from R GTO T008 T021 365 STO Q RCL R 10000 INT÷ XEQ Z052 + STO Q RCL X xy? GTO T126 STO-X 100 STO+R take days from X, add months to R RCL X 28 RCL R 10000 INT÷ XEQ Z052 + x>y? GTO T126 STO-X 100 STO+R ,, RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 30 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 30 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 30 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 30 x>y? GTO T126 STO-X 100 STO+R ,, RCL X 31 x>y? GTO T126 STO-X 100 STO+R ,, T126 RCL X IP STO-X STO+R move remaining days to R 24 STOxX convert X to hours RCL X IP 100 ÷ STO+R RCL X FP STO X move hours to R 60 STOxX convert X to mins RCL X 10000 ÷ STO+R move mins to R XEQ Z031 x<>R restore stack RTN U ##### Unix time -> Spreadsheet time ##### LN=28 CK=AA0E LBL U 86400 ÷ 25569 + RTN V ##### UTC time (YYYYMMDD.HHMM) -> Spreadsheet time ##### LN=479 CK=4B0A (writes vars M,R,X) LBL V XEQ Z002 STO X save stack 36526 STO R init calculated time to 2000 start RCL X FP 100 x HMS-> 24 ÷ STO+R add hours÷mins RCL X 10000 INT÷ STO M get year V018 2000 RCL M x>=y? GTO V029 calc days from year start to 2000 start XEQ Z052 STO-R 365 STO-R ,, 1 STO+M GTO V018 ,, V029 1 STO-M 2000 RCL M xR restore stack RTN W ##### Spreadsheet time -> weekday (1..7, Sunday = 1) ##### LN=197 CK=8390 LBL W XEQ Z002 save stack SF10 print messages IP 1 - 7 RMDR 1 + STO J 1 x!=y? GTO W016 EQN "SU" PSE GTO W054 W016 RCL J 2 x!=y? GTO W023 EQN "MO" PSE GTO W054 W023 RCL J 3 x=y? GTO W030 EQN "TU" PSE GTO W054 W030 RCL J 4 x=y? GTO W037 EQN "WE" PSE GTO W054 W037 RCL J 5 x=y? GTO W044 EQN "TH" PSE GTO W054 W044 RCL J 6 x=y? GTO W051 EQN "FR" PSE GTO W054 W051 RCL J EQN "SA" PSE W054 XEQ Z031 x<>J restore stack RTN Z ##### various subroutines ##### LN=243 CK=1944 LBL Z Z002 STO J save stack RDN 0 STO I RDN RCL J STO(I) ,, RDN 1 STO I RDN STO(I) ,, RDN 2 STO I RDN STO(I) ,, RDN 3 STO I RDn STO(I) ,, 4 STO I RDN 1 STO(I) ,, XEQ Z031 ,, RTN ,, Z031 0 STO I 0 RCL(I) + restore stack 3 STO I RCL(I) ,, 2 STO I RDN RCL(I) ,, 1 STO I RDN RCL(I) ,, 0 STO I RDN RCL(I) ,, RTN ,, Z052 STO I is leap year? (0/1) 4 RMDR x!=0? GTO Z069 ,, RDN RCL I 400 RMDR x=0? GTO Z072 ,, RDN RCL I 100 RMDR x!=0? GTO Z072 ,, Z069 RDN 0 RTN ,, Z072 RDN 1 RTN ,, ``` Edited: 3 Oct 2013, 4:33 p.m.

Go back to the main exhibit hall