1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-26 04:33:01 +01:00

Fixed: Next/previous/last air dates with Postgres DB

Closes #6790
This commit is contained in:
Bogdan 2024-05-09 04:43:51 +03:00 committed by GitHub
parent cae134ec7b
commit 7e8d8500f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 87 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore;
@ -28,7 +29,7 @@ namespace NzbDrone.Core.SeriesStats
try
{
if (!DateTime.TryParse(NextAiringString, out nextAiring))
if (!DateTime.TryParse(NextAiringString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out nextAiring))
{
return null;
}
@ -51,7 +52,7 @@ namespace NzbDrone.Core.SeriesStats
try
{
if (!DateTime.TryParse(PreviousAiringString, out previousAiring))
if (!DateTime.TryParse(PreviousAiringString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out previousAiring))
{
return null;
}
@ -74,7 +75,7 @@ namespace NzbDrone.Core.SeriesStats
try
{
if (!DateTime.TryParse(LastAiredString, out lastAired))
if (!DateTime.TryParse(LastAiredString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out lastAired))
{
return null;
}

View File

@ -7,83 +7,14 @@ namespace NzbDrone.Core.SeriesStats
public class SeriesStatistics : ResultSet
{
public int SeriesId { get; set; }
public string NextAiringString { get; set; }
public string PreviousAiringString { get; set; }
public string LastAiredString { get; set; }
public DateTime? NextAiring { get; set; }
public DateTime? PreviousAiring { get; set; }
public DateTime? LastAired { get; set; }
public int EpisodeFileCount { get; set; }
public int EpisodeCount { get; set; }
public int TotalEpisodeCount { get; set; }
public long SizeOnDisk { get; set; }
public List<string> ReleaseGroups { get; set; }
public List<SeasonStatistics> SeasonStatistics { get; set; }
public DateTime? NextAiring
{
get
{
DateTime nextAiring;
try
{
if (!DateTime.TryParse(NextAiringString, out nextAiring))
{
return null;
}
}
catch (ArgumentOutOfRangeException)
{
// GHI 3518: Can throw on mono (6.x?) despite being a Try*
return null;
}
return nextAiring;
}
}
public DateTime? PreviousAiring
{
get
{
DateTime previousAiring;
try
{
if (!DateTime.TryParse(PreviousAiringString, out previousAiring))
{
return null;
}
}
catch (ArgumentOutOfRangeException)
{
// GHI 3518: Can throw on mono (6.x?) despite being a Try*
return null;
}
return previousAiring;
}
}
public DateTime? LastAired
{
get
{
DateTime lastAired;
try
{
if (!DateTime.TryParse(LastAiredString, out lastAired))
{
return null;
}
}
catch (ArgumentOutOfRangeException)
{
// GHI 3518: Can throw on mono (6.x?) despite being a Try*
return null;
}
return lastAired;
}
}
}
}

View File

@ -40,23 +40,23 @@ namespace NzbDrone.Core.SeriesStats
private SeriesStatistics MapSeriesStatistics(List<SeasonStatistics> seasonStatistics)
{
var seriesStatistics = new SeriesStatistics
{
SeasonStatistics = seasonStatistics,
SeriesId = seasonStatistics.First().SeriesId,
EpisodeFileCount = seasonStatistics.Sum(s => s.EpisodeFileCount),
EpisodeCount = seasonStatistics.Sum(s => s.EpisodeCount),
TotalEpisodeCount = seasonStatistics.Sum(s => s.TotalEpisodeCount),
SizeOnDisk = seasonStatistics.Sum(s => s.SizeOnDisk),
ReleaseGroups = seasonStatistics.SelectMany(s => s.ReleaseGroups).Distinct().ToList()
};
{
SeasonStatistics = seasonStatistics,
SeriesId = seasonStatistics.First().SeriesId,
EpisodeFileCount = seasonStatistics.Sum(s => s.EpisodeFileCount),
EpisodeCount = seasonStatistics.Sum(s => s.EpisodeCount),
TotalEpisodeCount = seasonStatistics.Sum(s => s.TotalEpisodeCount),
SizeOnDisk = seasonStatistics.Sum(s => s.SizeOnDisk),
ReleaseGroups = seasonStatistics.SelectMany(s => s.ReleaseGroups).Distinct().ToList()
};
var nextAiring = seasonStatistics.Where(s => s.NextAiring != null).MinBy(s => s.NextAiring);
var previousAiring = seasonStatistics.Where(s => s.PreviousAiring != null).MaxBy(s => s.PreviousAiring);
var lastAired = seasonStatistics.Where(s => s.SeasonNumber > 0 && s.LastAired != null).MaxBy(s => s.LastAired);
seriesStatistics.NextAiringString = nextAiring?.NextAiringString;
seriesStatistics.PreviousAiringString = previousAiring?.PreviousAiringString;
seriesStatistics.LastAiredString = lastAired?.LastAiredString;
seriesStatistics.NextAiring = nextAiring?.NextAiring;
seriesStatistics.PreviousAiring = previousAiring?.PreviousAiring;
seriesStatistics.LastAired = lastAired?.LastAired;
return seriesStatistics;
}