utils: Rename/Add date functions
This commit is contained in:
والد
b2a7ea4031
کامیت
c5435c52f4
17
utils.cpp
17
utils.cpp
@ -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, <) == 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", <);
|
||||
size_t x = strftime(result, sizeof(result), format.c_str(), <);
|
||||
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";
|
||||
|
2
utils.h
2
utils.h
@ -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)
|
||||
{
|
||||
|
بارگذاری…
مرجع در شماره جدید
Block a user