(phixonline)-->
with javascript_semantics
include timedate.e
function doomsday_rule(integer y, m, d)
integer yr4 = remainder(y,4),
yr100 = remainder(y,100),
yr400 = remainder(y,400),
anchor_day = remainder(2 + 5*yr4 + 4*yr100 + 6*yr400,7)
bool leap_year = yr4=0 and (yr100!=0 or yr400=0)
sequence anchors = iff(leap_year?{4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5}
:{3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5})
integer w = d - anchors[m]
if w<0 then w += 7 end if
integer dow = remainder(anchor_day+w,7)
-- return dow
return iff(dow=0?7:dow) -- to agree with ISO 8601, and Phix.
end function
constant dates = {"1800-01-06",
"1875-03-29",
"1915-12-07",
"1970-12-23",
"2043-05-14",
"2077-02-12",
"2101-04-02"}
for i=1 to length(dates) do
timedate dt = parse_date_string(dates[i],{"YYYY-MM-DD"})
integer {y,m,d} = dt,
bid = day_of_week(y,m,d),
drd = doomsday_rule(y,m,d)
string ds = format_timedate(dt,"Dddd Mmmm D, YYYY"),
bis = day_of_week(y, m, d, bAsText:=true),
ok = iff(bid==drd?"(ok)":"*** ERROR ***")
printf(1,"%s\n%-30s (%d = %d ? %s)\n",{ds,bis,bid,drd,ok})
end for