4 ms·
Dealing with calendars can be pretty difficult. Since I recently wrote a script in Lua to be my personal assistant, processing calendars, todo lists, mailing l
by strenholme 4y ago
Dealing with calendars can be pretty difficult. Since I recently wrote a script in Lua to be my personal assistant, processing calendars, todo lists, mailing lists, etc., here’s a Lua form of the code to calculate the day of week. This is accurate for any Georgian date:
-- Calculate the day of the week
-- Input: year, month, day (e.g. 2022,9,16)
-- Output: day of week (0 = Sunday, 6 = Saturday)
function dayOfWeek(year, month, day)
-- Tomohiko Sakamoto algorithm
local monthX = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}
if month < 3 then year = year - 1 end
local yearX = (year + math.floor(year / 4) - math.floor(year / 100) +
math.floor(year / 400))
local out = yearX + monthX[month] + day
out = out % 7
return out
end
- zazaulola 4y agoIn C-lang the algorithm is more mysterious: dow(m,d,y) { y-=m<3; return(y+y/4-y/100+y/400+"-bed=pen+mad."[m]+d)%7; }