"ಮಾಡ್ಯೂಲ್:Citation/CS1/Date validation/sandbox" ಆವೃತ್ತಿಗಳ ಮಧ್ಯದ ಬದಲಾವಣೆಗಳು

Jump to navigation Jump to search
replace %a+ with [%D%S]- in check_date() because kn script includes Unicode character elements that aren't %a; mw.ustring.match() because kn month names use Unicode characters;
(possible tonumber() fix;)
(replace %a+ with [%D%S]- in check_date() because kn script includes Unicode character elements that aren't %a; mw.ustring.match() because kn month names use Unicode characters;)
--[[
History of changes since last sync: 2017-11-04
 
2017-11-11: i18n support for non-Western digits in access-date timestamps; see Help_talk:Citation_Style_1#Access_date_error_on_kannada_wikipedia
 
]]
-- access_ts = tonumber (access_ts); -- convert to numbers for the comparison
-- tomorrow_ts = tonumber (tomorrow_ts);
-- for wikis that do not use Western digits in their language scripts because lang.formatDate() returns a timestamp in the local script which tonumber() doesn't understand
access_ts = lang:parseFormattedNumber (access_ts); -- convert to numbers for the comparison
tomorrow_ts = lang:parseFormattedNumber (tomorrow_ts); -- these functions because lang.formatDate() returns a timestamp in kn script that tonumber() doesn't understand
else
return false; -- one or both failed to convert to unix time stamp
if 12 < tonumber(month) or 1 > tonumber(month) or 1582 > tonumber(year) or 0 == tonumber(day) then return false; end -- month or day number not valid or not Gregorian calendar
anchor_year = year;
elseif date_string:mw.ustring.match(date_string, "^[%D%a+S]- +[1-9]%d?, +[1-9]%d%d%d%a?$") then -- month-initial: month day, year
month, day, anchor_year, year=stringmw.ustring.match(date_string, "([%D%a+S]-)%s*(%d%d?),%s*((%d%d%d%d?)%a?)");
month = get_month_number (month);
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
elseif mw.ustring.match(date_string, "^[%a+D%S]- +[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=mw.ustring.match(date_string, "([%a+D%S]-) +(%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);
year2=year;
 
-- elseif date_string:mw.ustring.match(date_string, "^[1-9]%d? +[%a+D%S]- +[1-9]%d%d%d%a?$") then -- day-initial: day month year
day, elseif month, anchor_year, year=stringmw.ustring.match(date_string, "(^[0-9]%d? +[%d*)D%s*(%aS]- +)%s*(([1-9]%d%d%d%d?)%a?)$"); then -- day-initial: day month year
day, month, anchor_year, year=mw.ustring.match(date_string, "(%d%d*)%s*([%D%S]-)%s+((%d%d%d%d?)%a?)");
month = get_month_number (month);
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
 
elseif mw.ustring.match(date_string, "^[1-9]%d?[%-–][1-9]%d? +[%a+D%S]- +[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=mw.ustring.match(date_string, "(%d%d?)[%-–](%d%d?) +([%a+D%S]-) +((%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);
year2=year;
 
elseif mw.ustring.match(date_string, "^[1-9]%d? +[%a+D%S]- +[%-–] +[1-9]%d? +[%a+D%S]- +[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=mw.ustring.match(date_string, "(%d%d?) +([%a+D%S]-) +[%-–] +(%d%d?) +([%a+D%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 -- date range order is left to right: earlier to later;
month = get_month_number (month); -- for metadata
year2=year;
 
elseif mw.ustring.match(date_string, "^[%a+D%S]- +[1-9]%d? [%-–] [%a+D%S]- +[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=mw.ustring.match(date_string, "([%a+D%S]-) +(%d%d?) [%-–] ([%a+D%S]-) +(%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
year2=year;
 
elseif mw.ustring.match(date_string, "^[1-9]%d? +[%a+D%S]- +[1-9]%d%d%d [%-–] [1-9]%d? +[%a+D%S]- +[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=mw.ustring.match(date_string, "(%d%d?) +([%a+D%S]-) +(%d%d%d%d) [%-–] (%d%d?) +([%a+D%S]-) +((%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
month2 = get_month_number (month2);
 
elseif mw.ustring.match(date_string, "^[%a+D%S]- +[1-9]%d?, +[1-9]%d%d%d [%-–] [%a+D%S]- +[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=mw.ustring.match(date_string, "([%a+D%S]-) +(%d%d?), +(%d%d%d%d) [%-–] ([%a+D%S]-) +(%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
month2 = get_month_number (month2);
 
elseif mw.ustring.match(date_string, "^[%a+D%S]- +[1-9]%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=mw.ustring.match(date_string, "([%a+D%S]-) +((%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
month = get_season_number (month);
 
elseif mw.ustring.match(date_string, "^[%a+D%S]- +[1-9]%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=mw.ustring.match(date_string, "([%a+D%S]-) +(%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
month = get_season_number (month); -- for metadata
 
elseif mw.ustring.match(date_string, "^[%a+D%S]- +[1-9]%d%d%d +[%-–] +[%a+D%S]- +[1-9]%d%d%d%a?$") then -- month/season year - month/season year; separated by spaced endash
month, year, month2, anchor_year, year2=mw.ustring.match(date_string, "([%a+D%S]-) +(%d%d%d%d) +[%-–] +([%a+D%S]-) +((%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
end
 
elseif mw.ustring.match(date_string, "^[%a+D%S]-[%-–][%a+D%S]- +[1-9]%d%d%d%a?$") then -- month/season range year; months separated by endash
month, month2, anchor_year, year=mw.ustring.match(date_string, "([%a+D%S]-)[%-–]([%a+D%S]-)%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
year2=year;
elseif date_string:mw.ustring.match(date_string, "^[%D%a+S]- +%d%d%d%d%a?$") then -- month/season year or proper-name year
month, anchor_year, year=date_string:mw.ustring.match(date_string, "^([%a+)D%s*S]-) +((%d%d%d%d)%a?)");
if not is_valid_year(year) then return false; end
if not is_valid_month_or_season (month) and 0 == is_proper_name (month) then return false; end
for k, v in pairs(date_parameters_list) do -- for each date-holding parameter in the list
if is_set(v) then -- if the parameter has a value
v = mw.ustring.gsub (v, '[೦-೯]', {['೦'] = '0', ['೧'] = 1, ['೨'] = 2, ['೩'] = 3, ['೪'] = 4, ['೫'] = 5, ['೬'] = 6, ['೭'] = 7, ['೮'] = 8, ['೯'] = '9'})
if v:match("^c%. [1-9]%d%d%d?%a?$") then -- special case for c. year or with or without CITEREF disambiguator - only |date= and |year=
local year = v:match("c%. ([1-9]%d%d%d?)%a?"); -- get the year portion so it can be tested
೩೫

edits

"https://kn.wikipedia.org/wiki/ವಿಶೇಷ:MobileDiff/808258" ಇಂದ ಪಡೆಯಲ್ಪಟ್ಟಿದೆ

ಸಂಚರಣೆ ಪಟ್ಟಿ