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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-02-13 05:26:20 +08:00
|
|
|
#include "WindowsSupport.h"
|
2014-04-28 09:57:46 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/raw_ostream.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 {
|
2014-04-28 09:57:46 +08:00
|
|
|
std::string S;
|
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
|
|
|
|
2014-04-28 09:57:46 +08:00
|
|
|
char Buffer[sizeof("YYYY-MM-DD HH:MM:SS")];
|
|
|
|
strftime(Buffer, sizeof(Buffer), "%Y-%m-%d %H:%M:%S", LT);
|
|
|
|
raw_string_ostream OS(S);
|
|
|
|
OS << format("%s.%.9u", static_cast<const char *>(Buffer),
|
|
|
|
this->nanoseconds());
|
|
|
|
OS.flush();
|
|
|
|
return S;
|
2004-11-16 14:22:17 +08:00
|
|
|
}
|