Module:PageDates

From HighSpell Wiki
Revision as of 23:01, 4 June 2025 by Ryan (talk | contribs)
Jump to navigation Jump to search

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

local p = {}

-- Helper to add "st", "nd", "rd", "th" to day numbers
local function ordinal(n)
    local suffixes = { "th", "st", "nd", "rd" }
    local v = n % 100
    if v >= 11 and v <= 13 then
        return n .. "th"
    end
    return n .. (suffixes[v % 10] or "th")
end

function p.dates(frame)
    local lang = mw.language.getContentLanguage()
    local timestamp = frame:preprocess("{{REVISIONTIMESTAMP}}")

    -- Get parts of the date
    local day = tonumber(lang:formatDate("j", timestamp))
    local month = lang:formatDate("F", timestamp)
    local year = lang:formatDate("Y", timestamp)

    local formatted = string.format("%s %s, %s", month, ordinal(day), year)
    return formatted
end

return p