Module:Sandbox/Hellknowz/Test: Difference between revisions

Content deleted Content added
add y-y case
add printing of ranges
Line 81:
 
-- This will first verify that we have a valid date and time and then output an ISO datetime string
function checkAndOutput(year, month, day, hour, minute, second, year2, month2, day2, hour2, minute2, second2)
 
local s
 
if (year and not checkIfYearValid(year)) then return nil; end
Line 89 ⟶ 91:
if (minute and not checkIfMinuteValid(minute)) then return nil; end
if (second and not checkIfSecondValid(second)) then return nil; end
 
if (year2 and not checkIfYearValid(year2)) then return nil; end
if (month2 and not checkIfMonthValid(month2)) then return nil; end
if (day2 and not checkIfDayValid(day2, mont2, year2)) then return nil; end
if (hour2 and not checkIfHourValid(hour2)) then return nil; end
if (minute2 and not checkIfMinuteValid(minute2)) then return nil; end
if (second2 and not checkIfSecondValid(second2)) then return nil; end
 
-- time only
if (second and not year) then returns = string.format('%02d:%02d:%02d', hour, minute, second)
elseif (minute and not year) then returns = string.format('%02d:%02d', hour, minute)
elseif (hour and not year) then returns = string.format('%02d', hour)
 
-- date and time
elseif (second) then returns = string.format('%d-%02d-%02d %02d:%02d:%02d', year, month, day, hour, minute, second)
elseif (minute) then returns = string.format('%d-%02d-%02d %02d:%02d', year, month, day, hour, minute)
elseif (hour) then returns = string.format('%d-%02d-%02d %02d', year, month, day, hour)
 
-- date only
elseif (day) then returns = string.format('%d-%02d-%02d', year, month, day)
elseif (month) then returns = string.format('%d-%02d', year, month)
elseif (year) then returns = string.format('%d', year)
end
 
else return nil end -- why are we here again?
-- time only
if (second2 and not year2) then s = s .. '; ' .. string.format('%02d:%02d:%02d', hour2, minute2, second2)
elseif (minute2 and not year2) then s = s .. '; ' .. string.format('%02d:%02d', hour2, minute2)
elseif (hour2 and not year2) then s = s .. '; ' .. string.format('%02d', hour2)
 
-- date and time
elseif (second2) then s = s .. '; ' .. string.format('%d-%02d-%02d %02d:%02d:%02d', year2, month2, day2, hour2, minute2, second2)
elseif (minute2) then s = s .. '; ' .. string.format('%d-%02d-%02d %02d:%02d', year2, month2, day2, hour2, minute2)
elseif (hour2) then s = s .. '; ' .. string.format('%d-%02d-%02d %02d', year2, month2, day2, hour2)
 
-- date only
elseif (day2) then s = s .. '; ' .. string.format('%d-%02d-%02d', year2, month2, day2)
elseif (month2) then s = s .. '; ' .. string.format('%d-%02d', year2, month2)
elseif (year2) then s = s .. '; ' .. string.format('%d', year2)
end
 
return s
 
end