Module:Date

De louiki
Sauter à la navigation Sauter à la recherche

local date = {}

function date.i2p( dt )

   d = mw.text.split( dt.args[1], '/')
   return d[0]

end

function date.p2i( dt )

   d = mw.text.split( dt.args[1], '/')
   day   = tonumber(d[1])
   month = tonumber(d[2])
   year  = tonumber(d[3])
   return day

end

function date.i2u( dt )

   d = mw.text.split( dt.args[1], '/')
   day   = tonumber(d[1])
   month = tonumber(d[2])
   year  = tonumber(d[3])
   u = floor((year+4495)*365.25)- 241 + day +(month-5)*30 + _if(month>6, 1) + _if(month>9 and year%4==1, 1) - _if(month<5, 1) - _if(month < 4, 1) - _if(month < 2, 1)
   return u

end

function date.p2u( dt )

   d = mw.text.split( dt.args[1], '/')
   day   = tonumber(d[1])
   month = tonumber(d[2])
   year  = tonumber(d[3])
   u = math.floor((year+4495)*365.25)- 241 + day +(month-5)*30 + _if(month>6, 1) + _if(month>9 and year%4==1, 1) - _if(month<5, 1) - _if(month < 4, 1) - _if(month < 2, 1)
   return d

end

function _if(b, a)

   if b then
       return a
   else
       return 0
   end

end

return date