System Time Offset Implementation (#1101)
* System Time Offset Implementation * Addressed @Thog's comments * Addressed JD's comments * Addressed @Thog's and @AcK77's comments * formatting correction
This commit is contained in:
@@ -9,6 +9,7 @@ using LibHac.Ns;
|
||||
using LibHac.Spl;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Configuration;
|
||||
using Ryujinx.HLE.FileSystem.Content;
|
||||
using Ryujinx.HLE.HOS.Font;
|
||||
using Ryujinx.HLE.HOS.Kernel.Common;
|
||||
@@ -224,8 +225,24 @@ namespace Ryujinx.HLE.HOS
|
||||
// We assume the rtc is system time.
|
||||
TimeSpanType systemTime = TimeSpanType.FromSeconds((long)rtcValue);
|
||||
|
||||
// Configure and setup internal offset
|
||||
TimeSpanType internalOffset = TimeSpanType.FromSeconds(ConfigurationState.Instance.System.SystemTimeOffset);
|
||||
|
||||
TimeSpanType systemTimeOffset = new TimeSpanType(systemTime.NanoSeconds + internalOffset.NanoSeconds);
|
||||
|
||||
if (systemTime.IsDaylightSavingTime() && !systemTimeOffset.IsDaylightSavingTime())
|
||||
{
|
||||
internalOffset = internalOffset.AddSeconds(3600L);
|
||||
}
|
||||
else if (!systemTime.IsDaylightSavingTime() && systemTimeOffset.IsDaylightSavingTime())
|
||||
{
|
||||
internalOffset = internalOffset.AddSeconds(-3600L);
|
||||
}
|
||||
|
||||
internalOffset = new TimeSpanType(-internalOffset.NanoSeconds);
|
||||
|
||||
// First init the standard steady clock
|
||||
TimeServiceManager.Instance.SetupStandardSteadyClock(null, clockSourceId, systemTime, TimeSpanType.Zero, TimeSpanType.Zero, false);
|
||||
TimeServiceManager.Instance.SetupStandardSteadyClock(null, clockSourceId, systemTime, internalOffset, TimeSpanType.Zero, false);
|
||||
TimeServiceManager.Instance.SetupStandardLocalSystemClock(null, new SystemClockContext(), systemTime.ToSeconds());
|
||||
|
||||
if (NxSettings.Settings.TryGetValue("time!standard_network_clock_sufficient_accuracy_minutes", out object standardNetworkClockSufficientAccuracyMinutes))
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
{
|
||||
@@ -9,6 +10,8 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
|
||||
public static readonly TimeSpanType Zero = new TimeSpanType(0);
|
||||
|
||||
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
public long NanoSeconds;
|
||||
|
||||
public TimeSpanType(long nanoSeconds)
|
||||
@@ -21,6 +24,16 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||
return NanoSeconds / NanoSecondsPerSecond;
|
||||
}
|
||||
|
||||
public TimeSpanType AddSeconds(long seconds)
|
||||
{
|
||||
return new TimeSpanType(NanoSeconds + (seconds * NanoSecondsPerSecond));
|
||||
}
|
||||
|
||||
public bool IsDaylightSavingTime()
|
||||
{
|
||||
return UnixEpoch.AddSeconds(ToSeconds()).ToLocalTime().IsDaylightSavingTime();
|
||||
}
|
||||
|
||||
public static TimeSpanType FromSeconds(long seconds)
|
||||
{
|
||||
return new TimeSpanType(seconds * NanoSecondsPerSecond);
|
||||
|
Reference in New Issue
Block a user