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 13:23, 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 p1, m1, d1, y1, ex1 = string.match(args['1'], '(.*)(%a+)%s(%d+),%s(%d+)(.*)');
	local p2, m2, d2, y2, ex2 = string.match(args['2'], '(.*)(%a+)%s(%d+),%s(%d+)(.*)');
	if y1 == nil then
		dmy = true;
		p1, d1, m1, y1, ex1 = string.match(args['1'], '(.*)(%d+)%s(%a+)%s(%d+)(.*)');
		p2, 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 '';
		local dash = '&nbsp;– ';
		
		if y1 == y2 then
			if dmy == false then
				returnval = p1..' '..m1..' '..d1..ex1..dash..p2..' '..m2..' '..d2..', '..y2..ex2;
			else
				returnval = p1..' '..d1..' '..m1..ex1..dash..p2..' '..d2..' '..m2..' '..y2..ex2;
			end
		else
			if dmy == false then
				returnval = p1..' '..m1..' '..d1..', '..y1..ex1..dash..p2..' '..m2..' '..d2..', '..y2..ex2;
			else
				returnval = p1..' '..d1..' '..m1..' '..y1..ex1..dash..p2..' '..d2..' '..m2..' '..y2..ex2;
			end
		end
	else
		returnval = args['1']..dash..args['2'];
	end
	
	return returnval;
end

return p