Moduł:Wikidane/format/Pdata1
Wygląd
< Moduł:Wikidane | format
Dedykowana wtyczka formatująca wartość cechy, w której powinna być podana jedna data wydarzenia.
Przykładowe cechy do obsługi:
Zobacz też
local format = require("Moduł:Wikidane/format/snak").format
local function formatSomeValue(prop, options)
local i18n = {
earliestOnly = "nie wcześniej niż %s",
latestOnly = "nie później niż %s",
both = "pomiędzy %s a\194\160%s"
}
local formatQualifiers = require("Moduł:Wikidane/format/qualifiers")
local earliestDate = formatQualifiers.MINTIME(prop, options, "P1319")
local latestDate = formatQualifiers.MAXTIME(prop, options, "P1326")
if earliestDate and latestDate then
return string.format(i18n.both, earliestDate, latestDate)
elseif earliestDate then
return string.format(i18n.earliestOnly, earliestDate)
elseif latestDate then
return string.format(i18n.latestOnly, latestDate)
end
end
local function hasQualifierEntityId(prop, name, id)
if prop.qualifiers and prop.qualifiers[name] then
for _, v in ipairs(prop.qualifiers[name]) do
if (v.snaktype == "value") and (v.datatype == "wikibase-item") and (v.datavalue.type == "wikibase-entityid") and (v.datavalue.value.id == id) then
return true
end
end
end
return false
end
return {
scope = "prop",
options = {
default = {
separator = ", ",
lastSeparator = " lub\194\160",
linkDate = true,
},
},
format = function(prop, options)
if (prop.type ~= "statement") or not prop.mainsnak then
return
end
if prop.mainsnak.snaktype == "somevalue" then
return formatSomeValue(prop, options)
end
if hasQualifierEntityId(prop, 'P1480', 'Q5727902') then
-- circa
options.linkDate = false
local s = format(prop.mainsnak, options)
return (s and (#s > 0)) and ("ok. "..s) or nil
end
return format(prop.mainsnak, options)
end,
}