blob: 0ca87d423325d60018af8f80fd4e42babb802340 [file] [log] [blame]
Reid Spencer0d5716e2004-09-25 05:03:54 +00001//===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer0d5716e2004-09-25 05:03:54 +00007//
8//===----------------------------------------------------------------------===//
9//
Reid Spencera79a99a2004-11-15 04:47:22 +000010// This file provides the Win32 implementation of the TimeValue class.
Reid Spencer0d5716e2004-09-25 05:03:54 +000011//
12//===----------------------------------------------------------------------===//
13
Reid Spencer10366a42004-09-28 23:56:20 +000014#include "Win32.h"
Jeff Cohen626e38e2004-12-14 05:26:43 +000015#include <time.h>
Reid Spencer0d5716e2004-09-25 05:03:54 +000016
17namespace llvm {
18using namespace sys;
19
20//===----------------------------------------------------------------------===//
Reid Spencer10366a42004-09-28 23:56:20 +000021//=== WARNING: Implementation here must contain only Win32 specific code.
Reid Spencer0d5716e2004-09-25 05:03:54 +000022//===----------------------------------------------------------------------===//
23
Reid Spencer10366a42004-09-28 23:56:20 +000024TimeValue TimeValue::now() {
Jeff Cohen626e38e2004-12-14 05:26:43 +000025 uint64_t ft;
Reid Spencer10366a42004-09-28 23:56:20 +000026 GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft));
27
Jeff Cohen626e38e2004-12-14 05:26:43 +000028 TimeValue t(0, 0);
29 t.fromWin32Time(ft);
30 return t;
Reid Spencer10366a42004-09-28 23:56:20 +000031}
Reid Spencer0d5716e2004-09-25 05:03:54 +000032
Reid Spencer8bf7fba2004-11-16 06:22:17 +000033std::string TimeValue::toString() const {
Jeff Cohen23a1cf32005-02-19 03:01:13 +000034#ifdef __MINGW32__
Jeff Cohenb8b836d2004-12-16 04:06:56 +000035 // 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 Cohen003485a2004-12-15 04:28:44 +000038 time_t ourTime = time_t(this->toEpochTime());
39 struct tm *lt = ::localtime(&ourTime);
40#else
Jeff Cohen626e38e2004-12-14 05:26:43 +000041 __time64_t ourTime = this->toEpochTime();
Jeff Cohen003485a2004-12-15 04:28:44 +000042 struct tm *lt = ::_localtime64(&ourTime);
43#endif
Jeff Cohen626e38e2004-12-14 05:26:43 +000044
Jeff Cohen003485a2004-12-15 04:28:44 +000045 char buffer[25];
46 strftime(buffer, 25, "%a %b %d %H:%M:%S %Y", lt);
47 return std::string(buffer);
Reid Spencer8bf7fba2004-11-16 06:22:17 +000048}
49
Reid Spencer0d5716e2004-09-25 05:03:54 +000050
51}