summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bunnei2020-05-13 21:41:45 -0400
committerGravatar GitHub2020-05-13 21:41:45 -0400
commit670a7f51e8f3134fb246a471f0c9833904a6234e (patch)
treed20a6ccc6070f49aefd3069456545451a42e66cf /src/core
parentMerge pull request #3899 from ReinUsesLisp/float-comparisons (diff)
parenttime_zone: Use std::chrono::seconds for strong typing. (diff)
downloadyuzu-670a7f51e8f3134fb246a471f0c9833904a6234e.tar.gz
yuzu-670a7f51e8f3134fb246a471f0c9833904a6234e.tar.xz
yuzu-670a7f51e8f3134fb246a471f0c9833904a6234e.zip
Merge pull request #3909 from bunnei/timezone
Improve time zone support
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/time/time_manager.cpp11
-rw-r--r--src/core/hle/service/time/time_zone_content_manager.cpp24
-rw-r--r--src/core/settings.cpp16
-rw-r--r--src/core/settings.h4
4 files changed, 52 insertions, 3 deletions
diff --git a/src/core/hle/service/time/time_manager.cpp b/src/core/hle/service/time/time_manager.cpp
index 9d6c55865..b4dfe45e5 100644
--- a/src/core/hle/service/time/time_manager.cpp
+++ b/src/core/hle/service/time/time_manager.cpp
@@ -5,6 +5,7 @@
5#include <chrono> 5#include <chrono>
6#include <ctime> 6#include <ctime>
7 7
8#include "common/time_zone.h"
8#include "core/hle/service/time/ephemeral_network_system_clock_context_writer.h" 9#include "core/hle/service/time/ephemeral_network_system_clock_context_writer.h"
9#include "core/hle/service/time/local_system_clock_context_writer.h" 10#include "core/hle/service/time/local_system_clock_context_writer.h"
10#include "core/hle/service/time/network_system_clock_context_writer.h" 11#include "core/hle/service/time/network_system_clock_context_writer.h"
@@ -21,8 +22,16 @@ static std::chrono::seconds GetSecondsSinceEpoch() {
21 Settings::values.custom_rtc_differential; 22 Settings::values.custom_rtc_differential;
22} 23}
23 24
25static s64 GetExternalTimeZoneOffset() {
26 // With "auto" timezone setting, we use the external system's timezone offset
27 if (Settings::GetTimeZoneString() == "auto") {
28 return Common::TimeZone::GetCurrentOffsetSeconds().count();
29 }
30 return 0;
31}
32
24static s64 GetExternalRtcValue() { 33static s64 GetExternalRtcValue() {
25 return GetSecondsSinceEpoch().count(); 34 return GetSecondsSinceEpoch().count() + GetExternalTimeZoneOffset();
26} 35}
27 36
28TimeManager::TimeManager(Core::System& system) 37TimeManager::TimeManager(Core::System& system)
diff --git a/src/core/hle/service/time/time_zone_content_manager.cpp b/src/core/hle/service/time/time_zone_content_manager.cpp
index 78d4acd95..c070d6e97 100644
--- a/src/core/hle/service/time/time_zone_content_manager.cpp
+++ b/src/core/hle/service/time/time_zone_content_manager.cpp
@@ -5,6 +5,7 @@
5#include <sstream> 5#include <sstream>
6 6
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "common/time_zone.h"
8#include "core/core.h" 9#include "core/core.h"
9#include "core/file_sys/content_archive.h" 10#include "core/file_sys/content_archive.h"
10#include "core/file_sys/nca_metadata.h" 11#include "core/file_sys/nca_metadata.h"
@@ -14,6 +15,7 @@
14#include "core/hle/service/filesystem/filesystem.h" 15#include "core/hle/service/filesystem/filesystem.h"
15#include "core/hle/service/time/time_manager.h" 16#include "core/hle/service/time/time_manager.h"
16#include "core/hle/service/time/time_zone_content_manager.h" 17#include "core/hle/service/time/time_zone_content_manager.h"
18#include "core/settings.h"
17 19
18namespace Service::Time::TimeZone { 20namespace Service::Time::TimeZone {
19 21
@@ -68,10 +70,22 @@ static std::vector<std::string> BuildLocationNameCache(Core::System& system) {
68 70
69TimeZoneContentManager::TimeZoneContentManager(TimeManager& time_manager, Core::System& system) 71TimeZoneContentManager::TimeZoneContentManager(TimeManager& time_manager, Core::System& system)
70 : system{system}, location_name_cache{BuildLocationNameCache(system)} { 72 : system{system}, location_name_cache{BuildLocationNameCache(system)} {
71 if (FileSys::VirtualFile vfs_file; GetTimeZoneInfoFile("GMT", vfs_file) == RESULT_SUCCESS) { 73
74 std::string location_name;
75 const auto timezone_setting = Settings::GetTimeZoneString();
76 if (timezone_setting == "auto") {
77 location_name = Common::TimeZone::GetDefaultTimeZone();
78 } else if (timezone_setting == "default") {
79 location_name = location_name;
80 } else {
81 location_name = timezone_setting;
82 }
83
84 if (FileSys::VirtualFile vfs_file;
85 GetTimeZoneInfoFile(location_name, vfs_file) == RESULT_SUCCESS) {
72 const auto time_point{ 86 const auto time_point{
73 time_manager.GetStandardSteadyClockCore().GetCurrentTimePoint(system)}; 87 time_manager.GetStandardSteadyClockCore().GetCurrentTimePoint(system)};
74 time_manager.SetupTimeZoneManager("GMT", time_point, location_name_cache.size(), {}, 88 time_manager.SetupTimeZoneManager(location_name, time_point, location_name_cache.size(), {},
75 vfs_file); 89 vfs_file);
76 } else { 90 } else {
77 time_zone_manager.MarkAsInitialized(); 91 time_zone_manager.MarkAsInitialized();
@@ -114,6 +128,12 @@ ResultCode TimeZoneContentManager::GetTimeZoneInfoFile(const std::string& locati
114 128
115 vfs_file = zoneinfo_dir->GetFile(location_name); 129 vfs_file = zoneinfo_dir->GetFile(location_name);
116 if (!vfs_file) { 130 if (!vfs_file) {
131 LOG_ERROR(Service_Time, "{:016X} has no file \"{}\"! Using default timezone.",
132 time_zone_binary_titleid, location_name);
133 vfs_file = zoneinfo_dir->GetFile(Common::TimeZone::GetDefaultTimeZone());
134 }
135
136 if (!vfs_file) {
117 LOG_ERROR(Service_Time, "{:016X} has no file \"{}\"!", time_zone_binary_titleid, 137 LOG_ERROR(Service_Time, "{:016X} has no file \"{}\"!", time_zone_binary_titleid,
118 location_name); 138 location_name);
119 return ERROR_TIME_NOT_FOUND; 139 return ERROR_TIME_NOT_FOUND;
diff --git a/src/core/settings.cpp b/src/core/settings.cpp
index 2b0bdc4d3..da53cde05 100644
--- a/src/core/settings.cpp
+++ b/src/core/settings.cpp
@@ -63,6 +63,21 @@ const std::array<const char*, NumMouseButtons> mapping = {{
63 63
64Values values = {}; 64Values values = {};
65 65
66std::string GetTimeZoneString() {
67 static constexpr std::array<const char*, 46> timezones{{
68 "auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire",
69 "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0",
70 "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan",
71 "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT",
72 "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey",
73 "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu",
74 }};
75
76 ASSERT(Settings::values.time_zone_index < timezones.size());
77
78 return timezones[Settings::values.time_zone_index];
79}
80
66void Apply() { 81void Apply() {
67 GDBStub::SetServerPort(values.gdbstub_port); 82 GDBStub::SetServerPort(values.gdbstub_port);
68 GDBStub::ToggleServer(values.use_gdbstub); 83 GDBStub::ToggleServer(values.use_gdbstub);
@@ -87,6 +102,7 @@ void LogSettings() {
87 LogSetting("System_CurrentUser", Settings::values.current_user); 102 LogSetting("System_CurrentUser", Settings::values.current_user);
88 LogSetting("System_LanguageIndex", Settings::values.language_index); 103 LogSetting("System_LanguageIndex", Settings::values.language_index);
89 LogSetting("System_RegionIndex", Settings::values.region_index); 104 LogSetting("System_RegionIndex", Settings::values.region_index);
105 LogSetting("System_TimeZoneIndex", Settings::values.time_zone_index);
90 LogSetting("Core_UseMultiCore", Settings::values.use_multi_core); 106 LogSetting("Core_UseMultiCore", Settings::values.use_multi_core);
91 LogSetting("Renderer_UseResolutionFactor", Settings::values.resolution_factor); 107 LogSetting("Renderer_UseResolutionFactor", Settings::values.resolution_factor);
92 LogSetting("Renderer_UseFrameLimit", Settings::values.use_frame_limit); 108 LogSetting("Renderer_UseFrameLimit", Settings::values.use_frame_limit);
diff --git a/src/core/settings.h b/src/core/settings.h
index 163900f0b..c1266b341 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -394,6 +394,7 @@ struct Values {
394 s32 current_user; 394 s32 current_user;
395 s32 language_index; 395 s32 language_index;
396 s32 region_index; 396 s32 region_index;
397 s32 time_zone_index;
397 s32 sound_index; 398 s32 sound_index;
398 399
399 // Controls 400 // Controls
@@ -490,6 +491,9 @@ struct Values {
490bool IsGPULevelExtreme(); 491bool IsGPULevelExtreme();
491bool IsGPULevelHigh(); 492bool IsGPULevelHigh();
492 493
494std::string GetTimeZoneString();
495
493void Apply(); 496void Apply();
494void LogSettings(); 497void LogSettings();
498
495} // namespace Settings 499} // namespace Settings