Module:Date: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
initial
 
Sur (talk | contribs)
m format_date > p.format_date
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
}
}


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

Latest revision as of 15:34, 9 October 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 into month, day, and year
    local month, day, year = 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