utils: Rename/Add date functions

This commit is contained in:
Albert S. 2022-03-27 08:29:13 +02:00
부모 b2a7ea4031
커밋 c5435c52f4
2개의 변경된 파일17개의 추가작업 그리고 2개의 파일을 삭제

파일 보기

@ -166,7 +166,10 @@ std::string utils::regex_callback_replacer(std::regex regex, const std::string &
return result;
}
std::string utils::toISODate(time_t t)
/* TODO: Convert to C++20, but currently the state is rather poor and would
* require workarounds, so keep it this way for now, and do it properly
* once compiler support gets there */
std::string utils::formatLocalDate(time_t t, std::string format)
{
struct tm lt;
if(localtime_r(&t, &lt) == nullptr)
@ -174,7 +177,7 @@ std::string utils::toISODate(time_t t)
return {};
}
char result[20];
size_t x = strftime(result, sizeof(result), "%Y-%m-%d %H:%M:%S", &lt);
size_t x = strftime(result, sizeof(result), format.c_str(), &lt);
if(x == 0)
{
return {};
@ -182,6 +185,16 @@ std::string utils::toISODate(time_t t)
return std::string{result};
}
std::string utils::toISODateTime(time_t t)
{
return utils::formatLocalDate(t, "%Y-%m-%d %H:%M:%S");
}
std::string utils::toISODate(time_t t)
{
return utils::formatLocalDate(t, "%Y-%m-%d");
}
std::string utils::trim(std::string_view view)
{
std::string_view chars = " \t\n\r";

파일 보기

@ -81,7 +81,9 @@ inline unsigned int toUInt(const std::string &str)
return result;
}
std::string formatLocalDate(time_t t, std::string format);
std::string toISODate(time_t t);
std::string toISODateTime(time_t t);
template <class T> inline std::string toString(const T &v)
{