The implementation of GetTime is confusing:
- The value returned by
GetTimeis assumed to be equal toGetTime<std::chrono::seconds>(). Both are mockable and the only difference is return type, the value itself is equal. However, the implementation does not support this assumption. - On some systems,
time_tmight be a signed 32-bit integer (https://en.cppreference.com/w/c/chrono/time), thus breaking in the year 2038, whereasGetTime<std::chrono::seconds>does not. Also,time_tmight be-1"on error", where "error" is unspecified. GetTime<std::chrono::seconds>callsGetTimeMicros, which callsGetSystemTime, which callsstd::chrono::system_clock::now, which doesn't have the above issues. See https://en.cppreference.com/w/cpp/chrono/system_clock/nowGetTimeMicrosand the internal-onlyGetSystemTimewill likely be renamed (to clarify they are the non-mockable non-monotonic system time) or removed in the future to be replaced by appropriatestd::chrono::time_point<Clock>getters.
Fix all issues by:
- making
GetTime()an alias forGetTime<std::chrono::seconds>().count(). - inlining the needed parts of
GetSystemTimedirectly instead of needlessly increasing the function call stack with functions that are likely to be removed in the future.