make unixtimeint and unixtimefloat work after 2038 on 32 bits unix. timezone is still...
authorbeware <beware@bircd.org>
Sun, 23 Feb 2020 19:27:13 +0000 (19:27 +0000)
committerbeware <beware@bircd.org>
Sun, 23 Feb 2020 19:27:13 +0000 (19:27 +0000)
git-svn-id: file:///svnroot/lcore/trunk@155 b1de8a11-f9be-4011-bde0-cc7ace90066a

btime.pas

index 46cdf48a74189538993306a5985bd3fa7fa996c2..a0bfc5eaa012fe9e030565bf82150ce35a95c8e4 100644 (file)
--- a/btime.pas
+++ b/btime.pas
@@ -176,9 +176,14 @@ end;
 function unixtimefloat:float;\r
 var\r
   tv:ttimeval;\r
+  sec:tunixtimeint;\r
 begin\r
   gettimeofday(tv);\r
-  result := tv.tv_sec+(tv.tv_usec/1000000);\r
+  sec := tv.tv_sec;\r
+  {$ifndef cpu64}\r
+  if (sec < 0) then inc(sec,$100000000); //tv_sec is 32 bits\r
+  {$endif}\r
+  result := sec+(tv.tv_usec/1000000);\r
 end;\r
 \r
 {$ifdef linux}\r
@@ -263,9 +268,14 @@ end;
 function unixtimeint:tunixtimeint;\r
 var\r
   tv:ttimeval;\r
+  sec:tunixtimeint;\r
 begin\r
   gettimeofday(tv);\r
-  result := tv.tv_sec;\r
+  sec := tv.tv_sec;\r
+  {$ifndef cpu64}\r
+  if (sec < 0) then inc(sec,$100000000); //tv_sec is 32 bits\r
+  {$endif}\r
+  result := sec;\r
 end;\r
 \r
 {------------------------------ end of *nix/freepascal section}\r