Module:Drapeau/Data/Brouillondate

 Documentation[voir] [modifier] [historique] [purger]


1 22/05/1972
2 02/03/1951
3 04/02/1948
4 30/11/1814


2015-01-25 Flag of Sri Lanka.svg
1950-10-31 Flag of Ceylon (1948–1951).svg
1948 Flag of Ceylon (1875–1948).svg
--[[
This module is intended to replace the functionality of {{drapeau2}} and related
templates.  It provides several methods, including
]]

drapeau = {};

local flaghisto = {
	 {start=os.time({year=1972, month=5, day=22}),flag="Flag of Sri Lanka.svg"}
	,{start=os.time({year=1951, month=3, day=2}),flag="Flag of Ceylon (1951–1972).svg"}
	,{start=os.time({year=1948, month=2, day=4}),flag="Flag of Ceylon (1948–1951).svg"}
	,{start=os.time({year=1815, month=0, day=0}),flag="Flag of Ceylon (1875–1948).svg"}
}

function drapeau.test(frame)
    globalFrame = frame
    local args = frame.args
    local tmparg;
    if args[1] == nil then
        local pFrame = frame:getParent();
        args = pFrame.args;
        for k,v in pairs( frame.args ) do
            args[k] = v;
        end
    end
    
    for i=1,10 do 
        if args[i] == nil then 
            args[i] = ""
        else
            --1>--remove whitespace
            args[i]=args[i]:match( '^%s*(.-)%s*$' );
        end        
    end
    
    local res="";
    if args[1] == "" then
	    res="{|\r\n";
	    for k,v in pairs( flaghisto ) do
	            res= res .. "|<code>" .. k .. "</code> ||".. os.date("%d/%m/%Y", v["start"]) .. "|| [[image:" .. v["flag"] .. "|150px]]\n|-\n"
	        end
	    res= res .. "|}\r\n";
    else
      --définition de la date de référence
      local datargi=0
      local datearg='';
      local y=0
      local m=1
      local d=1;
      for datarglu in string.gmatch(args[1], "%d+") do
      	if datargi==0 then y=datarglu end;
      	if datargi==1 then m=datarglu end;
      	if datargi==2 then d=datarglu end;
      	datargi=datargi+1;
      end
      mw.log(y)
      datearg=os.time({year=y,month=m,day=d});
      
	  for k,v in pairs( flaghisto ) do
	  	if os.difftime( v["start"], datearg) >= 0 then
	  		--on prend
	        res= v["flag"] ;
  		else
  			--stop
	        res= v["flag"] ;
  			break;
  		end
  		
	  end
   end

	return res;

end

function drapeau.Test(frame)
    return drapeau.test(frame)
end

return drapeau