[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conversion of ISO Date-stamps into Weekday Numbers



jgharston writes:
>lach wrote:
>> ...and won't compile into an assembly subroutine of less than two
>> dozen instructions on a QL for both Julian & Gregorian dates,
>
>Dunno about 68000 code, but 6502 code here:
>http://mdfs.net/Info/Comp/6502/ProgTips/DayOfWeek

 That code is slow & dirty. On the one hand it assumes: that
 all dates are stored in non-standard fashion in 3 bytes, rather
 than 4 as CYMD (but if there's an over-riding constraint to store
 dates in 3 bytes, one may store the 1st digit of the century in
 the upper 3 bits of D, and the 2nd in the upper 4 bits of M); and in
 the alternative, that CY is to be pre-processed by subtracting 1900
 before passing the result to register Y. The latter is cheating--
 if that's acceptable, then one ought to cheat properly by looking up
 the Century offset in the offset-table, summing it with D, and then
 passing the sum to the subroutine when called. As 'month'<13, and
'century'>14 for Gregorian dates, both tables may be combined into
 one. Century offsets may be found at:

http://de.wikipedia.org/wiki/Wochentagsberechnung#Jahrhundertziffer

 This has the added benefit of the year register always being less
 than 100, so that there's no need to test for Century 21. Further
 improvements could be realised by rewriting the code to eliminate    
 the need to invert register A, due to A's total sum always being   
 less than 100. This will yield another benefit: to have the code
 also work for dates in BCD. The code can thus be streamlined to
 have a wider range of applicability, yet use fewer clock cycles.

>You didn't ask for Julian number, you asked for day of week.

Your lies never stop, eh?

I didn't ask for the day of week either. I'm telling how to find
the weekday number in a different, if not better, way.