The function getUTCtime returns a struct'time' instead of all values seperatly

This commit is contained in:
ollo 2016-05-15 16:37:55 +02:00
parent b441e62a4d
commit 7df7c53159
3 changed files with 9 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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)