Module:PageDates: Difference between revisions

No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


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


Line 15: Line 19:
     local timestamp = frame:preprocess("{{REVISIONTIMESTAMP}}")
     local timestamp = frame:preprocess("{{REVISIONTIMESTAMP}}")


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