Module:Sandbox/Subiloblee

Revision as of 06:38, 12 January 2018 by imported>Subiloblee
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Sandbox/Subiloblee/doc

local p = {} -- p stands for package

function p.dmy(frame)
	local n = 0
	local s = frame.args.text
	local txt = ""
	local sec = ""
	local word = 0
	local BA = frame.args.BA or ""
	local form = frame.args.form or "iso"
	if BA~= "" then BA = " " .. BA end
    while n<=#s do
    	n = n + 1
    	if string.match(string.sub(s,n,n),"%d")~=nil or string.match(string.sub(s,n,n),"%a")~=nil then sec = sec .. string.sub(s,n,n) else
    		word = word + 1
    		if tonumber(sec)==nil and tonumber(string.sub(sec,1,#sec-2))==nil then 
    		    if sec=="January" then if not month then month = "1" end txt = txt .. "1 <-Month<br>" end
    		    if sec=="February" then if not month then month = "2" end txt = txt .. "2 <-Month<br>" end
    		    if sec=="March" then if not month then month = "3" end txt = txt .. "3 <-Month<br>" end
    		    if sec=="April" then if not month then month = "4" end txt = txt .. "4 <-Month<br>" end
    		    if sec=="May" then if not month then month = "5" end txt = txt .. "5 <-Month<br>" end
    		    if sec=="June" then if not month then month = "6" end txt = txt .. "6 <-Month<br>" end
    		    if sec=="July" then if not month then month = "7" end txt = txt .. "7 <-Month<br>" end
    		    if sec=="August" then if not month then month = "8" end txt = txt .. "8 <-Month<br>" end
    		    if sec=="September" then if not month then month = "9" end txt = txt .. "9 <-Month<br>" end
    		    if sec=="October" then if not month then month = "10" end txt = txt .. "10 <-Month<br>" end
    		    if sec=="November" then if not month then month = "11" end txt = txt .. "11 <-Month<br>" end
    		    if sec=="December" then if not month then month = "12" end txt = txt .. "12 <-Month<br>" end
    		    if sec~="January" and sec~="February" and sec~="March" and sec~="April" and sec~="May" and sec~="June" and sec~="July" and 
    		    sec~="August" and sec~="September" and sec~="October" and sec~="November" and sec~="December" then txt = txt .. sec .. "<br>" end
    		end
		    if tonumber(sec)~=nil then 
		    	if tonumber(sec)<=31 then if not num then num = sec end txt = txt .. sec .. " <-Number<br>" end
		    	if tonumber(sec)>31 then if not yr then yr = sec end txt = txt .. sec .. " <-Year<br>" end
		    end
		    if tonumber(sec)==nil and tonumber(string.sub(sec,1,#sec-2)) ~= nil and tonumber(string.sub(sec,1,#sec-2))<=31 then 
		        if not num then num = string.sub(sec,1,#sec-2) end 
		        txt = txt .. string.sub(sec,1,#sec-2) .. " <-Number<br>"
		    end
		    if tonumber(sec)==nil and tonumber(string.sub(sec,1,#sec-2)) ~= nil and tonumber(string.sub(sec,1,#sec-2))>31 then 
		    	txt = txt .. sec .. "<br>"
		    end
		    sec = ""
    	end
    end 
    txt = txt .. sec 
    if num == "31" and month == "4" or "6" or "9" or "11" then num = 1 
    	month = month+1 end 
    if month == "2" and num > "29" then num = num - 28 
    	month = month+1 end 
  
    if yr and month and num then 
    	if form == "dmy" then if month == "1" then month = "January" end
    		if month == "2" then month = "February" end
    		if month == "3" then month = "March" end
    		if month == "4" then month = "April" end
    		if month == "5" then month = "May" end
    		if month == "6" then month = "June" end
    		if month == "7" then month = "July" end
    		if month == "8" then month = "August" end
    		if month == "9" then month = "September" end
    		if month == "10" then month = "October" end
    		if month == "11" then month = "November" end
    		if month == "12" then month = "December" end
    		txt = txt .. num .. "-" .. month .. "-" .. yr .. BA .. "<br>" end
    	if form == "mdy" then 
    		if month == "1" then month = "January" end
    		if month == "2" then month = "February" end
    		if month == "3" then month = "March" end
    		if month == "4" then month = "April" end
    		if month == "5" then month = "May" end
    		if month == "6" then month = "June" end
    		if month == "7" then month = "July" end
    		if month == "8" then month = "August" end
    		if month == "9" then month = "September" end
    		if month == "10" then month = "October" end
    		if month == "11" then month = "November" end
    		if month == "12" then month = "December" end
    		txt = txt .. month .. "-" .. num .. "-" .. yr .. BA .. "<br>" end 
    	if form == "y" then txt = txt .. yr .. BA .. "<br>" end
    	if form == "iso" then txt = txt .. yr .. "-" .. month .. "-" .. num .. BA .. "<br>" end
    	if form ~= "dmy" and form ~= "myd" and form ~= "y" and form ~= "iso" then txt = txt .. "incorrect formate<br>" end
    	else txt = txt .. "invalid date<br>" end
    return word .. " word(s)<br>" .. txt .. frame.args.text
end

return p