Jump to content

Module:Citation/CS1/Date validation and Module:Citation/CS1/Date validation/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
sync from sandbox;
 
No edit summary
 
Line 1: Line 1:
--[[
History of changes since last sync: 2024-08-17


]]


--[[--------------------------< F O R W A R D D E C L A R A T I O N S >--------------------------------------
--[[--------------------------< F O R W A R D D E C L A R A T I O N S >--------------------------------------
]]
]]
Line 177: Line 184:


Special case for |pmc-embargo-date=: years more than two years in the future are not acceptable
Special case for |pmc-embargo-date=: years more than two years in the future are not acceptable

This function also catches zero-padded years which are proscribed by MOS:BADDATE


]]
]]


local function is_valid_year (year, param)
local function is_valid_year (year, param)
if mw.ustring.match (year, '^0') then -- first digit of <year> must not be zero
return false;
end

if not is_set (year_limit) then
if not is_set (year_limit) then
year_limit = tonumber(os.date("%Y"))+1; -- global variable so we only have to fetch it once
year_limit = tonumber(os.date("%Y"))+1; -- global variable so we only have to fetch it once
Line 808: Line 821:
end
end


elseif mw.ustring.match(date_string, "%d%d%d%d[%-–]%d%d") then -- YYYY-YY date ranges
elseif mw.ustring.match(date_string, "^%d%d%d%d[%-–]%d%d$") then -- YYYY-YY date ranges; not to be confused with first part of YYYY-MM-DD
local century;
local century;
date1, century, date2 = mw.ustring.match(date_string, "((%d%d)%d%d)[%-–]+(%d%d)");
date1, century, date2 = mw.ustring.match(date_string, "((%d%d)%d%d)[%-–]+(%d%d)");