function to find difference between two times
function timeDifference(%time1, %time2)
{
%hr1 = getSubStr(%time1,0,2);
%min1 = getSubStr(%time1,3,2);
%sec1 = getSubStr(%time1,6,2);
%hr2 = getSubStr(%time2,0,2);
%min2 = getSubStr(%time2,3,2);
%sec2 = getSubStr(%time2,6,2);
%sec = %sec2 - %sec1;
%min = %min2 - %min1;
%hr = %hr2 - %hr1;
//Fixes negative times
if(%sec < 0)
{
%min--;
%sec += 60;
}
if(%min < 0)
{
%hr--;
%min += 60;
}
if(%hr < 0)
{
%hr += 24;
}
return(cleanTime(%hr,%min,%sec));
}
function to add two times together
function timeAdd(%time1, %time2)
{
%hr1 = getSubStr(%time1,0,2);
%min1 = getSubStr(%time1,3,2);
%sec1 = getSubStr(%time1,6,2);
%hr2 = getSubStr(%time2,0,2);
%min2 = getSubStr(%time2,3,2);
%sec2 = getSubStr(%time2,6,2);
%sec = %sec2 + %sec1;
%min = %min2 + %min1;
%hr = %hr2 + %hr1;
//Converts time into next unit if applicable
if(%sec >= 60)
{
%min += mfloor(%sec / 60);
%sec = %sec % 60;
}
if(%min >= 60)
{
%hr += mfloor(%min / 60);
%min = %min % 60;
}
return(cleanTime(%hr,%min,%sec));
}
function to keep times properly formatted in ##:##:##
function cleanTime(%hr,%min,%sec)
{
if(strLen(%hr) == 1)
{
%hr = "0" @ %hr;
}
if(strLen(%min) == 1)
{
%min = "0" @ %min;
}
if(strLen(%sec) == 1)
{
%sec = "0" @ %sec;
}
return(%hr @ ":" @ %min @ ":" @ %sec);
}
I was wondering if anyone could tell me if I'm doing anything incredibly stupid in this. I had trouble with keeping the time properly formatted in ##:##:## and spent more time than I should have fixing it but I've tested this with a bunch of numbers and I think it works. Just need to always have two digits in each number. Though as I was typing this I realized 3 digit hours will break this, but that's a problem I'll deal with later.