False change of time detected via NSNotificationCenter on Ventura, Monterey

I have the next problem: my app gets a false notification about time change.

// add observer and notification 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSystemTimeChangeNotification:) name:NSSystemClockDidChangeNotification object:nil];

// handle system notification about time change
- (void)handleSystemTimeChangeNotification:(NSNotification*)notification
{
    CLLogInfo(@"The time change detected");
}

It works without any problem on previous OS: Big Sur, Catalina. Only working with Monterey, Ventura I have these troubles.

Please, give me some recommendations about what I should do. How can I detect time change on macOS (Ventura, Monterey) ?

For notifications like this you shouldn’t assume that every notification corresponds to a visible change. Rather, use the notification to tell you that something has changed and then go from there. In most cases you can avoid doing extra work by storing a copy of the original value and then checking to see if that’s changed. That’s harder in this case because the “original value” is the current time, and you can’t reasonably store a copy of that [1]. My advice is that you simply try to minimise the amount of work you do in response to this notification.

And, to be clear, this issue is fundamental to the design of this API. Consider this sequence:

  1. Your app is undergoing app nap, and thus runs very infrequently.

  2. The user changes a value.

  3. And then immediately changes it back.

  4. Your app resumes from its app nap.

You’ll receive multiple notifications but there’s no visible state change.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] You could store the value of the kern.boottime sysctl, which changes when the clock changes to preserve the apparent up time, but that’s probably not worth it in this case.

False change of time detected via NSNotificationCenter on Ventura, Monterey
 
 
Q