Jump to content

Module:Years generator

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Naypta (talk | contribs) at 17:21, 7 June 2020 (add newlines and year names to break years). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {} --p stands for package

function p.templateEveryYearToPresent ( frame )
	years = yearsFromYearToPresent(frame.args[1])
	toReturn = ""
	for index, year in pairs( years ) do
		toReturn = toReturn .. ( index == 0 and '' or "\n" )
	    toReturn = toReturn .. "'''" .. tostring(year) .. "''': "
	    .. frame:expandTemplate{ title = frame.args[2], args = { tostring( year ) } }
	end
	return toReturn
end

function yearsFromYearToPresent( year )
	startyear = tonumber( year )
	if ( startyear == nil )
	then
		error( "Invalid start year provided" )
	end
	
	years = {}
    numyears = ( tonumber( os.date( "%Y" ) ) - startyear )
    for numadded = 0, numyears do -- equiv of i = 0; i <= numyears; i++
    	years[numadded] = startyear + numadded
    end
	return years
end

return p