Modulo:Data: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m abbreviato nome parametro |
rinominato d1 e d2 in d1_ut e d2_ut, +controllo per diff zero |
||
Riga 28:
return {
}
end
Riga 38:
end
-- Aggiunge un eventuale prefisso e suffisso al risultato invece del segno.
-- L'ultimo parametro diffVal è utilizzato solo da dateDiff per evitare che
local function formatResult(response, past, dir)▼
-- {{#invoke:Data|diff|inizio=2016/01/01|fine=2015/12/31|magnitudine=anni}} ritorni "-0 anni".
local ret
if dir then
-- ritorna il 'fa' anche con d1_ut == d2_ut (si potrebbe configurare con un parametro)
ret = d1_ut < d2_ut and 'tra ' .. result or result .. ' fa'
else
ret =
end
return ret
Line 53 ⟶ 56:
-------------------------------------------------------------------------------
-- Ritorna la differenza in anni, mesi e giorni tra le date
-- Se rawTable è true ritorna una table con le chiavi: year, month, day, seconds.
local function dateDiffYMD(
local monthdays = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
local
local ret = { seconds = math.abs(d1_ut - d2_ut) }
if
-- anni
Line 90 ⟶ 89:
end
return rawTable and ret or formatResult(mw.text.listToText(ret, ', ', ' e '),
end
Line 128 ⟶ 127:
local function convert(seconds, unit, text, text2)
local ret = math.floor(seconds / unit)
return ret, string.format('%s %s', ret, ret == 1 and text or text2)
end
-- Ritorna la differenza tra le date d1 e d2 (Unix time) in solo una tra le unità:
-- anni, mesi, settimane, giorni, ore, minuti e secondi.
local function dateDiff(
local diff, ret, val, result
diff = dateDiffYMD(
magnitudine = magnitudine or getMagnitudine(diff, magnitudine_min)
if magnitudine == 'secondi' then
elseif magnitudine == 'minuti' then
elseif magnitudine == 'ore' then
elseif magnitudine == 'giorni' then
elseif magnitudine == 'settimane' then
elseif magnitudine == 'mesi' then
val = diff.years * 12 + diff.months
else
result = string.format('%s %s', diff.years, diff.years == 1 and 'anno' or 'anni') end
return formatResult(
end
Riga 168:
function p._diff(args)
local success, result = xpcall(function() return parseArgs(args) end, errhandler)
return success and dateDiff(result.
end
Riga 174:
function p._diff_ymd(args)
local success, result = xpcall(function() return parseArgs(args) end, errhandler)
return success and dateDiffYMD(result.
end
|