Opened 3 years ago

Last modified 3 years ago

#17580 confirmed enhancement

Implement catching system time change

Reported by: oneeyeman Owned by:
Priority: low Milestone:
Component: base Version: dev-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

On Windows it is possible thru catching WM_TIMECHANGE.
On OSX/Cocoa it can be done with NSSystemClockDidChangeNotification.

Don't know about GTK+ yet.

Setting the component to base as it probably belong to the Application class. Please change accordingly if I'm wrong.

Change History (5)

comment:1 Changed 3 years ago by vadz

  • Status changed from new to confirmed

I am not sure if it's a good idea to wrap WM_TIMECHANGE directly because there is nothing like this under Unix to the best of my knowledge.

Instead we could provide some higher level facility allowing to execute some code at later time or after some time passes and this would indeed be useful. I.e. currently bad things probably happen during the DST change if you have a timer set to fire once per hour, it would be nice if we could ensure that we don't lose nor have spurious notifications in this case.

And WM_TIMECHANGE could be used to implement this but, again, I don't think it's a good idea to expose it directly. We need to understand why would a Windows program use it and provide a way to do the same thing portably.

comment:2 Changed 3 years ago by Nitch

We need to understand why would a Windows program use it and provide a way to do the same thing portably

Example 1
Server application that deal with timesynchronization - when it detect a timejump in a system, it should notify its client with new timestamp
(Don't ask why not using NTP :))

Example 2
Application that perform continuous data aquisition and archiving - timestamps and values. It should be able to detect a timejump in a system to store apropriate information into archive record - in addition to timestamp

All above - it's a live example coming from SCADA (industrial plant controlling applications)

The thimejump here is not only DST, but all possible case of time changes - by user manually or by another application (NTP, GPS time receiver and so on).

comment:3 follow-up: Changed 3 years ago by patlkli

wxGTKTimerImpl from wxGTK seems to rely on gtk_timeout_add, which AFAIK is implemented with a monotonic clock source, that is immune to system time changes.

wxUnixTimerImpl seems to be polling UTC time which is affected by system time change, but it should be pretty easy to change that to poll a monotonic clock source (or use timerfd and select without polling)

I honestly have no idea (and MSDN isn't very helpful here either), whether wxMSWTimerImpl (which uses Win32's SetTimer) is system time change affected or not.

IMHO, we still should have an interface for platforms that provide notifications about system time changes.
Maybe other platforms should just do nothing then.

comment:4 in reply to: ↑ 3 Changed 3 years ago by oneeyeman

Hi,
Replying to patlkli:

wxGTKTimerImpl from wxGTK seems to rely on gtk_timeout_add, which AFAIK is implemented with a monotonic clock source, that is immune to system time changes.

wxUnixTimerImpl seems to be polling UTC time which is affected by system time change, but it should be pretty easy to change that to poll a monotonic clock source (or use timerfd and select without polling)

I honestly have no idea (and MSDN isn't very helpful here either), whether wxMSWTimerImpl (which uses Win32's SetTimer) is system time change affected or not.

IMHO, we still should have an interface for platforms that provide notifications about system time changes.
Maybe other platforms should just do nothing then.

We should.
Thing is all 3 major platforms can have an implementation - on Windows its WM_TIMECHANGE, on OSX - appropriate notification and on Linux - timer catch. On Linux it should probably be done conditionally, because apparently as Vadim said GTK+ does not provide a signal it send on the system date/time change. Probably Qt follows.

comment:5 Changed 3 years ago by patlkli

You can't properly detect time changes with a "timer catch". You'd have to setup a monotonic timer with interval N and check the system time before and after and then check the difference. That's chaos.

In Linux kernels 3.0 and above, there's a TFD_TIMER_CANCEL_ON_SET flag for the timerfd_settime syscall, which make it possible to detect a time change.

Note: See TracTickets for help on using tickets.