diff --git a/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs index e646db1e..9142f7f6 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs @@ -81,5 +81,30 @@ { return date.FormatToBsgTime().Replace("-", ":").Replace("-", ":"); } + + /// + /// Does the provided date fit between the two defined dates? + /// Excludes year + /// Inclusive of end date up to 23 hours 59 minutes + /// + /// Date to check is between 2 dates + /// Lower bound for month + /// Lower bound for day + /// Upper bound for month + /// Upper bound for day + /// True when inside date range + public static bool DateIsBetweenTwoDates( + this DateTime dateToCheck, + int startMonth, + int startDay, + int endMonth, + int endDay + ) + { + var eventStartDate = new DateTime(dateToCheck.Year, startMonth, startDay); + var eventEndDate = new DateTime(dateToCheck.Year, endMonth, endDay, 23, 59, 0); + + return dateToCheck >= eventStartDate && dateToCheck <= eventEndDate; + } } } diff --git a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs index 67ff684f..fa0ae527 100644 --- a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs @@ -1,5 +1,6 @@ using SPTarkov.Common.Extensions; using SPTarkov.DI.Annotations; +using SPTarkov.Server.Core.Extensions; using SPTarkov.Server.Core.Helpers; using SPTarkov.Server.Core.Models.Eft.Common; using SPTarkov.Server.Core.Models.Eft.Common.Tables; @@ -304,8 +305,7 @@ public class SeasonalEventService( } if ( - DateIsBetweenTwoDates( - currentDate, + currentDate.DateIsBetweenTwoDates( events.StartMonth, events.StartDay, events.EndMonth, @@ -333,8 +333,7 @@ public class SeasonalEventService( foreach (var seasonRange in _weatherConfig.SeasonDates) { if ( - DateIsBetweenTwoDates( - currentDate, + currentDate.DateIsBetweenTwoDates( seasonRange.StartMonth ?? 0, seasonRange.StartDay ?? 0, seasonRange.EndMonth ?? 0, @@ -351,31 +350,6 @@ public class SeasonalEventService( return Season.SUMMER; } - /// - /// Does the provided date fit between the two defined dates? - /// Excludes year - /// Inclusive of end date upto 23 hours 59 minutes - /// - /// Date to check is between 2 dates - /// Lower bound for month - /// Lower bound for day - /// Upper bound for month - /// Upper bound for day - /// True when inside date range - private bool DateIsBetweenTwoDates( - DateTime dateToCheck, - int startMonth, - int startDay, - int endMonth, - int endDay - ) - { - var eventStartDate = new DateTime(dateToCheck.Year, startMonth, startDay); - var eventEndDate = new DateTime(dateToCheck.Year, endMonth, endDay, 23, 59, 0); - - return dateToCheck >= eventStartDate && dateToCheck <= eventEndDate; - } - /// /// Iterate through bots inventory and loot to find and remove christmas items (as defined in SeasonalEventService) ///