date functions, TOD clock and the year 2043

:Subject: TOD clock and the year 2043

:Does anyone have a set of Assembler routines that convert from a

:TOD clock value to a date and time? Is it as easy as getting the

:clock value into a pair of registers, shifting the pair of registers

:to the right 12 bits to get the number of micro seconds since January,

:1, 1900, divide that by 1000000 to convert to seconds and then calculate

:the year, month, day, hours, minutes, and seconds since 1/1/1900

:without forgetting about leap years? Although there sounds like quite

:a few steps none of the steps are very difficult. I would be interested

:in seeing routines that anyone else has that they would be willing

:to share.

One of the steps you will need is something to convert the julian

date into a month/day combination. What I use was published in

Communications of the ACM, October 1970, page 621, algorithm 398,

"Tableless Dave Conversion" by Richard A. Stone. For those of you

without immediate access to it, here it is roughly translated (by eye)

to rexx.

given y=year, n=julian date.

if (y // 4) = 0 then t = 1 else t = 0

if (y // 400) = 0 & (y // 100) ^= 0 then t = t else t = 0

if n > (59 + t)

then d = n + 2 - t

else d = n

m = (d + 91) * 100 % 3055

d = (d + 91) - (m * 3055) % 100

m = m - 2

Output is 'm' with the month and 'd' as the day in that month.

According to the article it works by adjusting february so that it

has 30 days in it. Then it uses the fact that 30.55 (m+2) - 91 days

pass preceeding each month.

Those of you with access to the source of TRACK should recognize

this algorithm. It looks very similar.