Modulo:Data: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
utilizzo wiki local time
rimosse variabili inutilizzate e vecchio controllo
Riga 43:
 
-- Ritorna la differenza in anni, mesi e giorni tra le date d1 e d2 (Unix time).
-- Se rawTable è true ritorna una table con le chiavi: year, month, day, seconds e dir.
local function dateDiffYMD(d1, d2, rawTable)
local monthdays = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
local ret = { dir = 1, seconds = math.abs(d1 - d2) }
 
if d1 > d2 then d1, d2 = d2, d1 end
d1, d2 = os.date('*t', d1), os.date('*t', d2)
 
-- se d1 >= d2 inverte
if d1.year > d2.year or
(d1.year == d2.year and d1.month > d2.month) or
(d1.year == d2.year and d1.month == d2.month and d1.day >= d2.day) then
d1, d2 = d2, d1
ret.dir = -1
end
 
-- anni
Line 126 ⟶ 119:
-- anni, mesi, settimane, giorni, ore, minuti e secondi.
local function dateDiff(d1, d2, magnitudine, magnitudine_min)
local diff, ret, dir, val
 
diff = dateDiffYMD(d1, d2, true)