From 610c48ddcbf1cc82ac9db3d2a62dc80af1a1b763 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 30 Jul 2015 11:57:23 +0200 Subject: [PATCH] Added getUTCString call to Util library. --- lib/timing.cpp | 12 ++++++++++++ lib/timing.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/lib/timing.cpp b/lib/timing.cpp index 3d7673a1..1d760ab1 100644 --- a/lib/timing.cpp +++ b/lib/timing.cpp @@ -4,6 +4,8 @@ #include "timing.h" #include //for gettimeofday #include //for time and nanosleep +#include +#include //emulate clock_gettime() for OSX compatibility #if defined(__APPLE__) || defined(__MACH__) @@ -97,3 +99,13 @@ long long unsigned int Util::getMicros(long long unsigned int previous) { long long int Util::epoch() { return time(0); } + +std::string Util::getUTCString(long long int epoch){ + if (!epoch){epoch = time(0);} + time_t rawtime = epoch; + struct tm * ptm; + ptm = gmtime(&rawtime); + char result[20]; + snprintf(result, 20, "%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + return std::string(result); +} diff --git a/lib/timing.h b/lib/timing.h index 0c027a45..e7486806 100644 --- a/lib/timing.h +++ b/lib/timing.h @@ -2,6 +2,7 @@ /// Utilities for handling time and timestamps. #pragma once +#include namespace Util { void wait(int ms); ///< Sleeps for the indicated amount of milliseconds or longer. @@ -12,4 +13,5 @@ namespace Util { long long unsigned int getMicros(long long unsigned int previous);///