Home > Software design >  If a computer changes geographic location, will the system clock still return the UTC accurately?
If a computer changes geographic location, will the system clock still return the UTC accurately?

Time:07-09

Suppose someone travels from a country with UTC to /- X hr timezone. Their device such as a computer or a mobile, is completely switched off during this journey.

Upon reaching the destination, once the device is switched ON without internet, Will the system_clock::now() return a correct value of the UTC time?

Related: How datetime.datetime.now() works without internet connection?

CodePudding user response:

Yes, as long as you don't change any settings.

If you change your computer's location without letting it be aware, it will continue to function as though it was in the previous location. The local time will be wrong, but the UTC will correctly calculate based on the previous settings.

CodePudding user response:

That is possibly an operating system issue, but normally I would expect the system clock to be universally set to UTC and the TZ offset to be stored separately and applied to higher level time functions such as std::time() for example.

If you specifically want UTC, perhaps std::gmtime() would be more appropriate, since it is explicitly documented as UTC regardless of local time or system clock.

Additionally, regardless of all that, you have to consider how this computer will acquire a local timezone - it needs information to determine that. It might be manually entered, or determined by GNSS position if it has one, or it might "guess" from IP address (which can easily be wrong in territories with multiple timezones). Either way it is not magic.

You can in any event easily test the behaviour of system_clock by temporarily manually modifying your system's TZ.

  • Related