Jump to content

Module:Date: Difference between revisions

From Deadlock Wiki
Sur (talk | contribs)
m format_date > p.format_date
Sur (talk | contribs)
m input date format from mm-dd-yyyy -> yyyy-mm-dd
 
Line 7: Line 7:


function p.format_date(date_string)
function p.format_date(date_string)
     -- Split the date string into month, day, and year
     -- Split the date string
     local month, day, year = date_string:match("(%d%d)-(%d%d)-(%d%d%d%d)")
     local year, month, day = date_string:match("(%d%d%d%d)-(%d%d)-(%d%d)")
      
      
     if month and day and year then
     if month and day and year then

Latest revision as of 21:59, 22 December 2024

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

local p = {}

local months = {
    "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"
}

function p.format_date(date_string)
    -- Split the date string
    local year, month, day = date_string:match("(%d%d%d%d)-(%d%d)-(%d%d)")
    
    if month and day and year then
        -- Convert month number to month name
        local month_name = months[tonumber(month)]
        -- Convert day (removing leading zero if needed)
        local day_num = tonumber(day)
        -- Return formatted date
        return string.format("%s %d, %s", month_name, day_num, year)
    else
        -- Return the original string if the format doesn't match
        return date_string
    end
end

return p