Module:Sandbox/Boboquack/Dates: Difference between revisions

Content deleted Content added
Boboquack (talk | contribs)
No edit summary
Boboquack (talk | contribs)
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 72:
--fourth try: parse as month,year-like format
local num8,mon3=nil
for i=1,12 do
num8=string.match(indate,monthregex[i].."%D+(%d+)")
if num8~=nil then
mon3=i
break
end
end
if p.valid(nil,mon3,num8) then month,year,inform=mon3,num8,"month and year" else
if mon3~=nil and num8~=nil then return "Invalid entry" end
--(the unmentioned case: day and month)
--fifth try: parse as year
local num9,mon4=nil
for i=1,12 do
num9=string.match(indate,"(%d+)%D+"..monthregex[i])
if num9~=nil then
mon4=i
break
end
end
if mon4~=nil and p.valid(num9,mon4,2016) then day,month,inform=num9,mon4,"day and month" else
if p.valid(nil,mon4,num9) then month,year,inform=mon4,num9,"month and year" else
if mon4~=nil and num9~=nil then return "Invalid entry" end
--fifth try: parse as year
end end end end end end end end end end-- ends from all the elses
if string.match(indate,"(%d+)%D*[^% %d]%D*(%d+)") then return "Invalid entry" end
local num0=string.match("A"..indate,".*%D(%d+)")
if p.valid(nil,nil,num0) then year,inform=num0,"year" else
return "Invalid entry"
end end end end end end end end end end end end end end -- ends from all the elses
--get era
if string.find(indate,"BCBCE") then era=" BCBCE"
elseif string.find(indate,"BCEBC") then era=" BCEBC"
elseif string.find(indate,"CE") then era=" CE"
elseif string.find(indate,"AD") then era=" AD"
Line 85 ⟶ 111:
--get uncertainty
if string.match(indate,"around") then circa="circa " elseif
elseif string.match(indate,"uncertain") then circa="circa " elseif
elseif string.match(indate,"about") then circa="circa " elseif
elseif string.match(indate,"approx") then circa="circa " elseif
elseif string.match(indate,"circa") then circa="circa " elseif
elseif string.match(indate,"ca%.") then circa="circa " else
else circa="" end
--convert output date to input format -> outdate
local outform=frame.args.format or inform or "whoops"
day,month,year=tonumber(day),tonumber(month),tonumber(year)
outdate = ""
if outform=="iso" then
Line 107 ⟶ 134:
end
if outform=="mdy" then
outdate = month..month
outdate = day..day
outdate = year..year
outdate = era..era
outdate = monthnames[month]..day..", "..year..era
end
if outform=="month and year" then
outdate = monthnames[month]..year..era
end
if outform=="day and month" then
outdate = monthday.." "..monthnames[month]
end
if outform=="year" then