Reid Spencer | 1cc1994 | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 1 | //===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===// |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | 1cc1994 | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | 1cc1994 | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Spencer | dacbf46 | 2004-11-15 04:47:22 +0000 | [diff] [blame] | 10 | // This file provides the Win32 implementation of the TimeValue class. |
Reid Spencer | 1cc1994 | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 14 | #include "Windows.h" |
Jeff Cohen | 2b60d39 | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 15 | #include <time.h> |
Reid Spencer | 1cc1994 | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 16 | |
| 17 | namespace llvm { |
| 18 | using namespace sys; |
| 19 | |
| 20 | //===----------------------------------------------------------------------===// |
Reid Spencer | 364cce4 | 2004-09-28 23:56:20 +0000 | [diff] [blame] | 21 | //=== WARNING: Implementation here must contain only Win32 specific code. |
Reid Spencer | 1cc1994 | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
| 23 | |
Reid Spencer | 364cce4 | 2004-09-28 23:56:20 +0000 | [diff] [blame] | 24 | TimeValue TimeValue::now() { |
Jeff Cohen | 2b60d39 | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 25 | uint64_t ft; |
Reid Spencer | 364cce4 | 2004-09-28 23:56:20 +0000 | [diff] [blame] | 26 | GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft)); |
| 27 | |
Jeff Cohen | 2b60d39 | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 28 | TimeValue t(0, 0); |
| 29 | t.fromWin32Time(ft); |
| 30 | return t; |
Reid Spencer | 364cce4 | 2004-09-28 23:56:20 +0000 | [diff] [blame] | 31 | } |
Reid Spencer | 1cc1994 | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 32 | |
Chris Lattner | c521f54 | 2009-08-23 22:45:37 +0000 | [diff] [blame] | 33 | std::string TimeValue::str() const { |
Rafael Espindola | 1761824 | 2013-07-11 16:11:21 +0000 | [diff] [blame^] | 34 | struct tm *LT; |
| 35 | #ifdef __MINGW32__ |
| 36 | // Old versions of mingw don't have _localtime64_s. Remove this once we drop support |
| 37 | // for them. |
| 38 | time_t OurTime = time_t(this->toEpochTime()); |
| 39 | LT = ::localtime(&OurTime); |
| 40 | assert(LT); |
| 41 | #else |
| 42 | struct tm Storage; |
Rafael Espindola | b1c1c5f | 2013-07-11 15:35:23 +0000 | [diff] [blame] | 43 | __time64_t OurTime = this->toEpochTime(); |
Rafael Espindola | 1761824 | 2013-07-11 16:11:21 +0000 | [diff] [blame^] | 44 | int Error = ::_localtime64_s(&Storage, &OurTime); |
Rafael Espindola | b1c1c5f | 2013-07-11 15:35:23 +0000 | [diff] [blame] | 45 | assert(!Error); |
Rafael Espindola | 1761824 | 2013-07-11 16:11:21 +0000 | [diff] [blame^] | 46 | LT = &Storage; |
| 47 | #endif |
Jeff Cohen | 2b60d39 | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 48 | |
Rafael Espindola | b1c1c5f | 2013-07-11 15:35:23 +0000 | [diff] [blame] | 49 | char Buffer[25]; |
| 50 | // FIXME: the windows version of strftime doesn't support %e |
Rafael Espindola | 1761824 | 2013-07-11 16:11:21 +0000 | [diff] [blame^] | 51 | strftime(Buffer, 25, "%b %d %H:%M %Y", LT); |
Rafael Espindola | b1c1c5f | 2013-07-11 15:35:23 +0000 | [diff] [blame] | 52 | return std::string(Buffer); |
Reid Spencer | 09e9f2a | 2004-11-16 06:22:17 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Reid Spencer | 1cc1994 | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 55 | |
| 56 | } |