Added windows-specific fixes, because strftime's implementation is different.

This commit is contained in:
sevas 2014-01-14 17:58:37 +01:00
parent c268cea41d
commit 9c6ab62b86

View File

@ -16,6 +16,7 @@
#include <assert.h> #include <assert.h>
#include <ctime> #include <ctime>
#include <cstring>
namespace Catch { namespace Catch {
@ -88,16 +89,26 @@ namespace Catch {
else else
xml.writeAttribute( "time", suiteTime ); xml.writeAttribute( "time", suiteTime );
time_t rawtime; #ifdef CATCH_PLATFORM_WINDOWS
struct tm * timeinfo; // %z does not return the offset from UTC with MSVC's strftime implementation
const size_t timestampLength = 33; // Timestamps will look like: "2014-01-14T17:22:09"
char iso8601Timestamp[timestampLength]; 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); time(&rawtime);
timeinfo = localtime(&rawtime); timeinfo = localtime(&rawtime);
strftime (iso8601Timestamp,timestampLength, "%Y-%m-%dT%T%z", timeinfo); size_t ret = strftime(timestampStr,timestampLength, fmt, timeinfo);
xml.writeAttribute( "timestamp", iso8601Timestamp ); assert(ret != 0);
xml.writeAttribute( "timestamp", timestampStr );
// Write test cases // Write test cases
for( TestGroupNode::ChildNodes::const_iterator for( TestGroupNode::ChildNodes::const_iterator