Page 1 of 1

multiply a time format with a percentage

Posted: Thu May 20, 2021 2:42 pm
by fanny
hey i really need some help. I am trying to mulitply a time format with a number example:

00:03:25 * 0,5 - > ??:??:??

i tried splitting the string and then mulitplient everything by itself, but then I have an array with these items: [00, 03, 35] and I would have to delete the leading zeros, and I dont know how to put the splitted array back together.

does someone know how to work with the time and multiply it?

Re: multiply a time format with a percentage

Posted: Thu May 20, 2021 4:59 pm
by Klaus
Hi Fanny,

the trick is to convert to SECONDS first like this, tested and works:

Code: Select all

on mouseUp
   put "00:03:25" into tDate
   
   ## We need to subtract the whole day from the seconds or we will get something like: 
   ##  85632:01:43 instead of the desired 00:01:43
   put the date into tDatum
   convert tDatum to seconds
   convert tDate to seconds
   subtract tDatum from tDate
   
   ## Now do the math:
   put round(tDate * .5) into tDate2
   
   ## Format as desired as SMPTE-lite:
   put smpt_lite(tDate) & CR & smpt_lite(tDate2)
end mouseUp

function smpt_lite tSecs
   return format("%02d:%02d:%02d", tSecs div 3600, (tSecs mod 3600) div 60, tSecs mod 60)
end smpt_lite
Gives:
00:03:25
00:01:43

Best

Klaus

Re: multiply a time format with a percentage

Posted: Thu May 20, 2021 7:48 pm
by dunbarx
Hi.

I am curious. I can understand scaling a time period one way or the other, but wonder what use it could be to scale an actual moment in time. What would you do with cutting the "seconds", say, in half?

Craig

Re: multiply a time format with a percentage

Posted: Tue Jun 08, 2021 1:42 pm
by fanny
Klaus wrote:
Thu May 20, 2021 4:59 pm
Hi Fanny,

the trick is to convert to SECONDS first like this, tested and works:

Code: Select all

on mouseUp
   put "00:03:25" into tDate
   
   ## We need to subtract the whole day from the seconds or we will get something like: 
   ##  85632:01:43 instead of the desired 00:01:43
   put the date into tDatum
   convert tDatum to seconds
   convert tDate to seconds
   subtract tDatum from tDate
   
   ## Now do the math:
   put round(tDate * .5) into tDate2
   
   ## Format as desired as SMPTE-lite:
   put smpt_lite(tDate) & CR & smpt_lite(tDate2)
end mouseUp

function smpt_lite tSecs
   return format("%02d:%02d:%02d", tSecs div 3600, (tSecs mod 3600) div 60, tSecs mod 60)
end smpt_lite
Gives:
00:03:25
00:01:43

Best

Klaus

hello klaus,

sorry fo the late response, but thank you!!! that is amazing, yes it works. You really helped me!