Refactoring the summer time function needs an struct as parameter instead of each time variable on its own

This commit is contained in:
ollo
2016-05-15 17:27:24 +02:00
parent 7df7c53159
commit 591f0f496a
4 changed files with 50 additions and 17 deletions

View File

@@ -9,7 +9,17 @@ WINTERTIME_OFFSET=1
-- so resultingHourDiff is 1 in wintertime
-- and 2 in summertime
function checkTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn,dowIn, resultingHourDiff)
local summerTime = isSummerTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn, dowIn)
-- Generate a time struct from the given parameter
time = {}
time.year = yearIn
time.month = monthIn
time.day = dayIn
time.hour = hourIn
time.minute = minutesIn
time.second = secondsIn
time.dow = dowIn
-- the test itself
local summerTime = isSummerTime(time)
if ((resultingHourDiff == SUMMERTIME_OFFSET and not (summerTime == true)) or (resultingHourDiff == WINTERTIME_OFFSET and not (summerTime == false))) then
print(yearIn .. "-" .. string.format("%0.2d", monthIn) .. "-" .. string.format("%0.2d", dayIn) .. " " .. string.format("%0.2d", hourIn) .. ":" .. string.format("%0.2d", minutesIn) .. ":" .. string.format("%0.2d", secondsIn) .. " (dow:" .. dowIn .. ") was not GMT+" .. resultingHourDiff .. " ( summer time was " .. tostring(summerTime) .. ")" )
os.exit(1)

View File

@@ -9,7 +9,17 @@ WINTERTIME_OFFSET=1
-- so resultingHourDiff is 1 in wintertime
-- and 2 in summertime
function checkTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn,dowIn, resultingHourDiff)
local summerTime = isSummerTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn, dowIn)
-- Generate a time struct from the given parameter
time = {}
time.year = yearIn
time.month = monthIn
time.day = dayIn
time.hour = hourIn
time.minute = minutesIn
time.second = secondsIn
time.dow = dowIn
-- the test itself
local summerTime = isSummerTime(time)
if ((resultingHourDiff == SUMMERTIME_OFFSET and not (summerTime == true)) or (resultingHourDiff == WINTERTIME_OFFSET and not (summerTime == false))) then
print(yearIn .. "-" .. string.format("%0.2d", monthIn) .. "-" .. string.format("%0.2d", dayIn) .. " " .. string.format("%0.2d", hourIn) .. ":" .. string.format("%0.2d", minutesIn) .. ":" .. string.format("%0.2d", secondsIn) .. " (dow:" .. dowIn .. ") was not GMT+" .. resultingHourDiff .. " ( summer time was " .. tostring(summerTime) .. ")" )
os.exit(1)
@@ -17,6 +27,7 @@ function checkTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn,dowIn, r
print(yearIn .. "-" .. string.format("%0.2d", monthIn) .. "-" .. string.format("%0.2d", dayIn) .. " " .. string.format("%0.2d", hourIn) .. ":" .. string.format("%0.2d", minutesIn) .. ":" .. string.format("%0.2d", secondsIn) .. " summertime is " .. tostring(summerTime) .. " (GMT+" .. resultingHourDiff .. ")" )
end
end
checkTime(2016, 3, 1, 0, 14, 34, 2, 1)
checkTime(2016, 3, 1, 1, 53, 5, 2, 1)
checkTime(2016, 3, 1, 2, 19, 51, 2, 1)

View File

@@ -9,7 +9,17 @@ WINTERTIME_OFFSET=1
-- so resultingHourDiff is 1 in wintertime
-- and 2 in summertime
function checkTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn,dowIn, resultingHourDiff)
local summerTime = isSummerTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn, dowIn)
-- Generate a time struct from the given parameter
time = {}
time.year = yearIn
time.month = monthIn
time.day = dayIn
time.hour = hourIn
time.minute = minutesIn
time.second = secondsIn
time.dow = dowIn
-- the test itself
local summerTime = isSummerTime(time)
if ((resultingHourDiff == SUMMERTIME_OFFSET and not (summerTime == true)) or (resultingHourDiff == WINTERTIME_OFFSET and not (summerTime == false))) then
print(yearIn .. "-" .. string.format("%0.2d", monthIn) .. "-" .. string.format("%0.2d", dayIn) .. " " .. string.format("%0.2d", hourIn) .. ":" .. string.format("%0.2d", minutesIn) .. ":" .. string.format("%0.2d", secondsIn) .. " (dow:" .. dowIn .. ") was not GMT+" .. resultingHourDiff .. " ( summer time was " .. tostring(summerTime) .. ")" )
os.exit(1)
@@ -17,3 +27,4 @@ function checkTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn,dowIn, r
print(yearIn .. "-" .. string.format("%0.2d", monthIn) .. "-" .. string.format("%0.2d", dayIn) .. " " .. string.format("%0.2d", hourIn) .. ":" .. string.format("%0.2d", minutesIn) .. ":" .. string.format("%0.2d", secondsIn) .. " summertime is " .. tostring(summerTime) .. " (GMT+" .. resultingHourDiff .. ")" )
end
end