local p =
p.date_formatting = function(frame) -- Unpacking date local date = frame.args.date or "Invalid entry" local format = frame.args.format or "" months = local year, day = string.match(date, "%D*(%d*)%D*(%d*)%D*") local ans = "" if year ~= "" and day ~= "" then if tonumber(day) > 31 then if tonumber(year) <= 31 then day, year = year, day else ans = "Invalid entry" end end end local k = nil local month = "" for i = 1, #months do k = string.find(date, months[i]) if k
nil then k = string.find(date, string.lower(string.sub(months[i], 1, 1)) .. string.sub(months[i], 2, 3)) end if k
"" and string.find(date, "[-,/]") ~= nil then day, month, year = string.match(date, "(%d+)[-, /](%d+)[-, /](%d+)") local a, b, c = day, month, year if tonumber(a) > 31 then year = a elseif tonumber(b) > 31 then year = b elseif tonumber(c) > 31 then year = c end if tonumber(a) > 12 and year ~= nil and year ~= a then day = a elseif tonumber(b) > 12 and year ~= nil and year ~= b then day = b elseif tonumber(c) > 12 and year ~= nil and year ~= c then day = c end if (year
b) or (year
a) then month = months[tonumber(c)] elseif (year
c) or (year
b) then month = months[a] elseif (year
c) or (year
a) then month = months[tonumber(b)] else day, month, year = a, months[tonumber(b)], c end end if month
"" and year
2 then if year % 400
0) then right[i] = 29 else right[i] = 28 end elseif i <= 7 then right[i] = 30 + i % 2 else right[i] = 31 - i % 2 end end if right[tonumber(months[month])] ~= nil and day ~= "" then if right[tonumber(months[month])] < tonumber(day) then ans = "Invalid entry" end elseif month
"" then format = format_oldend if ans ~= "Invalid entry" then if format
"dmy" then u_date = day .. " " .. month .. " " .. year elseif format
"year" then u_date = year elseif format