Jump to content

Module:Person date

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Zackmann08 (talk | contribs) at 07:37, 17 September 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function is_valid_date(str)
	local months = '(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)'
	months = '[Jan|January|Feb|February|Mar|March|Apr|April|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December]*'
	regex = '^%d+%s*'..months..'*%s*%d%d%d%d' 
	mw.log('-----')
	mw.log(str)
	
	
	match = mw.ustring.match(str,'^%d+%s*'..months..'%s*%d%d%d%d') or mw.ustring.match(str,'^'..months..'%s*%d+,%s*%d%d%d%d') or mw.ustring.match(str,'^'..months..'%s*%d%d%d%d')
	if match ~= nil then
		mw.log(match)
		return match
	end
	
	return match
end

function is_year_only(str)
	return mw.ustring.match(str, '^%s*%d%d%d%d%s*$')
end

function parse_birth(frame, args)
	local birth_date = args[1] or ''
	local death_date = args[2] or ''
	local original = birth_date
	
	if is_valid_date(birth_date) then
		if death_date == '' then
			return frame:expandTemplate{ title = 'Birth date and age text', args = {birth_date}}
		else
			return frame:expandTemplate{ title = 'Birth date', args = {birth_date}}
		end
	end
	if is_year_only(birth_date) then
		if death_date == '' then
			return frame:expandTemplate{ title = 'bya', args = {birth_date}}
		else
			return frame:expandTemplate{ title = 'birth year', args = {birth_date}}
		end
	end
	
	return original
end

function p.birth(frame)
	return parse_birth(frame, frame.args[1] and frame.args or frame:getParent().args)
end

function p.death(frame)
	return parse_death(frame, frame.args[1] and frame.args or frame:getParent().args)
end



return p