10REM > Times 1.01
20REM Various time and date functions
30REM 24-09-96 JGH
40:
50MODE7
60DIM ctrl% 30,data% 80
70REM Read time string on any machine
80PRINT"The time and date is";:A$=FNt
ime:IF A$="":PRINT" not set"' ELSE PRINT
":"'A$'
90:
100REM Read date as numbers
110d%=FNdate:m%=(d%AND&FF00)DIV256
120y%=(d%AND&FFFF0000)DIV65536
130d%=d%AND&FF
140:
150REM Find day of week
160day%=FNDayOfWeek(d%,m%,y%)
170day$=MID$("SunMonTueWedThuFriSat",d
ay%*3-2,3)
180PRINT"The date is: ";day$;", ";d%;"
/";m%;"/";y%
190IFd%=0 OR m%=0:PRINTSPC13"Date not
set"
200PRINT
210:
220REM Calculate days since past event
230PRINT"It is ";FNDaysSince(d%,m%,y%,
7,1,1969);" days since 1/7/1969."
240PRINT"There are ";FNDaysSince(1,1,2
001,d%,m%,y%);" days to the next century
."
250:
260END
270:
280:
290:
300REM Time & Date functions from HADF
S Reference Manual
310REM J.G.Harston 1996
320:
330REM Return Real-Time-Clock string,
or null if no clock available
340DEFFNtime:LOCAL A%,X%,Y%:X%=ctrl%:Y
%=X%DIV256:A%=14:?X%=0:CALL &FFF1
350IF?X%:X%?24=13:=$X% ELSE =""
360:
370REM Return Real-Time-Clock date, or
zero if no clock available
380DEFFNdate:LOCAL A%,X%,Y%:X%=ctrl%:Y
%=X%DIV256:A%=14:?X%=1:CALL &FFF1
390=VALSTR$÷X%?2+256*VALSTR$÷X%?1+6553
6*(1900+VALSTR$÷?X%-100*(?X%<&50))
400:
410:
420REM Return day of week, 1=Sunday, 7
=Saturday
430DEFFNDayOfWeek(d%,m%,y%):IFy%<100:y
%=y%+1900
440y%=y%MOD400
450=(y%*365.25+m%*30+d%+VALMID$("12011
2234455",m%,1)+((y%MOD4)=0)-((y%-1)DIV10
0)-(m%>2AND((y%MOD4)=0AND(y%MOD100)<>0OR
y%=0))+3)MOD7+1
460:
470REM Convert time and date to 5-byte
centi-second count since 1st Jan 1900
480DEFPROCConvDate(mem%,d%,m%,y%,hr%,m
n%,sc%,cs%):IFy%<100:y%=y%+1900
490y%=y%MOD400:d%=y%*365.25+m%*30+d%+V
ALMID$("120112234455",m%,1)+((y%MOD4)=0)
-((y%-1)DIV100)-(m%>2AND((y%MOD4)=0AND(y
%MOD100)<>0ORy%=0))+36493:IFd%>146096:d%
=d%-146097
500d%=d%*&41EB:mem%!1=d%+d%:d%=((hr%*6
0+mn%)*60+sc%)*100+cs%
510?mem%=d%:mem%!1=mem%!1+d%DIV256:END
PROC
520:
530REM Return number of days since a p
ast date
540DEFFNDaysSince(td%,tm%,ty%,pd%,pm%,
py%):LOCAL past%
550PROCConvDate(ctrl%,pd%,pm%,py%,0,0,
0,0):past%=ctrl%!1
560PROCConvDate(ctrl%,td%,tm%,ty%,0,0,
0,0):=(ctrl%!1-past%)DIV&83D6
570: