Time and Date functions
By J.G.Harston (W79)
I present here a few handy time and date handling functions that are
listed in my HADFS Reference Manual but are useful enough by themselves to
be made available to a wider audience. The functions are in the program
Times which also gives a brief demonstration of their usage.
The Master computers have a real-time-clock (RTC) readable with TIME$
which calls Osword 14. Some BBC B computers also have a RTC available,
but as Basic II doesn't have TIME$, it cannot be used, and some 6502
second processors lose the terminating byte. The function FNtime returns
the RTC time string by calling Osword 14 directly and is usable on any
machine. It returns a null string if no clock is available.
REM Return Real-Time-Clock string, or null if no clock available
DEFFNtime:LOCAL A%,X%,Y%:X%=ctrl%:Y%=X%DIV256:A%=14:!X%=0:CALL &FFF1
IF?X%:X%?24=13:=$X% ELSE =""
The function FNdate returns the date as a four-byte number as &yyymmdd
where yyyy, mm and dd are the year, month and date. Osword 14 returns
these values in Binary Coded Decimal and FNdate converts these to more
easily usable integers. If the returned year if 50 or more, it is
returned as 1950 to 1999, otherwise it is returned as 2000 to 2049, so
allowing years to span the end of the century.
REM Return Real-Time-Clock data, or zero if no clock available
DEFFNdate:LOCAL A%,X%,Y%:X%=ctrl%:Y%=X%DIV256:A%=14:!X%=1:CALL &FFF1
The following construction will get the date, month and year into separate
variables d%, m% and y%:
The function FNDayOfWeek calculates the day of the week that the supplied
date falls on.
REM Return day of week, 1=Sunday, 7=Saturday
To convert the day to a three-character string, the following construct is
day%=FNDayOfWeek(???, ???, ???)
This also works for the months of the year:
The procedure PROCConvDate converts a given date and time to the
centi-second count since midnight on 1/1/1900 that Acorn uses for measuring
REM Convert time and date to 5-byte centi-second count since 1st Jan 1900
The function FNDaysSince uses PROCConvDate to calculate the number of
days between two events. After writing this I discovered that I had just
missed the 10,000th daily anniversary of my birth by a couple of months!
Oh, well, just another 28 or so years to day number 20,000.
It is called with today's (or any other day's) date in td%, tm%, ty% and
the past date in pd%, pm% and py%.
REM Return number of days since a past date