మాడ్యూల్:Citation/CS1/Date validation: కూర్పుల మధ్య తేడాలు

Content deleted Content added
embargo date bug fix;
Synch from sandbox;
పంక్తి 72:
returns true and date value if that value has proper dmy, mdy, ymd format.
 
returns false and 9999 (embargoed forever) when date value is not proper format; assumes that when |embargo= is set, the editor
set, the editor intended to embargo a pmc but |embargo= does not hold a single date.
 
]]
పంక్తి 374:
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
elseif date_string:mw.ustring.match(date_string, "^%a+ +[1-9]%d?[%-][1-9]%d?, +[1-9]%d%d%d%a?$") then -- month-initial day range: month day–day, year; days are separated by endash
month, day, day2, anchor_year, year=stringmw.ustring.match(date_string, "(%a+) +(%d%d?)[%-](%d%d?), +((%d%d%d%d)%a?)");
if tonumber(day) >= tonumber(day2) then return false; end -- date range order is left to right: earlier to later; dates may not be the same;
month = get_month_number (month);
పంక్తి 387:
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
 
elseif date_string:mw.ustring.match(date_string, "^[1-9]%d?[%-][1-9]%d? +%a+ +[1-9]%d%d%d%a?$") then -- day-range-initial: day–day month year; days are separated by endash
day, day2, month, anchor_year, year=stringmw.ustring.match(date_string, "(%d%d?)[%-](%d%d?) +(%a+) +((%d%d%d%d)%a?)");
if tonumber(day) >= tonumber(day2) then return false; end -- date range order is left to right: earlier to later; dates may not be the same;
month = get_month_number (month);
పంక్తి 395:
year2=year;
 
elseif date_string:mw.ustring.match(date_string, "^[1-9]%d? +%a+ [%-] [1-9]%d? +%a+ +[1-9]%d%d%d%a?$") then -- day initial month-day-range: day month - day month year; uses spaced endash
day, month, day2, month2, anchor_year, year=date_string:mw.ustring.match(date_string, "(%d%d?) +(%a+) [%-] (%d%d?) +(%a+) +((%d%d%d%d)%a?)");
if (not is_valid_month_season_range(month, month2)) or not is_valid_year(year) then return false; end -- date range order is left to right: earlier to later;
month = get_month_number (month); -- for metadata
పంక్తి 402:
year2=year;
 
