(01-13-2019, 01:16 PM)jollytall Wrote: What I did now (and it works!) is the following:
Interesting, you took a completely different approach than what I was thinking. I was not aware of the LocalTimeToUniversal() and GetLocalTimeOffset() functions.
(01-13-2019, 01:16 PM)jollytall Wrote: DateUtils uses GetLocalTimeOffset to get the LocalTimeToUniversal conversion, so theoretically it would be enough to have:
result:=-GetLocalTimeOffset/60;
I like that better, but since it returns minutes, I think it needs to be dividing by 24 as well, to make it a proper TDateTime:
Code:
Result := -(GetLocalTimeOffset / 60 / 24);
Or:
Code:
Result := -1 * (GetLocalTimeOffset / 60 / 24);
That would be more inline with the existing USE_BASEUNIX code that divides tz_minuteswest from gettimeofday() by 1440 when converting to TDateTime.
Also, note FreePascal's documentation about GetLocalTimeOffset():
https://www.freepascal.org/docs-html/rtl...ffset.html
Quote:Note that on Linux/Unix, this information may be inaccurate around the DST time changes (for optimization). In that case, the unix.ReReadLocalTime unit must be used to re-initialize the timezone information.
So I would be worried about OffsetFromUTC() returning a bad value from stale data during a DST transition.
(01-13-2019, 01:16 PM)jollytall Wrote: Still if I do that in IdGlobal, it gives 0, not the real Offset. Either IdGlobal accesses another version of GetLocalTimeOffset from another library
It does not.
(01-13-2019, 01:16 PM)jollytall Wrote: or TZSeconds is not yet initialised if called directly.
I wouldn't know. Something to take up with the FreePascal community. However, I did just now find the following:
found bug on GetLocalTimeOffset
Why is LocalTimeToUniversal(Now) two hours later with Lazarus 1.6 / FPC 3.0?
UniversalTimeToLocal(UT: TDateTime) / LocalTimeToUniversal(LT: TDateTime)
0029176: LocalTimeToUniversal returns wrong value
So, now I'm a little hesitant to use FreePascal's functions, rather than using the Nix system calls as before.