Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2021-05

Is there a global timezone-independent time available?

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

If I use Now() to retrieve a TDateTime value I get it in whatever timezone (including DST) the box I run on is set to...
And there is no indication of the timezone used (TDateTime is just a double after all).

So now I wonder if there is some kind of globally constant time one can read which can be used in scheduling applications no matter what time zone is used. For example something like NowUTC() or similar?

I have been struggling with the user part of a remote monitoring system, which will run on a RaspberryPi under Linux (Debian flavour).

And there are lots of problems when going between the actual remote system and the config application because of the time zone differences. It would help a lot if one could use a time that is not messed with and is the same everywhere...

The important thing here is that two systems located at different places on Earth should agree on such a time value if it is taken at the same absolute instant.

And what is the useful resolution of the times?
seconds, miliseconds or what?

Bo Berglund Developer in Sweden

Reply by email

Denis Kozlov
to Bo Berglund

You can use LazSysUtils.NowUTC, and then there is also PascalTZ package if you want to convert between timezones.

There is a ticket with a patch for adding a similar function to FPC, but it needs some attention:
https://bugs.freepascal.org/view.php?id=30394
<https://bugs.freepascal.org/view.php?id=30394>

Regards,
Denis

Bo Berglund wrote 24 lines
If I use Now() to retrieve a TDateTime value I get it in whatever timezone (including DST) the box I run on is set to... And there is no indication of the timezone used (TDateTime is just a double after all). So now I wonder if there is some kind of globally constant time one can read which can be used in scheduling applications no matter what time zone is used. For example something like NowUTC() or similar? I have been struggling with the user part of a remote monitoring system, which will run on a RaspberryPi under Linux (Debian flavour). And there are lots of problems when going between the actual remote system and the config application because of the time zone differences. It would help a lot if one could use a time that is not messed with and is the same everywhere... The important thing here is that two systems located at different places on Earth should agree on such a time value if it is taken at the same absolute instant. And what is the useful resolution of the times? seconds, miliseconds or what?

Reply by email

Michael Van Canneyt
to Denis Kozlov
Denis Kozlov wrote 7 lines
You can use LazSysUtils.NowUTC, and then there is also PascalTZ package if you want to convert between timezones. There is a ticket with a patch for adding a similar function to FPC, but it needs some attention: https://bugs.freepascal.org/view.php?id=30394 <https://bugs.freepascal.org/view.php?id=30394>

I'm terribly sorry, I totally forgot about this bugreport :/

But Ondrej Pokorny has meanwhile implemented NowUTC and other related functions that allow more flexibility regarding the timezone.

So, Mr. Berglund, with FPC trunk, your problem will be solved. I'm not sure it will be in 3.2.2, because it is rather sensitive.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt

Op 2021-05-03 om 20:28 schreef Michael Van Canneyt via lazarus:

Show quoted text 5 lines
So, Mr. Berglund, with FPC trunk, your problem will be solved. I'm not sure it will be in 3.2.2, because it is rather sensitive.

Indeed, it (r47306) /won't be in 3.2.2

Reply by email

Bo Berglund
to Michael Van Canneyt: I'm terribly sorry, I totally forgot about this bugreport :/ But Ondrej Pokorny has…
Michael Van Canneyt wrote 20 lines
On Mon, 3 May 2021, Denis Kozlov via lazarus wrote: > You can use LazSysUtils.NowUTC, and then there is also PascalTZ package > if you want to convert between timezones. > > There is a ticket with a patch for adding a similar function to FPC, but > it needs some attention: > https://bugs.freepascal.org/view.php?id=30394 > <https://bugs.freepascal.org/view.php?id=30394> I'm terribly sorry, I totally forgot about this bugreport :/ But Ondrej Pokorny has meanwhile implemented NowUTC and other related functions that allow more flexibility regarding the timezone. So, Mr. Berglund, with FPC trunk, your problem will be solved. I'm not sure it will be in 3.2.2, because it is rather sensitive.

I only run with released versions so I will wait until then. I guess I can always do this to get an UTC timestamp:

function MyNowUTC: TDateTime;
begin
  Result := LocalTimeToUniversal(Now);
end;

Now I am at least running an UTC clock on screen using this call.

Bo Berglund Developer in Sweden

Reply by email