Sfoglia il codice sorgente

extra function: getFormattedDateTime

Michael 2 anni fa
parent
commit
52f00ec308

+ 2 - 0
cmake_modules/VCMI_lib.cmake

@@ -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 - 0
include/vstd/DateUtils.h

@@ -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

+ 1 - 0
lib/VCMI_lib.vcxproj

@@ -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>

+ 3 - 0
lib/VCMI_lib.vcxproj.filters

@@ -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>

+ 3 - 6
lib/mapping/CMapInfo.cpp

@@ -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 - 0
lib/vstd/DateUtils.cpp

@@ -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