The function getUTCtime returns a struct'time' instead of all values seperatly
This commit is contained in:
parent
b441e62a4d
commit
7df7c53159
@ -142,7 +142,7 @@ function getUTCtime(unixtimestmp)
|
|||||||
local sec = math.floor(dayclock % 60)
|
local sec = math.floor(dayclock % 60)
|
||||||
local min = math.floor( (dayclock % 3600) / 60)
|
local min = math.floor( (dayclock % 3600) / 60)
|
||||||
local hour = math.floor(dayclock / 3600)
|
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))
|
while (dayno >= yearsize(year))
|
||||||
do
|
do
|
||||||
@ -158,7 +158,7 @@ function getUTCtime(unixtimestmp)
|
|||||||
end
|
end
|
||||||
mday = dayno + 1
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ echo "Generating $OUTPUT ..."
|
|||||||
cat << EOF > $OUTPUT
|
cat << EOF > $OUTPUT
|
||||||
dofile("../timecore.lua")
|
dofile("../timecore.lua")
|
||||||
function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMinute, resultSecond, resultDow, unixtime)
|
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(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")
|
print(year .. "-" .. month .. "-" .. day .. " " .. hour .. ":" .. minute .. ":" .. second .. " day of week : " .. dow .. " found instead")
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
@ -33,7 +33,6 @@ function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMin
|
|||||||
print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " OK")
|
print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " OK")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
dofile("../timecore.lua")
|
dofile("../timecore.lua")
|
||||||
function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMinute, resultSecond, resultDow, unixtime)
|
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(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")
|
print(year .. "-" .. month .. "-" .. day .. " " .. hour .. ":" .. minute .. ":" .. second .. " day of week : " .. dow .. " found instead")
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
else
|
else
|
||||||
print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " OK")
|
print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " OK")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
checkUnixTime(2016, 1, 1, 16, 27, 0, 5, 1451665620)
|
checkUnixTime(2016, 1, 1, 16, 27, 0, 5, 1451665620)
|
||||||
checkUnixTime(2016, 1, 2, 4, 37, 39, 6, 1451709459)
|
checkUnixTime(2016, 1, 2, 4, 37, 39, 6, 1451709459)
|
||||||
|
Loading…
Reference in New Issue
Block a user