2004-09-25 05:03:54 +00:00
|
|
|
//===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===//
|
2010-11-29 18:16:10 +00:00
|
|
|
//
|
2004-09-25 05:03:54 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2010-11-29 18:16:10 +00:00
|
|
|
//
|
2004-09-25 05:03:54 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2004-11-15 04:47:22 +00:00
|
|
|
// This file provides the Win32 implementation of the TimeValue class.
|
2004-09-25 05:03:54 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "Windows.h"
|
2004-12-14 05:26:43 +00:00
|
|
|
#include <time.h>
|
2004-09-25 05:03:54 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
using namespace sys;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2004-09-28 23:56:20 +00:00
|
|
|
//=== WARNING: Implementation here must contain only Win32 specific code.
|
2004-09-25 05:03:54 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-28 23:56:20 +00:00
|
|
|
TimeValue TimeValue::now() {
|
2004-12-14 05:26:43 +00:00
|
|
|
uint64_t ft;
|
2004-09-28 23:56:20 +00:00
|
|
|
GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft));
|
|
|
|
|
2004-12-14 05:26:43 +00:00
|
|
|
TimeValue t(0, 0);
|
|
|
|
t.fromWin32Time(ft);
|
|
|
|
return t;
|
2004-09-28 23:56:20 +00:00
|
|
|
}
|
2004-09-25 05:03:54 +00:00
|
|
|
|
2009-08-23 22:45:37 +00:00
|
|
|
std::string TimeValue::str() const {
|
2013-07-11 16:11:21 +00:00
|
|
|
struct tm *LT;
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
// Old versions of mingw don't have _localtime64_s. Remove this once we drop support
|
|
|
|
// for them.
|
|
|
|
time_t OurTime = time_t(this->toEpochTime());
|
|
|
|
LT = ::localtime(&OurTime);
|
|
|
|
assert(LT);
|
|
|
|
#else
|
|
|
|
struct tm Storage;
|
2013-07-11 15:35:23 +00:00
|
|
|
__time64_t OurTime = this->toEpochTime();
|
2013-07-11 16:11:21 +00:00
|
|
|
int Error = ::_localtime64_s(&Storage, &OurTime);
|
2013-07-11 15:35:23 +00:00
|
|
|
assert(!Error);
|
2013-07-11 16:11:21 +00:00
|
|
|
LT = &Storage;
|
|
|
|
#endif
|
2013-07-11 15:35:23 +00:00
|
|
|
|
|
|
|
char Buffer[25];
|
|
|
|
// FIXME: the windows version of strftime doesn't support %e
|
2013-07-11 16:11:21 +00:00
|
|
|
strftime(Buffer, 25, "%b %d %H:%M %Y", LT);
|
2013-07-12 02:13:03 +00:00
|
|
|
assert((Buffer[3] == ' ' && isdigit(Buffer[5]) && Buffer[6] == ' ') ||
|
|
|
|
"Unexpected format in strftime()!");
|
|
|
|
// Emulate %e on %d to mute '0'.
|
|
|
|
if (Buffer[4] == '0')
|
|
|
|
Buffer[4] = ' ';
|
2013-07-11 15:35:23 +00:00
|
|
|
return std::string(Buffer);
|
2004-11-16 06:22:17 +00:00
|
|
|
}
|
|
|
|
|
2004-09-25 05:03:54 +00:00
|
|
|
|
|
|
|
}
|