Bước tới nội dung

Mô đun:Citation/CS1/Date validation và Mô đun:Citation/CS1/Date validation/sandbox: Khác biệt giữa các trang

(Khác biệt giữa các trang)
Nội dung được xóa Nội dung được thêm vào
Không có tóm lược sửa đổi
 
 
Dòng 1.207: Dòng 1.207:
end
end



--[[--------------------------< 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 with suggested
date from the |archive-url= timestamp in an appropriate format when the value in |archive-date= does not match
the timestamp.

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
|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)
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[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;
set_message ('archive_date không khớp với URL lưu trữ', archive_url_date); -- emit an error message
end
end


--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
Dòng 1.253: Dòng 1.212:


return { -- return exported functions
return { -- return exported functions
archive_date_check = archive_date_check,
dates = dates,
dates = dates,
year_date_check = year_date_check,
year_date_check = year_date_check,