using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Querying; namespace Emby.Server.Implementations.Sorting { /// /// Class ProductionYearComparer. /// public class ProductionYearComparer : IBaseItemComparer { /// /// Gets the name. /// /// The name. public string Name => ItemSortBy.ProductionYear; /// /// Compares the specified x. /// /// The x. /// The y. /// System.Int32. public int Compare(BaseItem? x, BaseItem? y) { return GetValue(x).CompareTo(GetValue(y)); } /// /// Gets the date. /// /// The x. /// DateTime. private static int GetValue(BaseItem? x) { if (x is null) { return 0; } if (x.ProductionYear.HasValue) { return x.ProductionYear.Value; } if (x.PremiereDate.HasValue) { return x.PremiereDate.Value.Year; } return 0; } } }