From 81a263b7d0ab02edce49ceb4ea2888c41ee556b6 Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 30 Jun 2025 10:12:55 +0100 Subject: [PATCH] Fixed incorrect logic in how weekly reset date is picked, choose the most recent previous day, not the closest --- .../Extensions/DateTimeExtensions.cs | 26 ++++++++++++++++++- .../Services/PostDbLoadService.cs | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs index 0b35c730..14e4af69 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs @@ -113,7 +113,7 @@ /// Date to get closest monday of /// Starting day of week - Default = Monday /// Monday as DateTime - public static DateTime GetStartOfWeek( + public static DateTime GetClosestDate( this DateTime dateTime, DayOfWeek startDay = DayOfWeek.Monday ) @@ -124,5 +124,29 @@ // Subtract difference to get date of most recent Monday return dateTime.AddDays(-1 * diff).Date; } + + /// + /// Get the most recent requested day from date + /// + /// Date to start from + /// Desired day to find + /// Should today be included in check, default = true + /// Datetime of desired day + public static DateTime GetMostRecentPreviousDay( + this DateTime dateTime, + DayOfWeek desiredDay, + bool inclusiveOfToday = true + ) + { + // Go back 1 day if we don't count today (exclusive) + var closestDate = inclusiveOfToday ? dateTime : dateTime.AddDays(-1); + + while (closestDate.DayOfWeek != desiredDay) + { + closestDate = closestDate.AddDays(-1); + } + + return closestDate; + } } } diff --git a/Libraries/SPTarkov.Server.Core/Services/PostDbLoadService.cs b/Libraries/SPTarkov.Server.Core/Services/PostDbLoadService.cs index cdf359a6..e6d1a9c9 100644 --- a/Libraries/SPTarkov.Server.Core/Services/PostDbLoadService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/PostDbLoadService.cs @@ -147,7 +147,7 @@ public class PostDbLoadService( protected WildSpawnType GetWeeklyBoss(List bosses, DayOfWeek bossResetDay) { // Get closest monday to today - var startOfWeek = DateTime.Today.GetStartOfWeek(bossResetDay); + var startOfWeek = DateTime.Today.GetMostRecentPreviousDay(bossResetDay); // Create a consistent seed for the week using the year and the day of the year of above monday chosen // This results in seed being identical for the week