blob: f45662948bc106b5cdc7b9afbf12144283f2a869 [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 Cohen626e38e2004-12-14 05:26:43 +000034 // Alas, asctime is not re-entrant on Windows...
35
36 __time64_t ourTime = this->toEpochTime();
37 char* buffer = ::asctime(::_localtime64(&ourTime));
38
39 std::string result(buffer);
40 return result.substr(0,24);
Reid Spencer8bf7fba2004-11-16 06:22:17 +000041}
42
Reid Spencer0d5716e2004-09-25 05:03:54 +000043// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
44
45}