Module:PageDates: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
local p = {}
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)
function p.dates(frame)
     local lang = mw.language.getContentLanguage()
     local lang = mw.language.getContentLanguage()
     local updatedTimestamp = frame:preprocess("{{REVISIONTIMESTAMP}}")
     local timestamp = frame:preprocess("{{REVISIONTIMESTAMP}}")
     local updatedDate = lang:formatDate("j F Y", updatedTimestamp)
 
    -- Get parts of the date
     local day = tonumber(lang:formatDate("j", timestamp))
    local month = lang:formatDate("F", timestamp)
    local year = lang:formatDate("Y", timestamp)


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


return p
return p