mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-17 20:58:07 +02:00
extra function: getFormattedDateTime
This commit is contained in:
parent
4d507f3d8a
commit
52f00ec308
@ -220,6 +220,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
|
||||
${MAIN_LIB_DIR}/spells/effects/RemoveObstacle.cpp
|
||||
${MAIN_LIB_DIR}/spells/effects/Sacrifice.cpp
|
||||
|
||||
${MAIN_LIB_DIR}/vstd/DateUtils.cpp
|
||||
${MAIN_LIB_DIR}/vstd/StringUtils.cpp
|
||||
|
||||
${MAIN_LIB_DIR}/ArtifactUtils.cpp
|
||||
@ -283,6 +284,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
|
||||
|
||||
${MAIN_LIB_DIR}/../include/vstd/ContainerUtils.h
|
||||
${MAIN_LIB_DIR}/../include/vstd/RNG.h
|
||||
${MAIN_LIB_DIR}/../include/vstd/DateUtils.h
|
||||
${MAIN_LIB_DIR}/../include/vstd/StringUtils.h
|
||||
|
||||
${MAIN_LIB_DIR}/../include/vcmi/events/AdventureEvents.h
|
||||
|
12
include/vstd/DateUtils.h
Normal file
12
include/vstd/DateUtils.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
namespace vstd
|
||||
{
|
||||
|
||||
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt);
|
||||
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@ -320,6 +320,7 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="VCMIDirs.cpp" />
|
||||
<ClCompile Include="VCMI_Lib.cpp" />
|
||||
<ClCompile Include="vstd\DateUtils.cpp" />
|
||||
<ClCompile Include="vstd\StringUtils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -393,6 +393,9 @@
|
||||
<ClCompile Include="registerTypes\TypesLobbyPacks.cpp">
|
||||
<Filter>registerTypes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="vstd\DateUtils.cpp">
|
||||
<Filter>vstd</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="vstd\StringUtils.cpp">
|
||||
<Filter>vstd</Filter>
|
||||
</ClCompile>
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "StdInc.h"
|
||||
#include "CMapInfo.h"
|
||||
|
||||
#include <vstd/DateUtils.h>
|
||||
|
||||
#include "../filesystem/ResourceID.h"
|
||||
#include "../StartInfo.h"
|
||||
#include "../GameConstants.h"
|
||||
@ -62,12 +64,7 @@ void CMapInfo::saveInit(const ResourceID & file)
|
||||
fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(file)).string();
|
||||
countPlayers();
|
||||
std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(file));
|
||||
|
||||
std::tm tm = *std::localtime(&time);
|
||||
std::stringstream s;
|
||||
s.imbue(std::locale(""));
|
||||
s << std::put_time(&tm, "%x %X");
|
||||
date = s.str();
|
||||
date = vstd::getFormattedDateTime(time);
|
||||
|
||||
// We absolutely not need this data for lobby and server will read it from save
|
||||
// FIXME: actually we don't want them in CMapHeader!
|
||||
|
20
lib/vstd/DateUtils.cpp
Normal file
20
lib/vstd/DateUtils.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "StdInc.h"
|
||||
#include <vstd/DateUtils.h>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
namespace vstd
|
||||
{
|
||||
|
||||
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt)
|
||||
{
|
||||
std::tm tm = *std::localtime(&dt);
|
||||
std::stringstream s;
|
||||
s.imbue(std::locale(""));
|
||||
s << std::put_time(&tm, "%x %X");
|
||||
return s.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user