Jump to content

Module:Infobox/dates/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Alex 21 (talk | contribs) at 01:15, 12 April 2016 (Created page with 'local getArgs = require('Module:Arguments').getArgs local p = {} function p.dates(frame) local returnval; local args = getArgs(frame); if table.getn(args)...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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 pr1, m1, d1, y1, su1 = string.match(args['1'], '(.*)(%a+)%s(%d+),%s(%d+)(.*)');
	local pr2, m2, d2, y2, su2 = string.match(args['2'], '(.*)(%a+)%s(%d+),%s(%d+)(.*)');
	if y1 == nil then
		dmy = true;
		pr1, d1, m1, y1, su1 = string.match(args['1'], '(.*)(%d+)%s(%a+)%s(%d+)(.*)');
		pr2, d2, m2, y2, su2 = string.match(args['2'], '(.*)(%d+)%s(%a+)%s(%d+)(.*)');
	end
	
	local dash = '&nbsp;– ';
	if y1 ~= nil and y2 ~= nil then
		su1 = su1 or '';
		su2 = su2 or '';
		
		if y1 == y2 then
			if dmy == false then
				returnval = pr1..m1..' '..d1..su1..dash..pr2..m2..' '..d2..', '..y2..su2;
			else
				returnval = pr1..d1..' '..m1..su1..dash..pr2..d2..' '..m2..' '..y2..su2;
			end
		else
			if dmy == false then
				returnval = pr1..m1..' '..d1..', '..y1..su1..dash..pr2..m2..' '..d2..', '..y2..su2;
			else
				returnval = pr1..d1..' '..m1..' '..y1..su1..dash..pr2..d2..' '..m2..' '..y2..su2;
			end
		end
	else
		returnval = args['1']..dash..args['2'];
	end
	
	return returnval;
end

return p