blob: 485022929b21ed4809642a3558da51491a727b17 [file] [log] [blame]
Reid Spencer1cc19942004-09-25 05:03:54 +00001//===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===//
Michael J. Spencer447762d2010-11-29 18:16:10 +00002//
Reid Spencer1cc19942004-09-25 05:03:54 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Michael J. Spencer447762d2010-11-29 18:16:10 +00007//
Reid Spencer1cc19942004-09-25 05:03:54 +00008//===----------------------------------------------------------------------===//
9//
Reid Spencerdacbf462004-11-15 04:47:22 +000010// This file provides the Win32 implementation of the TimeValue class.
Reid Spencer1cc19942004-09-25 05:03:54 +000011//
12//===----------------------------------------------------------------------===//
13
Michael J. Spencer447762d2010-11-29 18:16:10 +000014#include "Windows.h"
Jeff Cohen2b60d392004-12-14 05:26:43 +000015#include <time.h>
Reid Spencer1cc19942004-09-25 05:03:54 +000016
17namespace llvm {
18using namespace sys;
19
20//===----------------------------------------------------------------------===//
Reid Spencer364cce42004-09-28 23:56:20 +000021//=== WARNING: Implementation here must contain only Win32 specific code.
Reid Spencer1cc19942004-09-25 05:03:54 +000022//===----------------------------------------------------------------------===//
23
Reid Spencer364cce42004-09-28 23:56:20 +000024TimeValue TimeValue::now() {
Jeff Cohen2b60d392004-12-14 05:26:43 +000025 uint64_t ft;
Reid Spencer364cce42004-09-28 23:56:20 +000026 GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft));
27
Jeff Cohen2b60d392004-12-14 05:26:43 +000028 TimeValue t(0, 0);
29 t.fromWin32Time(ft);
30 return t;
Reid Spencer364cce42004-09-28 23:56:20 +000031}
Reid Spencer1cc19942004-09-25 05:03:54 +000032
Chris Lattnerc521f542009-08-23 22:45:37 +000033std::string TimeValue::str() const {
Rafael Espindola17618242013-07-11 16:11:21 +000034 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;
Rafael Espindolab1c1c5f2013-07-11 15:35:23 +000043 __time64_t OurTime = this->toEpochTime();
Rafael Espindola17618242013-07-11 16:11:21 +000044 int Error = ::_localtime64_s(&Storage, &OurTime);
Rafael Espindolab1c1c5f2013-07-11 15:35:23 +000045 assert(!Error);
Rafael Espindola17618242013-07-11 16:11:21 +000046 LT = &Storage;
47#endif
Jeff Cohen2b60d392004-12-14 05:26:43 +000048
Rafael Espindolab1c1c5f2013-07-11 15:35:23 +000049 char Buffer[25];
50 // FIXME: the windows version of strftime doesn't support %e
Rafael Espindola17618242013-07-11 16:11:21 +000051 strftime(Buffer, 25, "%b %d %H:%M %Y", LT);
Rafael Espindolab1c1c5f2013-07-11 15:35:23 +000052 return std::string(Buffer);
Reid Spencer09e9f2a2004-11-16 06:22:17 +000053}
54
Reid Spencer1cc19942004-09-25 05:03:54 +000055
56}