From 648bc6a577e5191fc2d2842cbc1c2dce368452bc Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 23 Jul 2013 17:21:57 -0400 Subject: [PATCH 1/1] src/timetable: Move argument checking in normalise to own function --- src/timetable.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 ) -- 2.39.5