Module:Sandbox/Hellknowz/Test: Difference between revisions

Content deleted Content added
>
parse to function
Line 30:
[12] = 31
}
 
function tryParseDate(input)
 
-- First try dMy
local matchDay, matchMonth, matchYear = input:match('^([0-9][0-9]?) ([A-Za-z]+) ([0-9][0-9][0-9][0-9])$')
 
if (matchDay ~= nil) then
local month = monthIndices[matchMonth:lower()]
if (month == nil) then return input .. ' -> does not have a recognized month name'nil end
 
return { tonumber(matchDay), month, tonumber(matchYear) }
end
 
end
 
function main.hello(frame)
Line 51 ⟶ 65:
local input = args[1]
 
local day, month, year = tryParseDate(input)
local matchDay, matchMonth, matchYear = input:match('^([0-9][0-9]?) ([A-Za-z]+) ([0-9][0-9][0-9][0-9])$')
 
if (matchDay == nil) then return input .. ' -> is not a recognized pattern match' end
--return matchDay .. '-' .. matchMonth .. '-' .. matchYear
 
local month = monthIndices[matchMonth:lower()]
if (month == nil) then return input .. ' -> does not have a recognized month name' end
 
localif (day == tonumber(matchDaynil) then
if (matchDay == nil) then return input .. ' -> is not a recognized pattern match' end
local year = tonumber(matchYear)
 
if (year < 1760) then