Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.sinclair > #155
| From | lachman@ebony.ppc.ubc.ca (Milton Lachman) |
|---|---|
| Newsgroups | comp.sys.sinclair |
| Subject | Re: Conversion of ISO Date-stamps into Weekday Numbers |
| Date | 2011-04-12 18:21 +0000 |
| Organization | Pulp and Paper Centre |
| Message-ID | <io256d$t5a$1@speranza.aioe.org> (permalink) |
| References | <hp10mo$atu$1@speranza.aioe.org> |
[This revision is optimised for speed, and
extended to Byzantine and Old-Style dates.]
HOW TO COMPUTE THE DAY OF THE WEEK FOR DATE-STAMPS 10010101 TO 99991231
- using Hans Lachman's Method of Congruence as generalised below -
Strictly adhering to Lachman's Maxim (Complexity is a diseconomy of scale),
this method is designed to run super-bly as a stand-alone subroutine when
the most BASIC of computer is the only resource--meaning no values needed
from user tables or system calls, and no floating point variables.
Although using a processor more sophisticated than found on four-function
calculators, this method is simpler to execute than Hans' original Method
of Congruence needing manipulation of data by numerically competent users.
It succeeds where other Methods do not when computing the day of the week
even on lowly Sinclair ZX BASIC: having no need of extra instructions for
data stored in tables as in Babwani's Method nor for redundant operations
as in Zeller's or Tondering's--nor even a C compiler running on a bloated
development system as in Mike Keith's--yet doing more in under 12 lines.
Given:
D$(8) as a Date-stamp YYYYMMDD in basic ISO format,
N% as its offset,
& F% as a false flag for non-Gregorian calendars:
300 0 Julian (historical)
301 0 Byzantine
325 0 Old-Style
300 50 Gregorian (historical)
the superBASIC subroutine below is to compute:
s$ as the offset Date-stamp
m$(2TO 3) as the MonthIndex
i% as the increment to K%
g% as the Gregorian increment
w% as the ISO-compatible number of the corresponding weekday:
Sun=0 Mon=1 Tue=2 Wed=3 Thu=4 Fri=5 Sat=6
AUTO start,gap
REM Step 0 - initialise parameters and offset D$
LET i%=F%+ F% : X%=256 : K%=19300 : s$=D$- N%
SELect ON N%
ON N%= 301
IF D$(5TO 6)> 8 THEN LET s$(1TO 4)=s$(1TO 4)- 1
IF s$(5TO 6)< 6 THEN LET i%=100
ON N%= 325
IF s$(5TO 8)> 9775 THEN LET i%=100
IF s$(5TO 8)> 9975 THEN LET s$(1TO 4)=s$(1TO 4)+ 1
END SELect
REM Step 1 - compute the MonthIndex & Gregorian increment
LET m$=X%*D$(5TO 6)+ K%+ i% : g%=F%*s$(1TO 2)DIV 8+ F%
REM Step 2 - compute the weekday-number
LET w%=(s$(1TO 4)DIV 4+ D$(1TO 4)+ m$(2TO 3)+ D$(7TO 8)+ g%)MOD 7
^space
The subroutine is streamlined such that the proper parameters for a
calendar are to be passed: for example, a flag of 50 for Gregorian
dates as of 15.oct.1582 (A.D.) & 0 for non-Gregorian as of 1.jan.1001
(A.D. for Julian & Old Style calendars; A.M. for Byzantine calendars).
The subroutine thereby gives compleat, valid, historical continuity of
date-stamp conversion until 31.dec.9999 for the relevant epoch.
Because of its initial overlap with the historical year, the K% addend
applies till December 31st. From January 1st, K%+i% applies till August
31st, the end of the Byzantine year, or March 24th, the end of the Old-
Style year. Month-numbers remain defined in terms of an historical year
for both (as for calendars where N%=300).
--
REFERENCES http://oz.ccnet.us/dayofweek/
http://www.guernsey.net/~sgibbs/roman.html
http://www.merlyn.demon.co.uk/zel-like.htm#Keith
http://en.wikipedia.org/wiki/Zeller%27s_congruence
http://www.tondering.dk/claus/cal/node3.html#SECTION00360000000000000000
babwani-congruence.blogspot.com/search/label/Frequently%20AskeD$20Questions
Back to comp.sys.sinclair | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Conversion of ISO Date-stamps into Weekday Numbers lachman@ebony.ppc.ubc.ca (Milton Lachman) - 2011-04-12 18:21 +0000
Re: Conversion of ISO Date-stamps into Weekday Numbers Guesser <alistair@alistairsserver.no-ip.org> - 2011-04-12 19:24 +0100
Re: Conversion of ISO Date-stamps into Weekday Numbers lachman@ebony.ppc.ubc.ca (Milton Lachman) - 2011-04-14 19:31 +0000
csiph-web