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 51: | Line 51: | ||
end | end | ||
end | end | ||
--[[--------------------------< G E T _ M O N T H _ N U M B E R >---------------------------------------------- | --[[--------------------------< G E T _ M O N T H _ N U M B E R >---------------------------------------------- | ||
Line 65: | Line 66: | ||
0; -- misspelled, improper case, or not a month name | 0; -- misspelled, improper case, or not a month name | ||
end | end | ||
--[[--------------------------< I S _ V A L I D _ E M B A R G O _ D A T E >------------------------------------ | |||
returns true and date value if that value has proper dmy, mdy, ymd format. | |||
returns false and 9999 when date value is not proper format; assumes that when |embargo= is set, the editor | |||
intended to embargo a pmc but |embargo does not hold a single date. | |||
]] | |||
local function is_valid_embargo_date (v) | |||
if v:match ('^%d%d%d%d%-%d%d%-%d%d$') or -- ymd | |||
v:match ('^%d%d?%s+%a+%s+%d%d%d%d$') or -- dmy | |||
v:match ('^%a+%s+%d%d?%s*,%s*%d%d%d%d$') then -- mdy | |||
return true, v; | |||
end | |||
return false, '9999'; -- if here not good date so return false and set embargo date to long time in future | |||
end | |||
--[[--------------------------< G E T _ S E A S O N _ N U M B E R >-------------------------------------------- | --[[--------------------------< G E T _ S E A S O N _ N U M B E R >-------------------------------------------- | ||
Line 525: | Line 546: | ||
local anchor_year; -- will return as nil if the date being tested is not |date= | 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 COinS_date; -- will return as nil if the date being tested is not |date= | ||
local embargo_date = '9999'; -- if good dmy, mdy, ymd date then holds original value else 9999 | |||
local error_message = ""; | local error_message = ""; | ||
local good_date = false; | local good_date = false; | ||
Line 546: | Line 568: | ||
good_date, anchor_year, COinS_date = check_date (v, tCOinS_date); -- go test the date | good_date, anchor_year, COinS_date = check_date (v, tCOinS_date); -- go test the date | ||
end | end | ||
elseif 'access-date'==k then -- if the parameter is |date= | elseif 'access-date'==k then -- if the parameter is |access-date= | ||
good_date = check_date (v); -- go test the date | good_date = check_date (v); -- go test the date | ||
if true == good_date then -- if the date is a valid date | if true == good_date then -- if the date is a valid date | ||
good_date = is_valid_accessdate (v); -- is Wikipedia start date < accessdate < tomorrow's date? | good_date = is_valid_accessdate (v); -- is Wikipedia start date < accessdate < tomorrow's date? | ||
end | |||
elseif 'embargo'==k then -- if the parameter is |embargo= | |||
good_date = check_date (v); -- go test the date | |||
if true == good_date then -- if the date is a valid date | |||
good_date, embargo_date = is_valid_embargo_date (v); -- is |embargo= date a single dmy, mdy, or ymd formatted date? yes:returns embargo; no: returns 9999 | |||
end | end | ||
else -- any other date-holding parameter | else -- any other date-holding parameter | ||
Line 562: | Line 589: | ||
end | end | ||
end | end | ||
return anchor_year, error_message; -- and done | return anchor_year, embargo_date, error_message; -- and done | ||
end | end | ||