Page 1 of 1

Timekeeper with tenths of seconds

Posted: Tue Jan 03, 2017 1:20 pm
by pixeldamage
Hi,

I'm pretty much new to LC but have a bit of experience in coding - but have been asked to look at developing an app to deal with timings.

I've figured out what I need and it's pretty straight forward, but what's complicating issues is the need to put in timings to tenth of a second... as this is what's being made available for a race.

Then need to sort, and in some instances calculate the difference between two selected times.

Obviously, it would be much easier if we didn't use tenths, but unfortunately, it's crucial. Is the best way to deal with this and store them in a datagrid to convert the HH:MM:SS.ss into a full integer and then convert as needed backwards and forwards? Obviously it would need milliseconds as ticks can only deal with 60th's and could get a .8 result.

Re: Timekeeper with tenths of seconds

Posted: Tue Jan 03, 2017 1:30 pm
by Klaus
Hi pixeldamage,

1. welcome to the forum! :D
2. Not sure what exactly your problem is, we HAVE in fact milliseconds in Livecode, check the dictionary!
But maybe I am just misunderstanding your problem.


Best

Klaus

Re: Timekeeper with tenths of seconds

Posted: Tue Jan 03, 2017 2:20 pm
by pixeldamage
Maybe it's just me.... but thanks for the welcome :)

I suppose my 'sticking point' is how to deal with hh:mm:ss:ss in a data grid, and then making sure the calculation works for the difference...

It's how if I pull XX:XX:XX:XX out of a DataGrid and then key in YY:YY:YY:YY - that it would know how to do the sums - so of that would it need to be totally converted into seconds, and then calculation performed, before being calculated back into hh:mm:ss

Re: Timekeeper with tenths of seconds

Posted: Tue Jan 03, 2017 2:51 pm
by Klaus
I would store the milliseconds in hidden columns in the datagrid, too!
This way you can do your calculations easily and THEN convert to hh:mm:ss:ms

Re: Timekeeper with tenths of seconds

Posted: Tue Jan 03, 2017 3:53 pm
by dunbarx
What everyone said.

But is your question really about converting and displaying milliseconds (a native function) to tenths (a user display format), or storing intermediate values somewhere that you can retrieve them (a user construct)?

Craig Newman

Re: Timekeeper with tenths of seconds

Posted: Tue Jan 03, 2017 4:03 pm
by pixeldamage
It would be the converting and displaying - and then storing it so it's easily retrieved..

Basically, is the best way to convert the time into a total number of seconds e.g. 67.4 which will then eventually be formatted back into 1 min 7.4 seconds... if you see what I mean, getting it to divide by 60 to get hours / minutes etc.

Probably the key thing is none of these times are being generated by the CPU.. they're all being manually inputted as and when they come in.

Re: Timekeeper with tenths of seconds

Posted: Tue Jan 03, 2017 5:21 pm
by dunbarx
Hmmm.

You may be well past this but try putting this handler in a button somewhere:

Code: Select all

on mouseUp
   put the millisecs into tStart
   wait 3567 millisecs -- an arbitrary duration
   put the millisecs - tStart into elapsedMilliSec
   
   put makeTenths(elapsedMilliSec) into tTenths
   put MMSS(elapsedMilliSec) into MMSS
   -- put MMSS(585678) into MMSS
   breakpoint
end mouseUp

function maketenths var
   return round(var/1000,1)
end maketenths

function MMSS var
   put var/1000 div 60 into tMinutes
   put round(var/1000 - (tMinutes * 60),1) into tSeconds
   return tMinutes & ":" & tSeconds
end MMSS
The variable "elapsedTime" here is a little over three seconds to give you a tenths value. If you try the commented line you can see the "MM:SS" formatted time without having to wait so long. Just simple chugging along constructing numbers.

But is this helpful?

Craig

Re: Timekeeper with tenths of seconds

Posted: Thu Jan 05, 2017 4:25 pm
by MaxV
I feel slow today, so this is my best code: :oops:
########CODE#######
function diff10 aaa,bbb
#format HH:MM:SS.ss
set itemdel to ":"
put item 1 of aaa into HHa
put item 2 of aaa into MMa
put item 3 of aaa into SSssa
put item 1 of bbb into HHb
put item 2 of bbb into MMb
put item 3 of bbb into SSssb
set itemdel to "."
put item 1 of SSssa into SSa
put item 2 of SSssa into SSa2 #1/10 sec
put item 1 of SSssb into SSb
put item 2 of SSssb into SSb2 #1/10 sec
put ssa2 + ssa * 10 + MMa * 60 * 10 + HHa * 60 * 60 * 10 into tota
put ssb2 + ssb * 10 + MMb * 60 * 10 + HHb * 60 * 60 * 10 into totb
put abs(tota - totb) into mydiff
put 0 into myhh
put 0 into mymm
put 0 into myss
put 0 into myss2
repeat for mydiff times
add 1 to myss2 #1/10 sec
if myss2 = 10 then
put 0 into myss2
add 1 to myss # sec
end if
if myss = 60 then
put 0 into myss
add 1 to mymm # minutes
end if
if mymm = 60 then
put 0 into mymm
add 1 to myhh # hours
end if
end repeat
return (myHH &":"& mymm &":"& myss &"."& myss2)
end diff10
#####END OF CODE#####