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