1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

code review

This commit is contained in:
Laserlicht 2023-12-16 21:10:27 +01:00 committed by GitHub
parent 8d75c30dca
commit 9299eaed36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 27 deletions

View File

@ -31,8 +31,6 @@
#include "../../lib/TextOperations.h"
#include "../../lib/Languages.h"
#include "vstd/DateUtils.h"
auto HighScoreCalculation::calculate()
{
struct Result
@ -265,7 +263,7 @@ int CHighScoreInputScreen::addEntry(std::string text) {
newNode["scenarioName"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].scenarioName;
newNode["days"].Integer() = calc.calculate().sumDays;
newNode["points"].Integer() = calc.calculate().cheater ? 0 : calc.calculate().total;
newNode["datetime"].String() = vstd::getFormattedDateTime(std::time(nullptr), Languages::getLanguageOptions(settings["general"]["language"].String()).dateTimeFormat);
newNode["datetime"].String() = TextOperations::getFormattedDateTimeLocal(std::time(nullptr));
newNode["posFlag"].Bool() = true;
baseNode.push_back(newNode);

View File

@ -13,8 +13,6 @@
#include "../lobby/SelectionTab.h"
#include <vstd/DateUtils.h>
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../widgets/CComponent.h"
@ -29,6 +27,7 @@
#include "../render/Graphics.h"
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/TextOperations.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/campaign/CampaignState.h"
#include "../../lib/mapping/CMap.h"
@ -200,7 +199,7 @@ CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
if(p.date.empty())
{
std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), p.tabType == ESelectionScreen::campaignList ? EResType::CAMPAIGN : EResType::MAP)));
w->setText(vstd::getFormattedDateTime(time, Languages::getLanguageOptions(settings["general"]["language"].String()).dateTimeFormat));
w->setText(TextOperations::getFormattedDateTimeLocal(time));
}
else
w->setText(p.date);

View File

@ -11,6 +11,10 @@
#include "TextOperations.h"
#include "CGeneralTextHandler.h"
#include "Languages.h"
#include "CConfigHandler.h"
#include <vstd/DateUtils.h>
#include <boost/locale.hpp>
@ -210,4 +214,9 @@ std::string TextOperations::escapeString(std::string input)
return input;
}
std::string TextOperations::getFormattedDateTimeLocal(std::time_t dt)
{
return vstd::getFormattedDateTime(dt, Languages::getLanguageOptions(settings["general"]["language"].String()).dateTimeFormat);
}
VCMI_LIB_NAMESPACE_END

View File

@ -56,6 +56,9 @@ namespace TextOperations
/// replaces all symbols that normally need escaping with appropriate escape sequences
std::string escapeString(std::string input);
/// get formatted DateTime depending on the language selected
DLL_LINKAGE std::string getFormattedDateTimeLocal(std::time_t dt);
};

View File

@ -10,8 +10,6 @@
#include "StdInc.h"
#include "CMapInfo.h"
#include <vstd/DateUtils.h>
#include "../filesystem/ResourcePath.h"
#include "../StartInfo.h"
#include "../GameConstants.h"
@ -23,6 +21,7 @@
#include "../filesystem/Filesystem.h"
#include "../serializer/CLoadFile.h"
#include "../CGeneralTextHandler.h"
#include "../TextOperations.h"
#include "../rmg/CMapGenOptions.h"
#include "../CCreatureHandler.h"
#include "../GameSettings.h"
@ -66,7 +65,7 @@ void CMapInfo::saveInit(const ResourcePath & file)
fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(file)).string();
countPlayers();
std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(file));
date = vstd::getFormattedDateTime(time, Languages::getLanguageOptions(settings["general"]["language"].String()).dateTimeFormat);
date = TextOperations::getFormattedDateTimeLocal(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!

View File

@ -10,29 +10,13 @@ namespace vstd
{
std::tm tm = *std::localtime(&dt);
std::stringstream s;
if(format.empty())
{
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");
}
else
s << std::put_time(&tm, format.c_str());
s << std::put_time(&tm, format.c_str());
return s.str();
}
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();
return getFormattedDateTime(dt, "%Y%m%dT%H%M%S");
}
}