Module:GetYear
From Bahaiworks
Documentation for this module may be created at Module:GetYear/doc
local p = {}
function p.fromDate(frame)
local date = frame.args[1] or ""
-- Clean up commas and trim spaces
date = mw.text.trim(date):gsub(",", "")
-- Extract a 4-digit year
local year = tonumber(date:match("(%d%d%d%d)"))
if year then
-- Calculate the decade
local decade = math.floor(year / 10) * 10
-- Return both the year and the decade categories
return string.format('[[Category:%d]] [[Category:%ss]]', year, decade)
else
return '[[Category:Pages with unknown date formats]]'
end
end
return p