mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Upgrade platform_get_locale_date_format()
This commit is contained in:
@@ -183,7 +183,7 @@ namespace Config
|
||||
model->use_vsync = reader->GetBoolean("use_vsync", true);
|
||||
model->virtual_floor_style = reader->GetEnum<VirtualFloorStyles>(
|
||||
"virtual_floor_style", VirtualFloorStyles::Glassy, Enum_VirtualFloorStyle);
|
||||
model->date_format = reader->GetEnum<int32_t>("date_format", platform_get_locale_date_format(), Enum_DateFormat);
|
||||
model->date_format = reader->GetEnum<int32_t>("date_format", Platform::GetLocaleDateFormat(), Enum_DateFormat);
|
||||
model->auto_staff_placement = reader->GetBoolean("auto_staff", true);
|
||||
model->handymen_mow_default = reader->GetBoolean("handymen_mow_default", false);
|
||||
model->default_inspection_interval = reader->GetInt32("default_inspection_interval", 2);
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
|
||||
|
||||
# include "platform.h"
|
||||
|
||||
# include "../core/Memory.hpp"
|
||||
# include "../core/Path.hpp"
|
||||
# include "../core/String.hpp"
|
||||
# include "../localisation/Date.h"
|
||||
# include "Platform2.h"
|
||||
# include "platform.h"
|
||||
|
||||
# include <cerrno>
|
||||
# include <clocale>
|
||||
@@ -22,6 +22,7 @@
|
||||
# include <cstring>
|
||||
# include <ctime>
|
||||
# include <dirent.h>
|
||||
# include <locale>
|
||||
# include <pwd.h>
|
||||
# include <sys/stat.h>
|
||||
|
||||
@@ -267,6 +268,26 @@ namespace Platform
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t GetLocaleDateFormat()
|
||||
{
|
||||
const std::time_base::dateorder dateorder = std::use_facet<std::time_get<char>>(std::locale()).date_order();
|
||||
|
||||
switch (dateorder)
|
||||
{
|
||||
case std::time_base::mdy:
|
||||
return DATE_FORMAT_MONTH_DAY_YEAR;
|
||||
|
||||
case std::time_base::ymd:
|
||||
return DATE_FORMAT_YEAR_MONTH_DAY;
|
||||
|
||||
case std::time_base::ydm:
|
||||
return DATE_FORMAT_YEAR_DAY_MONTH;
|
||||
|
||||
default:
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
}
|
||||
} // namespace Platform
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,11 +34,13 @@
|
||||
# include "../common.h"
|
||||
# include "../core/Path.hpp"
|
||||
# include "../core/String.hpp"
|
||||
# include "../localisation/Date.h"
|
||||
# include "../localisation/Language.h"
|
||||
# include "Platform2.h"
|
||||
# include "platform.h"
|
||||
|
||||
# include <iterator>
|
||||
# include <locale>
|
||||
|
||||
# if _WIN32_WINNT < 0x600
|
||||
# define swprintf_s(a, b, c, d, ...) swprintf(a, b, c, ##__VA_ARGS__)
|
||||
@@ -728,6 +730,57 @@ namespace Platform
|
||||
return MeasurementFormat::Metric;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t GetLocaleDateFormat()
|
||||
{
|
||||
# if _WIN32_WINNT >= 0x0600
|
||||
// Retrieve short date format, eg "MM/dd/yyyy"
|
||||
wchar_t dateFormat[20];
|
||||
if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SSHORTDATE, dateFormat, static_cast<int>(std::size(dateFormat)))
|
||||
== 0)
|
||||
{
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
|
||||
// The only valid characters for format types are: dgyM
|
||||
// We try to find 3 strings of format types, ignore any characters in between.
|
||||
// We also ignore 'g', as it represents 'era' and we don't have that concept
|
||||
// in our date formats.
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd317787(v=vs.85).aspx
|
||||
//
|
||||
wchar_t first[sizeof(dateFormat)];
|
||||
wchar_t second[sizeof(dateFormat)];
|
||||
if (swscanf_s(
|
||||
dateFormat, L"%l[dyM]%*l[^dyM]%l[dyM]%*l[^dyM]%*l[dyM]", first, static_cast<uint32_t>(std::size(first)), second,
|
||||
static_cast<uint32_t>(std::size(second)))
|
||||
!= 2)
|
||||
{
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
|
||||
if (wcsncmp(L"d", first, 1) == 0)
|
||||
{
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
if (wcsncmp(L"M", first, 1) == 0)
|
||||
{
|
||||
return DATE_FORMAT_MONTH_DAY_YEAR;
|
||||
}
|
||||
if (wcsncmp(L"y", first, 1) == 0)
|
||||
{
|
||||
if (wcsncmp(L"d", second, 1) == 0)
|
||||
{
|
||||
return DATE_FORMAT_YEAR_DAY_MONTH;
|
||||
}
|
||||
|
||||
// Closest possible option
|
||||
return DATE_FORMAT_YEAR_MONTH_DAY;
|
||||
}
|
||||
# endif
|
||||
|
||||
// Default fallback
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
} // namespace Platform
|
||||
|
||||
#endif
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace Platform
|
||||
CurrencyType GetLocaleCurrency();
|
||||
CurrencyType GetCurrencyValue(const char* currCode);
|
||||
MeasurementFormat GetLocaleMeasurementFormat();
|
||||
uint8_t GetLocaleDateFormat();
|
||||
rct2_time GetTimeLocal();
|
||||
rct2_date GetDateLocal();
|
||||
|
||||
|
||||
@@ -194,26 +194,6 @@ TemperatureUnit platform_get_locale_temperature_format()
|
||||
return TemperatureUnit::Celsius;
|
||||
}
|
||||
|
||||
uint8_t platform_get_locale_date_format()
|
||||
{
|
||||
const std::time_base::dateorder dateorder = std::use_facet<std::time_get<char>>(std::locale()).date_order();
|
||||
|
||||
switch (dateorder)
|
||||
{
|
||||
case std::time_base::mdy:
|
||||
return DATE_FORMAT_MONTH_DAY_YEAR;
|
||||
|
||||
case std::time_base::ymd:
|
||||
return DATE_FORMAT_YEAR_MONTH_DAY;
|
||||
|
||||
case std::time_base::ydm:
|
||||
return DATE_FORMAT_YEAR_DAY_MONTH;
|
||||
|
||||
default:
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
}
|
||||
|
||||
datetime64 platform_get_datetime_now_utc()
|
||||
{
|
||||
const datetime64 epochAsTicks = 621355968000000000;
|
||||
|
||||
@@ -197,56 +197,6 @@ TemperatureUnit platform_get_locale_temperature_format()
|
||||
return TemperatureUnit::Celsius;
|
||||
}
|
||||
|
||||
uint8_t platform_get_locale_date_format()
|
||||
{
|
||||
# if _WIN32_WINNT >= 0x0600
|
||||
// Retrieve short date format, eg "MM/dd/yyyy"
|
||||
wchar_t dateFormat[20];
|
||||
if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SSHORTDATE, dateFormat, static_cast<int>(std::size(dateFormat))) == 0)
|
||||
{
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
|
||||
// The only valid characters for format types are: dgyM
|
||||
// We try to find 3 strings of format types, ignore any characters in between.
|
||||
// We also ignore 'g', as it represents 'era' and we don't have that concept
|
||||
// in our date formats.
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd317787(v=vs.85).aspx
|
||||
//
|
||||
wchar_t first[sizeof(dateFormat)];
|
||||
wchar_t second[sizeof(dateFormat)];
|
||||
if (swscanf_s(
|
||||
dateFormat, L"%l[dyM]%*l[^dyM]%l[dyM]%*l[^dyM]%*l[dyM]", first, static_cast<uint32_t>(std::size(first)), second,
|
||||
static_cast<uint32_t>(std::size(second)))
|
||||
!= 2)
|
||||
{
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
|
||||
if (wcsncmp(L"d", first, 1) == 0)
|
||||
{
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
if (wcsncmp(L"M", first, 1) == 0)
|
||||
{
|
||||
return DATE_FORMAT_MONTH_DAY_YEAR;
|
||||
}
|
||||
if (wcsncmp(L"y", first, 1) == 0)
|
||||
{
|
||||
if (wcsncmp(L"d", second, 1) == 0)
|
||||
{
|
||||
return DATE_FORMAT_YEAR_DAY_MONTH;
|
||||
}
|
||||
|
||||
// Closest possible option
|
||||
return DATE_FORMAT_YEAR_MONTH_DAY;
|
||||
}
|
||||
# endif
|
||||
|
||||
// Default fallback
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
|
||||
# ifndef NO_TTF
|
||||
bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size)
|
||||
{
|
||||
|
||||
@@ -101,7 +101,6 @@ void platform_get_user_directory(utf8* outPath, const utf8* subDirectory, size_t
|
||||
bool platform_open_common_file_dialog(utf8* outFilename, file_dialog_desc* desc, size_t outSize);
|
||||
utf8* platform_open_directory_browser(const utf8* title);
|
||||
TemperatureUnit platform_get_locale_temperature_format();
|
||||
uint8_t platform_get_locale_date_format();
|
||||
bool platform_process_is_elevated();
|
||||
bool platform_get_steam_path(utf8* outPath, size_t outSize);
|
||||
std::string platform_get_rct1_steam_dir();
|
||||
|
||||
Reference in New Issue
Block a user