Merge pull request #6553 from ankenyr/master

This commit is contained in:
Claus Vium 2021-09-21 08:09:41 +02:00 committed by GitHub
commit c38d19682c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 11 deletions

View File

@ -28,16 +28,6 @@ namespace Emby.Server.Implementations.Sorting
throw new ArgumentNullException(nameof(y)); 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 episode1 = x as Episode;
var episode2 = y as Episode; var episode2 = y as Episode;
@ -156,8 +146,14 @@ namespace Emby.Server.Implementations.Sorting
{ {
var xValue = ((x.ParentIndexNumber ?? -1) * 1000) + (x.IndexNumber ?? -1); var xValue = ((x.ParentIndexNumber ?? -1) * 1000) + (x.IndexNumber ?? -1);
var yValue = ((y.ParentIndexNumber ?? -1) * 1000) + (y.IndexNumber ?? -1); var yValue = ((y.ParentIndexNumber ?? -1) * 1000) + (y.IndexNumber ?? -1);
var comparisonResult = xValue.CompareTo(yValue);
// If equal, compare premiere dates
if (comparisonResult == 0 && x.PremiereDate.HasValue && y.PremiereDate.HasValue)
{
comparisonResult = DateTime.Compare(x.PremiereDate.Value, y.PremiereDate.Value);
}
return xValue.CompareTo(yValue); return comparisonResult;
} }
/// <summary> /// <summary>

View File

@ -172,6 +172,25 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting
new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 },
1 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(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();