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 "Windows.h"
15#include <time.h>
16
17namespace llvm {
18using namespace sys;
19
20//===----------------------------------------------------------------------===//
21//=== WARNING: Implementation here must contain only Win32 specific code.
22//===----------------------------------------------------------------------===//
23
24TimeValue TimeValue::now() {
25  uint64_t ft;
26  GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft));
27
28  TimeValue t(0, 0);
29  t.fromWin32Time(ft);
30  return t;
31}
32
33std::string TimeValue::str() const {
34  struct tm *LT;
35#ifdef __MINGW32__
36  // Old versions of mingw don't have _localtime64_s. Remove this once we drop support
37  // for them.
38  time_t OurTime = time_t(this->toEpochTime());
39  LT = ::localtime(&OurTime);
40  assert(LT);
41#else
42  struct tm Storage;
43  __time64_t OurTime = this->toEpochTime();
44  int Error = ::_localtime64_s(&Storage, &OurTime);
45  assert(!Error);
46  LT = &Storage;
47#endif
48
49  char Buffer[25];
50  // FIXME: the windows version of strftime doesn't support %e
51  strftime(Buffer, 25, "%b %d %H:%M %Y", LT);
52  assert((Buffer[3] == ' ' && isdigit(Buffer[5]) && Buffer[6] == ' ') ||
53         "Unexpected format in strftime()!");
54  // Emulate %e on %d to mute '0'.
55  if (Buffer[4] == '0')
56    Buffer[4] = ' ';
57  return std::string(Buffer);
58}
59
60
61}
62