blob: de8f267089dc2f73f4a98a33e23c6bbc7024671a [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//
Reid Spencer10366a42004-09-28 23:56:20 +00005// This file was developed by Jeff Cohen and is distributed under the
Reid Spencer0d5716e2004-09-25 05:03:54 +00006// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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 Cohen003485a2004-12-15 04:28:44 +000034#ifdef __MINGW
35 time_t ourTime = time_t(this->toEpochTime());
36 struct tm *lt = ::localtime(&ourTime);
37#else
Jeff Cohen626e38e2004-12-14 05:26:43 +000038 __time64_t ourTime = this->toEpochTime();
Jeff Cohen003485a2004-12-15 04:28:44 +000039 struct tm *lt = ::_localtime64(&ourTime);
40#endif
Jeff Cohen626e38e2004-12-14 05:26:43 +000041
Jeff Cohen003485a2004-12-15 04:28:44 +000042 char buffer[25];
43 strftime(buffer, 25, "%a %b %d %H:%M:%S %Y", lt);
44 return std::string(buffer);
Reid Spencer8bf7fba2004-11-16 06:22:17 +000045}
46
Reid Spencer0d5716e2004-09-25 05:03:54 +000047// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
48
49}