1 //===- Unix/TimeValue.cpp - Unix TimeValue Implementation -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source 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::toString() const {
27 time_t ourTime = time_t(this->toEpochTime());
28 ::asctime_r(::localtime(&ourTime), buffer);
30 std::string result(buffer);
31 return result.substr(0,24);
34 TimeValue TimeValue::now() {
35 struct timeval the_time;
36 timerclear(&the_time);
37 if (0 != ::gettimeofday(&the_time,0))
38 ThrowErrno("Couldn't obtain time of day");
41 static_cast<TimeValue::SecondsType>( the_time.tv_sec ),
42 static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec *
43 NANOSECONDS_PER_MICROSECOND ) );
47 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab