diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp index cf3028e7..36f65db9 100644 --- a/include/reporters/catch_reporter_junit.hpp +++ b/include/reporters/catch_reporter_junit.hpp @@ -16,6 +16,7 @@ #include #include +#include namespace Catch { @@ -88,16 +89,26 @@ namespace Catch { else xml.writeAttribute( "time", suiteTime ); - time_t rawtime; - struct tm * timeinfo; - const size_t timestampLength = 33; - char iso8601Timestamp[timestampLength]; +#ifdef CATCH_PLATFORM_WINDOWS + // %z does not return the offset from UTC with MSVC's strftime implementation + // Timestamps will look like: "2014-01-14T17:22:09" + const size_t timestampLength = 20; + const char fmt[] = "%Y-%m-%dT%H:%M:%S"; +#else + // on posix systems, we can have the full timestamp (tested with gcc and clang) + const size_t timestampLength = 26; + const char fmt[] = "%Y-%m-%dT%T%z"; +#endif + char timestampStr[timestampLength]; + memset(timestampStr, 0, timestampLength); time(&rawtime); timeinfo = localtime(&rawtime); - strftime (iso8601Timestamp,timestampLength, "%Y-%m-%dT%T%z", timeinfo); - xml.writeAttribute( "timestamp", iso8601Timestamp ); + size_t ret = strftime(timestampStr,timestampLength, fmt, timeinfo); + assert(ret != 0); + + xml.writeAttribute( "timestamp", timestampStr ); // Write test cases for( TestGroupNode::ChildNodes::const_iterator