Call of Duty Esports Wiki
Call of Duty Esports Wiki

Documentation for this module may be created at Module:InfoboxUtil/doc

local lang = mw.getLanguage('en')
local util_time = require('Module:TimeUtil')
local Stat = require('Module:StatClass')

local p = {}
local h = {}
function p.makeBday(y, m, d, death)
	-- expect death to be a string yyyy-mm-dd
	if not ((m and d) or death) then
		return {}
	if not m then m = '1' end
	if not d then d = '1' end
	local m = tostring(util_time.monthNameToNumber[m])
	if #m == 1 then
		m = '0' .. m
	if #d == 1 then
		d = '0' .. d
	local full = y and m and d
	if not full then
		y = 2014 -- we won't print this, just a random year so that the formatting works
	local str = ('%s-%s-%s'):format(y,m,d)
	local tbl = {
		full = full,
		age = full and util_time.age(str, death),
		display = h.pickAndGetDisplay(full, str, death),
		store = death or (full and str) or ''
	tbl.displayandage = tbl.display .. (full and (' (age %s)'):format(tbl.age) or '')
	return tbl

function h.pickAndGetDisplay(full, str, death)
	if death then return h.getDisplay(death, true) end
	return h.getDisplay(str, full)

function h.getDisplay(time, full)
	return full and lang:formatDate('F j, Y', time) or lang:formatDate('F j', time)

function p.getFile(arg, default)
	local title = arg and mw.title.makeTitle('Media',arg or '')
	return title and title.exists and arg or default

function p.statDisplays(tbl)
	local ret = {}
	for _, v in ipairs(tbl) do
		ret[v] = Stat(v):flair()
	return ret

return p