Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WTF is the significance of {^1906-03-09 22:56:52}? :-)
Message
 
 
To
10/11/2003 19:13:33
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00848551
Message ID:
00848556
Views:
13
Hi Stefan,

Convert SYS(2015) value back File #9704 includes program to convert SYS(2015) value back to time.

>Perchance I noticed that the output of SYS(2015) seemed to be tightly correlated to the system time, and it just so happened that I was dissatisfied with both SECONDS() and DATETIME() for general elapsed-time measurement - the former because it resets at midnight and the latter because of its coarse resolution of 1 second. One can, of course, combine the two to get millisecond resolution over calender-worthy time spans but it is a bit of a hassle.
>
>So I looked a little closer at SYS(2015) and ten lines of code later I knew that it had exactly the same resolution as SECONDS() and that its value gets updated at the same frequency, unless one queries more often in which case it bumps its value at each query but then it lets the system time catch up if you give it a chance. So, unless you query SYS(2015) more often than a 1000 times per second on average over the whole time interval it will give results with the same accuracy as SECONDS() but it will not reset at midnight - the timer could run for thousands of years without wrapping (until {^5124-06-29 10:01:21}, according to Fox).
>
>Another dozen lines of code later I had my non-resetting-at-midnight version of SECONDS():
>
>
>* Sys2015ToSeconds.prg - like SECONDS() but does not wrap at midnight
>* 2003-11-10 sherlog@t-online.de
>
>#define B36_DIGITS  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>
>lparameters cSys2015
>
>if empty(m.cSys2015)
>   cSys2015 = sys(2015)
>endif
>
>local n, i, d
>n = $0
>for i = 2 to len(m.cSys2015)  && first char is an underscore - don't want it
>   d = at(upper(substr(m.cSys2015, m.i, 1)), B36_DIGITS) - 1
>   if m.d < 0
>      return 000000000000000.0000  && 0 with same width as legit result
>   endif
>   n = m.n * 36 + m.d
>next i
>
>return mton(m.n / 1000)
>
>
>In other words, underneath SYS(2015) is a millisecond count that can temporarily gets bumped ahead a bit if necessary but otherwise corresponds to the elapsed time since some unknown epoch; the output of SYS(2015) is a base-36 encoding of that value with "_" stuck in front.
>
>But what is that epoch?
>
>
? datetime() - floor(Sys2015ToSeconds())
>09.03.1906 22:56:52
>
>Compared to other known epochs (0000-01-01, 1601-01-01, 1970-01-01, 1980-01-01 and also 1900-01-01, give or take a couple of days) this seems a rather oddish choice, doesn't it?
>
>It stands to reason that the counter is somehow related to the Win32-internal time (64-bit, a.k.a FILETIME, 0.1 ms resolution) but that relation, if it exists, is not obvious to me. Looking at bit counts doesn't help:
>
>
? log(Sys2015ToSeconds() * 1000) / log(2)
>41,48716
>? log(Sys2015ToSeconds("_ZZZZZZZZZ") * 1000) / log(2)
>46,52933
>
>...
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform