From abb29b0b113102a7dea3e4691a853ee20e30f614 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 24 Jul 2013 11:52:27 -0400 Subject: [PATCH] src/timetable: Break out leap_years_since function from doomsday --- src/timetable.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 ( { } , { -- 2.39.5