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

View File

@ -7,83 +7,14 @@ namespace NzbDrone.Core.SeriesStats
public class SeriesStatistics : ResultSet public class SeriesStatistics : ResultSet
{ {
public int SeriesId { get; set; } public int SeriesId { get; set; }
public string NextAiringString { get; set; } public DateTime? NextAiring { get; set; }
public string PreviousAiringString { get; set; } public DateTime? PreviousAiring { get; set; }
public string LastAiredString { get; set; } public DateTime? LastAired { get; set; }
public int EpisodeFileCount { get; set; } public int EpisodeFileCount { get; set; }
public int EpisodeCount { get; set; } public int EpisodeCount { get; set; }
public int TotalEpisodeCount { get; set; } public int TotalEpisodeCount { get; set; }
public long SizeOnDisk { get; set; } public long SizeOnDisk { get; set; }
public List<string> ReleaseGroups { get; set; } public List<string> ReleaseGroups { get; set; }
public List<SeasonStatistics> SeasonStatistics { 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

@ -54,9 +54,9 @@ namespace NzbDrone.Core.SeriesStats
var previousAiring = seasonStatistics.Where(s => s.PreviousAiring != null).MaxBy(s => s.PreviousAiring); 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); var lastAired = seasonStatistics.Where(s => s.SeasonNumber > 0 && s.LastAired != null).MaxBy(s => s.LastAired);
seriesStatistics.NextAiringString = nextAiring?.NextAiringString; seriesStatistics.NextAiring = nextAiring?.NextAiring;
seriesStatistics.PreviousAiringString = previousAiring?.PreviousAiringString; seriesStatistics.PreviousAiring = previousAiring?.PreviousAiring;
seriesStatistics.LastAiredString = lastAired?.LastAiredString; seriesStatistics.LastAired = lastAired?.LastAired;
return seriesStatistics; return seriesStatistics;
} }