2023-08-12 01:13:03 +02:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include <vstd/DateUtils.h>
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
namespace vstd
|
|
|
|
{
|
|
|
|
|
2023-12-16 15:27:18 +02:00
|
|
|
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt, std::string format)
|
2023-08-12 01:13:03 +02:00
|
|
|
{
|
|
|
|
std::tm tm = *std::localtime(&dt);
|
|
|
|
std::stringstream s;
|
2023-12-16 15:27:18 +02:00
|
|
|
if(format.empty())
|
2023-08-23 21:46:15 +02:00
|
|
|
{
|
2023-12-16 15:27:18 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s.imbue(std::locale(""));
|
|
|
|
}
|
|
|
|
catch(const std::runtime_error & e)
|
|
|
|
{
|
|
|
|
// locale not be available - keep default / global
|
|
|
|
}
|
|
|
|
s << std::put_time(&tm, "%x %X");
|
2023-08-23 21:46:15 +02:00
|
|
|
}
|
2023-12-16 15:27:18 +02:00
|
|
|
else
|
|
|
|
s << std::put_time(&tm, format.c_str());
|
2023-08-12 01:13:03 +02:00
|
|
|
return s.str();
|
|
|
|
}
|
|
|
|
|
2023-08-23 01:47:55 +02:00
|
|
|
DLL_LINKAGE std::string getDateTimeISO8601Basic(std::time_t dt)
|
|
|
|
{
|
|
|
|
std::tm tm = *std::localtime(&dt);
|
|
|
|
std::stringstream s;
|
|
|
|
s << std::put_time(&tm, "%Y%m%dT%H%M%S");
|
|
|
|
return s.str();
|
|
|
|
}
|
|
|
|
|
2023-08-12 01:13:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|