Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 12:45 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: another getlength question...
PostPosted: May 18th, 2008, 9:30 am 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
I am looking for a (good) script that converts the long string of seconds recieved from a GetLength into an Hour:minute:seconds format
Who can help me.

Kind regards,

Ad Mulders


For this message Ad Mulders has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 18th, 2008, 11:17 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Ad,

I do not play much with audio/video.
You might do a Search here... for: time getlength
(all terms)
search.php?mode=results


(be logged-in to the forum and you will 'see' any Attachment files posted)

Cheers,
Larry

_________________
_good things come to those who wait(0)_


For this message Lar_123 has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: May 18th, 2008, 12:20 pm 
Offline

Joined: October 26th, 2004, 10:23 am
Posts: 666
Location: Digital Workshop
Code:
function TwoDigit(n)
{
   return ((n > 9) ? "" : "0") + n
}

function ConvertTime(sec)
{
   var min = Math.floor(sec/60)
   sec = sec % 60
   var hr = Math.floor(min/60)
   min = min % 60

   return TwoDigit(hr) + ":" + TwoDigit(min) + ":" + TwoDigit(sec)
}


Example:
Code:
BOB = ConvertTime(3660)
Debug.trace BOB

_________________
ddww Opus Developer


For this message Duncan Lilly has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 18th, 2008, 1:05 pm 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
thanks, gonne try it

Ad


For this message Ad Mulders has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 18th, 2008, 2:13 pm 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
:oops: Do you have an example because i don't understand the code you suggested. Sorry


Ad


For this message Ad Mulders has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 18th, 2008, 6:59 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Ad,

Duncan's example works perfectly..but the JS is a little compact unless you know what it does :-) - very cool thought :-)

Basically just copy the two functions into your script and pass the time in seconds to the ConvertTime(sec) function. You can do this in two ways, either place the function as part of a Constant Expression (like you did with the function I wrote for you) or have a variable receive the returned result from the function call as in Duncan's debug example.

If you want to understand the actual script then - the first function is a compact if, then else statement called a ternary operator that basically says if n greater than 9 return an empty string else add a leading zero.

The second function is some maths that finds how many times 60 goes exactly into each of the base elements (mins / hours) using the floor command and also what the remainders are using the modulo (%) command.

I've popped a small example on our website to show you this in action. There is a ticker action on the page:

www.interaktiv.co.uk/timer.zip

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 18th, 2008, 9:00 pm 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
Great, it works.
Thank your for your clear explenation.

Ad


For this message Ad Mulders has been thanked by : mackavi


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group