Module:Sandbox/Hellknowz/Test: Difference between revisions

Content deleted Content added
m not for year
just year format
Line 33:
function tryParseDate(input)
 
local matchDay, matchMonth, matchYear
-- First try dMy
 
local matchDay, matchMonth, matchYear = input:match('^([0-9][0-9]?) ([A-Za-z]+) ([0-9][0-9][0-9][0-9])$')
--[[ Try Y
 
matchYear = input:match('^([0-9][0-9][0-9][0-9])$')
 
if (matchDay ~= nil) then
return nil, nil, tonumber(matchYear)
end
 
-- First tryTry 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
Line 43 ⟶ 53:
end
 
-- Then tryTry Mdy
matchMonth, matchDay, matchYear = input:match('^([A-Za-z]+) ([0-9][0-9]?), ([0-9][0-9][0-9][0-9])$')
 
Line 53 ⟶ 63:
end
 
-- Finally tryTry ymd
matchYear, matchMonth, matchDay = input:match('^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$')
 
Line 65 ⟶ 75:
end
 
function main.helloparseDate(frame)
 
--[[
local args = frame.args
local arg1 = args[1]
local arg2 = args[2]
local arg3 = args[3]
local argNamed = args['named']
 
local s = 'Params: '
if (arg1 ~= nil) then s = s .. '1 = ' .. arg1 end
if (arg2 ~= nil) then s = s .. '; 2 = ' .. arg2 end
if (arg3 ~= nil) then s = s .. '; 3 = ' .. arg3 end
if (argNamed ~= nil) then s = s .. '; named = ' .. argNamed end
return s
]]
 
local args = frame.args
Line 87 ⟶ 82:
local day, month, year = tryParseDate(input)
 
if (dayyear == nil) then
return input .. ' -> is not a recognized pattern match' end
 
if (year ~= nil and month == nil) then
 
-- year only
 
if (year < 1760) then -- TODO: make this a validateDate or something function
return input .. ' -> year is too early (calendar discrepancy)' end
 
if (year > 2100) then
return input .. ' -> year is too far into future' end
 
return input .. ' -> parsed to year-only date ' .. year
 
]]end
 
-- The rest means year isn't nil and month isn't nil, so full date (case for month+year pending)
 
if (year < 1760) then
Line 115 ⟶ 126:
end
 
local --parent =stuff frame:getParent(infobox itself)
--local parentArgsparent = parent.argsframe:getParent()
--local extraparentArgs = parentArgs[1]parent.args
 
local date = string.format("%d-%02d-%02d", year, month, day)
 
local s = input .. ' -> parsed to full date ' .. date; -- won't add 0s
 
if-- (extra ~=stuff nil)for thens
s = s .. ' also: ' .. extra
end
 
return s