Timeline

From Young Beethoven
Jump to navigation Jump to search
Line 20: Line 20:
if not dates[timestamp] then
if not dates[timestamp] then
dates[timestamp] = {}
dates[timestamp] = {}
dates[timestamp]["date"] = date
end
end
dates[timestamp][#dates[timestamp]] = {
dates[timestamp][#dates[timestamp]] = {
Line 26: Line 27:
end
end
for num, row in pairs( peopleDeathDates ) do
for num, row in pairs( peopleDeathDates ) do
local timestamp = tonumber(lang:formatDate("U", row["Person:Date of death"]))
local date = row["Person:Date of death"]
local timestamp = tonumber(lang:formatDate("U", date))
if not dates[timestamp] then
if not dates[timestamp] then
dates[timestamp] = {}
dates[timestamp] = {}
dates[timestamp]["date"] = date
end
end
dates[timestamp][#dates[timestamp]] = {
dates[timestamp][#dates[timestamp]] = {
Line 35: Line 38:
end
end
for num, row in pairs( compositionDates ) do
for num, row in pairs( compositionDates ) do
local timestamp = tonumber(lang:formatDate("U", row["Composition:Date"]))
local date = row["Composition:Date"]
local timestamp = tonumber(lang:formatDate("U", date))
if not dates[timestamp] then
if not dates[timestamp] then
dates[timestamp] = {}
dates[timestamp] = {}
dates[timestamp]["date"] = date
end
end
dates[timestamp][#dates[timestamp]] = {
dates[timestamp][#dates[timestamp]] = {
Line 49: Line 54:
for _, key in ipairs( keys ) do
for _, key in ipairs( keys ) do
result = result .. tostring(key) .. "<br>"
result = result .. dates[key]["date"] .. "<br>"
result = result .. lang:formatDate("Y-m-d", tostring(key)) .. "<br>"
for num, row in pairs( dates[key] ) do
for num, row in pairs( dates[key] ) do
result = result .. row[1] ..'<br>'
if istable(row) then
result = result .. row[1] ..'<br>'
end
end
end
result = result ..'<br>'
result = result ..'<br>'

Revision as of 21:00, 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] = {}
			dates[timestamp]["date"] = date
		end
		dates[timestamp][#dates[timestamp]] = {
			row[1] .. " was born"
		}
	end
	for num, row in pairs( peopleDeathDates ) do
		local date = row["Person:Date of death"]
		local timestamp = tonumber(lang:formatDate("U", date))
		if not dates[timestamp] then
			dates[timestamp] = {}
			dates[timestamp]["date"] = date
		end
		dates[timestamp][#dates[timestamp]] = {
			row[1] .. " died"
		}
	end
	for num, row in pairs( compositionDates ) do
		local date = row["Composition:Date"]
		local timestamp = tonumber(lang:formatDate("U", date))
		if not dates[timestamp] then
			dates[timestamp] = {}
			dates[timestamp]["date"] = date
		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 .. dates[key]["date"] .. "<br>"
		for num, row in pairs( dates[key] ) do
			if istable(row) then
				result = result .. row[1] ..'<br>'
			end
		end
		result = result ..'<br>'
	end
	
	return result
end

return p