Module:Date : Différence entre versions
Sauter à la navigation
Sauter à la recherche
| Ligne 15 : | Ligne 15 : | ||
function date.i2u( dt ) | function date.i2u( dt ) | ||
| − | d = mw.text.split( dt.args[1], '/') | + | d = mw.text.split( dt.args[1], '/') |
| − | day | + | day = tonumber(d[1]) |
| − | + | week = tonumber(d[2]) | |
| − | year | + | season = tonumber(d[3]) |
| − | u = floor((year | + | year = tonumber(d[4]) |
| + | u = math.floor((year-1)*365.25)+_if(season>1,8*12)+_if(season>2,89)+_if(season>3,89)+(week-1)*8+day+92 | ||
return u | return u | ||
end | end | ||
| Ligne 30 : | Ligne 31 : | ||
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) | 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 u | return u | ||
| + | end | ||
| + | |||
| + | function date.u2p( du ) | ||
| + | year = math.ceil((du - 1)/365.25+0.00000001)-4495 | ||
| + | day_year = du%1461-365*math.floor((du%1461)/365.25)-_if(year%4==1,1) | ||
| + | dt = "" | ||
| + | return dt | ||
end | end | ||
Version du 12 février 2019 à 09:33
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]) week = tonumber(d[2]) season = tonumber(d[3]) year = tonumber(d[4]) u = math.floor((year-1)*365.25)+_if(season>1,8*12)+_if(season>2,89)+_if(season>3,89)+(week-1)*8+day+92 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 u
end
function date.u2p( du )
year = math.ceil((du - 1)/365.25+0.00000001)-4495 day_year = du%1461-365*math.floor((du%1461)/365.25)-_if(year%4==1,1) dt = "" return dt
end
function _if(b, a)
if b then
return a
else
return 0
end
end
return date