C++: How to simulate different timezones in unit tests using google test
<p>I'm working in C++ with Google test for unit testing. In our companies code we still have the problem, that system data types as for example CTime use for example the timezone of the actual system (we use the CTime datatype the same way like in the production code). For unit testing, we want to simulate different time zones because we have many problems with that.</p>

<p>I already invested hours researching how others do that because it can't be, that other companies don't have this problem :) But I didn't find a solution for that.
My thoughts are like this:
CTime itself saves the time in UTC and converts it on demand into local time. My assumption is that all these functions need the GetTimeZoneInformation() functionality which is declared in timezonapi.h.</p>

<pre><code>WINBASEAPI
_Success_(return != TIME_ZONE_ID_INVALID)
DWORD
WINAPI
GetTimeZoneInformation(_Out_ LPTIME_ZONE_INFORMATION lpTimeZoneInformation);
</code></pre>

<p>So the solution would maybe be to exchange this GetTimeZoneInformation() functionality by a customized function which then returns an object which I can change on demand. But I don't know how to do that and I also do not know if this is working then or not because it's maybe only calling this function once when the application starts.</p>

<p>Does anyone know how to deal with this topic? I don't want to change any behaviours, I only want to be able to set my own timezone without breaking any time calculation mechanism. The best thing would be if I could somehow mock these calls without changing production code for that.
The thing is that this program is very big, old, and... changing as less as possible is always the best :)</p>

<p>If I've not found an already existing post which solved my problem then I'm really sorry because I either didn't find it or I didn't get that this can help me.</p>