Module:Infobox tour

local p = {} local cargo = mw.ext.cargo

function p._firstLastDate(order, artist, tour, festival, year) artist = artist or '' tour = tour or '' festival = festival or '' year = year or '' local condSql = 'shows.date__precision=1'

if artist ~= '' then condSql = condSql .. ' AND artist = "' .. artist .. '"' end if tour ~= '' then condSql = condSql .. ' AND tour = "' .. tour .. '"' end if festival ~= '' then condSql = condSql .. ' AND festival = "' .. festival .. '"' end if year ~= '' then condSql = condSql .. ' AND YEAR(date) = "' .. year .. '"' end

local res = cargo.query(		'shows',		'_pageName, date',		{			where = condSql,			orderBy = 'date ' .. order,			limit = 1		}	)

if #res == 1 then return  .. res[1]['date'] ..  else return '' end end

function p._firstDate(artist, tour, festival, year) return p._firstLastDate('ASC', artist, tour, festival, year) end

function p._lastDate(artist, tour, festival, year) return p._firstLastDate('DESC', artist, tour, festival, year) end

function p.firstDate(frame) local artist = frame.args[1] local tour = frame.args[2] local festival = frame.args[3] local year = frame.args[4] return p._firstDate(artist, tour, festival, year) end

function p.lastDate(frame) local artist = frame.args[1] local tour = frame.args[2] local festival = frame.args[3] local year = frame.args[4] return p._lastDate(artist, tour, festival, year) end

return p