synopse / mORMot2

OpenSource RESTful ORM/SOA/MVC Framework for Delphi and FreePascal
https://synopse.info
Other
485 stars 122 forks source link

TSynSystemTime returns wrong local time #258

Closed zen010101 closed 2 weeks ago

zen010101 commented 2 weeks ago

image

OS: Ubuntu 20.04.6 LTS (GNU/Linux 4.19.232 aarch64) fpc: 3.2.2 mormot2: stable

code is simple , but in some machines, it returns wrong local time .

var
  t: TSynSystemTime;
  tz: TSynTimeZone;

  {$R mormot.tz.res}

begin

  t.FromNowLocal;
  writeln(t.ToText(True));
  readln;

end.
synopse commented 2 weeks ago

We use the Tzseconds global variable value from FPC RTL for the conversion.

Sounds like a bug in the FPC RTL, not in mORMot.

synopse commented 2 weeks ago

Hint: to fix and validate the FPC RTL? some reference code may be worth reading at https://github.com/golang/go/tree/master/src/time

zen010101 commented 2 weeks ago

We use the Tzseconds global variable value from FPC RTL for the conversion.

  • What is the RETURNED Tzseconds global variable value on those PC? 0

  • What is the EXPECTED Tzseconds global variable value on those PC? it should be 28800. When I assigned it to the correct value, the FromNowLocal is correct too.

  • By chance, isn't it on the PC which have RTC in local TZ: no value? what does it mean?

  • What is the exact Linux distribution (name + version) on those PC? on not worked host: Ubuntu 20.04.6 LTS ( focal, 4.19.232 aarch64) on worked host: Debian GNU/Linux 11 (bullseye, 5.10.160 aarch64)

  • Is not the TZ environment variable defined on those systems? There is no TZ environment variable on both systems.

Sounds like a bug in the FPC RTL, not in mORMot. Yes, maybe is related about Tzseconds.

synopse commented 2 weeks ago

If TZSeconds = 0, I guess it is indeed a bug in the FPC RTL, which is not able to properly handle Ubuntu - which is weird because it is Debian based.

RTC in local TZ: no is a message available in the timedatectl output. Normally, the Bios RTC should be in local TZ, as requested for Windows.

zen010101 commented 2 weeks ago

If TZSeconds = 0, I guess it is indeed a bug in the FPC RTL, which is not able to properly handle Ubuntu - which is weird because it is Debian based.

RTC in local TZ: no is a message available in the timedatectl output. Normally, the Bios RTC should be in local TZ, as requested for Windows.

RTC in local TZ: no is in both outputs on hosts which worked and not worked.

zen010101 commented 2 weeks ago

After inspecting the issue, I found the key to this problem. On the host that is not working, the '/etc/timezone' file contains 'Etc/UTC' instead of the correct 'Asia/Shanghai' timezone. The FPC(timezone.inc) looks for this information to determine the system's timezone. When I changed it to the correct timezone, the TZSeconds value was correct.