Skip to content

Commit

Permalink
lib: move TPAsString() to util.h
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz authored and alaaeddineelamri committed Aug 4, 2022
1 parent f57aa50 commit 8880c6d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
13 changes: 1 addition & 12 deletions core/src/lib/parse_conf.h
Expand Up @@ -34,6 +34,7 @@
#include "lib/parse_conf.h"
#include "lib/keyword_table_s.h"
#include "lib/message_destination_info.h"
#include "lib/util.h"

#include <functional>
#include <memory>
Expand Down Expand Up @@ -419,18 +420,6 @@ class ConfigurationParser {
};


static std::string TPAsString(const std::chrono::system_clock::time_point& tp)
{
std::time_t t = std::chrono::system_clock::to_time_t(tp);
char str[100];
if (!std::strftime(str, sizeof(str), "%Y-%m-%d_%H:%M:%S",
std::localtime(&t))) {
return std::string("strftime error");
}
std::string ts = str;
return ts;
}

class ConfigResourcesContainer {
public:
std::chrono::time_point<std::chrono::system_clock> timestamp_{};
Expand Down
12 changes: 12 additions & 0 deletions core/src/lib/util.cc
Expand Up @@ -1156,3 +1156,15 @@ std::string CreateDelimitedStringForSqlQueries(
}
return empty_list;
}

std::string TPAsString(const std::chrono::system_clock::time_point& tp)
{
std::time_t t = std::chrono::system_clock::to_time_t(tp);
char str[100];
if (!std::strftime(str, sizeof(str), "%Y-%m-%d_%H:%M:%S",
std::localtime(&t))) {
return std::string("strftime error");
}
std::string ts = str;
return ts;
}
3 changes: 3 additions & 0 deletions core/src/lib/util.h
Expand Up @@ -22,6 +22,7 @@
#define BAREOS_LIB_UTIL_H_

#include <sys/stat.h>
#include <chrono>

#include "lib/ascii_control_characters.h"
#include "lib/message.h"
Expand Down Expand Up @@ -82,4 +83,6 @@ std::string CreateDelimitedStringForSqlQueries(
const std::vector<char>& elements,
char delim);

std::string TPAsString(const std::chrono::system_clock::time_point& tp);

#endif // BAREOS_LIB_UTIL_H_

0 comments on commit 8880c6d

Please sign in to comment.