21 #include <sys/utime.h> 28 #include <sys/select.h> 36 #include <sys/types.h> 53 t.time_since_epoch().count() -
54 UINT64_C(116444736) * UINT64_C(1000000000)) /
64 double sec_frac = T - floor(T);
67 const time_t tt = time_t(T);
69 struct tm* parts = localTime ? localtime(&tt) : gmtime(&tt);
72 p.year = parts->tm_year + 1900;
73 p.month = parts->tm_mon + 1;
74 p.day = parts->tm_mday;
75 p.day_of_week = parts->tm_wday + 1;
76 p.daylight_saving = parts->tm_isdst;
77 p.hour = parts->tm_hour;
78 p.minute = parts->tm_min;
79 p.second = parts->tm_sec + sec_frac;
89 parts.tm_year =
p.year - 1900;
90 parts.tm_mon =
p.month - 1;
91 parts.tm_mday =
p.day;
92 parts.tm_wday =
p.day_of_week - 1;
93 parts.tm_isdst =
p.daylight_saving;
94 parts.tm_hour =
p.hour;
95 parts.tm_min =
p.minute;
96 parts.tm_sec = int(
p.second);
98 double sec_frac =
p.second - parts.tm_sec;
112 parts.tm_year =
p.year - 1900;
113 parts.tm_mon =
p.month - 1;
114 parts.tm_mday =
p.day;
115 parts.tm_wday =
p.day_of_week - 1;
116 parts.tm_isdst =
p.daylight_saving;
117 parts.tm_hour =
p.hour;
118 parts.tm_min =
p.minute;
119 parts.tm_sec = int(
p.second);
121 double sec_frac =
p.second - parts.tm_sec;
123 time_t tt = mktime(&parts);
133 double timeSeconds = (
t < 0) ? (-
t) :
t;
135 unsigned int nHours = (
unsigned int)timeSeconds / 3600;
136 unsigned int nMins = ((
unsigned int)timeSeconds % 3600) / 60;
137 unsigned int nSecs = (
unsigned int)timeSeconds % 60;
138 unsigned int milSecs =
139 (
unsigned int)(1000 * (timeSeconds - floor(timeSeconds)));
141 return format(
"%02u:%02u:%02u.%03u", nHours, nMins, nSecs, milSecs);
152 (
t.time_since_epoch().count() - ((
uint64_t)116444736 * 1000000000));
153 time_t auxTime = tmp / (
uint64_t)10000000;
154 unsigned int secFractions =
155 (
unsigned int)(1000000 * (tmp % 10000000) / 10000000.0);
156 tm* ptm = gmtime(&auxTime);
158 if (!ptm)
return std::string(
"(Malformed timestamp)");
161 "%u/%02u/%02u,%02u:%02u:%02u.%06u", 1900 + ptm->tm_year,
162 ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
163 (
unsigned int)ptm->tm_sec, secFractions);
175 (
t.time_since_epoch().count() - ((
uint64_t)116444736 * 1000000000));
176 time_t auxTime = tmp / (
uint64_t)10000000;
177 unsigned int secFractions =
178 (
unsigned int)(1000000 * (tmp % 10000000) / 10000000.0);
179 tm* ptm = localtime(&auxTime);
181 if (!ptm)
return "(Malformed timestamp)";
184 "%u/%02u/%02u,%02u:%02u:%02u.%06u", 1900 + ptm->tm_year,
185 ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
186 (
unsigned int)ptm->tm_sec, secFractions);
198 auto t = tt.time_since_epoch().count();
201 FileTimeToSystemTime((FILETIME*)&
t, &sysT);
202 return sysT.wHour * 3600.0 + sysT.wMinute * 60.0 + sysT.wSecond +
203 sysT.wMilliseconds * 0.001;
207 tm* ptm = gmtime(&auxTime);
209 return ptm->tm_hour * 3600.0 + ptm->tm_min * 60.0 + ptm->tm_sec;
221 auto t = tt.time_since_epoch().count();
224 const time_t auxTime = tmp / (
uint64_t)10000000;
225 const tm* ptm = localtime(&auxTime);
227 unsigned int secFractions =
228 (
unsigned int)(1000000 * (tmp % 10000000) / 10000000.0);
230 const unsigned int user_secondFractionDigits = secondFractionDigits;
231 while (secondFractionDigits++ < 6) secFractions = secFractions / 10;
234 "%02u:%02u:%02u.%0*u", ptm->tm_hour, ptm->tm_min,
235 (
unsigned int)ptm->tm_sec, user_secondFractionDigits, secFractions);
244 auto t = tt.time_since_epoch().count();
247 time_t auxTime = tmp / (
uint64_t)10000000;
248 unsigned int secFractions =
249 (
unsigned int)(1000000 * (tmp % 10000000) / 10000000.0);
250 tm* ptm = gmtime(&auxTime);
251 if (!ptm)
return string(
"(Malformed timestamp)");
254 "%02u:%02u:%02u.%06u", ptm->tm_hour, ptm->tm_min,
255 (
unsigned int)ptm->tm_sec, secFractions);
264 auto t = tt.time_since_epoch().count();
267 time_t auxTime = tmp / (
uint64_t)10000000;
268 tm* ptm = gmtime(&auxTime);
269 if (!ptm)
return string(
"(Malformed timestamp)");
272 "%u/%02u/%02u", 1900 + ptm->tm_year, ptm->tm_mon + 1, ptm->tm_mday);
283 if (seconds >= 365 * 24 * 3600)
284 return format(
"%.2f years", seconds / (365 * 24 * 3600));
285 else if (seconds >= 24 * 3600)
286 return format(
"%.2f days", seconds / (24 * 3600));
287 else if (seconds >= 3600)
288 return format(
"%.2f hours", seconds / 3600);
289 else if (seconds >= 60)
290 return format(
"%.2f minutes", seconds / 60);
291 else if (seconds >= 1)
292 return format(
"%.2f sec", seconds);
293 else if (seconds >= 1e-3)
294 return format(
"%.2f ms", seconds * 1e3);
295 else if (seconds >= 1e-6)
296 return format(
"%.2f us", seconds * 1e6);
298 return format(
"%.2f ns", seconds * 1e9);
303 const uint64_t v =
t.time_since_epoch().count();
void timestampToParts(TTimeStamp t, TTimeParts &p, bool localTime=false)
Gets the individual parts of a date/time (days, hours, minutes, seconds) - UTC time or local time...
std::ostream & operator<<(std::ostream &o, const TTimeStamp &t)
Textual representation of a TTimeStamp as the plain number in time_since_epoch().count() ...
time_t timegm(struct tm *tm)
An OS-independent version of timegm (which is not present in all compilers): converts a time structur...
mrpt::system::TTimeStamp buildTimestampFromParts(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in UTC)
double extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp t)
Returns the number of seconds ellapsed from midnight in the given timestamp.
std::string timeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM.
std::string formatTimeInterval(const double timeSeconds)
Returns a formated string with the given time difference (passed as the number of seconds)...
#define ASSERT_(f)
Defines an assertion mechanism.
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
std::string dateToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form: YEAR/MONTH/DAY.
The parts of a date/time (it's like the standard 'tm' but with fractions of seconds).
std::string intervalFormat(const double seconds)
This function implements time interval formatting: Given a time in seconds, it will return a string d...
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
GLsizei const GLchar ** string
mrpt::system::TTimeStamp buildTimestampFromPartsLocalTime(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in local time)
unsigned __int64 uint64_t
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string dateTimeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
std::string timeLocalToString(const mrpt::system::TTimeStamp t, unsigned int secondFractionDigits=6)
Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM.
std::string dateTimeLocalToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
mrpt::system::TTimeStamp time_tToTimestamp(const double t)
Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to T...
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
double timestampTotime_t(const mrpt::system::TTimeStamp t)
Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of...