From Wikipedia, the free encyclopedia

--[[--------------------------< F O R W A R D   D E C L A R A T I O N S >--------------------------------------

]]



local cfg;																		-- table of tables imported from slected Module:Citation/CS1/Configuration





local function _convert_year(val, local_digits)

	val = mw.ustring.gsub (val, '%d', local_digits);			-- translate 'local' digits to Western 0-9

	if val:match("^%d+$") then

		val = val-543;

		-- convert year to 4 digits to prevent it being interpreted as day in en module

		if val<0 then

			return false; -- TODO: handle this

		--elseif val<1 then

		--	val='000'..val;

		elseif val<10 then -- this should be faster than formatDate()?

			val='000'..val;

		elseif val<100 then

			val='00'..val;

		elseif val<1000 then

			val='0'..val;

		end

		return val;

	end

	return false;

end



local en_month_name = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'};

local function _convert_local_date(val, date_names_local, local_digits)

	local dmy = mw.text.split(val, '%s+');

	if #dmy == 3 then

		dmy2 = date_names_local.longdmy2]] or date_names_local.shortdmy2]];

		if dmy2 then

			--dmy[1] = tonumber(dmy[1]); if dmy[1]<10 then dmy[1]='0'..dmy[1]; end -- this should be faster than formatDate()

			--dmy[2] = tonumber(dmy[2]); if dmy[2]<10 then dmy[2]='0'..dmy[2]; end

			--return dmy[3]-543 ..'-'..dmy[2]..'-'..dmy[1];

			dmy1 = mw.ustring.gsub (dmy1], '%d', local_digits);			-- translate 'local' digits to Western 0-9

			-- always interprete dmy[1] as day

			if dmy1]:match("^%d%d?$") then

				dmy1 = tonumber(dmy1]); if dmy1>31 or dmy1<1 then return val; end

				dmy3 = _convert_year(dmy3], local_digits);

				if dmy3 then

					return dmy1..' '..en_month_namedmy2]]..' '..dmy3];

				end

				return val;

			end

			return val;

		end

		return val;

	elseif #dmy == 2 then

		local dmy1 = date_names_local.longdmy1]] or date_names_local.shortdmy1]];

		if dmy1 then

			dmy2 = _convert_year(dmy2], local_digits);

			if dmy2 then

				return en_month_namedmy1..' '..dmy2];

			end

			return val;

		end

		dmy2 = date_names_local.longdmy2]] or date_names_local.shortdmy2]];

		if dmy2 then

			dmy1 = mw.ustring.gsub (dmy1], '%d', local_digits);			-- translate 'local' digits to Western 0-9

			-- always interprete dmy[1] as day

			if dmy1]:match("^%d%d?$") then

				dmy1 = tonumber(dmy1]); if dmy1>31 or dmy1<1 then return val; end

				return dmy1..' '..en_month_namedmy2]];

			end

			return val;

		end

		return val;

	elseif #dmy == 1 then

		dmy1 = date_names_local.longdmy1]] or date_names_local.shortdmy1]];

		if dmy1 then

			return en_month_namedmy1]];

		end

		return val;

	else

		return val;

	end

end



--[[



Some local wiki use non-Gregorian calendar.

Use this function to convert local non-Gregorian calendar to Gregorian calendar



]]



local function convert_local_date(k, val)

	if 'year'==k then

		--return 2010;

		return val;

	--elseif 'date'==k or 'access-date'==k or 'archive-date'==k or 'doi-broken-date'==k or 'embargo'==k or 'lay-date'==k or 'publication-date'==k then

	--	return _convert_local_date(val, cfg.date_names['local'], cfg.date_names.local_digits);

	--elseif 'embargo'==k then

	--	return val;

	else

mw.log(k, _convert_local_date(val, cfg.date_names'local'], cfg.date_names.local_digits));

		return _convert_local_date(val, cfg.date_names'local'], cfg.date_names.local_digits);

		--return val;

	end

	--return '2010-04-30';

	--return val;

end



--[[--------------------------< S E T _ S E L E C T E D _ M O D U L E S >--------------------------------------



Sets local imported functions table to same (live or sandbox) as that used by the other modules.



]]



local function set_selected_modules (cfg_table_ptr, utilities_page_ptr)

	cfg = cfg_table_ptr;														-- import tables from selected Module:Citation/CS1/Configuration

end





--[[--------------------------< E X P O R T S >----------------------------------------------------------------

]]



return 	{

	convert_local_date = convert_local_date,

	set_selected_modules = set_selected_modules,

	_convert_local_date = _convert_local_date, -- TODO: split to another separated module?

	_convert_local_year = _convert_year, -- TODO: split to another separated module?

}
From Wikipedia, the free encyclopedia

