1 //===- Unix/TimeValue.cpp - Unix TimeValue Implementation -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Unix specific portion of the TimeValue class.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //=== is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
24 std::string TimeValue::str() const {
27 time_t ourTime = time_t(this->toEpochTime());
29 // note that the following line needs -D_REENTRANT on HP-UX to be picked up
30 asctime_r(localtime(&ourTime), buffer);
32 ::asctime_r(::localtime(&ourTime), buffer);
35 std::string result(buffer);
36 return result.substr(0,24);
39 TimeValue TimeValue::now() {
40 struct timeval the_time;
41 timerclear(&the_time);
42 if (0 != ::gettimeofday(&the_time,0)) {
43 // This is *really* unlikely to occur because the only gettimeofday
44 // errors concern the timezone parameter which we're passing in as 0.
45 // In the unlikely case it does happen, just return MinTime, no error
51 static_cast<TimeValue::SecondsType>( the_time.tv_sec + PosixZeroTime.seconds_ ),
52 static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec *
53 NANOSECONDS_PER_MICROSECOND ) );