ഘടകം:TestingModule

വിക്കിഗ്രന്ഥശാല സംരംഭത്തിൽ നിന്ന്

Purge

  • yehaaaa
  • -TestingModule-
  • -Input [20 ജനുവരി 2014] - Output [20/ജനുവരി/2014(2014-1-20>Okay)]-
  • -Input [2 ജനുവരി 2014] - Output [2/ജനുവരി/2014(2014-1-2>Okay)]-
  • -Input [ജനുവരി 2, 2014] - Output [2/ജനുവരി/2014(2014-1-2>Okay)]-
  • -Input [2014 ജനുവരി 2] - Output [2/ജനുവരി/2014(2014-1-2>Okay)]-
  • -Input [2 ജനുവരി 214] - Output [2/ജനുവരി/214(214-1-2>not okay)]-
  • -Input [21 ജനുവരി 2014] - Output [21/ജനുവരി/2014(2014-1-21>Okay)]-
  • -Input [21 Januvary 2014] - Output [21/Januvary/2014(21/Januvary/2014>not okay)]-
  • -Input [Januvary] - Output [stupid it comes as a single word!(stupid it comes as a single word!>not okay)]-
  • -Input [ജനുവരി] - Output [Error! The Format did not recognised.(Error! The Format did not recognised.>not okay)]-
  • -Input [] - Output [it starts and ends!(it starts and ends!>not okay)]-
  • -50,49,32,74,97,110,117,118,97,114,121,32,50,48,49,52,[21 Januvary 2014] Len(21 Januvary 2014):16/UStr:16-
  • -50,49,32,224,180,156,224,180,168,224,181,129,224,180,[21 ജനുà´] Len(21 ജനുവരി 2014):26/UStr:14-
  • -ലുവ പിഴവ് 91 വരിയിൽ : attempt to index field '?' (a nil value)-

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
"https://ml.wikisource.org/w/index.php?title=ഘടകം:TestingModule&oldid=145097" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്