Skip to content

Commit

Permalink
try to fix TSynTimeZone UtcToLocal()
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Oct 19, 2021
1 parent 4993e16 commit 8494081
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions SynTable.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3904,7 +3904,7 @@ TSynTimeZone = class
function SaveToBuffer: RawByteString;
/// retrieve the time bias (in minutes) for a given date/time on a TzId
function GetBiasForDateTime(const Value: TDateTime; const TzId: TTimeZoneID;
out Bias: integer; out HaveDaylight: boolean): boolean;
out Bias: integer; out HaveDaylight: boolean; DateIsUTC: boolean=false): boolean;
/// retrieve the display text corresponding to a TzId
// - returns '' if the supplied TzId is not recognized
function GetDisplay(const TzId: TTimeZoneID): RawUTF8;
Expand Down Expand Up @@ -17522,7 +17522,8 @@ function TSynTimeZone.GetDisplay(const TzId: TTimeZoneID): RawUTF8;
end;

function TSynTimeZone.GetBiasForDateTime(const Value: TDateTime;
const TzId: TTimeZoneID; out Bias: integer; out HaveDaylight: boolean): boolean;
const TzId: TTimeZoneID; out Bias: integer; out HaveDaylight: boolean;
DateIsUTC: boolean): boolean;
var ndx: integer;
d: TSynSystemTime;
tzi: PTimeZoneInfo;
Expand Down Expand Up @@ -17551,6 +17552,10 @@ function TSynTimeZone.GetBiasForDateTime(const Value: TDateTime;
HaveDaylight := true;
std := tzi.change_time_std.EncodeForTimeChange(d.Year);
dlt := tzi.change_time_dlt.EncodeForTimeChange(d.Year);
if DateIsUTC then begin // std shifts by the DST bias, dst by STD
std := ((std*MinsPerDay)+tzi.Bias+tzi.bias_dlt)/MinsPerDay;
dlt := ((dlt*MinsPerDay)+tzi.Bias+tzi.bias_std)/MinsPerDay;
end;
if std<dlt then
if (std<=Value) and (Value<dlt) then
Bias := tzi.Bias+tzi.bias_std else
Expand All @@ -17569,7 +17574,7 @@ function TSynTimeZone.UtcToLocal(const UtcDateTime: TDateTime;
begin
if (self=nil) or (TzId='') then
result := UtcDateTime else begin
GetBiasForDateTime(UtcDateTime,TzId,Bias,HaveDaylight);
GetBiasForDateTime(UtcDateTime,TzId,Bias,HaveDaylight,{DateIsUTC=}true);
result := ((UtcDateTime*MinsPerDay)-Bias)/MinsPerDay;
end;
end;
Expand Down
2 changes: 1 addition & 1 deletion SynopseCommit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'1.18.6336'
'1.18.6337'

0 comments on commit 8494081

Please sign in to comment.