Jump to content

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 9: Line 9:




--[[--------------------------< I S _ V A L I D _ A C C E S S D A T E >----------------------------------------
--[=[-------------------------< I S _ V A L I D _ A C C E S S D A T E >----------------------------------------


returns true if:
returns true if:
Line 21: Line 21:
adding 24 hours gives 2015-01-03T00:00:00 – one second more than tomorrow
adding 24 hours gives 2015-01-03T00:00:00 – one second more than tomorrow


]]
This function does not work for languages other than English.  Wikimedia #time: parser apparently doesn't understand
non-Engish date month names. This function will always return false when the date contains a non-English month name
because good1 is false after the call to lang.formatDate.
 
For the time being, to use this function, supply it with YYYY-MM-DD format dates.  See
[[bs:Modul:Citation/CS1/Date validation/igralište]] for one possible solution.
 
]=]


local function is_valid_accessdate (accessdate)
local function is_valid_accessdate (accessdate)
Line 54: Line 61:
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 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};
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};
local temp;
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
if temp then return temp; end -- if month is the long-form name
0; -- misspelled, improper case, or not a month name
temp=short_months[month];
if temp then return temp; end -- if month is the short-form name
return 0; -- misspelled, improper case, or not a month name
end
end


Line 195: Line 199:
local function is_valid_month_season_range(range_start, range_end)
local function is_valid_month_season_range(range_start, range_end)
local range_start_number = get_month_number (range_start);
local range_start_number = get_month_number (range_start);
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?
local range_start_number = get_season_number (range_start); -- not a month; is it a season? get start season number
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); -- get end season number
range_end_number = get_season_number (range_end); -- get end season number


if 0 ~= range_start_number then -- is start of range a season?
if 0 ~= range_start_number then -- is start of range a season?
Line 211: Line 216:
end
end


local range_end_number = get_month_number (range_end); -- get end month number
range_end_number = get_month_number (range_end); -- get end month number
if range_start_number < range_end_number then -- range_start is a month; does range_start precede 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?
if is_valid_month_range_style (range_start, range_end) then -- do months have the same style?
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.