Kromster80 / kam_remake

"KaM Remake" is an RTS game remake written in Delphi from scratch.
http://www.kamremake.com
GNU Affero General Public License v3.0
355 stars 88 forks source link

function UTCToLocal wrong #457

Closed AndreiCherniaev closed 3 years ago

AndreiCherniaev commented 3 years ago

I test function UTCToLocal with RAD Studio 10.4 As you can see it is wrong for some configurations: if all defines will not be fuction UTCToLocal doesn't contains begin end; at all.

function UTCToLocal(Input: TDateTime): TDateTime;
{$IFDEF WDC}
begin
  Result := TTimeZone.Local.ToLocalTime(Input);
end;
{$ENDIF}
//There seems to be no easy way to do this in FPC without an external library
//From: http://lists.lazarus.freepascal.org/pipermail/lazarus/2010-September/055568.html
{$IFDEF FPC}
var
  TZOffset: Integer;
  {$IFDEF MSWINDOWS}
  BiasType: Byte;
  TZInfo: TTimeZoneInformation;
  {$ENDIF}
begin
  Result := Input;
  {$IFDEF MSWINDOWS}
  BiasType := GetTimeZoneInformation(TZInfo);
  if (BiasType=0) then
    Exit; //No timezone so return the input

  // Determine offset in effect for DateTime UT.
  if (BiasType=2) then
    TZOffset := TZInfo.Bias + TZInfo.DaylightBias
  else
    TZOffset := TZInfo.Bias + TZInfo.StandardBias;
  {$ENDIF}
  {$IFDEF UNIX}
    TZOffset := -Tzseconds div 60;
  {$ENDIF}

  // Apply offset.
  if (TZOffset > 0) then
    // Time zones west of Greenwich.
    Result := Input - EncodeTime(TZOffset div 60, TZOffset mod 60, 0, 0)
  else if (TZOffset = 0) then
    // Time Zone = Greenwich.
    Result := Input
  else if (TZOffset < 0) then
    // Time zones east of Greenwich.
    Result := Input + EncodeTime(Abs(TZOffset) div 60, Abs(TZOffset) mod 60, 0, 0);
end;
{$ENDIF}
Kromster80 commented 3 years ago

Hi, thanks for report

Main development is in reyandme repo - https://github.com/reyandme/kam_remake

WDC define needs to be updated to include recent Delphi versions, then it's all good