Recent

Author Topic: Wrong time zone on Linux Mint?  (Read 10800 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Wrong time zone on Linux Mint?
« Reply #15 on: October 09, 2018, 08:28:03 pm »
Code: Pascal  [Select][+][-]
  1. Writeln( GetLocalTimeOffset div 60 );
returns a negated value of what it should be.
It's, I think, a question of interpretation of what the time offset represents. It can be either of:
  • how much must be summed to UTC to get the local time; or
  • how much must be summed to the local time to obtain UTC
and it's rather clear that GetLocalTimeOffset() uses the second interpretation: in my specific case it returns -120, i.e. the result of UTC - CEST, so that CEST_Time + (-120) = UTC. One just has to take this into account when using it.

Of course, it should also be clearly specified in the docs, which it isn't.
As it happens, it's clearly specified in the RTL Reference:
Quote
GetLocalTimeOffset returns the local timezone offset in minutes. This is the difference between UTC time and local time:
UTC = LocalTime + GetLocalTimeOffset
« Last Edit: October 10, 2018, 01:48:41 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

sash

  • Sr. Member
  • ****
  • Posts: 366
Re: Wrong time zone on Linux Mint?
« Reply #16 on: October 09, 2018, 09:28:41 pm »
  • how much must be summed to UTC to get the local time; or
  • how much must be summed to the local time to obtain UTC
As I understand GetLocalTimeOffset in English (not my native language) - it is an Offset (to Universal time) of Local Time.

And according to Wikipedia (about memory addressing, which maintains the same principle)
Quote
an offset usually denotes the number of address locations added to a base address in order to get to a specific absolute address.

So it seems that GetLocalTimeOffset should follow first interpretation.

Very confusing.
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Wrong time zone on Linux Mint?
« Reply #17 on: October 09, 2018, 09:54:40 pm »
Well, acording to Wikipedia too (UTC Offset):
Quote
A time offset is an amount of time subtracted from or added to Coordinated Universal Time (UTC) time to get the current civil time, whether it is standard time or daylight saving time (DST).
which implies the mirror sentence for Local offset.

The word offset in English is one of those (rather too many) words that "may mean whatever depending on context and phase of the moon".  :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

sash

  • Sr. Member
  • ****
  • Posts: 366
Re: Wrong time zone on Linux Mint?
« Reply #18 on: October 09, 2018, 10:23:46 pm »
@lucamar

No matter which sign offset has, of course offset is negative f.i. for America, I quoted Wiki to show a principle, what should be considered as a base (UTC) and what as a derivative (local).
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Wrong time zone on Linux Mint?
« Reply #19 on: October 09, 2018, 10:50:51 pm »
Ok, sorry. I rather thought that the whole point was precisely the inversion of the sign, when you said:
Code: Pascal  [Select][+][-]
  1. Writeln( GetLocalTimeOffset div 60 );
returns a negated value of what it should be.
The thing is that it returns a correct value according to the interpretation expressed in the RTL reference:
    UTC = LocalTime + GetLocalTimeOffset

Whether it should be so or otherwise, I leave to clearer minds than mine :D

edit: typos
« Last Edit: October 09, 2018, 10:53:53 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Wrong time zone on Linux Mint?
« Reply #20 on: October 10, 2018, 01:45:14 pm »
As I said it is a fairly recently fixed bug. Fairly recently means last three months, so 3.0.0.-3.0.4 have the bug. 3.2.0 and trunk do not have the bug.

Thaddy, I have just tried with 3.0.4 and 3.2.0 and I get the same results (Linux Mint 18.3).
My local time zone is central european (currently, still summer time, it is UTC+2).

GetLocalTimeOffset returns -120, which is correct according to documentation.
Quote
GetLocalTimeOffset returns the local timezone offset in minutes. This is the difference between UTC time and local time:

UTC = LocalTime + GetLocalTimeOffset

LocalTimeToUniversal(Now) correctly returns two hours less then Now.

So, if some bug was there, it was probably fixed before 3.0.4.
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 880
Re: Wrong time zone on Linux Mint?
« Reply #21 on: October 10, 2018, 02:21:39 pm »
Problem exists on 3.0.0, but doesn't exist on 3.0.4. Following change is made:
Code: Pascal  [Select][+][-]
  1. Function LocalTimeToUniversal(LT: TDateTime): TDateTime;
  2. begin
  3.   Result:=LocalTimeToUniversal(LT,{minus is added here:      -}GetLocalTimeOffset);
  4. end;
  5.  
I'm not sure, if this change is right one. I think GetLocalTimeOffset should be positive, i.e. LocalTime = UTC + GetLocalTimeOffset -> UTC = LocalTime - GetLocalTimeOffset. And GetLocalTImeOffset is defined like this:
Code: Pascal  [Select][+][-]
  1. function GetLocalTimeOffset: Integer;
  2. begin
  3.  Result := -Tzseconds div 60;
  4. end;
  5.  
Yeah, two minuses give plus. But this solution looks like a crutch. May be we should remove minus in GetLocalTimeOffset instead?

P.S. Minus is used for compatibility with Windows.
« Last Edit: October 10, 2018, 04:07:19 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Wrong time zone on Linux Mint?
« Reply #22 on: October 10, 2018, 03:04:37 pm »
For completeness sake, this little program:
Code: Pascal  [Select][+][-]
  1. program localtime;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes, SysUtils, DateUtils;
  7.  
  8. begin
  9.   WriteLn('Time zone is CEST (UTC+02:00)');
  10.   WriteLn('Local time offset (minutes): ', GetLocalTimeOffset);
  11.   WriteLn('Local Time ', TimeToStr(Now),
  12.           ' is UTC ', TimeToStr(LocalTimeToUniversal(Now)));
  13. end.
  14.  

gives this completely correct output when compiled with FPC 3.0.4:

Code: [Select]
Time zone is CEST (UTC+02:00)
Local time offset (minutes): -120
Local Time 15:01:53 is UTC 13:01:53
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018