Skip to content

Commit

Permalink
Fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasSchoenle committed Dec 6, 2016
1 parent 7ece784 commit f018f3e
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,30 @@ namespace g3 {

int timespec_get(struct timespec* ts/*, int base*/) {
#ifdef __MACH__
// std::timespec_get or posix clock_gettime)(...) are not
// implemented on OSX
// @return value of base if successful, else zero
struct timeval now = {};
int rv = gettimeofday(&now, nullptr);
if (-1 == rv) {
return rv;
}
// error mode. just return sec, microsecond
ts->tv_sec = now.tv_sec;
ts->tv_nsec = now.tv_usec * 1000;
return 0;
// std::timespec_get or posix clock_gettime)(...) are not
// implemented on OSX
// @return value of base if successful, else zero
struct timeval now = {};
int rv = gettimeofday(&now, nullptr);
if (-1 == rv) {
return rv;
}
// error mode. just return sec, microsecond
ts->tv_sec = now.tv_sec;
ts->tv_nsec = now.tv_usec * 1000;
return 0;
#elif(defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
static auto os =
std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now()).time_since_epoch() -
std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch();

auto now_ns = (std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch() + os).count();
ts ->tv_sec = now_ns / 1000000000;
ts ->tv_nsec = now_ns % 1000000000;
return TIME_UTC;
static auto os =
std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now()).time_since_epoch() -
std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch();

auto now_ns = (std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch() + os).count();
ts ->tv_sec = now_ns / 1000000000;
ts ->tv_nsec = now_ns % 1000000000;
return TIME_UTC;
#else
// ubuntu/gcc5 has no support for std::timespec_get(...) as of yet
return clock_gettime(CLOCK_REALTIME, ts);

// ubuntu/gcc5 has no support for std::timespec_get(...) as of yet
return clock_gettime(CLOCK_REALTIME, ts);
#endif
}

Expand Down

0 comments on commit f018f3e

Please sign in to comment.