Module:ShortDate

Από τη Βικιπαίδεια, την ελεύθερη εγκυκλοπαίδεια
Documentation icon Τεκμηρίωση module[δημιουργία]
local p = {}

local function Set(list)
    local set = {}
    for _, l in ipairs(list) do set[l] = true end
    return set
end

-- οι ιδιότητες με τύπο δεδομένων time https://www.wikidata.org/wiki/Category:Properties_with_time-datatype
local timeProps = Set{'P569', 'P570', 'P571', 'P574', 'P575', 'P576', 'P577', 'P578', 'P580', 'P582', 'P585', 'P606', 'P619', 'P620', 'P621', 'P622',
                      'P729', 'P730', 'P746', 'P813', 'P1191', 'P1249', 'P1317', 'P1319', 'P1326', 'P1619', 'P1636', 'P1734', 'P2031', 'P2032',
                      'P2285', 'P2310', 'P2311', 'P2669', 'P2754', 'P2913', 'P2960'}

function p.get(frame)
    local args = {}
    if frame == mw.getCurrentFrame() then
        args = frame:getParent().args
        for k, v in pairs(frame.args) do
            args[k] = v
        end
    else
        args = frame
    end
    return p._get(args)
end

function p._get(args)
    local wd = require('Module:Wikidata')
    if not timeProps[args.property] then
        return error('Η ιδιότητα ' .. args.property .. ' δεν βρίσκεται στη λίστα αποδεκτών ιδιοτήτων')
    end
    local claims = wd.getClaims(args)
    if not claims then
        return nil
    end
    date = wd.getDate(claims[1])
    return date.day .. '/' .. date.month .. '/' .. date.year
end

return p