multiply a time format with a percentage

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
fanny
Posts: 5
Joined: Mon Apr 26, 2021 2:54 pm

multiply a time format with a percentage

Post by fanny » Thu May 20, 2021 2:42 pm

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?

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: multiply a time format with a percentage

Post by Klaus » 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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: multiply a time format with a percentage

Post by dunbarx » Thu May 20, 2021 7:48 pm

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

fanny
Posts: 5
Joined: Mon Apr 26, 2021 2:54 pm

Re: multiply a time format with a percentage

Post by fanny » Tue Jun 08, 2021 1:42 pm

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!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”