Welcome, Guest
Username: Password: Remember me
Discussions for CodeTyphon Object Pascal Programming Language
  • Page:
  • 1
  • 2

TOPIC:

GetLocalTimeOffset return 0 3 years 1 month ago #15645

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 0
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.

GetLocalTimeOffset return 0 3 years 1 month ago #15647

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Thanks Sir
any sample for test

Did your set to your OS your local time ?
PilotLogic Architect and Core Programmer

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

Last edit: by Sternas Stefanos.

GetLocalTimeOffset return 0 3 years 1 month ago #15655

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 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.

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

Last edit: by Vital.

GetLocalTimeOffset return 0 3 years 1 month ago #15656

  • Vbxler
  • Vbxler's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 66
  • Thank you received: 4
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.

GetLocalTimeOffset return 0 3 years 1 month ago #15657

  • Jan Roza
  • Jan Roza's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 158
  • Thank you received: 6
Works as expected on Windows 10 as well, -60 for me being a Dutchman.
Operating Systems Windows 10 (64-bit), virtual Linux Mint (64-bit) and virtual Raspberry Pi Desktop

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

GetLocalTimeOffset return 0 3 years 1 month ago #15658

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 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:

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

Last edit: by Vital.

GetLocalTimeOffset return 0 3 years 1 month ago #15659

  • Vbxler
  • Vbxler's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 66
  • Thank you received: 4
What do you get after entering: timedatectl
 
Attachments:

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

GetLocalTimeOffset return 0 3 years 1 month ago #15660

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 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.

GetLocalTimeOffset return 0 3 years 1 month ago #15668

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 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!

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

Last edit: by Vital.

GetLocalTimeOffset return 0 3 years 1 month ago #15671

  • firliri
  • firliri's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 9
  • Thank you received: 1
Hi, did you test the ReReadLocalTime function ?

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

GetLocalTimeOffset return 0 3 years 1 month ago #15673

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 0

firliri wrote: 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:

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

Last edit: by Vital.

GetLocalTimeOffset return 0 3 years 1 month ago #15677

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 0
Installed NeonOS KDE 5.21, the same problem :(

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

GetLocalTimeOffset return 0 3 years 1 month ago #15678

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 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.

GetLocalTimeOffset return 0 3 years 1 month ago #15679

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 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.

GetLocalTimeOffset return 0 3 years 1 month ago #15680

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 80
  • Thank you received: 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.

GetLocalTimeOffset return 0 3 years 1 month ago #15691

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
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:
The following user(s) said Thank You: firliri

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

Last edit: by Sternas Stefanos.

GetLocalTimeOffset return 0 3 years 1 month ago #15702

  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • I do love ObjectPascal and WinApi
  • Posts: 20
  • Thank you received: 2
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.

GetLocalTimeOffset return 0 3 years 1 month ago #15703

  • Matis A.
  • Matis A.'s Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1060
  • Thank you received: 149
Thanks Sir
PilotLogic Core Programmer

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

GetLocalTimeOffset return 0 3 years 1 month ago #15704

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
A big "Thanks" and from me Sir
Always we want your help,
it's a "critical factor" for us.
PilotLogic Architect and Core Programmer

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

Last edit: by Sternas Stefanos.

GetLocalTimeOffset return 0 3 years 1 month ago #15707

  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • I do love ObjectPascal and WinApi
  • Posts: 20
  • Thank you received: 2
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.

  • Page:
  • 1
  • 2