1 //===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file provides the Win32 implementation of the TimeValue class. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "Windows.h" 15 #include <time.h> 16 17 namespace llvm { 18 using namespace sys; 19 20 //===----------------------------------------------------------------------===// 21 //=== WARNING: Implementation here must contain only Win32 specific code. 22 //===----------------------------------------------------------------------===// 23 24 TimeValue TimeValue::now() { 25 uint64_t ft; 26 GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft)); 27 28 TimeValue t(0, 0); 29 t.fromWin32Time(ft); 30 return t; 31 } 32 33 std::string TimeValue::str() const { 34 #ifdef __MINGW32__ 35 // This ban may be lifted by either: 36 // (i) a future MinGW version other than 1.0 inherents the __time64_t type, or 37 // (ii) configure tests for either the time_t or __time64_t type. 38 time_t ourTime = time_t(this->toEpochTime()); 39 struct tm *lt = ::localtime(&ourTime); 40 #else 41 __time64_t ourTime = this->toEpochTime(); 42 struct tm *lt = ::_localtime64(&ourTime); 43 #endif 44 45 char buffer[25]; 46 strftime(buffer, 25, "%a %b %d %H:%M:%S %Y", lt); 47 return std::string(buffer); 48 } 49 50 51 } 52