Module:PageDates: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


function p.dates(frame)
-- Properly handle ordinal suffixes
    local title = mw.title.getCurrentTitle()
local function ordinal(n)
     local page = mw.site.pages[title.fullText]
     local v = n % 100
 
     if v >= 11 and v <= 13 then
     if not page then
         return n .. "th"
         return "Page not found."
     end
     end
 
     local lastDigit = n % 10
     local revisions = page:getRevisions{ limit = 2, dir = "newer" }
    if lastDigit == 1 then return n .. "st"
     if not revisions or #revisions == 0 then
     elseif lastDigit == 2 then return n .. "nd"
        return "No revision history found."
    elseif lastDigit == 3 then return n .. "rd"
    else return n .. "th"
     end
     end
end


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


     local createdTimestamp = revisions[1].timestamp
    -- Extract date parts
     local createdDate = lang:formatDate("j F Y", createdTimestamp)
     local day = tonumber(lang:formatDate("j", timestamp))
     local month = lang:formatDate("F", timestamp)
    local year = lang:formatDate("Y", timestamp)


    -- Get latest revision timestamp (regardless of limit)
     local formatted = string.format("%s %s, %s", month, ordinal(day), year)
     local updatedTimestamp = title:getTimestamp()
     return formatted
    local updatedDate = lang:formatDate("j F Y", updatedTimestamp)
 
    if createdDate == updatedDate then
        return string.format("It was added on %s.", createdDate)
    else
        return string.format("It was added on %s and revised on or before %s.", createdDate, updatedDate)
     end
end
end


return p
return p

Latest revision as of 23:02, 4 June 2025

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

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)
    local lang = mw.language.getContentLanguage()
    local timestamp = frame:preprocess("{{REVISIONTIMESTAMP}}")

    -- Extract date parts
    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