Jump to content

Module:Citation/CS1/Date validation: Difference between revisions

Synch from sandbox;
m>Trappist the monk
(Synch from sandbox;)
m>Trappist the monk
(Synch from sandbox;)
Line 170: Line 170:
month2 = get_month_number (month2);
month2 = get_month_number (month2);


elseif date_string:match("^%a+ +[1-9]%d? – %a+ +[1-9]%d?, +[1-9]%d%d%d%a?$") then -- month initial month-day-range: month day – month day, year;  uses spaced endash
elseif date_string:match("^%a+ +[1-9]%d? – %a+ +[1-9]%d?, +[1-9]%d%d%d?%a?$") then -- month initial month-day-range: month day – month day, year;  uses spaced endash
month, day, month2, day2, anchor_year, year=date_string:match("(%a+) +(%d%d?) – (%a+) +(%d%d?), +((%d%d%d%d)%a?)");
month, day, month2, day2, anchor_year, year=date_string:match("(%a+) +(%d%d?) – (%a+) +(%d%d?), +((%d%d%d%d)%a?)");
if (not is_valid_month_season_range(month, month2)) or not is_valid_year(year) then return false; end
if (not is_valid_month_season_range(month, month2)) or not is_valid_year(year) then return false; end
month = get_month_number (month);
month = get_month_number (month);
month2 = get_month_number (month2);
month2 = get_month_number (month2);
elseif date_string:match("^[1-9]%d? +%a+ +[1-9]%d%d%d – [1-9]%d? +%a+ +[1-9]%d%d%d%a?$") then -- day initial month-day-year-range: day month year - day month year; uses spaced endash
day, month, year, day2, month2, anchor_year, year2=date_string:match("(%d%d?) +(%a+) +(%d%d%d%d?) – (%d%d?) +(%a+) +((%d%d%d%d?)%a?)");
if tonumber(year2) <= tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later
if not is_valid_year(year2) then return false; end -- year2 no more than one year in the future
month = get_month_number (month);
month2 = get_month_number (month2);
elseif date_string:match("^%a+ +[1-9]%d?, +[1-9]%d%d%d – %a+ +[1-9]%d?, +[1-9]%d%d%d%a?$") then -- month initial month-day-year-range: month day, year – month day, year;  uses spaced endash
month, day, year, month2, day2, anchor_year, year2=date_string:match("(%a+) +(%d%d?), +(%d%d%d%d) – (%a+) +(%d%d?), +((%d%d%d%d)%a?)");
if tonumber(year2) <= tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later
if not is_valid_year(year2) then return false; end -- year2 no more than one year in the future
month = get_month_number (month);
month2 = get_month_number (month2);
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;
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
year2 = century..year2; -- add the century to year2 for comparisons
if 1 ~= tonumber(year2) - tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later
if not is_valid_year(year2) then return false; end -- no year farther in the future than next year


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
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
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.