;wow... neat formula... I'm inclined to convert... I've already begun below
amidst the body of your message...
;I set out a few months ago to figure this out... and was easily sidetracked
;-)
;before I go on I just say that your mail showed up with an unusual Icon in
my MS Outlook express inbox...
;it was a little notepad with a pen or pencil... where as most of the other
mail shows up as an envelope...
;please enlighten me... I know it's got something to do with newsgroups...
but what?? ah isn't it sweet to be so
;young and naive...
; however I was hoping for a simpler way to just convert the day or month
into words
; and find any other calendar functions rather than using the switch
method...
;I've tossed in a few odd comments below but I think I get the jist of it...
; also you'll note that when you run this... it' will come back with an
error about integers
; cause I don't know how initialize these properly... any suggestions are
welcome
;thanks...
;jb
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"
year: integer! year
year: input
; 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"
mth: integer! mth ; how is this supposed to be set to integer?
mth: input
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: integer! dd
dd: input
; 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 */
temp: remainder temp 7
;>
;> 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 " month year " 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 );
; > }