Skip to content

Commit

Permalink
Change to use fmt::format and fmt::localtime instead of localtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Dec 8, 2022
1 parent 5252dd9 commit f7a73c9
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions src/utils/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "utils/tools.h"

#include <fmt/chrono.h>

void printXMLError(const std::string& where, const std::string& fileName, const pugi::xml_parse_result& result)
{
SPDLOG_ERROR("[{}] Failed to load {}: {}", where, fileName, result.description());
Expand Down Expand Up @@ -368,32 +370,12 @@ std::string convertIPToString(uint32_t ip)

std::string formatDate(time_t time)
{
const tm* tms = localtime(&time);
if (!tms) {
return {};
}

char buffer[20];
int res = sprintf(buffer, "%02d/%02d/%04d %02d:%02d:%02d", tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min, tms->tm_sec);
if (res < 0) {
return {};
}
return {buffer, 19};
return fmt::format("{:%d/%m/%Y %H:%M:%S}", fmt::localtime(time));
}

std::string formatDateShort(time_t time)
{
const tm* tms = localtime(&time);
if (!tms) {
return {};
}

char buffer[12];
size_t res = strftime(buffer, 12, "%d %b %Y", tms);
if (res == 0) {
return {};
}
return {buffer, 11};
return fmt::format("{:%Y-%m-%d %X}", fmt::localtime(time));
}

std::time_t getTimeNow() {
Expand Down

0 comments on commit f7a73c9

Please sign in to comment.