elseif date_string:mw.ustring.match(date_string, "^%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:mw.ustring.match(date_string, "(%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
month = get_month_number (month); -- for metadata
పంక్తి 409:
year2=year;
 
elseif date_string:mw.ustring.match(date_string, "^[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:mw.ustring.match(date_string, "(%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) or not is_valid_month_range_style(month, month2) then return false; end -- year2 no more than one year in the future; months same style
పంక్తి 416:
month2 = get_month_number (month2);
 
elseif date_string:mw.ustring.match(date_string, "^%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:mw.ustring.match(date_string, "(%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) or not is_valid_month_range_style(month, month2) then return false; end -- year2 no more than one year in the future; months same style
పంక్తి 423:
month2 = get_month_number (month2);
 
elseif date_string:mw.ustring.match(date_string, "^%a+ +[1-9]%d%d%d–d[%-–]%d%d%a?$") then -- special case Winter/Summer year-year (YYYY-YY); year separated with unspaced endash
local century;
month, year, century, anchor_year, year2=date_string:mw.ustring.match(date_string, "(%a+) +((%d%d)%d%d)[%-]((%d%d)%a?)");
if 'Winter' ~= month and 'Summer' ~= month then return false end; -- 'month' can only be Winter or Summer
anchor_year=year..'–'..anchor_year; -- assemble anchor_year from both years
పంక్తి 433:
month = get_season_number (month);
 
elseif date_string:mw.ustring.match(date_string, "^%a+ +[1-9]%d%d%d–d[%-–][1-9]%d%d%d%a?$") then -- special case Winter/Summer year-year; year separated with unspaced endash
month, year, anchor_year, year2=date_string:mw.ustring.match(date_string, "(%a+) +(%d%d%d%d)[%-]((%d%d%d%d)%a?)");
if 'Winter' ~= month and 'Summer' ~= month then return false end; -- 'month' can only be Winter or Summer
anchor_year=year..'–'..anchor_year; -- assemble anchor_year from both years
పంక్తి 441:
month = get_season_number (month); -- for metadata
 
elseif date_string:mw.ustring.match(date_string, "^%a+ +[1-9]%d%d%d% [%-] %a+ +[1-9]%d%d%d%a?$") then -- month/season year - month/season year; separated by spaced endash
month, year, month2, anchor_year, year2=date_string:mw.ustring.match(date_string, "(%a+) +(%d%d%d%d) [%-] (%a+) +((%d%d%d%d)%a?)");
anchor_year=year..'–'..anchor_year; -- assemble anchor_year from both years
if tonumber(year) >= tonumber(year2) then return false; end -- left to right, earlier to later, not the same
పంక్తి 456:
end
 
elseif date_string:mw.ustring.match (date_string, "^%a+[%-]%a+ +[1-9]%d%d%d%a?$") then -- month/season range year; months separated by endash
month, month2, anchor_year, year=date_string:mw.ustring.match (date_string, "(%a+)[%-](%a+)%s*((%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 0 ~= get_month_number(month) then -- determined to be a valid range so just check this one to know if month or season
పంక్తి 480:
end
 
elseif date_string:mw.ustring.match(date_string, "^[1-9]%d%d%d?[%-][1-9]%d%d%d?%a?$") then -- Year range: YYY-YYY or YYY-YYYY or YYYY–YYYY; separated by unspaced endash; 100-9999
year, anchor_year, year2=date_string:mw.ustring.match(date_string, "(%d%d%d%d?)[%-]((%d%d%d%d?)%a?)");
anchor_year=year..'–'..anchor_year; -- assemble anchor year from both years
if tonumber(year) >= tonumber(year2) then return false; end -- left to right, earlier to later, not the same
if not is_valid_year(year2) then return false; end -- no year farther in the future than next year
 
elseif date_string:mw.ustring.match(date_string, "^[1-9]%d%d%d–d[%-–]%d%d%a?$") then -- Year range: YYYY–YY; separated by unspaced endash
local century;
year, century, anchor_year, year2=date_string:mw.ustring.match(date_string, "((%d%d)%d%d)[%-]((%d%d)%a?)");
anchor_year=year..'–'..anchor_year; -- assemble anchor year from both years
if 13 > tonumber(year2) then return false; end -- don't allow 2003-05 which might be May 2003
పంక్తి 546:
local anchor_year; -- will return as nil if the date being tested is not |date=
local COinS_date; -- will return as nil if the date being tested is not |date=
local embargo_date; -- if embargo date is a good dmy, mdy, ymd date then holds original value else reset to 9999
local error_message = "";
local good_date = false;
పంక్తి 625:
end
 
elseif date_string:mw.ustring.match (date_string, "%d%d%d%d–d[%-–]%d%d") then -- YYYY-YY date ranges
local century;
date1, century, date2 = mw.ustring.match(date_string:match, ("((%d%d)%d%d)[%s%-–]+(%d%d)");
date2 = century..date2; -- convert YY to YYYY
if year ~= date1 and year ~= date2 then
పంక్తి 757:
end
return true; -- declare success and done
end
 
 
--[[--------------------------< D A T E _ H Y P H E N _ T O _ D A S H >----------------------------------------
 
Loops through the list of date-holding parameters and converts any hyphen to an ndash. Not called if the cs1|2
template has any date errors.
 
Modifies the date_parameters_list and returns true if hyphens are replaced, else returns false.
 
]]
 
local function date_hyphen_to_dash (date_parameters_list)
local result = false;
local n;
for param_name, param_val in pairs(date_parameters_list) do -- for each date-holding parameter in the list
if not param_val:match ('%d%d%d%d%-%d%d%-%d%d') then -- for those that are not ymd dates
param_val, n = param_val:gsub ('%-', '–'); -- replace any hyphen with ndash
if 0 ~= n then
date_parameters_list[param_name] = param_val; -- update the list
result = true;
end
end
end
return result; -- so we know if
end
 
Line 777 ⟶ 802:
year_date_check = year_date_check,
reformat_dates = reformat_dates,
date_hyphen_to_dash = date_hyphen_to_dash,
set_selected_modules = set_selected_modules
}