local p = function p.Dates (frame) local input = mw.text.trim(frame.args[1]) or 0 if input ~= 0 then input = " " .. input .. " " end local xformat = frame.args.format or 0 local xsuffix = frame.args.suffix or 0 local sSuffix = 0 local valid if input ~= 0 then valid = true else valid = false end local mnths = local yrs = local dts = local i = 1 local j = 1 local k = 1 local valid = true local leapYear = false local txt = "" local nums = local m = 1 local Months = for data in string.gmatch (input, "%w+") do data = " " .. data .. " " if data:find ("%s%d%a%a%s") then if tonumber(string.sub(data, 2, 2)) < 32 then dts[i] = tonumber(string.sub(data, 2, 2)) i = i + 1 end end if data:find ("%s%d%d%a%a%s") then if tonumber(string.sub(data, 2, 3)) < 32 then dts[i] = tonumber(string.sub(data, 2, 3)) i = i + 1 end end end if input:find ("%s%d%d%d%d%s") then yrs[k] = tonumber(string.sub(input, input:find ("%s%d%d%d%d%s")+1, input:find ("%s%d%d%d%d%s")+4)) k = k + 1 end for l = 1, 12 do if input:find(string.sub(Months[l], 1, 3)) or input:find(string.lower(string.sub(Months[l], 1, 3))) then mnths[j] = l j = j + 1 end end for data in string.gmatch (input, "%d+") do data = tonumber(data) if data > 31 then yrs[k] = data k = k + 1 else if data > 12 then if #dts
0 then dts [i] = nums[l] i = i + 1 elseif #mnths
0 then yrs[k] = nums[l] k = k + 1 end end end local date = dts[1] or 0 local month = mnths[1] or 0 local year = yrs[1] or 0 if xformat
0 then xformat = "year" end if input:find ("uncertain") or input:find("around") or input:find("sometime") then if input:find ("uncertain who") then sSuffix = 2 else sSuffix = 1 end end if xsuffix
0 -- xsuffix ~= 0 and (date
0) then xformat = "year" if date ~= 0 then year = date date = 0 else -- month ~= 0 year = month month = 0 end end if date ~= 0 and year
0 then valid = false end if month
6 or month
11 and date > 30 then valid = false end if year % 400
0) then leapYear = true end if month
true then if date > 29 then valid = false end elseif date > 28 then valid = false end end if date
0 and year
0 then for l = 1, 12 do if input:find(string.sub(Months[l], 1, 3)) or input:find(string.lower(string.sub(Months[l], 1, 3))) then valid = true break else valid = false end end end if valid
"iso" then if year ~= 0 then txt = txt .. year end if month ~= 0 then if month > 10 then txt = txt .. "-" .. month else month = "0" .. month txt = txt .. "-" .. month end end if date ~= 0 then if date > 10 then txt = txt .. "-" .. date else date = "0" .. date txt = txt .. "-" .. date end end elseif xformat
"mdy" then if month ~= 0 then txt = txt .. Months[month] end if date ~= 0 then txt = txt .. " " .. date end if year ~= 0 then txt = txt .. ", " .. year end elseif xformat
1 then txt = "c. " .. txt elseif sSuffix