Module:Citation/CS1/Date validation: திருத்தங்களுக்கு இடையிலான வேறுபாடு
உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
imported>Sukanthi சி 55 திருத்தங்கள் இறக்குமதி செய்யப்பட்டன |
imported>Info-farmer en:Module:Citation/CS1/Date_validation இலிருந்து திருத்தங்கள் இறக்குமதி செய்யப்பட்டன |
||
வரிசை 327:
input.year2 = tonumber (input.year2) or lang_object:parseFormattedNumber (input.year2); -- COinS dates are pseudo-ISO 8601 so convert to Arabic numerals
if ((1582 == input.year) and (10 > tonumber(input.month))) or (1582 > input.year) then
end▼
▲ if ((1582 == year) and (10 > month)) or (1582 > year) then -- if a Julian calendar date
tCOinS_date.rftdate = tostring (input.year); -- &rft.date gets year only
return; -- done
வரி 395 ⟶ 384:
--[[--------------------------< P A T T E R N S _ T >
this is the list of patterns for date formats that this module recognizes. Approximately the first half of these
வரி 407 ⟶ 396:
]]
local
-- year-initial numerical year-month-day
['ymd'] = {'^(%d%d%d%d)%-(%d%d)%-(%d%d)$', 'y', 'm', 'd'},
வரி 456 ⟶ 445:
local function is_valid_embargo_date (v)
if v:match (
v:match (
v:match (
return true, v;
end
வரி 497 ⟶ 486:
local coins_date;
if date_string:match (
year, month, day = date_string:match (
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 mw.ustring.match(date_string,
month, day, anchor_year, year = mw.ustring.match(date_string,
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,
month, day, day2, anchor_year, year = mw.ustring.match(date_string,
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);
வரி 515 ⟶ 504:
year2 = year;
elseif mw.ustring.match(date_string,
day, month, anchor_year, year = mw.ustring.match(date_string,
month = get_month_number (month);
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
--[[ NOT supported at en.wiki
elseif mw.ustring.match(date_string,
anchor_year, year, month, day = mw.ustring.match(date_string,
month = get_month_number (month);
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
-- end NOT supported at en.wiki ]]
elseif mw.ustring.match(date_string,
day, day2, month, anchor_year, year = mw.ustring.match(date_string,
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);
வரி 535 ⟶ 524:
year2 = year;
elseif mw.ustring.match(date_string,
day, month, day2, month2, anchor_year, year = mw.ustring.match(date_string,
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
வரி 542 ⟶ 531:
year2 = year;
elseif mw.ustring.match(date_string,
month, day, month2, day2, anchor_year, year = mw.ustring.match(date_string,
if (not is_valid_month_season_range(month, month2, param)) or not is_valid_year(year) then return false; end
month = get_month_number (month); -- for metadata
வரி 549 ⟶ 538:
year2 = year;
elseif mw.ustring.match(date_string,
day, month, year, day2, month2, anchor_year, year2 = mw.ustring.match(date_string,
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
வரி 557 ⟶ 546:
if 0 == month or 0 == month2 then return false; end -- both must be valid
elseif mw.ustring.match(date_string,
month, day, year, month2, day2, anchor_year, year2 = mw.ustring.match(date_string,
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
வரி 565 ⟶ 554:
if 0 == month or 0 == month2 then return false; end -- both must be valid
elseif mw.ustring.match(date_string,
local century;
month, year, century, anchor_year, year2 = mw.ustring.match(date_string,
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
வரி 575 ⟶ 564:
month = get_season_number(month, param);
elseif mw.ustring.match(date_string,
month, year, anchor_year, year2 = mw.ustring.match(date_string,
month = get_season_number (month, param); -- <month> can only be winter or summer; also for metadata
if (month ~= cfg.date_names['en'].season['Winter']) and (month ~= cfg.date_names['en'].season['Summer']) then
வரி 585 ⟶ 574:
if not is_valid_year(year2) then return false; end -- no year farther in the future than next year
elseif mw.ustring.match(date_string,
month, year, month2, anchor_year, year2 = mw.ustring.match(date_string,
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
வரி 600 ⟶ 589:
end
elseif mw.ustring.match(date_string,
month, month2, anchor_year, year = mw.ustring.match(date_string,
if (not is_valid_month_season_range(month, month2, param)) 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
வரி 613 ⟶ 602:
year2 = year;
elseif mw.ustring.match(date_string,
month, anchor_year, year = mw.ustring.match(date_string,
if not is_valid_year(year) then return false; end
month = get_element_number(month, param); -- get month season quarter proper-name number or nil
if not month then return false; end -- not valid whatever it is
elseif mw.ustring.match(date_string,
year, anchor_year, year2 = mw.ustring.match(date_string,
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 mw.ustring.match(date_string,
local century;
year, century, anchor_year, year2 = mw.ustring.match(date_string,
anchor_year = year .. '–' .. anchor_year; -- assemble anchor year from both years
வரி 639 ⟶ 628:
end
elseif mw.ustring.match(date_string,
anchor_year, year = mw.ustring.match(date_string,
if false == is_valid_year(year) then
return false;
வரி 754 ⟶ 743:
end
return anchor_year, embargo_date; -- and done
end
--[[--------------------------< Y E A R _ C H E C K >----------------------------------------------------------
Temporary function to test |year= for acceptable values:
YYY, YYYY, year-only ranges, their circa forms, with or without CITEREF disambiguators.
When |year= holds some form of date that is not one of these year-only dates, emit a maintenance message.
This function necessary because many non-cs1|2 templates have a |year= parameter so cirrus searches are more-or-
less useless
]]▼
local function year_check (year)
year = year:gsub ('c%. *', ''); -- remove circa annotation (if present) before testing <year>
for _, index in ipairs ({'y-y', 'y4-y2', 'y'}) do -- spin through these indexes into patterns_t
if mw.ustring.match (year, patterns_t[index][1]) then
return; -- if a match then |year= holds a valid 'year'
end
▲ end
set_message ('maint_year'); -- if here, |year= value is not an accepted value; add a maint cat
end
வரி 827 ⟶ 841:
format string used by string.format()
identifier letters ('d', 'm', 'y', 'd2', 'm2', 'y2') that serve as indexes into a table t{} that holds captures
from mw.ustring.match() for the various date parts specified by
Items in
['ymd'] = {'^(%d%d%d%d)%-(%d%d)%-(%d%d)$', 'y', 'm', 'd'}, where:
['ymd'] is pattern_idx
when a pattern matches a date, the captures are loaded into table t{} in capture order using the idemtifier
வரி 843 ⟶ 857:
format_param set to the desired format. This function loads table t{} as described and then calls string.format()
with the format string specified by re_format[pattern_idx][format_param][1] using values taken from t{} according
to the capture identifier letters specified by
]]
வரி 908 ⟶ 922:
local function reformatter (date, pattern_idx, format_param, mon_len)
if not in_array (pattern_idx, {'ymd', 'Mdy', 'Md-dy', 'dMy', 'yMd', 'd-dMy', 'dM-dMy', 'Md-Mdy', 'dMy-dMy', 'Mdy-Mdy', 'My-My', 'M-My', 'My'}) then
return; -- not in this set of date format
end
வரி 925 ⟶ 939:
end
local c1, c2, c3, c4, c5, c6, c7; -- these hold the captures specified in
c1, c2, c3, c4, c5, c6, c7 = mw.ustring.match (date,
local t = { -- table that holds k/v pairs of date parts from the captures and
[
[
[
[
[
[
[
};
வரி 1,035 ⟶ 1,049:
if is_set (param_val.val) then -- if the parameter has a value
if not (not all and in_array (param_name, {'access-date', 'archive-date'})) then -- skip access- or archive-date unless format is xxx-all; yeah, ugly; TODO: find a better way
for pattern_idx, pattern in pairs (
if mw.ustring.match (param_val.val, pattern[1]) then
if all and in_array (param_name, {'access-date', 'archive-date'}) then -- if this date is an access- or archive-date
வரி 1,071 ⟶ 1,085:
for param_name, param_val in pairs(date_parameters_list) do -- for each date-holding parameter in the list
if is_set (param_val.val) and
not mw.ustring.match (param_val.val,
param_val.val, n = param_val.val:gsub ('%-', '–'); -- replace any hyphen with ndash
if 0 ~= n then
வரி 1,163 ⟶ 1,177:
--[[--------------------------< A R C H I V E _ D A T E _ C H E C K >------------------------------------------
Compare value in |archive-date= with the timestamp in Wayback machine urls. Emits an error message
date from the |archive-url= timestamp in an appropriate format when the value in |archive-date= does not match
this function never called when any date in a cs1|2 template has errors
▲]]
error message suggests new |archive-date= value in an appropriate format specified by <df>. <df> is either
local function archive_date_check (archive_date, archive_url_timestamp)▼
|df= or cfg.global_df in that order. If <df> is nil, suggested date has format from |archive-date=. There is
a caveat: when |df=dmy or |df=mdy, the reformatter leaves |access-date= and |archive-date= formats as they are.
The error message suggested date is passed to the formatter as YYYY-MM-DD so when |df=dmy or |df=mdy, the format
is not changed.
]]
▲local function archive_date_check (archive_date, archive_url_timestamp, df)
set_message ('err_archive_date_url_ts_mismatch'); -- emit an error message▼
local archive_date_format = 'dmy-y'; -- holds the date format of date in |archive-date; default to ymd; 'dmy' used here to spoof reformat_dates()
for _, v_t in ipairs ({{'dMy', 'dmy-all'}, {'Mdy', 'mdy-all'}}) do -- is |archive-date= format dmy or mdy?
if archive_date:match (patterns_t[v_t[1]][1]) then -- does the pattern match?
archive_date_format = cfg.keywords_xlate[v_t[2]]; -- get appropriate |df= supported keyword from the i18n translator table
break;
end
end
local dates_t = {};
dates_t['archive-date'] = {val=archive_date, name=''}; -- setup to call reformat_dates(); never called when errors so <name> unset as not needed
reformat_dates (dates_t, 'dmy-y'); -- reformat |archive-date= to ymd; 'dmy' used here to spoof reformat_dates()
local archive_url_date = archive_url_timestamp:gsub ('(%d%d%d%d)(%d%d)(%d%d)%d*', '%1-%2-%3'); -- make ymd format date from timestamp
if dates_t['archive-date'].val == archive_url_date then -- are the two dates the same
return; -- yes, done
else
dates_t['archive-date'] = {val=archive_url_date, name=''}; -- setup to call reformat_dates() with the timestamp date
reformat_dates (dates_t, df or archive_date_format); -- reformat timestamp to format specified by <df> or format used in |archive-date=
archive_url_date = dates_t['archive-date'].val;
end
end
வரி 1,190 ⟶ 1,227:
reformat_dates = reformat_dates,
set_selected_modules = set_selected_modules,
year_check = year_check,
year_date_check = year_date_check,
}
| |||