Bonjour,
Voici 2 fonctions à intégrer à ton script pour calculer une somme ou une différence :
Code : Tout sélectionner
-------------------------------------------------------------------------------
--Fonction qui calcule et retourne la somme des horaires H1 et H2 (format string 'hh:mm')
-------------------------------------------------------------------------------
function SumTime(H1,H2)
local h1, h2, m1, m2 = string.sub(H1,1,2), string.sub(H2,1,2), string.sub(H1,4,5), string.sub(H2,4,5)
local t = tonumber(h1)*60 + tonumber(h2)*60 + tonumber(m1) + tonumber(m2)
local h, m = math.floor(t/60), math.fmod(t, 60)
if h>=24 then
h=h-24
end
local H, M = tostring(h), tostring(m)
if h<10 then
H = '0'..H
end
if m < 10 then
M = '0'..M
end
return H..':'..M
end
-------------------------------------------------------------------------------
--Fonction qui calcule et retourne la différence (H1 - H2) des horaires H1 et H2 (format string 'hh:mm')
-------------------------------------------------------------------------------
function DiffTime(H1,H2)
local h1, h2, m1, m2 = string.sub(H1,1,2), string.sub(H2,1,2), string.sub(H1,4,5), string.sub(H2,4,5)
local t = tonumber(h1)*60 - tonumber(h2)*60 + tonumber(m1) - tonumber(m2)
local h, m = math.floor(t/60), math.fmod(t, 60)
local H, M = tostring(h), tostring(m)
if h<10 then
H = '0'..H
end
if m < 10 then
M = '0'..M
end
return H..':'..M
end
Bonne journée.