Thursday, October 20, 2011

Fix: Now() returns incorrect time on iOS device, due to a FPC RTL bug

Due to a FPC RTL bug, the Now(), Time() and possibly Date() functions return an incorrect time unless you're actually in GMT.

A possible fix:

var
TZOffsetFromGMT : Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
TZOffsetFromGMT := NSTimeZone.localTimeZone.secondsFromGMT;
end;

use it later as follows:

var
Hour, Min, Sec, MSec : Word;
CurrTime : TDateTime;
begin
CurrTime := Now+TZOffsetFromGMT/3600.0/24.0;
DecodeTime(CurrTime,Hour,Min,Sec,MSec);

...

end;

10 comments:

  1. Just to be clear... this is the fault of the FPC RTL, and *NOT* the official Delphi RTL.

    ReplyDelete
  2. Yes! I figured that. I'll edit the post in a bit.

    Thanks Allen!

    ReplyDelete
  3. Where do I find the source for your Monday session?

    Regards,
    Jim

    ReplyDelete
  4. Probably next week.

    ReplyDelete
  5. Please do report any FPC bugs you find in the FPC bug tracker at http://bugs.freepascal.org

    Not doing so makes it much more likely that we'll miss them and that they won't be fixed in future versions.

    Thanks!

    ReplyDelete
  6. The bug has been fixed in FPC svn: http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&revision=19537

    ReplyDelete
  7. Thanks, Jonas!

    ReplyDelete
  8. You could undoubtedly go to your understanding the task you are writing. The arena hopes for far more fervent internet writers as you whom are not afraid to cover how they believe. All the time pursue a person's coronary heart.

    ReplyDelete
  9. Hello, just wanted to say, I liked this blog post. It was practical. Keep on posting!

    ReplyDelete
  10. Hi, just wanted to tell you, I enjoyed this post. It was inspiring. Keep on posting!

    ReplyDelete

Note: Only a member of this blog may post a comment.