Module:Citation/CS1/Date validation and Module:Citation/CS1/Date validation/sandbox: Difference between pages
(Difference between pages)
Jump to navigation
Jump to search
m (1 revision imported) |
m (1 revision) |
||
Line 1: | Line 1: | ||
--[[ | |||
History of changes since last sync: 2014-03-30 | |||
2014-04-06: Added code to allow "Winter YYYY–YY"; sequential years separated with unspaced endash; | |||
2014-04-24: Added whole date range validation for dmy - dmy and mdy - mdy formats; | |||
]] | |||
local p = {} | local p = {} | ||
Line 190: | Line 197: | ||
month2 = get_month_number (month2); | month2 = get_month_number (month2); | ||
elseif date_string:match("^ | elseif date_string:match("^Winter +[1-9]%d%d%d–%d%d%a?$") then -- special case Winter year-year (YYYY-YY); year separated with unspaced endash | ||
local century; | local century; | ||
year, century, anchor_year, year2=date_string:match(" | year, century, anchor_year, year2=date_string:match("Winter +((%d%d)%d%d)–((%d%d)%a?)"); | ||
anchor_year=year..'–'..anchor_year; -- assemble anchor_year from both years | anchor_year=year..'–'..anchor_year; -- assemble anchor_year from both years | ||
year2 = century..year2; -- add the century to year2 for comparisons | year2 = century..year2; -- add the century to year2 for comparisons | ||
Line 199: | Line 205: | ||
if not is_valid_year(year2) then return false; end -- no year farther in the future than next year | if not is_valid_year(year2) then return false; end -- no year farther in the future than next year | ||
elseif date_string:match("^ | elseif date_string:match("^Winter +[1-9]%d%d%d–[1-9]%d%d%d%a?$") then -- special case Winter year-year; year separated with unspaced endash | ||
year, anchor_year, year2=date_string:match("Winter +(%d%d%d%d)–((%d%d%d%d)%a?)"); | |||
year, anchor_year, year2=date_string:match(" | |||
anchor_year=year..'–'..anchor_year; -- assemble anchor_year from both years | anchor_year=year..'–'..anchor_year; -- assemble anchor_year from both years | ||
if 1 ~= tonumber(year2) - tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later | if 1 ~= tonumber(year2) - tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later |