Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-08-01 23:00:30 +0200
committerMartin Hořeňovský2025-08-02 08:31:34 +0200
commit17fe5eaa5c0c28e7a6a197420f0f16b085a8fa9a (patch)
tree33d09eaa38e2e5538b6a67498724447f91b96d65 /src
parentfbfd13501ca288e5ffeb725328827786abb99d23 (diff)
downloadcatch3-17fe5eaa5c0c28e7a6a197420f0f16b085a8fa9a.tar.gz
Fix StringMaker for time_point<system_clock> with non-default duration
Fixes #2685
Diffstat (limited to 'src')
-rw-r--r--src/catch2/catch_tostring.hpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp
index 70741663..ab91c618 100644
--- a/src/catch2/catch_tostring.hpp
+++ b/src/catch2/catch_tostring.hpp
@@ -626,17 +626,19 @@ struct ratio_string<std::milli> {
template<typename Duration>
struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
- auto converted = std::chrono::system_clock::to_time_t(time_point);
+ const auto systemish = std::chrono::time_point_cast<
+ std::chrono::system_clock::duration>( time_point );
+ const auto as_time_t = std::chrono::system_clock::to_time_t( systemish );
#ifdef _MSC_VER
std::tm timeInfo = {};
- const auto err = gmtime_s(&timeInfo, &converted);
+ const auto err = gmtime_s( &timeInfo, &as_time_t );
if ( err ) {
return "gmtime from provided timepoint has failed. This "
"happens e.g. with pre-1970 dates using Microsoft libc";
}
#else
- std::tm* timeInfo = std::gmtime(&converted);
+ std::tm* timeInfo = std::gmtime( &as_time_t );
#endif
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");