Timeline
Jump to navigation
Jump to search
| Line 16: | Line 16: | ||
for num, row in pairs( peopleBirthDates ) do | for num, row in pairs( peopleBirthDates ) do | ||
local timestamp = tonumber(lang:formatDate("U", | local date = row["Person:Date of birth"] | ||
local timestamp = tonumber(lang:formatDate("U", date)) | |||
if not dates[timestamp] then | if not dates[timestamp] then | ||
dates[timestamp] = {} | dates[timestamp] = {} | ||
end | end | ||
dates[timestamp][#dates[timestamp]] = { | dates[timestamp][#dates[timestamp]] = { | ||
| Line 48: | Line 49: | ||
for _, key in ipairs( keys ) do | for _, key in ipairs( keys ) do | ||
result = result .. lang:formatDate("Y-m-d", tostring(key)) | result = result .. lang:formatDate("Y-m-d", tostring(key/1000)) | ||
for num, row in pairs( dates[key] ) do | for num, row in pairs( dates[key] ) do | ||
result = result .. row[1] | result = result .. row[1] | ||
Revision as of 20:50, 10 November 2022
Documentation for this module may be created at Module:Timeline/doc
local p = {}
local lang = mw.language.new("en")
function p.render( frame )
if not mw.smw then
return "mw.smw module not found"
end
local dates = {}
local peopleBirthDates = mw.smw.ask("[[Category:Person]]|?Person:Name|?Person:Date of birth")
local peopleDeathDates = mw.smw.ask("[[Category:Person]]|?Person:Name|?Person:Date of death")
local compositionDates = mw.smw.ask("[[Category:Composition]]|?Person:Title|?Composition:Date")
local result = ""
for num, row in pairs( peopleBirthDates ) do
local date = row["Person:Date of birth"]
local timestamp = tonumber(lang:formatDate("U", date))
if not dates[timestamp] then
dates[timestamp] = {}
end
dates[timestamp][#dates[timestamp]] = {
row[1] .. " was born"
}
end
for num, row in pairs( peopleDeathDates ) do
local timestamp = tonumber(lang:formatDate("U", row["Person:Date of death"]))
if not dates[timestamp] then
dates[timestamp] = {}
end
dates[timestamp][#dates[timestamp]] = {
row[1] .. " died"
}
end
for num, row in pairs( compositionDates ) do
local timestamp = tonumber(lang:formatDate("U", row["Composition:Date"]))
if not dates[timestamp] then
dates[timestamp] = {}
end
dates[timestamp][#dates[timestamp]] = {
row[1] .. " was composed"
}
end
local keys = {}
for k in pairs(dates) do table.insert(keys, k) end
table.sort(keys)
for _, key in ipairs( keys ) do
result = result .. lang:formatDate("Y-m-d", tostring(key/1000))
for num, row in pairs( dates[key] ) do
result = result .. row[1]
end
end
return result
end
return p