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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorZXShady2025-09-12 00:52:11 +0300
committerMartin Hořeňovský2025-10-04 22:10:36 +0200
commita58df2d7c59b037adca33c66c28ac63323d33cd4 (patch)
tree951e88281c4ddda452b81687e90fe3c41dc4bcb4 /src/catch2
parenta9223b2bb363c6e33bf1532b9cba0a472a69a023 (diff)
downloadcatch3-a58df2d7c59b037adca33c66c28ac63323d33cd4.tar.gz
Outline part of formatting system_clock's time_point into cpp file
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_tostring.cpp24
-rw-r--r--src/catch2/catch_tostring.hpp27
2 files changed, 28 insertions, 23 deletions
diff --git a/src/catch2/catch_tostring.cpp b/src/catch2/catch_tostring.cpp
index 20b0a629..dad62410 100644
--- a/src/catch2/catch_tostring.cpp
+++ b/src/catch2/catch_tostring.cpp
@@ -63,6 +63,30 @@ namespace Detail {
return n;
}
+ std::string formatTimeT(std::time_t time) {
+#ifdef _MSC_VER
+ std::tm timeInfo = {};
+ const auto err = gmtime_s( &timeInfo, &time );
+ 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( &time );
+#endif
+
+ auto const timeStampSize = sizeof( "2017-01-16T17:06:45Z" );
+ char timeStamp[timeStampSize];
+ const char* const fmt = "%Y-%m-%dT%H:%M:%SZ";
+
+#ifdef _MSC_VER
+ std::strftime( timeStamp, timeStampSize, fmt, &timeInfo );
+#else
+ std::strftime( timeStamp, timeStampSize, fmt, timeInfo );
+#endif
+ return std::string( timeStamp, timeStampSize - 1 );
+ }
+
std::string convertIntoString(StringRef string, bool escapeInvisibles) {
std::string ret;
// This is enough for the "don't escape invisibles" case, and a good
diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp
index aca1f7e0..db0338df 100644
--- a/src/catch2/catch_tostring.hpp
+++ b/src/catch2/catch_tostring.hpp
@@ -8,7 +8,7 @@
#ifndef CATCH_TOSTRING_HPP_INCLUDED
#define CATCH_TOSTRING_HPP_INCLUDED
-
+#include <ctime>
#include <vector>
#include <cstddef>
#include <type_traits>
@@ -42,6 +42,8 @@ namespace Catch {
std::size_t catch_strnlen(const char *str, std::size_t n);
+ std::string formatTimeT( std::time_t time );
+
constexpr StringRef unprintableString = "{?}"_sr;
//! Encases `string in quotes, and optionally escapes invisibles
@@ -629,28 +631,7 @@ struct ratio_string<std::milli> {
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, &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( &as_time_t );
-#endif
-
- auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
- char timeStamp[timeStampSize];
- const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
-
-#ifdef _MSC_VER
- std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
-#else
- std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
-#endif
- return std::string(timeStamp, timeStampSize - 1);
+ return ::Catch::Detail::formatTimeT( as_time_t );
}
};
}