IOS – Reasons for iOS system time jumping backwards on an iPad while being offline

clockiosipadiphonetime

My team and I ran into a bug, which is probably caused by the iOS system time not incrementing monotonically, but jumping backwards. The measured time difference was about -50 milliseconds. (That's obviously no leap second or time zone issue.)

We understand that iOS devices synchronize their time with NTP servers while being online. But the negative time difference was observed while having no network connection at all.

Are there any reasons iOS would update the system time while offline?

Relevant posts:

  • We'll certainly need to follow this approach for measuring elapsed times. But nevertheless, we'd like to understand what was causing the jump.

  • This answer mentions reasons for such time jumps, but none of them seems to apply in my case.

  • This answer mentions significant time changes. But what are insignificant changes?

Update: After 2 hours in airplane mode we observed a time jump of 637 ms into the past with System.DateTime.Now on a iPad Mini 2, while CACurrentMediaTime kept increasing monotonically. It's still unclear why iOS should do such a significant jump after such a long time without NTP updates.

Best Answer

The RTC clock is "tweaked" periodically to correct its time (for example to account for clock drift) - this happens no matter if you're online or offline. This is standard on modern operating systems, not just iOS.

The bug is not in your operating system, but in your app. If you want a monotonically increasing clock, you should not be using System.DateTime.Now.

In order to select the correct timer/clock function for your app, you need to determine what you want to use the time for - and then select accordingly. I.e. it is a very different need to want the current time to display to the user in a "clock app" compared to needing time to run a timer that will fire every 50 ms periodically in a game.