Module:Citation/CS1/Date validation: Difference between revisions
season range fix;
(sync from sandbox;) |
(season range fix;) |
||
Line 284: | Line 284: | ||
]] | ]] | ||
local function is_valid_month_season_range(range_start, range_end) | local function is_valid_month_season_range(range_start, range_end, param) | ||
local range_start_number = get_month_number (range_start); | local range_start_number = get_month_number (range_start); | ||
local range_end_number; | local range_end_number; | ||
if 0 == range_start_number then -- is this a month range? | if 0 == range_start_number then -- is this a month range? | ||
range_start_number = get_season_number (range_start); | range_start_number = get_season_number (range_start, param); -- not a month; is it a season? get start season number | ||
range_end_number = get_season_number (range_end); | range_end_number = get_season_number (range_end, param); -- get end season number | ||
if (0 ~= range_start_number) and (0 ~= range_end_number) then | if (0 ~= range_start_number) and (0 ~= range_end_number) then | ||
Line 482: | Line 482: | ||
]] | ]] | ||
local function check_date (date_string, param, tCOinS_date) | local function check_date (date_string, param, tCOinS_date) | ||
local year; | local year; -- assume that year2, months, and days are not used; | ||
local year2=0; | local year2=0; -- second year in a year range | ||
local month=0; | local month=0; | ||
local month2=0; | local month2=0; -- second month in a month range | ||
local day=0; | local day=0; | ||
local day2=0; | local day2=0; -- second day in a day range | ||
local anchor_year; | local anchor_year; | ||
local coins_date; | local coins_date; | ||
Line 546: | Line 545: | ||
elseif mw.ustring.match(date_string, patterns['Md-Mdy'][1]) then -- month initial month-day-range: month day – month day, year; uses spaced endash | elseif mw.ustring.match(date_string, patterns['Md-Mdy'][1]) 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, patterns['Md-Mdy'][1]); | month, day, month2, day2, anchor_year, year=mw.ustring.match(date_string, patterns['Md-Mdy'][1]); | ||
if (not is_valid_month_season_range(month, month2)) or not is_valid_year(year) then return false; end | 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 | month = get_month_number (month); -- for metadata | ||
month2 = get_month_number (month2); | month2 = get_month_number (month2); | ||
Line 573: | Line 572: | ||
if 1 ~= tonumber(year2) - tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later | if 1 ~= tonumber(year2) - tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later | ||
if not is_valid_year(year2) then return false; end -- no year farther in the future than next year | if not is_valid_year(year2) then return false; end -- no year farther in the future than next year | ||
month = get_season_number (month); | month = get_season_number (month, param); | ||
elseif mw.ustring.match(date_string, patterns['Sy-y'][1]) then -- special case Winter/Summer year-year; year separated with unspaced endash | elseif mw.ustring.match(date_string, patterns['Sy-y'][1]) then -- special case Winter/Summer year-year; year separated with unspaced endash | ||
Line 581: | Line 580: | ||
if 1 ~= tonumber(year2) - tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later | if 1 ~= tonumber(year2) - tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later | ||
if not is_valid_year(year2) then return false; end -- no year farther in the future than next year | if not is_valid_year(year2) then return false; end -- no year farther in the future than next year | ||
month = get_season_number (month); | month = get_season_number (month, param); -- for metadata | ||
elseif mw.ustring.match(date_string, patterns['My-My'][1]) then -- month/season year - month/season year; separated by spaced endash | elseif mw.ustring.match(date_string, patterns['My-My'][1]) then -- month/season year - month/season year; separated by spaced endash | ||
Line 591: | Line 590: | ||
month = get_month_number(month); | month = get_month_number(month); | ||
month2 = get_month_number(month2); | month2 = get_month_number(month2); | ||
elseif 0 ~= get_season_number(month) and 0 ~= get_season_number(month2) then -- both must be | elseif 0 ~= get_season_number(month, param) and 0 ~= get_season_number(month2, param) then -- both must be season year, not mixed | ||
month = get_season_number(month); | month = get_season_number(month, param); | ||
month2 = get_season_number(month2); | month2 = get_season_number(month2, param); | ||
else | else | ||
return false; | return false; | ||
Line 600: | Line 599: | ||
elseif mw.ustring.match(date_string, patterns['M-My'][1]) then -- month/season range year; months separated by endash | elseif mw.ustring.match(date_string, patterns['M-My'][1]) then -- month/season range year; months separated by endash | ||
month, month2, anchor_year, year=mw.ustring.match(date_string, patterns['M-My'][1]); | month, month2, anchor_year, year=mw.ustring.match(date_string, patterns['M-My'][1]); | ||
if (not is_valid_month_season_range(month, month2)) or (not is_valid_year(year)) then return false; end | 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 | if 0 ~= get_month_number(month) then -- determined to be a valid range so just check this one to know if month or season | ||
month = get_month_number(month); | month = get_month_number(month); | ||
month2 = get_month_number(month2); | month2 = get_month_number(month2); | ||
else | else | ||
month = get_season_number(month); | month = get_season_number(month, param); | ||
month2 = get_season_number(month2); | month2 = get_season_number(month2, param); | ||
end | end | ||
year2=year; | year2=year; | ||
Line 721: | Line 720: | ||
end | end | ||
elseif 'embargo'==k then -- if the parameter is |embargo= | elseif 'embargo'==k then -- if the parameter is |embargo= | ||
good_date = check_date (v.val); | good_date = check_date (v.val, k); -- 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, embargo_date = is_valid_embargo_date (v.val); -- is |embargo= date a single dmy, mdy, or ymd formatted date? yes:returns embargo; no: returns 9999 | good_date, embargo_date = is_valid_embargo_date (v.val); -- is |embargo= date a single dmy, mdy, or ymd formatted date? yes:returns embargo; no: returns 9999 |