From adf4ebcd60d00f5ef43d2168c3ba9893ff2c1153 Mon Sep 17 00:00:00 2001 From: Ac_K Date: Mon, 8 May 2023 00:31:08 +0200 Subject: [PATCH] Ava: Fix SystemTimeOffset calculation (#4848) * Ava: Fix SystemTimeOffset calculation During testing of #4822, Mary pointed out the way we calculate time offset is wrong in our Avalonia UI. This PR fixed that. The axaml file is autoformatted too. * DateTime.Now in local var --- .../UI/ViewModels/SettingsViewModel.cs | 16 +-- .../Views/Settings/SettingsSystemView.axaml | 105 +++++++++--------- 2 files changed, 59 insertions(+), 62 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs index 08612117a7..75a5168fc4 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs @@ -238,8 +238,9 @@ namespace Ryujinx.Ava.UI.ViewModels } } - public DateTimeOffset DateOffset { get; set; } - public TimeSpan TimeOffset { get; set; } + public DateTimeOffset CurrentDate { get; set; } + public TimeSpan CurrentTime { get; set; } + internal AvaloniaList TimeZones { get; set; } public AvaloniaList GameDirectories { get; set; } public ObservableCollection AvailableGpus { get; set; } @@ -397,10 +398,11 @@ namespace Ryujinx.Ava.UI.ViewModels Language = (int)config.System.Language.Value; TimeZone = config.System.TimeZone; - DateTime dateTimeOffset = DateTime.Now.AddSeconds(config.System.SystemTimeOffset); + DateTime currentDateTime = DateTime.Now; + + CurrentDate = currentDateTime.Date; + CurrentTime = currentDateTime.TimeOfDay.Add(TimeSpan.FromSeconds(config.System.SystemTimeOffset)); - DateOffset = dateTimeOffset.Date; - TimeOffset = dateTimeOffset.TimeOfDay; EnableVsync = config.Graphics.EnableVsync; EnableFsIntegrityChecks = config.System.EnableFsIntegrityChecks; ExpandDramSize = config.System.ExpandRam; @@ -487,9 +489,7 @@ namespace Ryujinx.Ava.UI.ViewModels config.System.TimeZone.Value = TimeZone; } - TimeSpan systemTimeOffset = DateOffset - DateTime.Now; - - config.System.SystemTimeOffset.Value = systemTimeOffset.Seconds; + config.System.SystemTimeOffset.Value = Convert.ToInt64((CurrentDate.ToUnixTimeSeconds() + CurrentTime.TotalSeconds) - DateTimeOffset.Now.ToUnixTimeSeconds()); config.Graphics.EnableVsync.Value = EnableVsync; config.System.EnableFsIntegrityChecks.Value = EnableFsIntegrityChecks; config.System.ExpandRam.Value = ExpandDramSize; diff --git a/src/Ryujinx.Ava/UI/Views/Settings/SettingsSystemView.axaml b/src/Ryujinx.Ava/UI/Views/Settings/SettingsSystemView.axaml index 1d4f040fd9..cc60ef24db 100644 --- a/src/Ryujinx.Ava/UI/Views/Settings/SettingsSystemView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Settings/SettingsSystemView.axaml @@ -3,12 +3,12 @@ xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels" - mc:Ignorable="d" x:CompileBindings="True" - x:DataType="viewModels:SettingsViewModel"> + x:DataType="viewModels:SettingsViewModel" + mc:Ignorable="d"> @@ -27,13 +27,15 @@ - - + + @@ -58,20 +60,21 @@ - - + + - + @@ -104,71 +107,67 @@ - + - + - + - + - + - + - + - - + + - + - + @@ -180,12 +179,10 @@ Margin="10,0,0,0" HorizontalAlignment="Stretch" Orientation="Vertical"> - + - +