Roovet Articles

Module:Infobox/dates

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

-- Module:Infobox/dates — safe stub to satisfy `require`
-- Replace with the real module when convenient.

local function getArg(frame, keys)
    if type(frame) ~= 'table' then return '' end
    local a = frame.args or (frame.getParent and frame:getParent() and frame:getParent().args) or {}
    for _, k in ipairs(keys) do
        if a[k] and a[k] ~= '' then return a[k] end
    end
    return ''
end

local p = {}

-- Common entrypoints some stacks expect:
function p.main(frame)                      -- fallback
    return getArg(frame, {'date', '1'}) or ''
end

function p.formatDate(frame)                -- returns input as-is
    return getArg(frame, {'date', '1'}) or ''
end

function p.formatDateRange(frame)           -- join two dates with an en dash
    local d1 = getArg(frame, {'from', 'start', 'date1', '1'})
    local d2 = getArg(frame, {'to', 'end', 'date2', '2'})
    if d1 ~= '' and d2 ~= '' then
        return tostring(d1) .. ' – ' .. tostring(d2)
    end
    return d1 ~= '' and d1 or d2
end

-- Be forgiving: any other function name returns a harmless no-op.
return setmetatable(p, {
    __index = function()
        return function() return '' end
    end
})