2004-09-25 13:03:54 +08:00
|
|
|
//===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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.
|
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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-29 07:56:20 +08:00
|
|
|
#include "Win32.h"
|
2004-12-14 13:26:43 +08:00
|
|
|
#include <time.h>
|
2004-09-25 13:03:54 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
using namespace sys;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
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
|
|
|
|
2004-11-16 14:22:17 +08:00
|
|
|
std::string TimeValue::toString() const {
|
2005-02-19 11:01:13 +08:00
|
|
|
#ifdef __MINGW32__
|
2004-12-16 12:06:56 +08:00
|
|
|
// This ban may be lifted by either:
|
|
|
|
// (i) a future MinGW version other than 1.0 inherents the __time64_t type, or
|
|
|
|
// (ii) configure tests for either the time_t or __time64_t type.
|
2004-12-15 12:28:44 +08:00
|
|
|
time_t ourTime = time_t(this->toEpochTime());
|
|
|
|
struct tm *lt = ::localtime(&ourTime);
|
|
|
|
#else
|
2004-12-14 13:26:43 +08:00
|
|
|
__time64_t ourTime = this->toEpochTime();
|
2004-12-15 12:28:44 +08:00
|
|
|
struct tm *lt = ::_localtime64(&ourTime);
|
|
|
|
#endif
|
2004-12-14 13:26:43 +08:00
|
|
|
|
2004-12-15 12:28:44 +08:00
|
|
|
char buffer[25];
|
|
|
|
strftime(buffer, 25, "%a %b %d %H:%M:%S %Y", lt);
|
|
|
|
return std::string(buffer);
|
2004-11-16 14:22:17 +08:00
|
|
|
}
|
|
|
|
|
2004-09-25 13:03:54 +08:00
|
|
|
|
|
|
|
}
|