23 #include <sys/utime.h>
27 #include <sys/select.h>
36 #include <sys/types.h>
53 double sec_frac = T - floor(T);
56 const auto tt = time_t(T);
58 struct tm* parts = localTime ? localtime(&tt) : gmtime(&tt);
61 p.
year = parts->tm_year + 1900;
62 p.
month = parts->tm_mon + 1;
63 p.
day = parts->tm_mday;
66 p.
hour = parts->tm_hour;
68 p.
second = parts->tm_sec + sec_frac;
80 parts.tm_year = p.
year - 1900;
81 parts.tm_mon = p.
month - 1;
82 parts.tm_mday = p.
day;
85 parts.tm_hour = p.
hour;
87 parts.tm_sec = int(p.
second);
89 double sec_frac = p.
second - parts.tm_sec;
105 parts.tm_year = p.
year - 1900;
106 parts.tm_mon = p.
month - 1;
107 parts.tm_mday = p.
day;
110 parts.tm_hour = p.
hour;
112 parts.tm_sec = int(p.
second);
114 double sec_frac = p.
second - parts.tm_sec;
116 time_t tt = mktime(&parts);
126 double timeSeconds = (t < 0) ? (-t) : t;
129 const auto nDays =
static_cast<unsigned int>(timeSeconds / (3600 * 24));
130 timeSeconds -= nDays * 3600 * 24;
131 const auto nHours =
static_cast<unsigned int>(timeSeconds / 3600);
132 timeSeconds -= nHours * 3600;
133 const auto nMins =
static_cast<unsigned int>(timeSeconds / 60);
134 const auto nSecs =
static_cast<unsigned int>(timeSeconds) % 60;
136 static_cast<unsigned int>(1000 * timeSeconds - floor(timeSeconds));
147 return static_cast<unsigned int>(
148 1e6 *
static_cast<double>(tmp % 10000000) / 1e7);
159 (t.time_since_epoch().count() - ((uint64_t)116444736 * 1000000000));
160 time_t auxTime = tmp / (uint64_t)10000000;
162 tm* ptm = gmtime(&auxTime);
164 if (!ptm)
return std::string(
"(Malformed timestamp)");
167 "%u/%02u/%02u,%02u:%02u:%02u.%06u", 1900 + ptm->tm_year,
168 ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
169 (
unsigned int)ptm->tm_sec, secFractions);
181 (t.time_since_epoch().count() - ((uint64_t)116444736 * 1000000000));
182 time_t auxTime = tmp / (uint64_t)10000000;
184 tm* ptm = localtime(&auxTime);
186 if (!ptm)
return "(Malformed timestamp)";
189 "%u/%02u/%02u,%02u:%02u:%02u.%06u", 1900 + ptm->tm_year,
190 ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
191 (
unsigned int)ptm->tm_sec, secFractions);
203 auto t = tt.time_since_epoch().count();
206 FileTimeToSystemTime((FILETIME*)&t, &sysT);
207 return sysT.wHour * 3600.0 + sysT.wMinute * 60.0 + sysT.wSecond +
208 sysT.wMilliseconds * 0.001;
211 (t - ((uint64_t)116444736 * 1000000000)) / (uint64_t)10000000;
212 tm* ptm = gmtime(&auxTime);
214 return ptm->tm_hour * 3600.0 + ptm->tm_min * 60.0 + ptm->tm_sec;
226 auto t = tt.time_since_epoch().count();
228 uint64_t tmp = (t - ((uint64_t)116444736 * 1000000000));
229 const time_t auxTime = tmp / (uint64_t)10000000;
230 const tm* ptm = localtime(&auxTime);
233 const unsigned int user_secondFractionDigits = secondFractionDigits;
234 while (secondFractionDigits++ < 6) secFractions = secFractions / 10;
237 "%02u:%02u:%02u.%0*u", ptm->tm_hour, ptm->tm_min,
238 (
unsigned int)ptm->tm_sec, user_secondFractionDigits, secFractions);
247 auto t = tt.time_since_epoch().count();
249 uint64_t tmp = (t - ((uint64_t)116444736 * 1000000000));
250 time_t auxTime = tmp / (uint64_t)10000000;
252 tm* ptm = gmtime(&auxTime);
253 if (!ptm)
return string(
"(Malformed timestamp)");
256 "%02u:%02u:%02u.%06u", ptm->tm_hour, ptm->tm_min,
257 (
unsigned int)ptm->tm_sec, secFractions);
266 auto t = tt.time_since_epoch().count();
268 uint64_t tmp = (t - ((uint64_t)116444736 * 1000000000));
269 time_t auxTime = tmp / (uint64_t)10000000;
270 tm* ptm = gmtime(&auxTime);
271 if (!ptm)
return string(
"(Malformed timestamp)");
274 "%u/%02u/%02u", 1900 + ptm->tm_year, ptm->tm_mon + 1, ptm->tm_mday);
285 if (seconds >= 365 * 24 * 3600)
286 return format(
"%.2f years", seconds / (365 * 24 * 3600));
287 else if (seconds >= 24 * 3600)
288 return format(
"%.2f days", seconds / (24 * 3600));
289 else if (seconds >= 3600)
290 return format(
"%.2f hours", seconds / 3600);
291 else if (seconds >= 60)
292 return format(
"%.2f minutes", seconds / 60);
293 else if (seconds >= 1)
294 return format(
"%.2f sec", seconds);
295 else if (seconds >= 1e-3)
296 return format(
"%.2f ms", seconds * 1e3);
297 else if (seconds >= 1e-6)
298 return format(
"%.2f us", seconds * 1e6);
300 return format(
"%.2f ns", seconds * 1e9);
305 const uint64_t v = t.time_since_epoch().count();