local months =
local allowedFormats =
local formatNames =
local christ =
local circa =
local p =
local glueString = function(one, two, three, between) return one .. between .. two .. between .. threeend
local identifyDate = function(dateString) local day, month, year, frmt = nil for index, val in ipairs(months) do -- Checks for months in the string through the first 3 chars of each month if string.match(string.lower(dateString), string.lower(string.sub(months[index], 1, 3))) then month = val end end for _, val in ipairs(formatNames) do -- If there is a pattern in the text it gets whatever data belongs to that. if string.match(dateString, allowedFormats[val]) then datePart = string.sub(dateString, string.find(dateString, allowedFormats[val])) if string.match(datePart, "%a+") and not (month
"ds" then frmt = "dmy" datePart = string.gsub(datePart,"%a%a", "", 1) end if val
"dd" then frmt = "dmy" day = string.match(datePart, "%d+") datePart = string.gsub(dateString, allowedFormats[val], "") year = string.match(datePart, "%d+") else if val
nil) then frmt = "plain" day = string.match(dateString, "(%d+) %a+") elseif val
"iso" then frmt = "iso" year, monthNum, day = string.match(datePart, allowedFormats[val]) month = months[tonumber(monthNum)] elseif val
nil) then return end end end end return end
local transformDate = function(text, dateData, dateFormat) if ((dateData["day"]
nil) and (dateData["year"]
nil then return "Invalid entry" end if dateFormat
nil)) and (not (dateData["month"]
nil)) then if tonumber(dateData["day"]) < 10 then dateData["day"] = "0" .. dateData["day"] end if dateFormat
"mdy" then returnString = dateData["month"] .. " " .. dateData["day"] .. ", " .. dateData["year"] elseif dateFormat
dateData["month"] then month = index end end local monthString = tostring(month) if month < 10 then monthString = "0" .. monthString end returnString = glueString(dateData["year"], monthString, dateData["day"], "-") end end if (not (dateData["month"]
nil)) and (dateFormat
"year") and (not (dateData["year"]
"plain" then returnString = glueString(dateData["day"], dateData["month"], "", " ") end if returnString
p.getDate = function(frame) local text = frame.args.date local format = frame.args.format or "" -- identifyDate gets the day, month, year and standard format of the text local dateData = identifyDate(text) -- transformDate transforms to the right type of date local dateString = transformDate(text, dateData, string.lower(format))
return dateStringend
return p