Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 1 | //===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===// |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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 | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Spencer | a79a99a | 2004-11-15 04:47:22 +0000 | [diff] [blame] | 10 | // This file provides the Win32 implementation of the TimeValue class. |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 14 | #include "Windows.h" |
Jeff Cohen | 626e38e | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 15 | #include <time.h> |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 16 | |
| 17 | namespace llvm { |
| 18 | using namespace sys; |
| 19 | |
| 20 | //===----------------------------------------------------------------------===// |
Reid Spencer | 10366a4 | 2004-09-28 23:56:20 +0000 | [diff] [blame] | 21 | //=== WARNING: Implementation here must contain only Win32 specific code. |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
| 23 | |
Reid Spencer | 10366a4 | 2004-09-28 23:56:20 +0000 | [diff] [blame] | 24 | TimeValue TimeValue::now() { |
Jeff Cohen | 626e38e | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 25 | uint64_t ft; |
Reid Spencer | 10366a4 | 2004-09-28 23:56:20 +0000 | [diff] [blame] | 26 | GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft)); |
| 27 | |
Jeff Cohen | 626e38e | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 28 | TimeValue t(0, 0); |
| 29 | t.fromWin32Time(ft); |
| 30 | return t; |
Reid Spencer | 10366a4 | 2004-09-28 23:56:20 +0000 | [diff] [blame] | 31 | } |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 74382b7 | 2009-08-23 22:45:37 +0000 | [diff] [blame] | 33 | std::string TimeValue::str() const { |
Jeff Cohen | 23a1cf3 | 2005-02-19 03:01:13 +0000 | [diff] [blame] | 34 | #ifdef __MINGW32__ |
Jeff Cohen | b8b836d | 2004-12-16 04:06:56 +0000 | [diff] [blame] | 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. |
Jeff Cohen | 003485a | 2004-12-15 04:28:44 +0000 | [diff] [blame] | 38 | time_t ourTime = time_t(this->toEpochTime()); |
| 39 | struct tm *lt = ::localtime(&ourTime); |
| 40 | #else |
Jeff Cohen | 626e38e | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 41 | __time64_t ourTime = this->toEpochTime(); |
Jeff Cohen | 003485a | 2004-12-15 04:28:44 +0000 | [diff] [blame] | 42 | struct tm *lt = ::_localtime64(&ourTime); |
| 43 | #endif |
Jeff Cohen | 626e38e | 2004-12-14 05:26:43 +0000 | [diff] [blame] | 44 | |
Jeff Cohen | 003485a | 2004-12-15 04:28:44 +0000 | [diff] [blame] | 45 | char buffer[25]; |
| 46 | strftime(buffer, 25, "%a %b %d %H:%M:%S %Y", lt); |
| 47 | return std::string(buffer); |
Reid Spencer | 8bf7fba | 2004-11-16 06:22:17 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 50 | |
| 51 | } |