Module:Sandbox/Jikat2/datehanding: Difference between revisions
< Module:Sandbox | Jikat2
imported>Bumbleglue123 No edit summary |
(No difference)
|
Latest revision as of 19:24, 28 December 2020
Documentation for this module may be created at Module:Sandbox/Jikat2/datehanding/doc
--Google Code-in 2017, Create a general date-handling function, made by Om Desai
local 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 <br>"
if type == "dmy" then
msg = day.." "..month.." "..year.."<br>"
if year =="" or month=="" or day=="" then
msg = "Invalid date <br>"
end
elseif type == "y" then
msg = year.."<br>"
if year =="" then
msg = "Invalid date <br>"
end
elseif type == "mdy" then
msg = month.." "..day..", "..year.."<br>"
if year =="" or month=="" or day =="" then
msg = "Invalid date <br>"
end
elseif type == "iso" then
if tonumber(day) < 10 then day = "0"..day
end
if month2 < 10 then month2 = "0"..month2
end
msg = year.."-"..month2.."-"..day.."<br>"
if year =="" or month2 =="" or day =="" then
msg = "Invalid date <br>"
end
end
return msg
end
return p