0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 22:18:54 +02:00

ircd: Add additional formatted microdate().

This commit is contained in:
Jason Volk 2019-08-03 19:57:51 -07:00
parent 432e317314
commit 8dd0a22351
2 changed files with 29 additions and 0 deletions

View file

@ -46,6 +46,7 @@ namespace ircd
// Other tools
string_view smalldate(const mutable_buffer &buf, const time_t &ltime);
string_view microdate(const mutable_buffer &buf);
// Interface conveniences.
std::ostream &operator<<(std::ostream &, const microtime_t &);

View file

@ -54,6 +54,34 @@ ircd::smalldate(const mutable_buffer &buf,
};
}
ircd::string_view
ircd::microdate(const mutable_buffer &buf)
{
auto mt
{
microtime()
};
struct tm lt;
localtime_r(&mt.first, &lt);
const auto length
{
::snprintf(data(buf), size(buf), "%04d/%02d/%02d %02d:%02d:%02d.%06d",
lt.tm_year + 1900,
lt.tm_mon + 1,
lt.tm_mday,
lt.tm_hour,
lt.tm_min,
lt.tm_sec,
mt.second)
};
return string_view
{
data(buf), size_t(length)
};
}
ircd::string_view
ircd::timef(const mutable_buffer &out,
const char *const &fmt)