Getting the time elapsed [SOLVED]

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
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Getting the time elapsed [SOLVED]

Post by atout66 » Fri Apr 04, 2014 8:42 pm

Hi to all,
I'm trying to get the time elapsed for an action. I get it, but it's wrong and not exactly the way I'd like.
I've seen the lessons:
How to use date and time in Rev http://lessons.runrev.com/s/lessons/m/4 ... ime-in-rev
Storing a modification timestamp http://lessons.runrev.com/s/lessons/m/2 ... -timestamp
Here is the code:

Code: Select all

put the seconds into theStartTime -- theStartTime
send "doYourJob lesData" to me -- 200 values to check format and order
put the seconds into theActualTime --  greater than theStartTime
put theActualTime - theStartTime into theTimeElapsed -- theTimeElapsed
convert theTimeElapsed from seconds to time --
put theTimeElapsed into field "leTemps" -- gives me allays 1:04 AM which is wrong!
The last test I did, I started exactly at 21:27:00
The routine ended exactly at 21:31:28 so 4'28''.
And I always get 1:04 AM ?!?
I've tried to deal with system time , short system time , etc. without sucess :lol:
Last edited by atout66 on Sat Apr 05, 2014 12:31 pm, edited 1 time in total.
Discovering LiveCode Community 6.5.2.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Getting the time elapsed

Post by Dixie » Fri Apr 04, 2014 9:22 pm

Code: Select all

on mouseUp
   put the seconds into tStart
   -- do a lot of things
   put the seconds - tStart into theTimeTaken
   put theTimeTaken
end mouseUp
The 'theTimeTaken' contains just that, the amount of time it took to 'do a lot of things' will be the seconds that it took.... You can then convert it into minutes and seconds however you want to...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Getting the time elapsed

Post by bn » Fri Apr 04, 2014 9:28 pm

Hi atout,

the seconds are at the base of date and time calculations as you have found out.
On a mac the epoch starts at Jan 1 1970 midnight.

So you had 268 seconds for your computation and ask the time for that

imlicitely the answer gives you the time elapsed since begin of the epoch which is 4 minutes. Now you have daylight saving on and it adds an hour

You can see if you put this

Code: Select all

convert theTimeElapsed to short internet date
since I am in the same time zone as you are I get
1/1/70 Thu, 1 Jan 1970 01:04:28 +0100
To make a long story short, if you want to know how many seconds, minutes, hours your routine used you have to do it yourself
(div and mod are your friend)

Kind regards
Bernd

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Getting the time elapsed

Post by atout66 » Sat Apr 05, 2014 10:38 am

Bernd, I look in the dictionnary for <div> and <mod> but I don't find anything...
Never mind, I understood from Dixie I had to format myself the duration in second according to my needs.
When I'll get the solution, I'll post it here for other beginners and may be for optimisation too :)
Discovering LiveCode Community 6.5.2.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Getting the time elapsed

Post by Thierry » Sat Apr 05, 2014 11:14 am

atout66 wrote:Bernd, I look in the dictionnary for <div> and <mod> but I don't find anything...
Bonjour,

Sure they are not there?
Here are 2 screenshots from the dictionary for mod and div!

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Getting the time elapsed

Post by Dixie » Sat Apr 05, 2014 11:23 am

Atout66...

Bernd did indeed point you in the right direction... I am surprised that you cannot find 'div' (Divides one number by another and returns the integer part of the result.) and 'mod' (Evaluates to the remainder left over when one number is divided by another.) in the dictionary ! But to draw your problem out, let's look at an example of how Bernd's suggestion of using 'div' and 'mod' would work for you... Bernd picked a figure of 268 seconds for the time it took to do all your stuff, so ...

Code: Select all

on mouseUp
   put 268 div 60 into theMinutes
   put 268 mod 60 into theSeconds
   
   put theMinutes & ":" & theSeconds
end mouseUp
This will return '4:28'...

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Getting the time elapsed

Post by atout66 » Sat Apr 05, 2014 11:24 am

Arght !
I didn't notice I was not in the <operator> section of the dictionnary... I should have been in the <all> section.

Anyway here is my two cents to this question. It's surely not the best one but it works :wink:

Code: Select all

put the seconds  - leTempsInitial into leTempsPasser -- leTempsPasser = theTimeElapsed
   switch leTempsPasser -- leTempsPasser = theTimeElapsed
      case leTempsPasser > 3600 -- hours
         put leTempsPasser / 3600 into lesHeures
         round(lesHeures) 
         put (leTempsPasser - 3600)/60 into lesMinutes
         round(lesMinutes) 
         put (leTempsPasser - 3600) - (lesMinutes * 60 ) into lesSecondes
         send "showTheDuration lesHeures,lesMinutes,lesSecondes" to me
         break
      case leTempsPasser > 60 -- minutes
         put "0" into lesHeures
         put leTempsPasser / 60 into lesMinutes
         round(lesMinutes) 
         put leTempsPasser - (lesMinutes * 60 ) into lesSecondes
         send "showTheDuration lesHeures,lesMinutes,lesSecondes" to me
         break
       case leTempsPasser < 60 -- secondes
         put "0" into lesHeures
         put "0" into lesMinutes
         put leTempsPasser into lesSecondes
         send "showTheDuration lesHeures,lesMinutes,lesSecondes" to me
         break
   end switch
   
Kind regards.
Discovering LiveCode Community 6.5.2.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Getting the time elapsed

Post by bn » Sat Apr 05, 2014 12:27 pm

Hi atout,

expanding on what Dixie said

Code: Select all

put "21868" into leTempsPasser
put leTempsPasser div 3600 into lesHeures
put leTempsPasser mod 3600 into leTempsPasser
put leTempsPasser div 60 into lesMinutes
put leTempsPasser mod 60 into lesSecondes
send "showTheDuration lesHeures,lesMinutes,lesSecondes" to me
Kind regards
Bernd

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Getting the time elapsed

Post by atout66 » Sat Apr 05, 2014 12:30 pm

Thanks Dixie. I didn't test your script yet, but you do in 3 lines of code what I do with 30 :shock:
But you don't have the hours like me :lol:

I hope this topic will be usefull for other beginners. Thanks to all.

Kind regards.
Discovering LiveCode Community 6.5.2.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Getting the time elapsed [SOLVED]

Post by bn » Sat Apr 05, 2014 12:35 pm

Hi atout,

have a look at my script which expands Dixie's script.

I think our postings crossed.

Kind regards
Bernd

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Getting the time elapsed [SOLVED]

Post by atout66 » Sat Apr 05, 2014 1:31 pm

Yes Bernd, our posting crossed.
I must say I'm jealous because you get the hours, you :wink:
But I can tell your script works very well.

For my needs, i formated the time like below:

Code: Select all

on showTheDuration lesHeures,lesMinutes,lesSecondes
   put lesHeures &"h : "& lesMinutes &"mn : " & lesSecondes &"s." into leTempsPasser
   put leTempsPasser into field "leTemps" -- this gives : 1h : 22mn : 18s. for example
end showTheDuration
Thanks for your help,
Kind regards.
Discovering LiveCode Community 6.5.2.

Post Reply