[DEV] add log of time

This commit is contained in:
Edouard DUPIN 2015-02-26 21:44:16 +01:00
parent 025b59a8c7
commit a9aa042ecd
2 changed files with 23 additions and 0 deletions

View File

@ -1377,3 +1377,22 @@ std::ostream& std::operator <<(std::ostream& _os, const std::vector<uint8_t>& _o
}
#endif
namespace std {
std::ostream& operator <<(std::ostream& _os, const std11::chrono::system_clock::time_point& _obj) {
std11::chrono::nanoseconds ns = std11::chrono::duration_cast<std11::chrono::nanoseconds>(_obj.time_since_epoch());
int64_t totalSecond = ns.count()/1000000000;
int64_t millisecond = (ns.count()%1000000000)/1000000;
int64_t microsecond = (ns.count()%1000000)/1000;
int64_t nanosecond = ns.count()%1000;
//_os << totalSecond << "s " << millisecond << "ms " << microsecond << "µs " << nanosecond << "ns";
int32_t second = totalSecond % 60;
int32_t minute = (totalSecond/60)%60;
int32_t hour = (totalSecond/3600)%24;
int32_t day = (totalSecond/(24*3600))%365;
int32_t year = totalSecond/(24*3600*365);
_os << year << "y " << day << "d " << hour << "h" << minute << ":"<< second << "s " << millisecond << "ms " << microsecond << "µs " << nanosecond << "ns";
return _os;
}
}

View File

@ -16,6 +16,7 @@
#include <string>
#include <iomanip>
#include <algorithm>
#include <etk/chrono.h>
namespace u32char {
extern const char32_t Null; //!< '\0'
@ -545,6 +546,9 @@ namespace std {
std::ostream& operator <<(std::ostream& _os, const std::vector<uint16_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<int8_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<uint8_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std11::chrono::system_clock::time_point& _obj);
};
int32_t strlen(const char32_t * _data);