مۆدیوول:Sandbox/CdRBot/Test

لە ئینسایکڵۆپیدیای ئازادی ویکیپیدیاوە
Jump to navigation Jump to search
بەڵگەدارکردنی مۆدیوول[دروست بکە]
local p ={}
local lang = mw.getContentLanguage();
p.test = function (frame)
	--print("Language = ",lang)
	chap = ""
	for i,v in pairs(lang) do
		chap = chap .. "type(i, v) = {" .. type(i) .."," .. type(v) .. "} > "
		if (type(i) == "string") then
			chap = chap .." i = " .. i .."<br/>"
		end
		if (type(v) == "string") then
			chap = chap .. " v = " .. v .."<br/>"
		end
	end
	dFormat = lang.formatDate
	--print("Date Format = ",dFormat)
	return type(dFormat) .. ", ".. chap
end

p.is_valid_accessdate = function (accessdate)
	local good1, good2;
	local access_ts, tomorrow_ts;												-- to hold Unix time stamps representing the dates

	good1, access_ts = pcall (lang.formatDate, accessdate );			-- convert accessdate value to Unix timestamp 
	good2, tomorrow_ts = pcall (lang.formatDate, 'today + 2 days' );	-- today midnight + 2 days is one second more than all day tomorrow
	
	if good1 and good2 then														-- lang.formatDate() returns a timestamp in the local script which which tonumber() may not understand
		access_ts = tonumber (access_ts) or lang:parseFormattedNumber (access_ts);		-- convert to numbers for the comparison;
		tomorrow_ts = tonumber (tomorrow_ts) or lang:parseFormattedNumber (tomorrow_ts);
	else
		return "goods" .. access_ts;															-- 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 "WP Start";															-- accessdate out of range
	end
end

return p