1218885Sdim//===- Unix/TimeValue.cpp - Unix TimeValue Implementation -------*- C++ -*-===// 2218885Sdim// 3218885Sdim// The LLVM Compiler Infrastructure 4218885Sdim// 5218885Sdim// This file is distributed under the University of Illinois Open Source 6218885Sdim// License. See LICENSE.TXT for details. 7218885Sdim// 8218885Sdim//===----------------------------------------------------------------------===// 9218885Sdim// 10218885Sdim// This file implements the Unix specific portion of the TimeValue class. 11218885Sdim// 12218885Sdim//===----------------------------------------------------------------------===// 13218885Sdim 14218885Sdim//===----------------------------------------------------------------------===// 15218885Sdim//=== WARNING: Implementation here must contain only generic UNIX code that 16218885Sdim//=== is guaranteed to work on *all* UNIX variants. 17218885Sdim//===----------------------------------------------------------------------===// 18218885Sdim 19218885Sdim#include "Unix.h" 20218885Sdim 21218885Sdimnamespace llvm { 22218885Sdim using namespace sys; 23218885Sdim 24218885Sdimstd::string TimeValue::str() const { 25263508Sdim time_t OurTime = time_t(this->toEpochTime()); 26263508Sdim struct tm Storage; 27263508Sdim struct tm *LT = ::localtime_r(&OurTime, &Storage); 28263508Sdim assert(LT); 29263508Sdim char Buffer[25]; 30263508Sdim strftime(Buffer, 25, "%b %e %H:%M %Y", LT); 31263508Sdim return std::string(Buffer); 32218885Sdim} 33218885Sdim 34218885SdimTimeValue TimeValue::now() { 35218885Sdim struct timeval the_time; 36218885Sdim timerclear(&the_time); 37218885Sdim if (0 != ::gettimeofday(&the_time,0)) { 38218885Sdim // This is *really* unlikely to occur because the only gettimeofday 39218885Sdim // errors concern the timezone parameter which we're passing in as 0. 40218885Sdim // In the unlikely case it does happen, just return MinTime, no error 41218885Sdim // message needed. 42218885Sdim return MinTime; 43218885Sdim } 44218885Sdim 45218885Sdim return TimeValue( 46249423Sdim static_cast<TimeValue::SecondsType>( the_time.tv_sec + 47249423Sdim PosixZeroTimeSeconds ), 48218885Sdim static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * 49218885Sdim NANOSECONDS_PER_MICROSECOND ) ); 50218885Sdim} 51218885Sdim 52218885Sdim} 53