FANDOM


-- <pre> Creates dated statements 
local p={}
local u = require("module:utility")
local dateHelper = require("Module:Date")
local tValidMonths = {janvier=1,fevrier=2,mars=3,avril=4,
        mai=5,juin=6,juillet=7,aout=8,septembre=9,octobre=10,novembre=11,decembre=12}
 
function p.main(frame)
    local tArgs =  u.getArgs(frame)
 
    if not tArgs then
        return
    end
 
    local sYear = tonumber(tArgs[1]) 
    local sMonth = string.lower(tArgs[2] or"")
    local sDay = tonumber(tArgs[3] )
    local lc = tArgs["lc"] 
    local prefix = ""
    local lang = mw.language.new("fr")
    local sFormat = "Y"
    local x =dateHelper()
 
    local isYear,isMonth,isDay =u.isValidDate(sYear,sMonth,sDay)
    if not isYear then 
        return error("Date non valide, l'année est érronée.")
    end
 
    if isMonth then
        sMonth = tonumber(sMonth) or tValidMonths[sMonth]
        sFormat = "F " .. sFormat 
        if isDay then 
            sFormat = "d " .. sFormat 
 
            prefix = "Au "
            if lc then
                prefix = "au "
            end
        else
            sDay = os.date("%d")
 
            prefix = "En "
            if lc then
                prefix = "en "
            end
        end
 
    else 
        sDay = sDay or os.date("%d") 
        sMonth = os.date("%m")
    end
 
       local sDefOutput = prefix .. lang:formatDate(sFormat,sYear.."/"..sMonth.."/"..sDay)
       local sOutput = tArgs["alt"] or sDefOutput 
    return sOutput 
end
 
return p