1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-06 08:15:34 +00:00

Merge branch 'chrono_fix' into 'master'

Simplify file_time_type to time_t conversion

See merge request OpenMW/openmw!3161
This commit is contained in:
psi29a 2023-08-03 21:47:40 +00:00
commit ed81baf864

View file

@ -15,14 +15,11 @@ namespace Misc
{
inline std::time_t toTimeT(std::filesystem::file_time_type tp)
{
using namespace std::chrono;
#if __cpp_lib_chrono >= 201907
const auto systemTime = clock_cast<system_clock>(tp);
#else
auto systemTime = time_point_cast<system_clock::duration>(
tp - std::filesystem::file_time_type::clock::now() + system_clock::now());
#endif
return system_clock::to_time_t(systemTime);
// Note: this conversion has a precision loss, so it should not be used in exact comparisons
// or another cases when milliseconds matter.
auto systemTime = time_point_cast<std::chrono::system_clock::duration>(
tp - std::filesystem::file_time_type::clock::now() + std::chrono::system_clock::now());
return std::chrono::system_clock::to_time_t(systemTime);
}
inline std::string timeTToString(const std::time_t tp, const char* fmt)