[Lazarus] Possible error with Now function over summer/winter time change?
Michael Van Canneyt
michael at freepascal.org
Sun Oct 27 17:40:11 CET 2013
On Sun, 27 Oct 2013, David Taylor wrote:
> I noticed that over the clock change in the Autumn my wall clock continued to
> display summer time rather than winter time - my guess is that the Now
> function doesn't check for a change in the minutes offset very frequently, if
> at all since it was first called. Restarting the program fixed the problem,
> but it would be nice to have the fix in the code.
It is a known problem.
Doing this 100% correctly involves re-reading the timezone file at every call of Now() or Date().
Clearly, this is a huge performance impact, severely skewing the time information.
So this is not done.
The "unix" unit contains
which will re-initialize the necessary variables. You can call this routine at regular intervals as you see fit.
In your case, you may want to insert a call to this after every clock update, which would be once a second.
> This with FPC for the Raspberry Pi.
> Code extract:
> procedure TClockForm.TimerClockTimer (Sender: TObject);
> when: TDateTime;
> hours, minutes, seconds, th: Word;
> when := Now;
> DecodeTime (when, hours, minutes, seconds, th);
> if seconds <> FOldSeconds then
> FOldSeconds := seconds;
> LabelHHMM.Caption := FormatDateTime ('hh:mm', when);
> LabelSS.Caption := FormatDateTime (' ss', when);
> if hours <> FOldHours then
> FOldHours := hours;
> LabelDate.Caption := FormatDateTime ('yyyy-mmm-dd', when);
> LabelDay.Caption := FormatDateTime ('dddd', when);
> LabelDate.Left := (ClientWidth - LabelDate.Width) div 2;
> LabelDay.Left := (ClientWidth - LabelDay.Width) div 2;
> Web: http://www.satsignal.eu
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
More information about the Lazarus