Browse Source

* use timezone information from fpgettimeofday for getting local datetime

git-svn-id: trunk@47527 -
(cherry picked from commit f5a95782a94e41a09184808b54f3857b9afe8b2e)
ondrej 4 years ago
parent
commit
073d47e77f
2 changed files with 24 additions and 18 deletions
  1. 11 7
      rtl/unix/dos.pp
  2. 13 11
      rtl/unix/sysutils.pp

+ 11 - 7
rtl/unix/dos.pp

@@ -144,11 +144,13 @@ end;
 
 
 Procedure GetDate(Var Year, Month, MDay, WDay: Word);
 Procedure GetDate(Var Year, Month, MDay, WDay: Word);
 var
 var
-  tz:timeval;
+  tv:timeval;
+  tz:timezone;
   hour,min,sec : word;
   hour,min,sec : word;
 begin
 begin
-  fpgettimeofday(@tz,nil);
-  EpochToLocal(tz.tv_sec,year,month,mday,hour,min,sec);
+  fpgettimeofday(@tv,@tz);
+  tv.tv_sec:=tv.tv_sec-tz.tz_minuteswest*60;
+  EpochToUniversal(tv.tv_sec,year,month,mday,hour,min,sec);
   Wday:=weekday(Year,Month,MDay);
   Wday:=weekday(Year,Month,MDay);
 end;
 end;
 
 
@@ -189,12 +191,14 @@ end;
 
 
 Procedure GetTime(Var Hour, Minute, Second, Sec100: Word);
 Procedure GetTime(Var Hour, Minute, Second, Sec100: Word);
 var
 var
-  tz:timeval;
+  tv:timeval;
+  tz:timezone;
   year,month,day : word;
   year,month,day : word;
 begin
 begin
-  fpgettimeofday(@tz,nil);
-  EpochToLocal(tz.tv_sec,year,month,day,hour,minute,second);
-  sec100:=tz.tv_usec div 10000;
+  fpgettimeofday(@tv,@tz);
+  tv.tv_sec:=tv.tv_sec-tz.tz_minuteswest*60;
+  EpochToUniversal(tv.tv_sec,year,month,day,hour,minute,second);
+  sec100:=tv.tv_usec div 10000;
 end;
 end;
 
 
 
 

+ 13 - 11
rtl/unix/sysutils.pp

@@ -1385,12 +1385,12 @@ end;
 Procedure DoGetUniversalDateTime(var year, month, day, hour, min,  sec, msec, usec : word);
 Procedure DoGetUniversalDateTime(var year, month, day, hour, min,  sec, msec, usec : word);
 
 
 var
 var
-  tz:timeval;
+  tp:timeval;
 begin
 begin
-  fpgettimeofday(@tz,nil);
-  EpochToUniversal(tz.tv_sec,year,month,day,hour,min,sec);
-  msec:=tz.tv_usec div 1000;
-  usec:=tz.tv_usec mod 1000;
+  fpgettimeofday(@tp,nil);
+  EpochToUniversal(tp.tv_sec,year,month,day,hour,min,sec);
+  msec:=tp.tv_usec div 1000;
+  usec:=tp.tv_usec mod 1000;
 end;
 end;
 
 
 // Now, adjusted to local time.
 // Now, adjusted to local time.
@@ -1398,12 +1398,14 @@ end;
 Procedure DoGetLocalDateTime(var year, month, day, hour, min,  sec, msec, usec : word);
 Procedure DoGetLocalDateTime(var year, month, day, hour, min,  sec, msec, usec : word);
 
 
 var
 var
-  tz:timeval;
-begin
-  fpgettimeofday(@tz,nil);
-  EpochToLocal(tz.tv_sec,year,month,day,hour,min,sec);
-  msec:=tz.tv_usec div 1000;
-  usec:=tz.tv_usec mod 1000;
+  tv:timeval;
+  tz:timezone;
+begin
+  fpgettimeofday(@tv,@tz);
+  tv.tv_sec:=tv.tv_sec-tz.tz_minuteswest*60;
+  EpochToUniversal(tv.tv_sec,year,month,day,hour,min,sec);
+  msec:=tv.tv_usec div 1000;
+  usec:=tv.tv_usec mod 1000;
 end;
 end;
 
 
 procedure GetTime(var hour,min,sec,msec,usec:word);
 procedure GetTime(var hour,min,sec,msec,usec:word);