; Here's a working zeller.r script...
; corrected a few of the goofs from previous post.

; note that this isn't quite what I was looking for when I posted the
calendar.r html making letter
; however it's nice to know about  Zeller's Congruence...


REBOL [
    Title:  "bpaddock revival of Zeller's Convergenc or print the day of the
Week"
    Date:   18-Feb--2000
    Author: "converted from c? by JB c source provided by bpaddock"
    Version: 1.0.0
    Purpose: "Shows day of the week, because we can"
]


;>
;> The 'standard', if there is such a thing, for figuring out
;> the day of the week is "Zeller's Congruence".  His formula
;> might help you out.
;>
;> Sorry that I didn't take the time to convert it to Rebol.
;> Would like to see it that way if some one is so inclined.
;>
; jb was inclined as long as bpaddock edits...and error corrects
;> /* Zeller's Congruence: From "Acta Mathematica #7, Stockholm, 1887.
;>
;> Determine the day of the week give the year, month, and the
;> day of the month; which are passed in the structure 'utc'
;>
;> return(  0 = Sunday...6=Saturday ) and also set utc->wday
;>
;> J = Century (ie 19), K = Year (ie 91), q = Day of the month, m = Month
;>
;> March = month #3....December = month #12,
;> January = month #13, February = month #14 OF THE PREVIOUS YEAR.
;>
;> [q + [((m + 1) * 26 ) / 10] + K + (K / 4) + (J / 4) - (2 * J)] % 7
;>  Because of the "% 7" term, -(2*J), and +(5*J) give the same answer.
;>
;> */
;> ;

Print "If you want to know what day of the week any date is?"
Print " Please, enter the year give all four digits yyyy"
oyear: input
year: make integer! oyear


; I DON'T know what the equivalent commands in Rebol are for initializing?
;> UINT weekday( gmt )
;> struct utc *gmt;
;> {
;>  UINT  mth, year, cent;
;>  register UINT temp;
;>  year = gmt->year;
;>  mth  = gmt->month;
;>

Print "Enter the month as m or mm"

omth: input
mth: make integer! omth ; how is this supposed to be set to integer?
if mth < 3


    mth: mth + 12
    year: year - 1
    ] ;end if
; what is the proper way to enter more than one statement?
; could I have written:
; if mth < 3 [mth: mth + 12 year: year - 1]
;>  if( mth < 3 )
;>  {
;>   mth += 12;
;>   --year;
;>  }
;>

cent:  year / 100
;>  cent = year / 100; /* 19th, 20th, or 21th etc century */

; ok bpaddock what's the % command do here?  remainder? Modulo? Integer
Modulo?
; Just what is this dulo that I'm asking more of ? (imagine that being said
by Groucho Marx?)
; even though I know it's not modulus does rebol have a modulus operator?

;>  year %= 100; /* Tens of years (00->99) */

year:  remainder year 100


Print "Enter the day of the month as either d or dd"

dd: input
dd: make integer! dd

; or the above could be extraced from the present day as in the line below:
; dd: now/day ; but I prefer the interactive effect... the present is so
limiting

;>  temp  = gmt->day; /* Start with the day of the month */
; we have day of the month from input
;>  temp += (((mth + 1) * 26) / 10); /* Advance to the start of the month */
temp: dd + (((mth + 1) * 26) / 10) ; gosh I hope that syntax works in
Rebol...

;>
;>  temp += year; /* [K]   Add in the year */
temp: temp + year

;>
;>  temp += (year / 4); /* [K/4] Correct for leap years */
temp: temp + year / 4
;  I haven't reviewed the hierarchy of operators but above line should
work...
;>
;> /* Because of the "% 7" term, -(2*J), and +(5*J) give the same answer: */
;>  temp += (cent * 5); /* [J*5]  Correct for centuries  */
temp: temp + (cent * 5)
;>
;>  temp += (cent / 4); /* [J/4] Give extra day ever 400 years */
temp: temp + (cent / 4)
;>
;>  temp %= 7; /* 7 days in a week */

print ["temp before dividing by 7 = " temp]

temp:  remainder temp 7

print ["temp after dividing by 7 = " temp]

temp: make integer! temp

print ["temp after temp: make integer! temp = " temp]

;>
;>  if( !temp ) /* Wrap Saturday to be the last day of week */
if temp = 0 [ temp = 7]
;>   temp = 7;
;>
;>  temp -= 1; /* 0 = Sunday...6=Saturday */
; in my case I want 1 = Sunday .... 7 = Saturday...


print [" The day of the week you were looking for "dd"/"omth"/"oyear " is "
   switch temp [
    1 ["Sunday"]
    2 ["Monday"]
    3 ["Tuesday"]
    4 ["Wednesday"]
    5 ["Thursday"]
    6 ["Friday"]
    7 ["Saturday"]
   ]; ends switch
]; ends print


; >
; >  gmt->wday = temp;
; >
; >  return( temp );
; > }

Reply via email to