Zum Inhalt springen

Modul:TwitterSnowflake: Unterschied zwischen den Versionen

Add datecheck function, duplicating Template:TwitterSnowflake/datecheck, for WP:PEIS reasons.
Keine Bearbeitungszusammenfassung
(Add datecheck function, duplicating Template:TwitterSnowflake/datecheck, for WP:PEIS reasons.)
Zeile 38: Zeile 38:
local date = Date(frame.args.date) or 0 -- if we error here, then an input of no date causes an error, which is contrary to the entire way {{TwitterSnowflake/datecheck}} works
local date = Date(frame.args.date) or 0 -- if we error here, then an input of no date causes an error, which is contrary to the entire way {{TwitterSnowflake/datecheck}} works
return date - twitterdate
return date - twitterdate
end
local function abs_datediff(x)
if type(x) == 'number' then return math.abs(x) end
return math.abs(x.age_days)
end
function p.datecheck(frame)
local args = frame.args
if not (args.date and args.id_str) then
error('Must define date and id_str, even if they are blank.')
end
local errors = {
args.error1 or 'Date mismatch of two or more days',
args.error2 or 'No date, and posted before November 4, 2010',
args.error3 or 'Invalid id_str'
}
if not args.date:match('^%s*$') then -- #if:{{{date|}}}
local testResult = p.getDate{ args = { date = args.date, id_str = args.id_str }}
if testResult == -2 then return errors[3] end
if abs_datediff(testResult) > 1 then return errors[1] end
elseif not args.id_str:match('^%s*$') then
local testResult = p.getDate{ args = { id_str = args.id_str }}
if testResult == -1 then return errors[2] end
if testResult == -2 then return errors[3] end
end
end
end


return p
return p
Anonymer Benutzer