From 44c7c712267b564a6f310cff7f9397fa92a54f5a Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 28 Jul 2024 12:56:30 +0300 Subject: [PATCH] Fixed: Calculate movie availability comparing UTC dates --- .../RssSync/AvailabilitySpecification.cs | 21 +++++++++---------- src/NzbDrone.Core/Movies/Movie.cs | 8 +++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/AvailabilitySpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/AvailabilitySpecification.cs index 704145dbb..036be785b 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/AvailabilitySpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/AvailabilitySpecification.cs @@ -7,12 +7,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync { public class AvailabilitySpecification : IDecisionEngineSpecification { - private readonly IConfigService _settingsService; + private readonly IConfigService _configService; private readonly Logger _logger; - public AvailabilitySpecification(IConfigService settingsService, Logger logger) + public AvailabilitySpecification(IConfigService configService, Logger logger) { - _settingsService = settingsService; + _configService = configService; _logger = logger; } @@ -21,18 +21,17 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync public Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria) { - if (searchCriteria != null) + if (searchCriteria is { UserInvokedSearch: true }) { - if (searchCriteria.UserInvokedSearch) - { - _logger.Debug("Skipping availability check during search"); - return Decision.Accept(); - } + _logger.Debug("Skipping availability check during search"); + return Decision.Accept(); } - if (!subject.Movie.IsAvailable(_settingsService.AvailabilityDelay)) + var availabilityDelay = _configService.AvailabilityDelay; + + if (!subject.Movie.IsAvailable(availabilityDelay)) { - return Decision.Reject("Movie {0} will only be considered available {1} days after {2}", subject.Movie, _settingsService.AvailabilityDelay, subject.Movie.MinimumAvailability.ToString()); + return Decision.Reject("Movie {0} will only be considered available {1} days after {2}", subject.Movie, availabilityDelay, subject.Movie.MinimumAvailability.ToString()); } return Decision.Accept(); diff --git a/src/NzbDrone.Core/Movies/Movie.cs b/src/NzbDrone.Core/Movies/Movie.cs index ce9dd483b..1e4999ef7 100644 --- a/src/NzbDrone.Core/Movies/Movie.cs +++ b/src/NzbDrone.Core/Movies/Movie.cs @@ -81,7 +81,7 @@ namespace NzbDrone.Core.Movies // This more complex sequence handles the delay DateTime minimumAvailabilityDate; - if ((MinimumAvailability == MovieStatusType.TBA) || (MinimumAvailability == MovieStatusType.Announced)) + if (MinimumAvailability is MovieStatusType.TBA or MovieStatusType.Announced) { minimumAvailabilityDate = DateTime.MinValue; } @@ -105,16 +105,16 @@ namespace NzbDrone.Core.Movies } else { - minimumAvailabilityDate = MovieMetadata.Value.InCinemas.HasValue ? MovieMetadata.Value.InCinemas.Value.AddDays(90) : DateTime.MaxValue; + minimumAvailabilityDate = MovieMetadata.Value.InCinemas?.AddDays(90) ?? DateTime.MaxValue; } } if (minimumAvailabilityDate == DateTime.MinValue || minimumAvailabilityDate == DateTime.MaxValue) { - return DateTime.Now >= minimumAvailabilityDate; + return DateTime.UtcNow >= minimumAvailabilityDate; } - return DateTime.Now >= minimumAvailabilityDate.AddDays((double)delay); + return DateTime.UtcNow >= minimumAvailabilityDate.AddDays(delay); } public override string ToString()