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 <ctime>
#include <cstring>
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