While running one of my test programs, the duration counter reported negative time. Puzzled as to how I could have miscoded my app, I checked and rechecked but found nothing wrong. So I wrote a test line of code and sure enough it "fails" about once every 5-20 tries when in the last 1/10 second. I'm using VFP 9.0 SP1. (No, we haven't moved up to SP2 yet, not my call.)
I'm thinking TIME() must be doing some rounding up internally to the next second. Within my code it seemed the TIME function was a little slower then the SECONDS function, not incrementing to the new second soon enough, but in the command line test it seemed the TIME function was rounding up to the next second about 18 milliseconds too soon. So I guess I'm confused a bit as to what really is happening here.
Upon further testing, it seems that in a program loop TIME() has already updated to the next second once SECONDS() reaches nnnnn.982 (sometimes?) or nnnnn.988 or nnnnn.997. From the command line it seems to be as soon as SECONDS()=nnnnn.909.
So you need to be careful not to take a shortcut like I did and append just the fractional part of SECONDS onto TIME as I did here. You need to parse the rest of SECONDS.
Initially I had larger discrepancies when I got my negative duration error but now I can't duplicate them. Not sure why. The only difference I can imagine is that code was accessing objects. Also, I noticed that if I made my test code longer, such as a second set of loops after the first loops, there were no errors detected. It did not make a difference whether I checked TIME() first or SECONDS() first.
Code:
? TIME() +" -- "+ STR(SECONDS(),9,3) + IIF(SUBSTR(TIME(),8,1)<>SUBSTR(STR(SECONDS(),9,3),5,1),"time error!","")
Upon further testing, it seems that in a program loop TIME() has already updated to the next second once SECONDS() reaches nnnnn.982 (sometimes?) or nnnnn.988 or nnnnn.997. From the command line it seems to be as soon as SECONDS()=nnnnn.909.
So you need to be careful not to take a shortcut like I did and append just the fractional part of SECONDS onto TIME as I did here. You need to parse the rest of SECONDS.
Code:
myTime = TIME()+RIGHT(STR(SECONDS(),9,3),4) && may report wrong second/fraction combination