< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Sorting.PremiereDateComparer
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Sorting/PremiereDateComparer.cs
Line coverage
91%
Covered lines: 11
Uncovered lines: 1
Coverable lines: 12
Total lines: 63
Line coverage: 91.6%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%11100%
Compare(...)100%11100%
GetDate(...)83.33%6.04690%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Sorting/PremiereDateComparer.cs

#LineLine coverage
 1using System;
 2using Jellyfin.Data.Enums;
 3using MediaBrowser.Controller.Entities;
 4using MediaBrowser.Controller.Sorting;
 5using MediaBrowser.Model.Querying;
 6
 7namespace Emby.Server.Implementations.Sorting
 8{
 9    /// <summary>
 10    /// Class PremiereDateComparer.
 11    /// </summary>
 12    public class PremiereDateComparer : IBaseItemComparer
 13    {
 14        /// <summary>
 15        /// Gets the name.
 16        /// </summary>
 17        /// <value>The name.</value>
 118        public ItemSortBy Type => ItemSortBy.PremiereDate;
 19
 20        /// <summary>
 21        /// Compares the specified x.
 22        /// </summary>
 23        /// <param name="x">The x.</param>
 24        /// <param name="y">The y.</param>
 25        /// <returns>System.Int32.</returns>
 26        public int Compare(BaseItem? x, BaseItem? y)
 27        {
 1428            return GetDate(x).CompareTo(GetDate(y));
 29        }
 30
 31        /// <summary>
 32        /// Gets the date.
 33        /// </summary>
 34        /// <param name="x">The x.</param>
 35        /// <returns>DateTime.</returns>
 36        private static DateTime GetDate(BaseItem? x)
 37        {
 2838            if (x is null)
 39            {
 040                return DateTime.MinValue;
 41            }
 42
 2843            if (x.PremiereDate.HasValue)
 44            {
 1845                return x.PremiereDate.Value;
 46            }
 47
 1048            if (x.ProductionYear.HasValue)
 49            {
 50                try
 51                {
 852                    return new DateTime(x.ProductionYear.Value, 1, 1, 0, 0, 0, DateTimeKind.Utc);
 53                }
 254                catch (ArgumentOutOfRangeException)
 55                {
 56                    // Don't blow up if the item has a bad ProductionYear, just return MinValue
 257                }
 58            }
 59
 460            return DateTime.MinValue;
 661        }
 62    }
 63}