X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/055fa6bf18e0733d1bf2f97075d6bb33c76e72b5..9d2bca1f897628eaed87c733670f82ddb96b8c01:/btime.pas?ds=inline diff --git a/btime.pas b/btime.pas index 9bb9550..62b957d 100644 --- a/btime.pas +++ b/btime.pas @@ -12,6 +12,11 @@ unit btime; interface +{$ifdef win32} +uses + ltimevalstuff; +{$endif} + type float=extended; @@ -48,13 +53,18 @@ function unixtimefloat_systemtime:float; function oletounixfloat(t:float):float; function oletounix(t:tdatetime):integer; -function unixtoole(i:integer):tdatetime; +function unixtoole(i:float):tdatetime; {$ifdef win32} function mmtimefloat:float; function qpctimefloat:float; {$endif} +{$ifdef win32} +procedure gettimeofday(var tv:ttimeval); +{$endif} + + const mmtime_driftavgsize=32; mmtime_warmupnum=4; @@ -120,7 +130,7 @@ begin result := trunc(oletounixfloat(t)); end; -function unixtoole(i:integer):tdatetime; +function unixtoole(i:float):tdatetime; begin result := ((i)/86400)+daysdifference; end; @@ -169,6 +179,22 @@ end; {$else} {delphi 3} {------------------------------ windows/delphi code to read time} + +{simulate gettimeofday on windows so one can always use gettimeofday if preferred} + +procedure gettimeofday(var tv:ttimeval); +var + e:extended; +begin + e := unixtimefloat; + tv.tv_sec := round(int(e)); + tv.tv_usec := trunc(frac(e)*1000000); + {just in case} + if (tv.tv_usec < 0) then tv.tv_usec := 0; + if (tv.tv_usec > 999999) then tv.tv_usec := 999999; +end; + + { time float: gettickcount resolution: 9x: ~55 ms NT: 1/64th of a second