Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FpGetTimeOfDay gives no timezone
#4
(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.

Reply


Messages In This Thread
FpGetTimeOfDay gives no timezone - by jollytall - 01-04-2019, 03:59 PM
RE: FpGetTimeOfDay gives no timezone - by rlebeau - 01-06-2019, 08:00 PM
RE: FpGetTimeOfDay gives no timezone - by rlebeau - 01-14-2019, 09:15 PM
RE: FpGetTimeOfDay gives no timezone - by rlebeau - 01-15-2019, 06:22 PM
RE: FpGetTimeOfDay gives no timezone - by rlebeau - 01-19-2019, 01:18 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)