blob: 8f0ad38d8ef39dad13469a67579317b57dbbaa8a [file] [log] [blame]
Reid Spencer0d5716e2004-09-25 05:03:54 +00001//===- Unix/TimeValue.cpp - Unix TimeValue Implementation -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
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.
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
Reid Spencerd3518712004-11-14 22:10:08 +000021namespace llvm {
22 using namespace sys;
23
Reid Spencer8bf7fba2004-11-16 06:22:17 +000024std::string TimeValue::toString() const {
Reid Spencerd3518712004-11-14 22:10:08 +000025 char buffer[32];
26
27 time_t ourTime = time_t(this->toEpochTime());
28 ::asctime_r(::localtime(&ourTime), buffer);
29
30 std::string result(buffer);
31 return result.substr(0,24);
32}
33
Reid Spencer00b5df42004-11-15 04:36:35 +000034TimeValue TimeValue::now() {
35 struct timeval the_time;
Reid Spencer2e83ea52004-11-15 04:42:44 +000036 timerclear(&the_time);
Reid Spencer00b5df42004-11-15 04:36:35 +000037 if (0 != ::gettimeofday(&the_time,0))
38 ThrowErrno("Couldn't obtain time of day");
39
40 return TimeValue(
41 static_cast<TimeValue::SecondsType>( the_time.tv_sec ),
42 static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec *
43 NANOSECONDS_PER_MICROSECOND ) );
44}
45
Reid Spencer0d5716e2004-09-25 05:03:54 +000046}
47// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab