local p = {}
local function get_month_number (month)
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 malayalam_months = {['ജനുവരി']=1, ['ഫെബ്രുവരി']=2, ['മാർച്ച്']=3, ['ഏപ്രിൽ']=4, ['മെയ്']=5, ['ജൂൺ']=6, ['ജൂലൈ']=7, ['ഓഗസ്റ്റ്']=8, ['സെപ്റ്റംബർ']=9, ['ഒക്ടോബർ']=10, ['നവംബർ']=11, ['ഡിസംബർ']=12};
local temp;
temp=long_months[month];
if temp then return temp; end -- if month is the long-form name
temp=malayalam_months[month];
if temp then return temp; end -- if month is the malayalam 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
local function is_valid_accessdate (accessdate)
local lang = mw.getContentLanguage();
local good1, good2;
local access_ts, tomorrow_ts; -- to hold unix time stamps representing the dates
good1, access_ts = pcall( lang.formatDate, lang, 'U', accessdate ); -- convert accessdate value to unix timesatmp
good2, tomorrow_ts = pcall( lang.formatDate, lang, 'U', 'today + 2 days' ); -- today midnight + 2 days is one second more than all day tomorrow
if good1 and good2 then
access_ts = tonumber (access_ts); -- convert to numbers for the comparison
tomorrow_ts = tonumber (tomorrow_ts);
else
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;
else
return false; -- accessdate out of range
end
end
--[[--------------------------< C O N V E R T _ M L _ D A T E _ T O _ E N >--------------------------
Malayalam months are not validated to Time Stamp and is getting rejected in the Access Dates Check.
This fix is to work around it by converting Malayalam date to english date and then validating it.
Returns the English Date in "YYYY-MM-DD" format
]]
local function convert_ml_dat_to_en (ml_date)
local year;
local month=0;
local day=0;
local retVal = ml_date;
if mw.ustring.match(ml_date, "^%d%d? [%C%D%P%W]+ %d%d%d%d?$") then -- dd മാസം year
day, month, year=mw.ustring.match(ml_date, "(%d%d?)% ([%C%D%P%W]+) (%d%d%d%d?)");
month=get_month_number(month);
elseif mw.ustring.match(ml_date, "^[%C%D%P%W]+ %d%d?, %d%d%d%d?$") then -- മാസം dd, year
month, day, year=mw.ustring.match(ml_month, "([%C%D%P%W]+) (%d%d?)%, (%d%d%d%d?)");
month=get_month_number(month);
elseif mw.ustring.match(ml_date, "^%d%d%d%d? [%C%D%P%W]+ %d%d?$") then -- year മാസം dd
year, month, day=mw.ustring.match(ml_date, "(%d%d%d%d?) ([%C%D%P%W]+) (%d%d?)");
month=get_month_number(month);
elseif mw.ustring.match(ml_date, "^%d%d?/[%C%D%P%W]+/%d%d%d%d?$") then -- year മാസം dd
day, month, year=mw.ustring.match(ml_date, "(%d%d?)/([%C%D%P%W]+)/(%d%d%d%d?)");
month=get_month_number(month);
else
retVal = ml_date;
end
if month > 0 then
retVal = year .. "-" .. month .. "-" .. day;
end
return retVal;
end
function p.getMalayalamCalDay(frame)
local data_module = "ഘടകം:TestingModule/data";
local data_code = mw.loadData(data_module);
local curYear = os.date( "!%Y" );
local curMonth = os.date( "!%b" );
local curday = os.date( "!%d" );
--{{#expr:{{LOCALYEAR}}-824}}'''<br />
--{{#ifexpr:({{LOCALDAY}}+15)<31
--|[[ചിങ്ങം]] <br />'''{{#expr:{{LOCALDAY}}+15}}'''
--|[[കന്നി]]<br /> '''{{#expr:{{LOCALDAY}}-16}}'''
local curConfig = data_code.data_config[curYear][curMonth];
local retValue = (curYear - curConfig[1]);
if (curday + curConfig[5] + 1) < curConfig[4] then
retValue = retValue .. " - " .. curConfig[3] .. " - " .. (curday + curConfig[5] + 1);
else
retValue = retValue .. " - " .. curConfig[6] .. " - " .. (curday - curConfig[5] + 1);
end;
return retValue;
end
function p.testFunction( frame )
return frame.args[1]
end
function p.testLength( frame )
local val = "";
local temp = "";
local inputStr = frame.args[1];
local i = 0;
for ch = 1, mw.ustring.len(inputStr) do
charCode = mw.ustring.byte( inputStr, ch, ch);
val = val .. charCode .. "," ;
temp = temp .. mw.ustring.char(charCode);
end;
return val .. "[" .. temp .. "] Len(" .. frame.args[1] .. "):" .. string.len(frame.args[1]) .. "/UStr:" .. mw.ustring.len(frame.args[1]);
end
function constructDate(year, month, day)
return day .. "/" .. month .. "/" .. year;
end
function p.testDate( frame )
local year=2000;--{{CURRENTYEAR}}; -- assume that year2, months, and days are not used;
local month=0;
local day=0;
local date_string=frame.args[1];
if mw.ustring.match(date_string, "^%d%d? [%C%D%P%W]+ %d%d%d%d?$") then
day, month, year=mw.ustring.match(date_string, "(%d%d?)% ([%C%D%P%W]+) (%d%d%d%d?)");
date_string=constructDate(year, month, day);
elseif mw.ustring.match(date_string, "^[%C%D%P%W]+ %d%d?, %d%d%d%d?$") then
month, day, year=mw.ustring.match(date_string, "([%C%D%P%W]+) (%d%d?)%, (%d%d%d%d?)");
date_string=constructDate(year, month, day);
elseif mw.ustring.match(date_string, "^%d%d%d%d? [%C%D%P%W]+ %d%d?$") then
year, month, day=mw.ustring.match(date_string, "(%d%d%d%d?) ([%C%D%P%W]+) (%d%d?)");
date_string=constructDate(year, month, day);
elseif mw.ustring.match(date_string, "^%d%d . %d%d%d%d$") then
day, month, year=mw.ustring.match(date_string, "(%d%d)% (.) (%d%d%d%d)");
date_string=constructDate(year, month, day);
elseif date_string:match("^%x$") then
date_string="Got all Hex chars!";
elseif mw.ustring.match(date_string, "^.$") then
date_string="Got all chars!";
elseif date_string:match("^%g+$") then
date_string="Got it in printable chars!";
elseif mw.ustring.match(date_string, "^%a+$") then
date_string="stupid it comes as a single word!";
elseif date_string:match("^$") then
date_string="it starts and ends!";
else
date_string="Error! The Format did not recognised.";
end
local v = convert_ml_dat_to_en(date_string);
-- Now time stamp conversion should work
--good_date = is_valid_accessdate (v);
local var = "not okay";
if is_valid_accessdate(v) then var = "Okay"; end;
return "Input [" .. frame.args[1] .. "] - Output [" .. date_string .. "(" .. v .. ">" .. var .. ")]" ;
end
function p.getHistory( frame )
local title = mw.title.makeTitle( 'Module', 'TestingModule')
if title then
return (title.text)
else
return ('Not Found!')
end
end
return p