From: daurnimator Date: Tue, 23 Jul 2013 21:21:57 +0000 (-0400) Subject: src/timetable: Move argument checking in normalise to own function X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/648bc6a577e5191fc2d2842cbc1c2dce368452bc?ds=sidebyside src/timetable: Move argument checking in normalise to own function --- diff --git a/src/timetable.lua b/src/timetable.lua index 9af7994..81fcbf8 100644 --- a/src/timetable.lua +++ b/src/timetable.lua @@ -63,13 +63,17 @@ local function increment ( tens , units , base ) return tens , units end +local function unpack_tm ( tm ) + return assert ( tm.year , "year required" ) , + assert ( tm.month , "month required" ) , + assert ( tm.day , "day required" ) , + tm.hour or 12 , + tm.min or 0 , + tm.sec or 0 +end + local function normalise ( tm ) - local sec = tm.sec or 0 - local min = tm.min or 0 - local hour = tm.hour or 12 - local day = assert ( tm.day , "day required" ) - local month = assert ( tm.month , "month required" ) - local year = assert ( tm.year , "year required" ) + local year , month , day , hour , min , sec = unpack_tm ( tm ) min , sec = increment ( min , sec , 60 ) -- TODO: consider leap seconds? hour , min = increment ( hour , min , 60 )