Dick Kriesel wrote:

On 10/6/05 4:21 AM, "Alex Tweedly" <[EMAIL PROTECTED]> wrote:

Hmmm - can you give a case where Kay's method gives wrong answers
because of a negative seconds value ?
As far as I can see (both by inspection and by testing) it always gets
it right.

Whenever the negative seconds cause the result to be negative, the result is
wrong. For example, "00:01:00.5",-61 gives 23:59:59.5.
But that's the right answer !
00:01:00.5 represents 60.5 seconds after midnight. Subtract 61 seconds and you should get .6 seconds before midnight - i.e. 23:59:59.5

But even if the
convert function didn't cause a wrap-around, the result would be wrong,
because the decimal digit is appended without checking the sign. The
function would compute (60-61)&.5 = -1.5 seconds, instead of -.5 seconds.
There's no need to check a sign here. Any fractional part of a second in the original time value is always positive; so you always want to add it. Since the result is also always positive (it uses wrap-around rather than return negative times), the positive fractional part should always be added.

In the case you mention, (60-61)&.5 doesn't give -1.5, what it gives is the wrapped version, i.e. (something:59)&.5


On the other hand, both your method and mine (which is really just a
variant of yours) get it wrong in key cases of negative seconds (e.g.
00:00:00.1   - 31 gives   0:00:0-31 for you and 0:00:0-31.0 for me -
both rather hopeless :-)

So I'm glad I wasn't throwing any stones.  Here's a new version that handles
negative seconds and negative results correctly (I think):

No, it doesn't I'm afraid.
00:00:00.0 - 31 gives a wrong answer.

You can fix that with an extra if test to put in a sign if the whole tSeconds is negative. But once you've done that, even using the "format" variant for its speed, it's slower than Kay's version using twelvehourtime.

Rob indicated in another email that they could change the spec to allow wrap-around within the 24-hour space.

So *if* Rob can accept the missing trailing "0" then Kay is the "winner apparent" for the QP (pending any other faster method).

function addTimeAndSeconds pTime,pSeconds
 set the itemDelimiter to ":"
 put item 1 of pTime * 3600 + item 2 of pTime * 60 + item 3 of pTime \
   + pSeconds into tSeconds
 put tSeconds div 3600 & ":" & abs(tSeconds) mod 3600 div 60 & ":" \
   & abs(tSeconds) mod 60 into tTime
 if item 2 of tTime < 10 then put 0 before item 2 of tTime
 if item 3 of tTime < 10 then put 0 before item 3 of tTime
 return tTime
end addTimeAndSeconds

The new version runs faster than my old, invalid version, oddly enough.

I wonder if Rob still cares...

-- Dick


_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution




--
Alex Tweedly       http://www.tweedly.net

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.13/123 - Release Date: 06/10/2005

_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to