(day-of-week) ( year month day -- n )


Vocabulary
calendar

Inputs
yearan integer
monthan integer
dayan integer


Outputs
nan integer


Word description
An implementation of the Zeller's congruence 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


: (day-of-week) ( 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 ;