From d2917062e87579e266c33de0a1f00ca5e5ce713c Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 27 Jan 2025 12:06:02 +0000 Subject: [PATCH] Updated all instances of DateTime.Now to be DateTime.UtcNow --- Libraries/Core/Context/ContextVariable.cs | 2 +- Libraries/Core/Generators/WeatherGenerator.cs | 4 ++-- Libraries/Core/Utils/TimeUtil.cs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Libraries/Core/Context/ContextVariable.cs b/Libraries/Core/Context/ContextVariable.cs index 6e27e6e5..29c4b1ec 100644 --- a/Libraries/Core/Context/ContextVariable.cs +++ b/Libraries/Core/Context/ContextVariable.cs @@ -2,7 +2,7 @@ namespace Core.Context; public class ContextVariable(object value, ContextVariableType contextVariableInternalType) { - private readonly DateTime _timestamp = DateTime.Now; + private readonly DateTime _timestamp = DateTime.UtcNow; public T GetValue() { return (T)value; diff --git a/Libraries/Core/Generators/WeatherGenerator.cs b/Libraries/Core/Generators/WeatherGenerator.cs index 18d658c8..e43cf230 100644 --- a/Libraries/Core/Generators/WeatherGenerator.cs +++ b/Libraries/Core/Generators/WeatherGenerator.cs @@ -1,4 +1,4 @@ -using SptCommon.Annotations; +using SptCommon.Annotations; using Core.Helpers; using Core.Models.Eft.Weather; using Core.Models.Enums; @@ -28,7 +28,7 @@ public class WeatherGenerator( */ public void CalculateGameTime(WeatherData data) { - var computedDate = DateTime.Now; + var computedDate = _timeUtil.GetDateTimeNow(); var formattedDate = _timeUtil.FormatDate(computedDate); data.Date = formattedDate; diff --git a/Libraries/Core/Utils/TimeUtil.cs b/Libraries/Core/Utils/TimeUtil.cs index 0b863e17..913d0f2c 100644 --- a/Libraries/Core/Utils/TimeUtil.cs +++ b/Libraries/Core/Utils/TimeUtil.cs @@ -70,13 +70,13 @@ public class TimeUtil /// /// Gets the start of day timestamp for the given date /// - /// datetime to get the time stamp for, if null it uses current date. + /// datetime to get the time stamp for, if null it uses current date. /// Unix epoch for the start of day of the calculated date public long GetStartOfDayTimeStamp(long? timestamp) { DateTime now = timestamp.HasValue ? DateTimeOffset.FromUnixTimeMilliseconds(timestamp.Value).DateTime - : DateTime.Now; + : GetDateTimeNow(); DateTime startOfDay = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0); return ((DateTimeOffset)startOfDay).ToUnixTimeMilliseconds(); @@ -137,7 +137,7 @@ public class TimeUtil /// Time stamp of the next hour in unix time seconds public long GetTimeStampOfNextHour() { - DateTime now = DateTime.Now; + DateTime now = DateTime.UtcNow; TimeSpan timeUntilNextHour = TimeSpan.FromMinutes(60 - now.Minute) .Subtract(TimeSpan.FromSeconds(now.Second)) .Subtract(TimeSpan.FromMilliseconds(now.Millisecond)); @@ -154,7 +154,7 @@ public class TimeUtil /// Timestamp public long GetTodayMidnightTimeStamp() { - DateTime now = DateTime.Now; + DateTime now = DateTime.UtcNow; int hours = now.Hour; int minutes = now.Minute;