util/TimeISO8601: new utility library

This commit is contained in:
Max Kellermann
2018-07-25 08:29:34 +02:00
parent 517f5b1999
commit 235ddc0990
5 changed files with 123 additions and 14 deletions

View File

@@ -20,27 +20,19 @@
#include "config.h"
#include "TimePrint.hxx"
#include "client/Response.hxx"
#include "util/TimeConvert.hxx"
#include "util/TimeISO8601.hxx"
void
time_print(Response &r, const char *name,
std::chrono::system_clock::time_point t)
{
struct tm tm;
StringBuffer<64> s;
try {
tm = GmTime(t);
s = FormatISO8601(t);
} catch (...) {
return;
}
char buffer[32];
strftime(buffer, sizeof(buffer),
#ifdef _WIN32
"%Y-%m-%dT%H:%M:%SZ",
#else
"%FT%TZ",
#endif
&tm);
r.Format("%s: %s\n", name, buffer);
r.Format("%s: %s\n", name, s.c_str());
}