LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Unix/TimeValue.inc
Go to the documentation of this file.
1 //===- Unix/TimeValue.cpp - Unix 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 implements the Unix specific portion of the TimeValue class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //=== is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
18 
19 #include "Unix.h"
20 
21 namespace llvm {
22  using namespace sys;
23 
24 std::string TimeValue::str() const {
25  time_t OurTime = time_t(this->toEpochTime());
26  struct tm Storage;
27  struct tm *LT = ::localtime_r(&OurTime, &Storage);
28  assert(LT);
29  char Buffer[25];
30  strftime(Buffer, 25, "%b %e %H:%M %Y", LT);
31  return std::string(Buffer);
32 }
33 
34 TimeValue TimeValue::now() {
35  struct timeval the_time;
36  timerclear(&the_time);
37  if (0 != ::gettimeofday(&the_time,0)) {
38  // This is *really* unlikely to occur because the only gettimeofday
39  // errors concern the timezone parameter which we're passing in as 0.
40  // In the unlikely case it does happen, just return MinTime, no error
41  // message needed.
42  return MinTime;
43  }
44 
45  return TimeValue(
46  static_cast<TimeValue::SecondsType>( the_time.tv_sec +
47  PosixZeroTimeSeconds ),
48  static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec *
50 }
51 
52 }
std::string str() const
Convert time to a string.
TimeValue()
Default construct a time value, initializing to ZeroTime.
Definition: TimeValue.h:86
static TimeValue now()
Creates a TimeValue with the current time (UTC).
static const TimeValue MinTime
The smallest possible time value.
Definition: TimeValue.h:41
int gettimeofday(struct timeval *tp, void *tzp);
uint64_t toEpochTime() const
Definition: TimeValue.h:250