--[[--------------------------< F O R W A R D   D E C L A R A T I O N S >--------------------------------------

]]



local cfg;																		-- table of tables imported from slected Module:Citation/CS1/Configuration





local function _convert_year(val, local_digits)

	val = mw.ustring.gsub (val, '%d', local_digits);			-- translate 'local' digits to Western 0-9

	if val:match("^%d+$") then

		val = val-543;

		-- convert year to 4 digits to prevent it being interpreted as day in en module

		if val<0 then

			return false; -- TODO: handle this

		--elseif val<1 then

		--	val='000'..val;

		elseif val<10 then -- this should be faster than formatDate()?

			val='000'..val;

		elseif val<100 then

			val='00'..val;

		elseif val<1000 then

			val='0'..val;

		end

		return val;

	end

	return false;

end



local en_month_name = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'};

local function _convert_local_date(val, date_names_local, local_digits)

	local dmy = mw.text.split(val, '%s+');

	if #dmy == 3 then

		dmy2 = date_names_local.longdmy2]] or date_names_local.shortdmy2]];

		if dmy2 then

			--dmy[1] = tonumber(dmy[1]); if dmy[1]<10 then dmy[1]='0'..dmy[1]; end -- this should be faster than formatDate()

			--dmy[2] = tonumber(dmy[2]); if dmy[2]<10 then dmy[2]='0'..dmy[2]; end

			--return dmy[3]-543 ..'-'..dmy[2]..'-'..dmy[1];

			dmy1 = mw.ustring.gsub (dmy1], '%d', local_digits);			-- translate 'local' digits to Western 0-9

			-- always interprete dmy[1] as day

			if dmy1]:match("^%d%d?$") then

				dmy1 = tonumber(dmy1]); if dmy1>31 or dmy1<1 then return val; end

				dmy3 = _convert_year(dmy3], local_digits);

				if dmy3 then

					return dmy1..' '..en_month_namedmy2]]..' '..dmy3];

				end

				return val;

			end

			return val;

		end

		return val;

	elseif #dmy == 2 then

		local dmy1 = date_names_local.longdmy1]] or date_names_local.shortdmy1]];

		if dmy1 then

			dmy2 = _convert_year(dmy2], local_digits);

			if dmy2 then

				return en_month_namedmy1..' '..dmy2];

			end

			return val;

		end

		dmy2 = date_names_local.longdmy2]] or date_names_local.shortdmy2]];

		if dmy2 then

			dmy1 = mw.ustring.gsub (dmy1], '%d', local_digits);			-- translate 'local' digits to Western 0-9

			-- always interprete dmy[1] as day

			if dmy1]:match("^%d%d?$") then

				dmy1 = tonumber(dmy1]); if dmy1>31 or dmy1<1 then return val; end

				return dmy1..' '..en_month_namedmy2]];

			end

			return val;

		end

		return val;

	elseif #dmy == 1 then

		dmy1 = date_names_local.longdmy1]] or date_names_local.shortdmy1]];

		if dmy1 then

			return en_month_namedmy1]];

		end

		return val;

	else

		return val;

	end

end



--[[



Some local wiki use non-Gregorian calendar.

Use this function to convert local non-Gregorian calendar to Gregorian calendar



]]



local function convert_local_date(k, val)

	if 'year'==k then

		--return 2010;

		return val;

	--elseif 'date'==k or 'access-date'==k or 'archive-date'==k or 'doi-broken-date'==k or 'embargo'==k or 'lay-date'==k or 'publication-date'==k then

	--	return _convert_local_date(val, cfg.date_names['local'], cfg.date_names.local_digits);

	--elseif 'embargo'==k then

	--	return val;

	else

mw.log(k, _convert_local_date(val, cfg.date_names'local'], cfg.date_names.local_digits));

		return _convert_local_date(val, cfg.date_names'local'], cfg.date_names.local_digits);

		--return val;

	end

	--return '2010-04-30';

	--return val;

end



--[[--------------------------< S E T _ S E L E C T E D _ M O D U L E S >--------------------------------------



Sets local imported functions table to same (live or sandbox) as that used by the other modules.



]]



local function set_selected_modules (cfg_table_ptr, utilities_page_ptr)

	cfg = cfg_table_ptr;														-- import tables from selected Module:Citation/CS1/Configuration

end





--[[--------------------------< E X P O R T S >----------------------------------------------------------------

]]



return 	{

	convert_local_date = convert_local_date,

	set_selected_modules = set_selected_modules,

	_convert_local_date = _convert_local_date, -- TODO: split to another separated module?

	_convert_local_year = _convert_year, -- TODO: split to another separated module?

}

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook