1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00
vcmi/lib/vstd/DateUtils.cpp

45 lines
893 B
C++
Raw Normal View History

2023-08-12 01:13:03 +02:00
#include "StdInc.h"
#include <vstd/DateUtils.h>
2023-09-24 12:54:35 +02:00
#include "../CConfigHandler.h"
#include "../Languages.h"
2023-09-23 17:27:00 +02:00
2023-08-12 01:13:03 +02:00
VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt)
{
2023-09-24 12:54:35 +02:00
std::string lang = settings["general"]["language"].String();
std::string locale = Languages::getLanguageOptions(lang).locale;
2023-09-23 17:27:00 +02:00
2023-08-12 01:13:03 +02:00
std::tm tm = *std::localtime(&dt);
std::stringstream s;
2023-08-23 21:46:15 +02:00
try
{
2023-09-24 12:54:35 +02:00
if(locale.empty())
s.imbue(std::locale(""));
else
s.imbue(std::locale(locale));
2023-08-23 21:46:15 +02:00
}
catch(const std::runtime_error & e)
{
// locale not be available - keep default / global
}
2023-08-12 01:13:03 +02:00
s << std::put_time(&tm, "%x %X");
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