From: daurnimator Date: Wed, 24 Jul 2013 15:52:27 +0000 (-0400) Subject: src/timetable: Break out leap_years_since function from doomsday X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/abb29b0b113102a7dea3e4691a853ee20e30f614 src/timetable: Break out leap_years_since function from doomsday --- diff --git a/src/timetable.lua b/src/timetable.lua index c71c59b..b58ad0f 100644 --- a/src/timetable.lua +++ b/src/timetable.lua @@ -27,9 +27,13 @@ local function month_length ( m , y ) end end +local function leap_years_since ( year ) + return idiv ( year , 4 ) - idiv ( year , 100 ) + idiv ( year , 400 ) +end + local function doomsday ( year ) return ( 3 -- Tuesday - - 1 + year + idiv ( year , 4 ) - idiv ( year , 100 ) + idiv ( year , 400 ) ) + - 1 + year + leap_years_since ( year ) ) % 7 + 1 end local doomsday_cache = setmetatable ( { } , {