diff options
author | Brad King <brad.king@kitware.com> | 2009-12-21 15:29:00 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-12-21 15:29:00 (GMT) |
commit | cb27cfb1cc6d8a273f69506414c2991b6c989621 (patch) | |
tree | 1bca1146b68f5a64b0434ccd2aecc835625e876a | |
parent | 5cf77136cb938915c244d82ca55fcaf5177fd381 (diff) | |
download | CMake-cb27cfb1cc6d8a273f69506414c2991b6c989621.zip CMake-cb27cfb1cc6d8a273f69506414c2991b6c989621.tar.gz CMake-cb27cfb1cc6d8a273f69506414c2991b6c989621.tar.bz2 |
Use human-readable Git commit times in Update.xml
Previously we produced commit times formatted like
1261403774 -0500
which is what the Git plumbing prints. Now we use a human-readable
format like
2009-12-21 15:28:06 -0500
which is still easy to machine-parse.
-rw-r--r-- | Source/CTest/cmCTestGIT.cxx | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 5b0e8ff..8108b19 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -19,6 +19,8 @@ #include <cmsys/ios/sstream> #include <cmsys/Process.h> +#include <sys/types.h> +#include <time.h> #include <ctype.h> //---------------------------------------------------------------------------- @@ -336,16 +338,28 @@ private: Person author; this->ParsePerson(this->Line.c_str()+7, author); this->Rev.Author = author.Name; - char buf[1024]; + + // Convert the time to a human-readable format that is also easy + // to machine-parse: "CCYY-MM-DD hh:mm:ss". + time_t seconds = static_cast<time_t>(author.Time); + struct tm* t = gmtime(&seconds); + char dt[1024]; + sprintf(dt, "%04d-%02d-%02d %02d:%02d:%02d", + t->tm_year+1900, t->tm_mon+1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); + this->Rev.Date = dt; + + // Add the time-zone field "+zone" or "-zone". + char tz[32]; if(author.TimeZone >= 0) { - sprintf(buf, "%lu +%04ld", author.Time, author.TimeZone); + sprintf(tz, " +%04ld", author.TimeZone); } else { - sprintf(buf, "%lu -%04ld", author.Time, -author.TimeZone); + sprintf(tz, " -%04ld", -author.TimeZone); } - this->Rev.Date = buf; + this->Rev.Date += tz; } } |