Content deleted Content added
add other 3 combos |
validations |
||
Line 140:
return nil
function checkIfDayValid(day, month)
-- First check that the month can have at least this many days
if (day > monthDays[month]) then return false end▼
-- February leap year check▼
if (month == 2) then▼
if (day == 29 and not ((year % 4 == 0) and (year % 100 ~= 0) or (year % 400 == 0))) then▼
end▼
end
return true
end
function checkIfMonthValid(year)
return month ~= 0 and month <= 12 -- <0 never happens with [0-9] pattern
end
function checkIfYearValid(year)
return year >= 1583 -- up to 9999
end
function checkIfYearValid(hour)
return hour < 24 -- <0 never happens with [0-9] pattern
end
function checkIfMinuteValid(minute)
return minute < 60 -- <0 never happens with [0-9] pattern
end
function checkIfSecondValid(second)
return second < 60 -- <0 never happens with [0-9] pattern
end
Line 146 ⟶ 180:
local input = frame.args[1]
-- First, try to get a date and time
local day, month, year, hour, minute, second = tryParseDateTime(input)
-- If we have a second, we have all 6
if (second) then
if (not checkIfYearValid(year) or not checkIfMonthValid(month) or not checkIfDayValid(day, month) or not checkIfHourValid(hour) or not checkIfMinuteValid(minute) or not checkIfSecondValid(second)) then return nil end
▲ if (hour >= 24) then return nil end
return string.format("%d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second)
Line 158 ⟶ 192:
end
-- Second, try to get just the date
day, month, year = tryParseDateOnly(input)
if (not year) then return nil
if (year and not month) then
Line 167 ⟶ 202:
-- year only
if (not checkIfYearValid(year
return year
Line 181 ⟶ 212:
-- month and year only
if (
-- Month always comes from month name pattern string, so always valid, can skip the check▼
▲ -- Month comes from month name string, so always valid, can skip the check
return string.format("%d-%02d", year, month)
Line 193 ⟶ 219:
end
if (not checkIfYearValid(year) or not checkIfMonthValid(month) or not checkIfDayValid(day, month) or not checkIfHourValid(hour)) then return nil end
▲ if (day > monthDays[month]) then
▲ -- February leap year check
▲ if (month == 2) then
▲ if (day == 29 and not ((year % 4 == 0) and (year % 100 ~= 0) or (year % 400 == 0))) then
▲ end
▲ end
--parent stuff (infobox itself)
|