Jump to content

Module:Infobox/dates

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Alex 21 (talk | contribs) at 01:48, 11 April 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.dates(frame)
	local returnval;
	local args = getArgs(frame);
	
	if table.getn(args) < 2 then
		if args['1'] == nil and args['2'] == nil then
			return '';
		elseif args['1'] == nil then 
			return args['2'];
		elseif args['2'] == nil then 
			return args['1'];
		end
	end
	
	args['1'] = args['1']:gsub("&nbsp;"," ");
	args['2'] = args['2']:gsub("&nbsp;"," ");
	
	local dmy = false;
	local m1, d1, y1, ex1 = string.match(args['1'], '(%a+)%s(%d+),%s(%d+)(.*)');
	local m2, d2, y2, ex2 = string.match(args['2'], '(%a+)%s(%d+),%s(%d+)(.*)');
	if y1 == nil then
		dmy = true;
		d1, m1, y1, ex1 = string.match(args['1'], '(%d+)%s(%a+)%s(%d+)(.*)');
		d2, m2, y2, ex2 = string.match(args['2'], '(%d+)%s(%a+)%s(%d+)(.*)');
	end
	
	if y1 ~= nil and y2 ~= nil then
		ex1 = ex1 or '';
		ex2 = ex2 or '';
		
		if y1 == y2 then
			if dmy == false then
				returnval = m1..' '..d1..ex1..'&nbsp;–&nbsp;'..m2..' '..d2..', '..y2..ex2;
			else
				returnval = d1..' '..m1..ex1..'&nbsp;–&nbsp;'..d2..' '..m2..' '..y2..ex2;
			end
		else
			if dmy == false then
				returnval = m1..' '..d1..', '..y1..ex1..'&nbsp;–&nbsp;'..m2..' '..d2..', '..y2..ex2;
			else
				returnval = d1..' '..m1..' '..y1..ex1..'&nbsp;–&nbsp;'..d2..' '..m2..' '..y2..ex2;
			end
		end
	else
		returnval = args['1']..'&nbsp;–&nbsp;'..args['2'];
	end
	
	--return returnval:gsub(" ","&nbsp;");
	return returnval;
end

return p