LLVM  3.7.0
Windows/TimeValue.inc
Go to the documentation of this file.
1 //===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides the Win32 implementation of the TimeValue class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "WindowsSupport.h"
15 #include "llvm/Support/Format.h"
17 #include <cctype>
18 #include <time.h>
19 
20 using namespace llvm;
21 using namespace llvm::sys;
22 
23 //===----------------------------------------------------------------------===//
24 //=== WARNING: Implementation here must contain only Win32 specific code.
25 //===----------------------------------------------------------------------===//
26 
28  uint64_t ft;
29  GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft));
30 
31  TimeValue t(0, 0);
32  t.fromWin32Time(ft);
33  return t;
34 }
35 
36 std::string TimeValue::str() const {
37  std::string S;
38  struct tm *LT;
39 #ifdef __MINGW32__
40  // Old versions of mingw don't have _localtime64_s. Remove this once we drop support
41  // for them.
42  time_t OurTime = time_t(this->toEpochTime());
43  LT = ::localtime(&OurTime);
44  assert(LT);
45 #else
46  struct tm Storage;
47  __time64_t OurTime = this->toEpochTime();
48  int Error = ::_localtime64_s(&Storage, &OurTime);
49  assert(!Error);
50  (void)Error;
51  LT = &Storage;
52 #endif
53 
54  char Buffer[sizeof("YYYY-MM-DD HH:MM:SS")];
55  strftime(Buffer, sizeof(Buffer), "%Y-%m-%d %H:%M:%S", LT);
56  raw_string_ostream OS(S);
57  OS << format("%s.%.9u", static_cast<const char *>(Buffer),
58  this->nanoseconds());
59  OS.flush();
60  return S;
61 }
std::string str() const
Provides conversion of the TimeValue into a readable time & date.
static TimeValue now()
This is a static constructor that returns a TimeValue that represents the current time...
NanoSecondsType nanoseconds() const
Returns only the nanoseconds component of the TimeValue.
Definition: TimeValue.h:212
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:111
uint64_t toEpochTime() const
Converts the TimeValue into the corresponding number of seconds since the epoch (00:00:00 Jan 1...
Definition: TimeValue.h:250
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:465
This class is used where a precise fixed point in time is required.
Definition: TimeValue.h:31