From 5886320bb6ce1f60beaeaa8538956efb43209566 Mon Sep 17 00:00:00 2001 From: CWX Date: Sun, 20 Apr 2025 14:33:14 +0100 Subject: [PATCH] change to seconds not ms --- .../Generators/PlayerScavGenerator.cs | 2 +- .../Generators/WeatherGenerator.cs | 4 ++-- .../Helpers/WeatherHelper.cs | 2 +- .../Services/RaidWeatherService.cs | 18 +++++++++--------- .../SPTarkov.Server.Core/Utils/TimeUtil.cs | 14 +------------- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Generators/PlayerScavGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/PlayerScavGenerator.cs index 3a6c25ff..186c0e65 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/PlayerScavGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/PlayerScavGenerator.cs @@ -376,7 +376,7 @@ public class PlayerScavGenerator( if (scavData?.Info != null) { - scavData.Info.SavageLockTime = Math.Round(_timeUtil.GetTimeStampFromEpoch() / 1000 + (scavLockDuration ?? 0)); + scavData.Info.SavageLockTime = Math.Round(_timeUtil.GetTimeStamp() + (scavLockDuration ?? 0)); } return scavData; diff --git a/Libraries/SPTarkov.Server.Core/Generators/WeatherGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/WeatherGenerator.cs index a55724d0..afeb3426 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/WeatherGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/WeatherGenerator.cs @@ -140,10 +140,10 @@ public class WeatherGenerator( var formattedDate = _timeUtil.FormatDate(timestamp.HasValue ? _timeUtil.GetDateTimeFromTimeStamp(timestamp.Value) : DateTime.UtcNow); var datetimeBsgFormat = $"{formattedDate} {normalTime}"; - weather.Timestamp = timestamp ?? _timeUtil.GetTimeStampFromEpoch(inRaidTime) / 1000; // matches weather.date + weather.Timestamp = timestamp ?? _timeUtil.GetTimeStamp(); // matches weather.date weather.Date = formattedDate; // matches weather.timestamp weather.Time = datetimeBsgFormat; // matches weather.timestamp - weather.SptInRaidTimestamp = _timeUtil.GetTimeStampFromEpoch(inRaidTime); + weather.SptInRaidTimestamp = weather.Timestamp; } protected WindDirection GetWeightedWindDirection(SeasonalValues weather) diff --git a/Libraries/SPTarkov.Server.Core/Helpers/WeatherHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/WeatherHelper.cs index 4d6658a5..8c869a45 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/WeatherHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/WeatherHelper.cs @@ -28,7 +28,7 @@ public class WeatherHelper( var twentyFourHoursMilliseconds = _timeUtil.GetHoursAsSeconds(24) * 1000; var currentTimestampMilliSeconds = timestamp.HasValue ? timestamp ?? 0 - : _timeUtil.GetTimeStampFromEpoch(); + : _timeUtil.GetTimeStamp(); return _timeUtil.GetDateTimeFromTimeStamp( (long) diff --git a/Libraries/SPTarkov.Server.Core/Services/RaidWeatherService.cs b/Libraries/SPTarkov.Server.Core/Services/RaidWeatherService.cs index 34055626..9d8c5805 100644 --- a/Libraries/SPTarkov.Server.Core/Services/RaidWeatherService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/RaidWeatherService.cs @@ -27,23 +27,23 @@ public class RaidWeatherService( public void GenerateWeather(Season currentSeason) { // When to start generating weather from in milliseconds - var staringTimestampMs = _timeUtil.GetTodayMidnightTimeStamp(); + var staringTimestamp = _timeUtil.GetTodayMidnightTimeStamp(); // How far into future do we generate weather - var futureTimestampToReachMs = - staringTimestampMs + _timeUtil.GetHoursAsSeconds(_weatherConfig.Weather.GenerateWeatherAmountHours ?? 1) * 1000; // Convert to milliseconds + var futureTimestampToReach = + staringTimestamp + _timeUtil.GetHoursAsSeconds(_weatherConfig.Weather.GenerateWeatherAmountHours ?? 1); // Keep adding new weather until we have reached desired future date - var nextTimestampMs = staringTimestampMs; - while (nextTimestampMs <= futureTimestampToReachMs) + var nextTimestamp = staringTimestamp; + while (nextTimestamp <= futureTimestampToReach) { - var newWeatherToAddToCache = _weatherGenerator.GenerateWeather(currentSeason, nextTimestampMs); + var newWeatherToAddToCache = _weatherGenerator.GenerateWeather(currentSeason, nextTimestamp); // Add generated weather for time period to cache _weatherForecast.Add(newWeatherToAddToCache); // Increment timestamp so next loop can begin at correct time - nextTimestampMs += GetWeightedWeatherTimePeriodMs(); + nextTimestamp += GetWeightedWeatherTimePeriod(); } } @@ -51,7 +51,7 @@ public class RaidWeatherService( /// Get a time period to increment by, e.g. 15 or 30 minutes as milliseconds /// /// milliseconds - protected long GetWeightedWeatherTimePeriodMs() + protected long GetWeightedWeatherTimePeriod() { var chosenTimePeriodMinutes = _weightedRandomHelper.WeightedRandom( _weatherConfig.Weather.TimePeriod.Values, @@ -59,7 +59,7 @@ public class RaidWeatherService( ) .Item; - return chosenTimePeriodMinutes * 60 * 1000; // Convert to milliseconds + return chosenTimePeriodMinutes * 60; } /// diff --git a/Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs b/Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs index 0d3d17a5..e108e3dd 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs @@ -167,7 +167,7 @@ public class TimeUtil // Create a new DateTime with the last full hour, 0 minutes, and 0 seconds var lastFullHour = new DateTime(now.Year, now.Month, now.Day, hours, 0, 0); - return ((DateTimeOffset) lastFullHour).ToUnixTimeMilliseconds(); + return ((DateTimeOffset) lastFullHour).ToUnixTimeSeconds(); } /// @@ -190,18 +190,6 @@ public class TimeUtil return DateTimeOffset.FromUnixTimeSeconds(timeStamp).DateTime; } - /// - /// Takes a date and gets difference between Epoch time and time provided resulting in a timestamp (date defaults to utcnow) - /// This attempts to mimic gettime() in js - /// - /// - /// - public long GetTimeStampFromEpoch(DateTime? date = null) - { - var dateToCompare = date ?? DateTime.UtcNow; - return (long) (dateToCompare - DateTime.UnixEpoch).TotalMilliseconds; - } - public int GetSecondsAsMilliseconds(int seconds) { return seconds * 60 * 1000;