Module:InterviewUtils

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 09:51, 6 May 2023 by Vish (talk | contribs) (Created page with "local p = {} function p.parse(dateString) local year, month, day local yearOnlyPattern = '^(%d%d%d%d)$' local monthYearPattern = '^(%a+)%s(%d%d%d%d)$' local fullDatePattern = '^(%a+)%s(%d+),%s(%d%d%d%d)$' year = dateString:match(yearOnlyPattern) if not year then month, year = dateString:match(monthYearPattern) if not year then month, day, year = dateString:match(fullDatePattern) end end...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local p = {}

function p.parse(dateString)
    local year, month, day
    local yearOnlyPattern = '^(%d%d%d%d)$'
    local monthYearPattern = '^(%a+)%s(%d%d%d%d)$'
    local fullDatePattern = '^(%a+)%s(%d+),%s(%d%d%d%d)$'
    
    year = dateString:match(yearOnlyPattern)
    
    if not year then
        month, year = dateString:match(monthYearPattern)
        
        if not year then
            month, day, year = dateString:match(fullDatePattern)
        end
    end
    
    return tonumber(year), month, tonumber(day)
end

return p