From 2b5f3f294ed7b3660c0a5898d0ece42a7d7cca72 Mon Sep 17 00:00:00 2001 From: ankenyr Date: Sun, 12 Sep 2021 15:05:37 -0700 Subject: [PATCH] Fixing #6269 by comparing PremiereDate when episode comparison would otherwise be equal. --- .../Sorting/AiredEpisodeOrderComparer.cs | 20 +++++++++---------- .../Sorting/AiredEpisodeOrderComparerTests.cs | 19 ++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs b/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs index 2b0ab536f..821fa9778 100644 --- a/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs +++ b/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs @@ -28,16 +28,6 @@ namespace Emby.Server.Implementations.Sorting throw new ArgumentNullException(nameof(y)); } - if (x.PremiereDate.HasValue && y.PremiereDate.HasValue) - { - var val = DateTime.Compare(x.PremiereDate.Value, y.PremiereDate.Value); - - if (val != 0) - { - // return val; - } - } - var episode1 = x as Episode; var episode2 = y as Episode; @@ -156,8 +146,16 @@ namespace Emby.Server.Implementations.Sorting { var xValue = ((x.ParentIndexNumber ?? -1) * 1000) + (x.IndexNumber ?? -1); var yValue = ((y.ParentIndexNumber ?? -1) * 1000) + (y.IndexNumber ?? -1); + var compare_val = xValue.CompareTo(yValue); + if (compare_val == 0) + { + if (x.PremiereDate.HasValue & y.PremiereDate.HasValue) + { + compare_val = DateTime.Compare(x.PremiereDate.Value, y.PremiereDate.Value); + } + } - return xValue.CompareTo(yValue); + return compare_val; } /// diff --git a/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs index d9b206f66..e94c509d7 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs @@ -172,6 +172,25 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 }, 1 }; + // Premiere Date + yield return new object?[] + { + new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 12, 0, 0, 0) }, + new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 12, 0, 0, 0) }, + 0 + }; + yield return new object?[] + { + new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 11, 0, 0, 0) }, + new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 12, 0, 0, 0) }, + -1 + }; + yield return new object?[] + { + new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 12, 0, 0, 0) }, + new Episode { ParentIndexNumber = 1, IndexNumber = 1, PremiereDate = new DateTime(2021, 09, 11, 0, 0, 0) }, + 1 + }; } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();