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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/catch_tostring.cpp
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/catch_tostring.cpp
parenta9223b2bb363c6e33bf1532b9cba0a472a69a023 (diff)
downloadcatch3-a58df2d7c59b037adca33c66c28ac63323d33cd4.tar.gz
Outline part of formatting system_clock's time_point into cpp file
Diffstat (limited to 'src/catch2/catch_tostring.cpp')
-rw-r--r--src/catch2/catch_tostring.cpp24
1 files changed, 24 insertions, 0 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