Page 1 of 1
Getting the time elapsed [SOLVED]
Posted: Fri Apr 04, 2014 8:42 pm
by atout66
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

Re: Getting the time elapsed
Posted: Fri Apr 04, 2014 9:22 pm
by Dixie
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...
Re: Getting the time elapsed
Posted: Fri Apr 04, 2014 9:28 pm
by bn
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
Re: Getting the time elapsed
Posted: Sat Apr 05, 2014 10:38 am
by atout66
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

Re: Getting the time elapsed
Posted: Sat Apr 05, 2014 11:14 am
by Thierry
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
Re: Getting the time elapsed
Posted: Sat Apr 05, 2014 11:23 am
by Dixie
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'...
Re: Getting the time elapsed
Posted: Sat Apr 05, 2014 11:24 am
by atout66
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
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.
Re: Getting the time elapsed
Posted: Sat Apr 05, 2014 12:27 pm
by bn
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
Re: Getting the time elapsed
Posted: Sat Apr 05, 2014 12:30 pm
by atout66
Thanks Dixie. I didn't test your script yet, but you do in 3 lines of code what I do with 30
But you don't have the hours like me
I hope this topic will be usefull for other beginners. Thanks to all.
Kind regards.
Re: Getting the time elapsed [SOLVED]
Posted: Sat Apr 05, 2014 12:35 pm
by bn
Hi atout,
have a look at my script which expands Dixie's script.
I think our postings crossed.
Kind regards
Bernd
Re: Getting the time elapsed [SOLVED]
Posted: Sat Apr 05, 2014 1:31 pm
by atout66
Yes Bernd, our posting crossed.
I must say I'm jealous because you get the hours, you
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.