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])$')▼
matchYear = input:match('^([0-9][0-9][0-9][0-9])$')
if (matchDay ~= nil) then
return nil, nil, tonumber(matchYear)
end▼
▲
if (matchDay ~= nil) then
Line 43 ⟶ 53:
end
--
matchMonth, matchDay, matchYear = input:match('^([A-Za-z]+) ([0-9][0-9]?), ([0-9][0-9][0-9][0-9])$')
Line 53 ⟶ 63:
end
--
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.
▲ --[[
local args = frame.args
Line 87 ⟶ 82:
local day, month, year = tryParseDate(input)
if (
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
-- 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
--local
local date = string.format("%d-%02d-%02d", year, month, day)
local s = input .. ' -> parsed to full date ' .. date
▲ end
return s
|