Get current date and time from the internet (NTP?)

Hi -

It sometimes happens that our clients’ desktop PCs’ dates and/or times are way out (e.g. weeks ahead or behind)!

So obviously our Clarion code running under those circumstances gets incorrect values from today() and clock() - which are often used as default values on the GUIs… which users just glance over and don’t pay mush attention to, which in turn creates havoc within the logistical systems that we build and provide to our clients.

So we’ve countered this (to an extent) by checking the date/time of the on-prem SQL servers (via a simple SQL query) that our clients work with. But sometimes even our clients’ SERVERs date/time are way wrong!

So: we’re looking at having our applications obtain the correct local date and time at startup FROM A RELIABLE INTERNET SOURCE, e.g. an NTP server? And then adjust the PCs clock accordingly.

Any hints on the best way of obtaining the correct local date and time from the internet? Code examples perhaps?

Does NetTalk perhaps have a built-in function for this?

Thanks
Fred

so yeah, there are time servers on the internet. You can use the NetWebClient class to make a request to any of them. For example;
http://time.nist.gov:13

the NetTalk Demo app, testWebClient procedure, Atomic Time Server tab has an example of that GET and an example of parsing the string. (I suspect that parsing code could be updated now, now that we have StringTheory.)

One thing to note here, to be able to adjust the system clock, your user is going to need the SeSystemtimePrivilege. See docs here

Mark

1 Like

The protocol NTP is implemented in library Catalyst Socket Tools.
I used to work with NTP and did not require a license.
A file with a description of the prototypes was created for Clarion.
SocketTools

catalyst.zip (18,3 КБ)

Hi Fred
If you were to use a WorldTimeAPI call with a URL like this … https://worldtimeapi.org/api/timezone/Europe/London.txt

It will return a text block that is easy to parse …

abbreviation: GMT
client_ip: 212.159.61.92
datetime: 2024-03-17T09:53:27.264986+00:00
day_of_week: 0
day_of_year: 77
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: 0
timezone: Europe/London
unixtime: 1710669207
utc_datetime: 2024-03-17T09:53:27.264986+00:00
utc_offset: +00:00
week_number: 11

See https://worldtimeapi.org/api for more info

1 Like

Fred,

Perhaps obvious, but Windows has time/date control panel settings where it will do this internet inquiry for you and set the PC’s clock.

Mark

Hi Mark -

Yeah sure.

But we need something in our application that

(a) does a “sanity check” directly to the “outside world” to see if the PC’s date & time is OK;

and if NOT OK

(b) warns the user that the application will not continue until the PC’s date & time is properly set (by either the application itself, or by the user).

Fred