Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.sinclair > #70

Re: Conversion of ISO Date-stamps into Weekday Numbers

From lachman@ebony.ppc.ubc.ca (Milton Lachman)
Newsgroups comp.sys.sinclair
Subject Re: Conversion of ISO Date-stamps into Weekday Numbers
Date 2011-03-15 10:26 +0000
Organization Pulp and Paper Centre
Message-ID <ilnet7$svj$1@droog.sdf-eu.org> (permalink)

Show all headers | View raw


  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 superbly 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 amount of shifting,
    &  F% as a false flag for non-Gregorian calendars:
 300    0    Julian (historical)
 301    0    Byzantine
 325    0    Old-Style
 300   50    Gregorian (historical);
 K%    as an addend (19300 for integer arithmetic)
 X%    as a multiplier (256 for integer arithmetic)

the Sinclair BASIC subroutine below is to compute:

 y%    as the Year
 m%    as the month
 m$    whereby m$(2TO3)=MonthIndex
 d%    as the day's number within the month
 i%    as an increment to K%
 w%    as the ISO-compatible number of the corresponding weekday:
          Sun=0  Mon=1  Tue=2  Wed=3  Thu=4  Fri=5  Sat=6


 REM Step 0 - isolate components of & offset the Date-stamp:
 LET y%=D$(1TO4) : m%=D$(5TO6) : d%=D$(7TO8) : s$=D$-N% : i%=F%+F%
 IF N%=301 THEN
    IF m%>8 THEN LET s$(1TO4)=s$(1TO4)-1
    IF s$(5TO6)<6 THEN LET i%=100
 END IF
 IF N%=325 THEN
    IF s$(5TO8)>9775 THEN LET i%=100
    IF s$(5TO8)>9975 THEN LET s$(1TO4)=s$(1TO4)+1
 END IF

 REM Step 1 - compute the MonthIndex:
 LET m$=m%*X% + K% + i%

 REM Step 2 - compute the weekday-number:
 LET w%=(s$(1TO4)DIV4 + y% + m$(2TO3) + d% + F%*s$(1TO2)DIV8 + F%)MOD7    


 The subroutine is streamlined such that parameters are to be passed in
 proper format. For example, one must pass 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 in the relevant epoch.

 Because of its initial overlap with the historical year, a 93 addend is
 to apply till December 31st. From January 1st, a 94 addend applies till
 the end of the Old Style year on March 24th or also till the end of the
 Byzantine year on August 31st. Month-numbers remain defined in terms of
 the historical year for both (as for calendars where N%=300).


--

REFERENCES             http://oz.ccnet.us/dayofweek/
                http://www.guernsey.net/~sgibbs/roman.html
           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 | NextNext in thread | Find similar | Unroll thread


Thread

Re: Conversion of ISO Date-stamps into Weekday Numbers lachman@ebony.ppc.ubc.ca (Milton Lachman) - 2011-03-15 10:26 +0000
  Re: Conversion of ISO Date-stamps into Weekday Numbers lachman@ebony.ppc.ubc.ca (Milton Lachman) - 2011-03-15 12:00 +0000
  Re: Conversion of ISO Date-stamps into Weekday Numbers "Brian Gaff" <Briang1@blueyonder.co.uk> - 2011-03-16 10:15 +0000
    Re: Conversion of ISO Date-stamps into Weekday Numbers spike1@freenet.co.uk - 2011-03-16 12:26 +0000
      Re: Conversion of ISO Date-stamps into Weekday Numbers "Brian Gaff" <Briang1@blueyonder.co.uk> - 2011-03-17 08:36 +0000
        Re: Conversion of ISO Date-stamps into Weekday Numbers spike1@freenet.co.uk - 2011-03-17 09:36 +0000
          Re: Conversion of ISO Date-stamps into Weekday Numbers korax1214 <korax1214@gmail.com> - 2011-03-17 16:15 -0700
            Re: Conversion of ISO Date-stamps into Weekday Numbers jgharston <jgh@arcade.demon.co.uk> - 2011-03-17 17:49 -0700
              Re: Conversion of ISO Date-stamps into Weekday Numbers "Brian Gaff" <Briang1@blueyonder.co.uk> - 2011-03-18 07:10 +0000
        Re: Conversion of ISO Date-stamps into Weekday Numbers lachman@ebony.ppc.ubc.ca (Milton Lachman) - 2011-03-23 18:06 +0000
          Re: Conversion of ISO Date-stamps into Weekday Numbers jgharston <jgh@arcade.demon.co.uk> - 2011-03-24 16:04 -0700
            Re: Conversion of ISO Date-stamps into Weekday Numbers lachman@ebony.ppc.ubc.ca (Milton Lachman) - 2011-03-27 16:48 +0000
        Re: Conversion of ISO Date-stamps into Weekday Numbers lachman@ebony.ppc.ubc.ca (Milton Lachman) - 2011-03-23 21:32 +0000

csiph-web