Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:DateCategory

From Gerald R. Lucas

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

local p = {}

local months = {
	["01"] = "January", ["02"] = "February", ["03"] = "March",
	["04"] = "April", ["05"] = "May", ["06"] = "June",
	["07"] = "July", ["08"] = "August", ["09"] = "September",
	["10"] = "October", ["11"] = "November", ["12"] = "December"
}

function p.monthYear(frame)
	local date = frame.args[1]
	if not date or #date < 6 then return '[[Category:Unknown]]' end
	local year = string.sub(date, 1, 4)
	local month = string.sub(date, 5, 6)
	return string.format('[[Category:%s/%s]]', month, year)
end

function p.fullDate(frame)
	local date = frame.args[1]
	if not date or #date < 8 then return '[[Category:UnknownDate]]' end
	local year = string.sub(date, 1, 4)
	local month = string.sub(date, 5, 6)
	local day = string.sub(date, 7, 8)
	return string.format('[[Category:%s-%s-%s]]', year, month, day)
end

function p.prettyDate(frame)
	local date = frame.args[1]
	if not date or tostring(date) == '' or #date < 8 then
		return ''
	end
	local year = string.sub(date, 1, 4)
	local month = months[string.sub(date, 5, 6)] or 'Invalid'
	local day = tonumber(string.sub(date, 7, 8))
	return string.format('%s %d, %s', month, day, year)
end

return p