From c2f23781178393e2b5a6a78eb18115566796937c Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 30 Aug 2013 15:44:59 -0400 Subject: [PATCH 1/1] src/timetable: Fix month incrementing --- src/timetable.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/timetable.lua b/src/timetable.lua index d1cd534..3b3b2ed 100644 --- a/src/timetable.lua +++ b/src/timetable.lua @@ -21,7 +21,6 @@ local function year_length ( y ) end local function month_length ( m , y ) - m = ( m - 1 ) % 12 + 1 if m == 2 then return is_leap ( y ) and 29 or 28 else @@ -91,18 +90,23 @@ local function normalise ( year , month , day , hour , min , sec ) day = day + year_length ( year ) end + -- Lua months start from 1, need -1 and +1 around this increment + month = month - 1 + year , month = increment ( year , month , 12 ) + month = month + 1 + -- This could potentially be slow if `day` is very large while true do local i = month_length ( month , year ) if day <= i then break end day = day - i month = month + 1 + if month > 12 then + month = 1 + year = year + 1 + end end - -- Lua months start from 1, need -1 and +1 around this increment - year , month = increment ( year , month - 1 , 12 ) - month = month + 1 - return year , month , day , hour , min , sec end -- 2.39.5