Browse Source

unix: fix timezone info for timers after the last transition

git-svn-id: trunk@49005 -
(cherry picked from commit 2a61397d373f2ef7e8df8c5112be64770309b626)
ondrej 4 years ago
parent
commit
ab9be15686
1 changed files with 32 additions and 1 deletions
  1. 32 1
      rtl/unix/timezone.inc

+ 32 - 1
rtl/unix/timezone.inc

@@ -64,8 +64,22 @@ var
     else
     else
       Exit(0);
       Exit(0);
   end;
   end;
+var
+  timerLoUTC, timerHiUTC: int64;
 begin
 begin
-  if (num_transitions=0) or (timer<transitions[0]) then
+  if (num_transitions>0) and not timerIsUTC then
+   begin
+     timerLoUTC:=timer-types[type_idxs[0]].offset;
+     timerHiUTC:=timer-types[type_idxs[num_transitions-1]].offset;
+   end
+  else
+   begin
+     timerLoUTC:=timer;
+     timerHiUTC:=timer;
+   end;
+
+  if (num_transitions=0) or (timerLoUTC<transitions[0]) then
+   { timer is before the first transition }
    begin
    begin
      i:=0;
      i:=0;
      while (i<num_types) and (types[i].isdst) do
      while (i<num_types) and (types[i].isdst) do
@@ -77,6 +91,15 @@ begin
      trans_end:=high(trans_end);
      trans_end:=high(trans_end);
    end
    end
   else
   else
+  if (num_transitions>0) and (timerHiUTC>=transitions[num_transitions-1]) then
+   { timer is after the last transition }
+   begin
+     i:=type_idxs[num_transitions-1];
+     trans_start:=transitions[num_transitions-1];
+     trans_end:=high(trans_end);
+   end
+  else
+   { timer inbetween }
    begin
    begin
       // Use binary search.
       // Use binary search.
       L := 1;
       L := 1;
@@ -410,6 +433,13 @@ var
 
 
     readdata:=true;
     readdata:=true;
   end;
   end;
+  procedure ClearCurrentTZinfo;
+  var
+    i:integer;
+  begin
+    for i:=low(CurrentTZinfo) to high(CurrentTZinfo) do
+      CurrentTZinfo[i] := Default(TTZInfo);
+  end;
 begin
 begin
   if fn='' then
   if fn='' then
    fn:='localtime';
    fn:='localtime';
@@ -422,6 +452,7 @@ begin
   tzhead:=default(ttzhead);
   tzhead:=default(ttzhead);
   LockTZInfo;
   LockTZInfo;
   ReadTimezoneFile:=(readheader() and readdata());
   ReadTimezoneFile:=(readheader() and readdata());
+  ClearCurrentTZinfo;
   UnlockTZInfo;
   UnlockTZInfo;
   fpclose(f);
   fpclose(f);
 end;
 end;