Einzelnen Beitrag anzeigen

philipp.hofmann

Registriert seit: 21. Mär 2012
Ort: Hannover
859 Beiträge
 
Delphi 10.4 Sydney
 
#15

AW: Differenz zur echten Uhrzeit in Sekunden ermitteln

  Alt 21. Jan 2021, 12:20
So ich habe mich jetzt mal durch Indy-debuggt, der Fehler passierte inIdGlobalProtocols.TimeZoneBias:
Delphi-Quellcode:
function TimeZoneBias: TDateTime;
{$IFNDEF FPC}
  {$IFDEF UNIX}
var
  T: Time_T;
  TV: TimeVal;
  UT: {$IFDEF USE_VCL_POSIX}tm{$ELSE}TUnixTime{$ENDIF};
  {$ELSE}
    {$IFDEF USE_INLINE} inline; {$ENDIF}
  {$ENDIF}
{$ELSE}
  {$IFDEF USE_INLINE} inline; {$ENDIF}
{$ENDIF}
begin
{$IFNDEF FPC}
  {$IFDEF UNIX}
                                                                     
  {from http://edn.embarcadero.com/article/27890 }
  gettimeofday(TV, nil);
  T := TV.tv_sec;
  localtime_r({$IFNDEF USE_VCL_POSIX}@{$ENDIF}T, UT);
// __tm_gmtoff is the bias in seconds from the UTC to the current time.
// so I multiply by -1 to compensate for this.
  Result := (UT.{$IFNDEF USE_VCL_POSIX}__tm_gmtoff{$ELSE}tm_gmtoff{$ENDIF} / 60 / 60 / 24);
  {$ELSE}
  ...
Keine Ahnung, warum die so kompliziert implementiert ist, ich habe es mal mit folgendem Code ersetzt:
Delphi-Quellcode:
function TimeZoneBias: TDateTime;
{$IFNDEF FPC}
  {$IFDEF UNIX}
    var nowDt:TDateTime;
  {$ELSE}
    {$IFDEF USE_INLINE} inline; {$ENDIF}
  {$ENDIF}
{$ELSE}
  {$IFDEF USE_INLINE} inline; {$ENDIF}
{$ENDIF}
begin
{$IFNDEF FPC}
  {$IFDEF UNIX}
  nowDt:=NOW;
  Result := TTimeZone.Local.ToUniversalTime(nowDt)-nowDt;
  {$ELSE}
  ...
Zumindest für Google-Android und iOS funktioniert es jetzt. Für Amazon-FireOS-Android scheint es noch ein weiteres Problem zu geben, dies ignoriere ich jetzt mal und setze die Differenz auf 0.0s.
  Mit Zitat antworten Zitat