Skip to content
Snippets Groups Projects
Commit 7743a35f authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[BL] added datetime formatting function

parent b88fb2f1
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <sstream>
#include <logog/include/logog.hpp>
......@@ -114,4 +115,17 @@ int xmlDate2int(const std::string &s)
}
return 0;
}
std::string formatDate(
std::chrono::time_point<std::chrono::system_clock> const& time)
{
auto const time_t = std::chrono::system_clock::to_time_t(time);
char time_str[100];
if (std::strftime(time_str, sizeof(time_str), "%F %T%z",
std::localtime(&time_t))) {
return time_str;
} else {
return "FAILED FORMATTING THE GIVEN TIME POINT.";
}
}
} // end namespace BaseLib
......@@ -15,9 +15,11 @@
#ifndef DATETOOLS_H
#define DATETOOLS_H
#include <chrono>
#include <string>
namespace BaseLib {
namespace BaseLib
{
/**
* Converts three integers representing a date into a double.
......@@ -55,6 +57,15 @@ int strDate2int(const std::string &s);
*/
int xmlDate2int(const std::string &s);
/**
* Formats the given time point according to RFC 3339 (cf. man-page of the unix
* date utility).
*
* Example: 2006-08-14 02:34:56-06:00
*/
std::string formatDate(
std::chrono::time_point<std::chrono::system_clock> const& time);
} // namespace BaseLib
#endif //DATETOOLS_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment