× Discussions for CodeTyphon Object Pascal Programming Language

Question GetLocalTimeOffset return 0

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 months 1 week ago #15645 by Vital
GetLocalTimeOffset return 0 was created by Vital
My zone - Moscow (+3), but function GetLocalTimeOffset return 0. Why?
OS: Ubuntu 21.04 (64-bit)
CT: 7.3

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
2 months 1 week ago - 2 months 1 week ago #15647 by Sternas Stefanos
Replied by Sternas Stefanos on topic GetLocalTimeOffset return 0
Thanks Sir
any sample for test

Did your set to your OS your local time ?

PilotLogic Architect and Core Programmer
Last edit: 2 months 1 week ago by Sternas Stefanos.

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 months 1 week ago - 2 months 1 week ago #15655 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0

any sample for test

procedure showOffset;
var
  val: Integer;
begin
  val:= GetLocalTimeOffset; // or any other with options
  ShowMessage(val.ToString);
end;

Did your set to your OS your local time ?

Yes.
On Ubuntu 20.04 same problem as on Ubuntu 21.04. So not problem in OS.
Function Now() and NowUTC() return 0 both.
Last edit: 2 months 1 week ago by Vital.

Please Log in or Create an account to join the conversation.

More
2 months 1 week ago #15656 by Vbxler
Replied by Vbxler on topic GetLocalTimeOffset return 0
I have tested the code above and get, as expected, -60 for the time offset of one hour.

Xubuntu 20.04 and latest CT.

Please Log in or Create an account to join the conversation.

More
2 months 1 week ago #15657 by Jan Roza
Replied by Jan Roza on topic GetLocalTimeOffset return 0
Works as expected on Windows 10 as well, -60 for me being a Dutchman.

Operating Systems Windows 10 (64-bit) and virtual Linux Mint (64-bit)

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 months 6 days ago - 2 months 6 days ago #15658 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0
 
ShowMessage(DateTimeToStr(Now));
or
ShowMessage(DateTimeToStr(NowUTC));

Now 8:45 in Moscow (in systray), but functions Now() and NowUTC() show 5:45 both
Attachments:
Last edit: 2 months 6 days ago by Vital.

Please Log in or Create an account to join the conversation.

More
2 months 6 days ago #15659 by Vbxler
Replied by Vbxler on topic GetLocalTimeOffset return 0
What do you get after entering: timedatectl
 
Attachments:

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 months 5 days ago #15660 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0
$ timedatectl
Local time: Пт 2021-03-12 12:16:24 MSK
Universal time: Пт 2021-03-12 09:16:24 UTC
RTC time: Пт 2021-03-12 09:16:24
Time zone: Europe/Moscow (MSK, +0300)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 months 1 day ago - 2 months 1 day ago #15668 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0
Can I specify the time zone manually? Or how else can you force the compiled program to determine the correct timezone?
The project is on fire! We urgently need to do something!
Last edit: 2 months 1 day ago by Vital.

Please Log in or Create an account to join the conversation.

More
2 months 1 day ago #15671 by firliri
Replied by firliri on topic GetLocalTimeOffset return 0
Hi, did you test the ReReadLocalTime function ?

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 months 10 hours ago - 2 months 10 hours ago #15673 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0

Hi, did you test the ReReadLocalTime function ?


 

procedure TForm1.FormCreate(Sender: TObject);
var
  s: string;
