From f7a73c92f850f5a060e2d9747a76379a8cbd5c60 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Thu, 8 Dec 2022 09:24:07 -0300 Subject: [PATCH] Change to use fmt::format and fmt::localtime instead of localtime Credits: https://github.com/otland/forgottenserver/pull/4249 --- src/utils/tools.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/utils/tools.cpp b/src/utils/tools.cpp index 7e656cb8c3c..caa530c9b40 100644 --- a/src/utils/tools.cpp +++ b/src/utils/tools.cpp @@ -23,6 +23,8 @@ #include "utils/tools.h" +#include + 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()); @@ -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() {