"मोड्युल:Citation/CS1/Date validation" को बिचमी भिन्नता
Content deleted Content added
MF-Warburg (कुरणि • योगदानअन) ना १ संशोधन आयात भयो: Importing from Incubator |
कुनै सम्पादन सारांश छैन |
||
पंक्ति ९:
--[
returns true if:
पंक्ति २१:
adding 24 hours gives 2015-01-03T00:00:00 – one second more than tomorrow
]]▼
local function is_valid_accessdate (accessdate)
Line ४२ ⟶ ३७:
return false; -- one or both failed to convert to unix time stamp
end
if 979516800 <= access_ts and access_ts < tomorrow_ts then -- Wikipedia start date <= accessdate < tomorrow's date
return true;
Line ४९ ⟶ ४४:
end
end
--[[--------------------------< G E T _ M O N T H _ N U M B E R >----------------------------------------------
Line ६० ⟶ ५४:
local long_months = {['January']=1, ['February']=2, ['March']=3, ['April']=4, ['May']=5, ['June']=6, ['July']=7, ['August']=8, ['September']=9, ['October']=10, ['November']=11, ['December']=12};
local short_months = {['Jan']=1, ['Feb']=2, ['Mar']=3, ['Apr']=4, ['May']=5, ['Jun']=6, ['Jul']=7, ['Aug']=8, ['Sep']=9, ['Oct']=10, ['Nov']=11, ['Dec']=12};
return long_months[month] or -- if month is the long-form name▼
temp=long_months[month];
short_months[month] or -- if month is the short-form name▼
0; -- misspelled, improper case, or not a month name▼
temp=short_months[month];
end
▲]]
--[[--------------------------< G E T _ S E A S O N _ N U M B E R >--------------------------------------------
Line २१८ ⟶ १९५:
local function is_valid_month_season_range(range_start, range_end)
local range_start_number = get_month_number (range_start);
if 0 == range_start_number then -- is this a month range?
local range_start_number = get_season_number (range_start); -- not a month; is it a season? get start season number
local range_end_number = get_season_number (range_end);
if 0 ~= range_start_number then -- is start of range a season?
Line २३५ ⟶ २११:
end
local range_end_number = get_month_number (range_end);
if range_start_number < range_end_number then -- range_start is a month; does range_start precede range_end?
if is_valid_month_range_style (range_start, range_end) then -- do months have the same style?
Line ३५२ ⟶ ३२८:
]]
local function check_date (date_string, tCOinS_date
local year; -- assume that year2, months, and days are not used;
local year2=0; -- second year in a year range
Line ३७२ ⟶ ३४८:
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
elseif
month, day, day2, anchor_year, year=
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);
Line ३८५ ⟶ ३६१:
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
elseif
day, day2, month, anchor_year, year=
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);
Line ३९३ ⟶ ३६९:
year2=year;
elseif
day, month, day2, month2, anchor_year, year=
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
Line ४०० ⟶ ३७६:
year2=year;
elseif
month, day, month2, day2, anchor_year, year=
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
Line ४०७ ⟶ ३८३:
year2=year;
elseif
day, month, year, day2, month2, anchor_year, year2=
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
Line ४१४ ⟶ ३९०:
month2 = get_month_number (month2);
elseif
month, day, year, month2, day2, anchor_year, year2=
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
Line ४२१ ⟶ ३९७:
month2 = get_month_number (month2);
elseif
local century;
month, year, century, anchor_year, year2=
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
Line ४३१ ⟶ ४०७:
month = get_season_number (month);
elseif
month, year, anchor_year, year2=
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
Line ४३९ ⟶ ४१५:
month = get_season_number (month); -- for metadata
elseif
month, year, month2, anchor_year, year2=
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
Line ४५४ ⟶ ४३०:
end
elseif
month, month2, anchor_year, year=
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
Line ४७८ ⟶ ४५४:
end
elseif
year, anchor_year, year2=
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
local century;
year, century, anchor_year, year2=
anchor_year=year..'–'..anchor_year; -- assemble anchor year from both years
if 13 > tonumber(year2) then return false; end -- don't allow 2003-05 which might be May 2003
Line ५०१ ⟶ ४७७:
else
return false; -- date format not one of the MOS:DATE approved formats
end▼
end
Line ५५५ ⟶ ५२०:
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 error_message = "";
local good_date = false;
Line ५७० ⟶ ५३४:
end
elseif 'date'==k then -- if the parameter is |date=
if v:match("^n%.d%.%a?
good_date, anchor_year, COinS_date = true, v:match("((n%.d%.)%a?)"); --"n.d."; no error when date parameter is set to no date
elseif v:match("^nd%a?$") then -- if |date=nd with or without a CITEREF disambiguator
Line ५७६ ⟶ ५४०:
else
good_date, anchor_year, COinS_date = check_date (v, tCOinS_date); -- go test the date
end
elseif 'access-date'==k then -- if the parameter is |date=
good_date = check_date (v); -- go test the date
if true == good_date then -- if the date is a valid date
good_date
end
else -- any other date-holding parameter
Line ५९९ ⟶ ५५७:
end
end
return anchor_year
end
Line ६३५ ⟶ ५९३:
end
elseif
local century;
date1, century, date2 =
date2 = century..date2; -- convert YY to YYYY
if year ~= date1 and year ~= date2 then
Line ७६० ⟶ ७१८:
format_str = long_formats[format];
end
date_parameters_list[param_name] =
end
end
Line ७६७ ⟶ ७२५:
end
return true; -- declare success and done
▲ local n;
end
Line ८१२ ⟶ ७४५:
year_date_check = year_date_check,
reformat_dates = reformat_dates,
set_selected_modules = set_selected_modules
}
|