Module:PageDates: Difference between revisions

No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
-- Properly handle ordinal suffixes
local function ordinal(n)
    local v = n % 100
    if v >= 11 and v <= 13 then
        return n .. "th"
    end
    local lastDigit = n % 10
    if lastDigit == 1 then return n .. "st"
    elseif lastDigit == 2 then return n .. "nd"
    elseif lastDigit == 3 then return n .. "rd"
    else return n .. "th"
    end
end


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


     -- Only thing Scribunto gives us reliably:
     -- Extract date parts
     local updatedTimestamp = title:getTimestamp()
    local day = tonumber(lang:formatDate("j", timestamp))
     local updatedDate = lang:formatDate("j F Y", updatedTimestamp)
     local month = lang:formatDate("F", timestamp)
     local year = lang:formatDate("Y", timestamp)


     -- Since we can't get the true creation timestamp, fallback phrasing
     local formatted = string.format("%s %s, %s", month, ordinal(day), year)
    return string.format("This page was last updated on %s.", updatedDate)
    return formatted
end
end


return p
return p