Module:Sandbox/Jikat2/datehanding explained

--Google Code-in 2017, Create a general date-handling function, made by Om Desailocal p = p.datehandle = function(frame)local text = frame.args.text or ""local type = frame.args.type or "dmy"local year = ""local day = ""local month = ""local month2 = ""for i in string.gmatch(text, "%w+") do local object, object2 = string.find(i, "%d+") if object then i = string.sub(i, object, object2) end if tonumber(i) then if tonumber(i) < 31 then day = i else year = i end end if string.find("A.D B.C BCE CE",i,1,true) then year = year.." "..i end s = string.sub(i,1,3) local monthcheck = string.find("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",s,1,true) if monthcheck then month = i month2 = (monthcheck + 3)/4 end end

local msg = "Invalid Date
"if type

"dmy" then msg = day.." "..month.." "..year.."
" if year

"" or month

"" or day

"" then msg = "Invalid date
" endelseif type

"y" then msg = year.."
" if year

"" then msg = "Invalid date
" endelseif type

"mdy" then msg = month.." "..day..", "..year.."
" if year

"" or month

"" or day

"" then msg = "Invalid date
" endelseif type

"iso" then if tonumber(day) < 10 then day = "0"..day end if month2 < 10 then month2 = "0"..month2 end msg = year.."-"..month2.."-"..day.."
" if year

"" or month2

"" or day

"" then msg = "Invalid date
" endend

return msgendreturn p