mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-26 19:18:48 +02:00
37 lines
988 B
C++
37 lines
988 B
C++
/* Icinga 2 | (c) 2025 Icinga GmbH | GPLv2+ */
|
|
|
|
#include "utils.hpp"
|
|
#include <cstring>
|
|
#include <iomanip>
|
|
#include <sstream>
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
tm make_tm(std::string s)
|
|
{
|
|
int dst = -1;
|
|
size_t l = strlen("YYYY-MM-DD HH:MM:SS");
|
|
if (s.size() > l) {
|
|
std::string zone = s.substr(l);
|
|
if (zone == " PST") {
|
|
dst = 0;
|
|
} else if (zone == " PDT") {
|
|
dst = 1;
|
|
} else {
|
|
// tests should only use PST/PDT (for now)
|
|
BOOST_CHECK_MESSAGE(false, "invalid or unknown time time: " << zone);
|
|
}
|
|
}
|
|
|
|
std::tm t = {};
|
|
#if defined(__GNUC__) && __GNUC__ < 5
|
|
// GCC did not implement std::get_time() until version 5
|
|
strptime(s.c_str(), "%Y-%m-%d %H:%M:%S", &t);
|
|
#else /* defined(__GNUC__) && __GNUC__ < 5 */
|
|
std::istringstream stream(s);
|
|
stream >> std::get_time(&t, "%Y-%m-%d %H:%M:%S");
|
|
#endif /* defined(__GNUC__) && __GNUC__ < 5 */
|
|
t.tm_isdst = dst;
|
|
|
|
return t;
|
|
}
|