More actions
For the EntryHead template. |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | 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) | 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 | end | ||
function p.fullDate(frame) | 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 | end | ||
return p | return p |
Latest revision as of 09:25, 29 March 2025
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