begin
  s:= DateTimeToStr(Now)+' UTC:'+DateTimeToStr(NowUTC)+#13#10;
  ReReadLocalTime;
  s+= (' ReReading:'+#13#10+DateTimeToStr(Now)+' UTC:'+DateTimeToStr(NowUTC));
  Label1.Caption:= s;
end;
  

But real time in my timezone 14:27:21
 
Attachments:
Last edit: 2 months 10 hours ago by Vital.

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 month 4 weeks ago #15677 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0
Installed NeonOS KDE 5.21, the same problem :(

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 month 4 weeks ago #15678 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0
In Windows 10 it works as it should. In Ubuntu 20.04, Gnome 3.36 does not work as expected.

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 month 4 weeks ago #15679 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0
In Lazarus 2.0.12, fpc 3.2.0 works as it should
procedure TForm1.FormCreate(Sender: TObject);
var
  s: string;
begin
  s:= DateTimeToStr(Now)+' UTC:'+DateTimeToStr(LocalTimeToUniversal(Now));
  Label1.Caption:= s;
end;
 
 
Attachments:

Please Log in or Create an account to join the conversation.

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 month 4 weeks ago #15680 by Vital
Replied by Vital on topic GetLocalTimeOffset return 0
CT 7.0 works as it should.
There is no time to conduct more experiments. I remain until the delivery of the project on CT 7.0

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
1 month 4 weeks ago - 1 month 4 weeks ago #15691 by Sternas Stefanos
Replied by Sternas Stefanos on topic GetLocalTimeOffset return 0
Sir
after today update from FPC SVN: 49001   more info

With the above source, I get this

 


On Fedora 33 with the same Local time with your local time (UTC+3)

Just download from SVN the file :
rtl\unix\timezone.inc
and replace the CT file:
codetyphon/fpcsrc/rtl/unix/timezone.inc

Rebuild ALL (FPC and Typhon)

We try hard to offer "On User Side Real Time Support", but sometime we want help ... 
 

PilotLogic Architect and Core Programmer
Attachments:
Last edit: 1 month 4 weeks ago by Sternas Stefanos.
The following user(s) said Thank You: firliri

Please Log in or Create an account to join the conversation.

  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • I do love ObjectPascal and WinApi
More
1 month 3 weeks ago #15702 by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
Replied by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰 on topic GetLocalTimeOffset return 0
hello, i am new to CT and was searching for some practice.
i did played abit with code and for windows this solution came out, maybe usfull or not, you decide, for me just fun to do :)
program Project1;

uses Windows, SysUtils, DateUtils;

// include winapi methods
function TzSpecificLocalTimeToSystemTime(lpTimeZoneInformation: PTimeZoneInformation; var lpLocalTime, lpUniversalTime: TSystemTime): BOOL; stdcall; external kernel32 name 'TzSpecificLocalTimeToSystemTime';
function SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation: PTimeZoneInformation; var lpUniversalTime, lpLocalTime: TSystemTime): BOOL; stdcall; external kernel32 name 'SystemTimeToTzSpecificLocalTime';

// convert local time to UTC
function DateTimeToUTC(const Local: TDateTime): TDateTime;
var
  TZI: TTimeZoneInformation;
  LocalTime,
  UniversalTime: TSystemTime;
begin
  GetTimeZoneInformation(TZI);
  DateTimeToSystemTime(Local, LocalTime);
  TzSpecificLocalTimeToSystemTime(@TZI, LocalTime, UniversalTime);
  Result := SystemTimeToDateTime(UniversalTime);
end;

// convert UTC to local time
function UTCToLocalDateTime(const UTC: TDateTime): TDateTime;
var
  TZI: TTimeZoneInformation;
  LocalTime,
  UniversalTime: TSystemTime;
begin
  GetTimeZoneInformation(TZI);
  DateTimeToSystemTime(UTC, UniversalTime);
  SystemTimeToTzSpecificLocalTime(@TZI, UniversalTime, LocalTime);
  Result := SystemTimeToDateTime(LocalTime);
end;

// example usage
var
  Local,
  UTC: TDateTime;
begin
  Local := Now;
  UTC := DateTimeToUTC(Local);
  WriteLn('Local:  ' + DateTimeToStr(Local));
  WriteLn('UTC:    ' + DateTimeToStr(UTC));
  WriteLn('Offset: ' + IntToStr(SecondsBetween(Local, UTC) div 60 div 60));
  ReadLn;
end.

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #15703 by Matis A.
Replied by Matis A. on topic GetLocalTimeOffset return 0
Thanks Sir

PilotLogic Core Programmer

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
1 month 3 weeks ago - 1 month 3 weeks ago #15704 by Sternas Stefanos
Replied by Sternas Stefanos on topic GetLocalTimeOffset return 0
A big "Thanks" and from me Sir
Always we want your help,
it's a "critical factor" for us.

PilotLogic Architect and Core Programmer
Last edit: 1 month 3 weeks ago by Sternas Stefanos.

Please Log in or Create an account to join the conversation.

  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • I do love ObjectPascal and WinApi
More
1 month 3 weeks ago #15707 by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
Replied by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰 on topic GetLocalTimeOffset return 0
It's nice that you like what I've done there.
My source texts are unfortunately only suitable for windows.
Certainly there are methods in the existing libraries that achieve the same thing.
But I'm a little stubborn and usually go my own way.
I'll see what there is in the forum for questions.
If something appeals to me, especially with regard to windows and its api methods, i will tinker something.
If you are satisfied with what I offer, a small click on "thankyou" is enough to give me more incentive.
(For me, that reflects how well something is received or rejected.)
I don't want to violate forum rules, is there a kind of time limit until when you can answer a topic if you have perhaps found a better solution?
(I only picked this topic out because it was only a week old.)

Please forgive my spelling mistakes or the wrong sentence structure.
And please do not call me "Sir", call me KodeZwerg or in abbreviated form Kode.
 
The following user(s) said Thank You: Sternas Stefanos, Matis A.

Please Log in or Create an account to join the conversation.