zeller-congruence ( year month day -- n )


Vocabulary
calendar

Inputs and outputs
yearan integer
monthan integer
dayan integer
nan integer


Word description
An implementation of an algorithm that computes the day of the week given a date. Days are indexed starting from Sunday, which is index 0.

Notes
User code should use the day-of-week word, which takes a timestamp instead of integers.

Definition


: zeller-congruence ( year month day -- n )
[
dup 2 <= [ [ 1 - ] [ 12 + ] bi* ] when
[ dup [ 4 /i + ] [ 100 /i - ] [ 400 /i + ] tri ] dip
[ 1 + 3 * 5 /i + ] keep 2 * +
] dip 1 + + 7 mod ;