From 7df7c53159b454e765f12c754cace8ae7748c8a2 Mon Sep 17 00:00:00 2001 From: ollo Date: Sun, 15 May 2016 16:37:55 +0200 Subject: [PATCH] The function getUTCtime returns a struct'time' instead of all values seperatly --- timecore.lua | 4 ++-- unit/generateUnixtimes.sh | 11 +++++------ unit/testUnixtimes.lua | 6 ++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/timecore.lua b/timecore.lua index 3464a34..5027667 100644 --- a/timecore.lua +++ b/timecore.lua @@ -142,7 +142,7 @@ function getUTCtime(unixtimestmp) local sec = math.floor(dayclock % 60) local min = math.floor( (dayclock % 3600) / 60) local hour = math.floor(dayclock / 3600) - local wday = math.floor( (dayno + 4) % 7) -- Day 0 was a thursday + local dow = math.floor( (dayno + 4) % 7) -- Day 0 was a thursday while (dayno >= yearsize(year)) do @@ -158,7 +158,7 @@ function getUTCtime(unixtimestmp) end mday = dayno + 1 - return year, (mon+1), mday, hour, min, sec, wday + return { year = year, month = (mon+1), day = mday, hour = hour, minute = min, second = sec, dow = dow } end diff --git a/unit/generateUnixtimes.sh b/unit/generateUnixtimes.sh index 42c868a..e10cf2d 100755 --- a/unit/generateUnixtimes.sh +++ b/unit/generateUnixtimes.sh @@ -23,16 +23,15 @@ echo "Generating $OUTPUT ..." cat << EOF > $OUTPUT dofile("../timecore.lua") function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMinute, resultSecond, resultDow, unixtime) - year, month, day, hour, minute, second, dow = getUTCtime(unixtime) + time = getUTCtime(unixtime) - if not (year == resultYear and resultMonth == month and day == resultDay and hour == resultHour and minute == resultMinute and second == resultSecond and dow == resultDow) then - print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " day of week : " .. resultDow .. " not extracted from " .. unixtime) - print(year .. "-" .. month .. "-" .. day .. " " .. hour .. ":" .. minute .. ":" .. second .. " day of week : " .. dow .. " found instead") + if not (time.year == resultYear and resultMonth == time.month and time.day == resultDay and time.hour == resultHour and time.minute == resultMinute and time.second == resultSecond and time.dow == resultDow) then + print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " day of week : " .. resultDow .. " not extracted from " .. unixtime) + print(year .. "-" .. month .. "-" .. day .. " " .. hour .. ":" .. minute .. ":" .. second .. " day of week : " .. dow .. " found instead") os.exit(1) else - print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " OK") + print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " OK") end - end EOF diff --git a/unit/testUnixtimes.lua b/unit/testUnixtimes.lua index 64fdd13..9bd5ad0 100644 --- a/unit/testUnixtimes.lua +++ b/unit/testUnixtimes.lua @@ -1,16 +1,14 @@ dofile("../timecore.lua") function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMinute, resultSecond, resultDow, unixtime) - year, month, day, hour, minute, second, dow = getUTCtime(unixtime) + time = getUTCtime(unixtime) - if not (year == resultYear and resultMonth == month and day == resultDay and hour == resultHour and minute == resultMinute and second == resultSecond and dow == resultDow) then + if not (time.year == resultYear and resultMonth == time.month and time.day == resultDay and time.hour == resultHour and time.minute == resultMinute and time.second == resultSecond and time.dow == resultDow) then print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " day of week : " .. resultDow .. " not extracted from " .. unixtime) print(year .. "-" .. month .. "-" .. day .. " " .. hour .. ":" .. minute .. ":" .. second .. " day of week : " .. dow .. " found instead") os.exit(1) else print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " OK") end - - end checkUnixTime(2016, 1, 1, 16, 27, 0, 5, 1451665620) checkUnixTime(2016, 1, 2, 4, 37, 39, 6, 1451709459)