Modul:Datum i dob
| Koristi Lua modul: |
U infookvirima
[uredi kôd]Primjer postavljanja modula u {{Infookvir životopis}}:
{{Infookvir
...
| param1 = Rođenje
| vrijednost1 = {{#invoke:Datum i dob|birth|{{{rođenje|}}}|{{{smrt|}}} }}
| param2 = Smrt
| vrijednost2 = {{#invoke:Datum i dob|death|{{{rođenje|}}}|{{{smrt|}}} }}
...
}}
Primjer prikaza u infookviru:
Unos u infookvir {{Infookvir životopis
| rođenje = 30. studenoga 1952.
}}
|
Prikaz
| ||||||||
Unos u infookvir {{Infookvir životopis
| rođenje = 30. studenoga 1952.
| smrt = 25. listopada 2023.
}}
|
Prikaz
| ||||||||||
Upotreba
[uredi kôd]Modul koristi modul za formatiranje datuma koji pronalazi valjani unos datuma, pretvara ga u format ISO 8601, te računa trenutnu dob (ako je unesen samo jedan datum), odnosno dob između dva datuma (ako su unesena dva datuma).
Funkcija birth prikazuje datum rođenja te označava datum kao rođendan (bday) u HTML kodu stranice, a funkcija death prikazuje datum smrti.
Primjeri
[uredi kôd]Cjeloviti datumi
[uredi kôd]{{#invoke:Datum i dob|birth|30. srpnja 1961.}}→ 30. srpnja 1961. (64 god.){{#invoke:Datum i dob|death|30. srpnja 1961.|1. studenoga 2023.}}→ 1. studenoga 2023. (62 god.)
Nepotpuni datumi
[uredi kôd]{{#invoke:Datum i dob|birth|srpanj 1961.}}→ srpanj 1961. (64 god.){{#invoke:Datum i dob|death|srpanj 1961.|studeni 2023.}}→ studeni 2023. (62 god.){{#invoke:Datum i dob|birth|1961.}}→ 1961. (64–65 god.){{#invoke:Datum i dob|death|1961.|2023.}}→ 2023. (61–62 god.)
Kombinacije
[uredi kôd]{{#invoke:Datum i dob|death|1959.|23. rujna 2019.}}→ 23. rujna 2019. (59–60 god.){{#invoke:Datum i dob|death|30. kolovoza 1960.|2024.}}→ 2024. (63–64 god.)
Bilješke
[uredi kôd]Modul ne treba djelovati ako dob već izračunavaju predlošci poput {{datum rođenja i godine}} ili {{datum smrti i godine}}.
{{#invoke:Datum i dob|birth|{{datum rođenja i godine|1996|7|17}}}} → 17. srpnja 1996.
Dodavanje izvora nakon datuma je podržano.
{{#invoke:Datum i dob|birth|30. kolovoza 1960.<ref>...</ref>}} → 30. kolovoza 1960.[1] (65 god.)
Modul ne djeluje ako se oko datuma nalazi bilokakav tekst. U infookvirima stoga unos u parametrima mora biti isključivo datum.
{{#invoke:Datum i dob|birth|Zagreb, 19. rujna 1960.}} → Zagreb, 19. rujna 1960.
Dob se ne prikazuje ako je izračunato da je osoba starija od 122 godine.
{{#invoke:Datum i dob|birth|25. lipnja 1900.}} → 25. lipnja 1900.
Kategorije za praćenje
[uredi kôd]
local p = {}
local formatirajDatum = require('Module:Formatiraj datum')
local function getMinMaxIso(isoDatum)
local y, m, d = isoDatum:match('(%d+)-(%d+)-(%d+)')
if y then
return isoDatum, isoDatum
end
y, m = isoDatum:match('(%d+)-(%d+)')
if y and m then
local maxDan = formatirajDatum.getMaxDan(y, m)
local earliest = string.format("%s-%s-01", y, m)
local latest = string.format("%s-%s-%02d", y, m, maxDan)
return earliest, latest
end
y = isoDatum:match('(%d+)')
if y then
return y .. "-01-01", y .. "-12-31"
end
return nil, nil
end
local function CalculateAge(isoPocetak, isoKraj)
if not isoPocetak or not isoKraj then return nil end
local p_min, p_max = getMinMaxIso(isoPocetak)
local k_min, k_max = getMinMaxIso(isoKraj)
if not p_min or not k_max then return nil end
local y1_min, m1_min, d1_min = p_max:match('(%d+)-(%d+)-(%d+)')
local y2_min, m2_min, d2_min = k_min:match('(%d+)-(%d+)-(%d+)')
y1_min, m1_min, d1_min = tonumber(y1_min), tonumber(m1_min), tonumber(d1_min)
y2_min, m2_min, d2_min = tonumber(y2_min), tonumber(m2_min), tonumber(d2_min)
local minGodine = y2_min - y1_min
if (m2_min < m1_min) or (m2_min == m1_min and d2_min < d1_min) then
minGodine = minGodine - 1
end
local y1_max, m1_max, d1_max = p_min:match('(%d+)-(%d+)-(%d+)')
local y2_max, m2_max, d2_max = k_max:match('(%d+)-(%d+)-(%d+)')
y1_max, m1_max, d1_max = tonumber(y1_max), tonumber(m1_max), tonumber(d1_max)
y2_max, m2_max, d2_max = tonumber(y2_max), tonumber(m2_max), tonumber(d2_max)
local maxGodine = y2_max - y1_max
if (m2_max < m1_max) or (m2_max == m1_max and d2_max < d1_max) then
maxGodine = maxGodine - 1
end
if minGodine < 0 or maxGodine > 122 then
return nil
end
if minGodine == maxGodine then
if minGodine > 0 then
return string.format("%d god.", minGodine)
else
local mjeseci = (y2_max - y1_max) * 12 + (m2_max - m1_max)
if d2_max < d1_max then mjeseci = mjeseci - 1 end
if mjeseci < 0 then mjeseci = 0 end
return string.format("%d mj.", mjeseci)
end
else
return string.format("%d–%d god.", minGodine, maxGodine)
end
end
function p.birth(frame)
local args = frame.args
local birthDate = mw.text.trim(args[1] or "")
local deathDate = mw.text.trim(args[2] or "")
if birthDate == "" then return "" end
if string.find(birthDate, 'god', 1, true) or string.find(birthDate, 'godina', 1, true) or string.find(birthDate, 'mj', 1, true) or string.find(birthDate, 'ForceAgeToShow', 1, true) or string.find(birthDate, 'dob', 1, true) then
return birthDate
end
local bdaySpan = formatirajDatum.formatDateWithClass{ args = { [1] = birthDate, [2] = 'bday' } }
local ISObirth = formatirajDatum.getISO{ args = { [1] = birthDate } }
local visiblePart = birthDate
local category = ""
if deathDate == "" then
if ISObirth then
local today = mw.getContentLanguage():formatDate('Y-m-d')
local age = CalculateAge(ISObirth, today)
if age then
visiblePart = visiblePart .. " (" .. age .. ")"
if mw.title.getCurrentTitle().namespace == 0 then
category = '[[Kategorija:Stranice s automatskim izračunom dobi osobe]]'
end
else
if mw.title.getCurrentTitle().namespace == 0 then
category = '[[Kategorija:Stranice bez izračuna dobi osobe]]'
end
end
else
if mw.title.getCurrentTitle().namespace == 0 then
category = '[[Kategorija:Stranice bez izračuna dobi osobe]]'
end
end
end
if bdaySpan ~= "" then
return bdaySpan .. " " .. visiblePart .. category
else
return visiblePart .. category
end
end
function p.death(frame)
local args = frame.args
local birthDate = mw.text.trim(args[1] or "")
local deathDate = mw.text.trim(args[2] or "")
if deathDate == "" then
return ""
end
if string.find(deathDate, 'god', 1, true) or string.find(deathDate, 'godina', 1, true) or string.find(deathDate, 'mj', 1, true) or string.find(deathDate, 'ForceAgeToShow', 1, true) or string.find(deathDate, 'dob', 1, true) then
return deathDate
end
if string.find(birthDate, 'god', 1, true) or string.find(birthDate, 'godina', 1, true) or string.find(birthDate, 'mj', 1, true) or string.find(birthDate, 'ForceAgeToShow', 1, true) or string.find(birthDate, 'dob', 1, true) then
return deathDate
end
local ISObirth = formatirajDatum.getISO{ args = { [1] = birthDate } }
local ISOdeath = formatirajDatum.getISO{ args = { [1] = deathDate } }
local display = deathDate
local category = ""
if ISObirth and ISOdeath then
local age = CalculateAge(ISObirth, ISOdeath)
if age then
display = display .. " (" .. age .. ")"
if mw.title.getCurrentTitle().namespace == 0 then
category = '[[Kategorija:Stranice s automatskim izračunom dobi osobe]]'
end
else
if mw.title.getCurrentTitle().namespace == 0 then
category = '[[Kategorija:Stranice bez izračuna dobi osobe]]'
end
end
else
if mw.title.getCurrentTitle().namespace == 0 then
category = '[[Kategorija:Stranice bez izračuna dobi osobe]]'
end
end
return display .. category
end
return p