Modul:Ukens konkurranse

uk = {}

function uk.navn(frame)
    local year
    local week
    if frame.args[1] == nil then
        return uk.naa(frame)
    end
    if frame.args[2] == nil then
        local spl = mw.text.split(frame.args[1], '-', true)
        year = tonumber(spl[1])
        week = tonumber(spl[2])
    else
        year = tonumber(frame.args[1])
        week = tonumber(frame.args[2])
    end
    local modname = 'Module:Ukens konkurranse-liste ' .. year
    local topics = require(modname)
    local topic = topics[week]
    return topic
end

function uk.fortid(fname)
    fname.args[1] = - tonumber(fname.args[1])
    return uk.fremtid(fname)
end

function uk.naa(frame)
    local lang = mw.getContentLanguage()
    local week = tonumber(lang:formatDate('W', now, true))
    local year = tonumber(lang:formatDate('o', now, true))
    local modname = 'Module:Ukens konkurranse-liste ' .. year
    local topics = require(modname)
    local topic = topics[week]
    return topic
end

function uk.fremtid(frame)
    local lang = mw.getContentLanguage()
    local diff = frame.args[1]
    local week = tonumber(lang:formatDate('W', diff..' week', true))
    local year = tonumber(lang:formatDate('o', diff..' week', true))
    local modname = 'Module:Ukens konkurranse-liste ' .. year
    local topics = require(modname)
    local topic = topics[week]
    return topic
end

return uk