Module:Période de risque

De Triple Performance
Aller à :navigation, rechercher

La documentation pour ce module peut être créée à Module:Période de risque/doc

local p = {} --p stands for package

function p.buildPeriodeDeReferenceTable( frame )

	local debut = mw.text.trim( frame.args[1] )
	local fin = mw.text.trim( frame.args[2] )
	local debut2 = mw.text.trim( frame.args[3] )
	local fin2 = mw.text.trim( frame.args[4] )
	
	local t = {}
	t[0] = "Jan"
	t[1] = "Fév"
	t[2] = "Mar"
	t[3] = "Avr"
	t[4] = "Mai"
	t[5] = "Juin"
	t[6] = "Juil"
	t[7] = "Août"
	t[8] = "Sept"
	t[9] = "Oct"
	t[10] = "Nov"
	t[11] = "Déc"

	local mm = {}
	mm[0] = "J"
	mm[1] = "F"
	mm[2] = "M"
	mm[3] = "A"
	mm[4] = "M"
	mm[5] = "J"
	mm[6] = "J"
	mm[7] = "A"
	mm[8] = "S"
	mm[9] = "O"
	mm[10] = "N"
	mm[11] = "D"

	local txt0 = [[Période de présence : 
{| class="calendrier" 
|-
]]
	
	local k = 0
	local inPeriod = false
	
	while ( k < 12 ) do
		local mois = t[k]
		
		if (mois == debut) or (mois == debut2) then
			inPeriod = true
			periodLength = 1
		end
		
		if not inPeriod then
			txt0 = txt0 .. '| ' .. mm[k] .. '\n'
		else
			txt0 = txt0 .. '| class="rempli" | ' .. mm[k] .. '\n'

			if (mois == fin) or (mois == fin2) then
				inPeriod = false
			end
		end
		
		k = k + 1
	end
	
	txt0 = txt0 .. '|}\n'
	

	if mw.smw then

		local tt = {}
		tt[0] = "Janvier"
		tt[1] = "Février"
		tt[2] = "Mars"
		tt[3] = "Avril"
		tt[4] = "Mai"
		tt[5] = "Juin"
		tt[6] = "Juillet"
		tt[7] = "Août"
		tt[8] = "Septembre"
		tt[9] = "Octobre"
		tt[10] = "Novembre"
		tt[11] = "Décembre"
	
		local smwData = { ['Mois d\'intérêt de la page'] = {} }
		k = 0
		inPeriod = false
		periodLength = 1

		while ( k < 12 ) do
			local mois = t[k]

			if (mois == debut) or (mois == debut2) then
				inPeriod = true
				periodLength = 1
			end

			if inPeriod then
				table.insert(smwData['Mois d\'intérêt de la page'], tt[k])

				if (mois == fin) or (mois == fin2) then
					inPeriod = false
				end

				periodLength = periodLength + 1
			end

			k = k + 1
		end

		mw.smw.set( smwData )
	end

	return txt0
	end

return p
Partager sur :