mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
date time format
This commit is contained in:
parent
3cf22f0395
commit
56562ad8dc
@ -156,14 +156,6 @@ public class NativeMethods
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings(Const.JNI_METHOD_SUPPRESS)
|
||||
public static String getFormattedDateTime()
|
||||
{
|
||||
String currentDate = new SimpleDateFormat((new SimpleDateFormat()).toLocalizedPattern(), Locale.getDefault()).format(new Date());
|
||||
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
private static void internalProgressDisplay(final boolean show)
|
||||
{
|
||||
final Context ctx = SDL.getContext();
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "../../lib/CCreatureHandler.h"
|
||||
#include "../../lib/constants/EntityIdentifiers.h"
|
||||
#include "../../lib/TextOperations.h"
|
||||
#include "../../lib/Languages.h"
|
||||
|
||||
#include "vstd/DateUtils.h"
|
||||
|
||||
@ -264,7 +265,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));
|
||||
newNode["datetime"].String() = vstd::getFormattedDateTime(std::time(nullptr), Languages::getLanguageOptions(settings["general"]["language"].String()).dateTimeFormat);
|
||||
newNode["posFlag"].Bool() = true;
|
||||
|
||||
baseNode.push_back(newNode);
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "../../lib/serializer/CLoadFile.h"
|
||||
#include "../../lib/StartInfo.h"
|
||||
#include "../../lib/rmg/CMapGenOptions.h"
|
||||
#include "../../lib/Languages.h"
|
||||
|
||||
CMapOverview::CMapOverview(std::string mapName, std::string fileName, std::string date, ResourcePath resource, ESelectionScreen tabType)
|
||||
: CWindowObject(BORDERED | RCLICK_POPUP), resource(resource), mapName(mapName), fileName(fileName), date(date), tabType(tabType)
|
||||
@ -199,7 +200,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));
|
||||
w->setText(vstd::getFormattedDateTime(time, Languages::getLanguageOptions(settings["general"]["language"].String()).dateTimeFormat));
|
||||
}
|
||||
else
|
||||
w->setText(p.date);
|
||||
|
@ -5,7 +5,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
namespace vstd
|
||||
{
|
||||
|
||||
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt);
|
||||
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt, std::string format = "");
|
||||
DLL_LINKAGE std::string getDateTimeISO8601Basic(std::time_t dt);
|
||||
|
||||
}
|
||||
|
@ -68,6 +68,9 @@ struct Options
|
||||
/// primary IETF language tag
|
||||
std::string tagIETF;
|
||||
|
||||
/// DateTime format
|
||||
std::string dateTimeFormat;
|
||||
|
||||
/// Ruleset for plural forms in this language
|
||||
EPluralForms pluralForms = EPluralForms::NONE;
|
||||
|
||||
@ -79,27 +82,27 @@ inline const auto & getLanguageList()
|
||||
{
|
||||
static const std::array<Options, 20> languages
|
||||
{ {
|
||||
{ "czech", "Czech", "Čeština", "CP1250", "cs", EPluralForms::CZ_3, true },
|
||||
{ "chinese", "Chinese", "简体中文", "GBK", "zh", EPluralForms::VI_1, true }, // Note: actually Simplified Chinese
|
||||
{ "english", "English", "English", "CP1252", "en", EPluralForms::EN_2, true },
|
||||
{ "finnish", "Finnish", "Suomi", "CP1252", "fi", EPluralForms::EN_2, true },
|
||||
{ "french", "French", "Français", "CP1252", "fr", EPluralForms::FR_2, true },
|
||||
{ "german", "German", "Deutsch", "CP1252", "de", EPluralForms::EN_2, true },
|
||||
{ "hungarian", "Hungarian", "Magyar", "CP1250", "hu", EPluralForms::EN_2, true },
|
||||
{ "italian", "Italian", "Italiano", "CP1250", "it", EPluralForms::EN_2, true },
|
||||
{ "korean", "Korean", "한국어", "CP949", "ko", EPluralForms::VI_1, true },
|
||||
{ "polish", "Polish", "Polski", "CP1250", "pl", EPluralForms::PL_3, true },
|
||||
{ "portuguese", "Portuguese", "Português", "CP1252", "pt", EPluralForms::EN_2, true }, // Note: actually Brazilian Portuguese
|
||||
{ "russian", "Russian", "Русский", "CP1251", "ru", EPluralForms::UK_3, true },
|
||||
{ "spanish", "Spanish", "Español", "CP1252", "es", EPluralForms::EN_2, true },
|
||||
{ "swedish", "Swedish", "Svenska", "CP1252", "sv", EPluralForms::EN_2, true },
|
||||
{ "turkish", "Turkish", "Türkçe", "CP1254", "tr", EPluralForms::EN_2, true },
|
||||
{ "ukrainian", "Ukrainian", "Українська", "CP1251", "uk", EPluralForms::UK_3, true },
|
||||
{ "vietnamese", "Vietnamese", "Tiếng Việt", "UTF-8", "vi", EPluralForms::VI_1, true }, // Fan translation uses special encoding
|
||||
{ "czech", "Czech", "Čeština", "CP1250", "cs", "%d.%m.%Y %T", EPluralForms::CZ_3, true },
|
||||
{ "chinese", "Chinese", "简体中文", "GBK", "zh", "%F %T", EPluralForms::VI_1, true }, // Note: actually Simplified Chinese
|
||||
{ "english", "English", "English", "CP1252", "en", "%F %T", EPluralForms::EN_2, true }, // English uses international date/time format here
|
||||
{ "finnish", "Finnish", "Suomi", "CP1252", "fi", "%d.%m.%Y %T", EPluralForms::EN_2, true },
|
||||
{ "french", "French", "Français", "CP1252", "fr", "%d/%m/%Y %T", EPluralForms::FR_2, true },
|
||||
{ "german", "German", "Deutsch", "CP1252", "de", "%d.%m.%Y %T", EPluralForms::EN_2, true },
|
||||
{ "hungarian", "Hungarian", "Magyar", "CP1250", "hu", "%Y. %m. %d. %T", EPluralForms::EN_2, true },
|
||||
{ "italian", "Italian", "Italiano", "CP1250", "it", "%d/%m/%Y %T", EPluralForms::EN_2, true },
|
||||
{ "korean", "Korean", "한국어", "CP949", "ko", "%F %T", EPluralForms::VI_1, true },
|
||||
{ "polish", "Polish", "Polski", "CP1250", "pl", "%d.%m.%Y %T", EPluralForms::PL_3, true },
|
||||
{ "portuguese", "Portuguese", "Português", "CP1252", "pt", "%d/%m/%Y %T", EPluralForms::EN_2, true }, // Note: actually Brazilian Portuguese
|
||||
{ "russian", "Russian", "Русский", "CP1251", "ru", "%F %T", EPluralForms::UK_3, true },
|
||||
{ "spanish", "Spanish", "Español", "CP1252", "es", "%d/%m/%Y %T", EPluralForms::EN_2, true },
|
||||
{ "swedish", "Swedish", "Svenska", "CP1252", "sv", "%F %T", EPluralForms::EN_2, true },
|
||||
{ "turkish", "Turkish", "Türkçe", "CP1254", "tr", "%d.%m.%Y %T", EPluralForms::EN_2, true },
|
||||
{ "ukrainian", "Ukrainian", "Українська", "CP1251", "uk", "%d.%m.%Y %T", EPluralForms::UK_3, true },
|
||||
{ "vietnamese", "Vietnamese", "Tiếng Việt", "UTF-8", "vi", "%d/%m/%Y %T", EPluralForms::VI_1, true }, // Fan translation uses special encoding
|
||||
|
||||
{ "other_cp1250", "Other (East European)", "", "CP1250", "", EPluralForms::NONE, false },
|
||||
{ "other_cp1251", "Other (Cyrillic Script)", "", "CP1251", "", EPluralForms::NONE, false },
|
||||
{ "other_cp1252", "Other (West European)", "", "CP1252", "", EPluralForms::NONE, false }
|
||||
{ "other_cp1250", "Other (East European)", "", "CP1250", "", "", EPluralForms::NONE, false },
|
||||
{ "other_cp1251", "Other (Cyrillic Script)", "", "CP1251", "", "", EPluralForms::NONE, false },
|
||||
{ "other_cp1252", "Other (West European)", "", "CP1252", "", "", EPluralForms::NONE, false }
|
||||
} };
|
||||
static_assert(languages.size() == static_cast<size_t>(ELanguages::COUNT), "Languages array is missing a value!");
|
||||
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include "../CCreatureHandler.h"
|
||||
#include "../GameSettings.h"
|
||||
#include "../CHeroHandler.h"
|
||||
#include "../Languages.h"
|
||||
#include "../CConfigHandler.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@ -64,7 +66,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);
|
||||
date = vstd::getFormattedDateTime(time, Languages::getLanguageOptions(settings["general"]["language"].String()).dateTimeFormat);
|
||||
|
||||
// We absolutely not need this data for lobby and server will read it from save
|
||||
// FIXME: actually we don't want them in CMapHeader!
|
||||
|
@ -1,33 +1,29 @@
|
||||
#include "StdInc.h"
|
||||
#include <vstd/DateUtils.h>
|
||||
|
||||
#if defined(VCMI_ANDROID)
|
||||
#include "../CAndroidVMHelper.h"
|
||||
#endif
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
namespace vstd
|
||||
{
|
||||
|
||||
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt)
|
||||
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt, std::string format)
|
||||
{
|
||||
#if defined(VCMI_ANDROID)
|
||||
CAndroidVMHelper vmHelper;
|
||||
return vmHelper.callStaticStringMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "getFormattedDateTime");
|
||||
#endif
|
||||
|
||||
std::tm tm = *std::localtime(&dt);
|
||||
std::stringstream s;
|
||||
try
|
||||
if(format.empty())
|
||||
{
|
||||
s.imbue(std::locale(""));
|
||||
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");
|
||||
}
|
||||
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());
|
||||
return s.str();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user