Timeline

From Young Beethoven
Jump to navigation Jump to search
Line 43: Line 43:
end
end
for date, row in pairs( dates ) do
local keys = {}
for num, row2 in pairs( row ) do
for k in pairs(dates) do table.insert(keys, k) end
result = result .. row2[1]
table.sort(keys)
for _, key in ipairs( keys ) do
for num, row in pairs( dates[key] ) do
result = result .. row[1]
end
end
end
end

Revision as of 20:42, 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 timestamp = lang:formatDate("U", row["Person:Date of birth"])
		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 = 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 = 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
		for num, row in pairs( dates[key] ) do
			result = result .. row[1]
		end
	end
	
	return result
end

return p