X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/eabec5f434225aa68aa33565d8cf5055f287662e..cdaad9ec35371fcfc3b398b7302f1e8fe313b4f6:/luatz/timetable.lua diff --git a/luatz/timetable.lua b/luatz/timetable.lua index e2930d8..6bae913 100644 --- a/luatz/timetable.lua +++ b/luatz/timetable.lua @@ -76,8 +76,8 @@ local function carry ( tens , units , base ) tens = tens + idiv ( units , base ) units = units % base elseif units < 0 then - tens = tens - 1 + idiv ( -units , base ) - units = base - ( -units % base ) + tens = tens + idiv ( units , base ) + units = ( base + units ) % base end return tens , units end @@ -107,8 +107,12 @@ local function normalise ( year , month , day , hour , min , sec ) -- Add a whole year of days at a time, this is later resolved by adding months -- TODO[OPTIMIZE]: This could be slow if `day` is far out of range while day < 0 do - year = year - 1 - day = day + year_length ( year ) + month = month - 1 + if month < 0 then + year = year - 1 + month = 11 + end + day = day + month_length ( month + 1 , year ) end year , month = carry ( year , month , 12 )