Fix a FIXME about the format and add a test.

While at it, use strftime on Unix too and use the thread safe versions
of localtime.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186090 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2013-07-11 15:35:23 +00:00
parent 11eb51e239
commit 71857ccdb8
4 changed files with 43 additions and 40 deletions

View File

@@ -22,18 +22,13 @@ namespace llvm {
using namespace sys;
std::string TimeValue::str() const {
char buffer[32];
time_t ourTime = time_t(this->toEpochTime());
#ifdef __hpux
// note that the following line needs -D_REENTRANT on HP-UX to be picked up
asctime_r(localtime(&ourTime), buffer);
#else
::asctime_r(::localtime(&ourTime), buffer);
#endif
std::string result(buffer);
return result.substr(0,24);
time_t OurTime = time_t(this->toEpochTime());
struct tm Storage;
struct tm *LT = ::localtime_r(&OurTime, &Storage);
assert(LT);
char Buffer[25];
strftime(Buffer, 25, "%b %e %H:%M %Y", LT);
return std::string(Buffer);
}
TimeValue TimeValue::now() {