ProductionYearComparer.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Sorting;
  3. using MediaBrowser.Model.Querying;
  4. namespace Emby.Server.Implementations.Sorting
  5. {
  6. /// <summary>
  7. /// Class ProductionYearComparer
  8. /// </summary>
  9. public class ProductionYearComparer : IBaseItemComparer
  10. {
  11. /// <summary>
  12. /// Compares the specified x.
  13. /// </summary>
  14. /// <param name="x">The x.</param>
  15. /// <param name="y">The y.</param>
  16. /// <returns>System.Int32.</returns>
  17. public int Compare(BaseItem x, BaseItem y)
  18. {
  19. return GetValue(x).CompareTo(GetValue(y));
  20. }
  21. /// <summary>
  22. /// Gets the date.
  23. /// </summary>
  24. /// <param name="x">The x.</param>
  25. /// <returns>DateTime.</returns>
  26. private static int GetValue(BaseItem x)
  27. {
  28. if (x.ProductionYear.HasValue)
  29. {
  30. return x.ProductionYear.Value;
  31. }
  32. if (x.PremiereDate.HasValue)
  33. {
  34. return x.PremiereDate.Value.Year;
  35. }
  36. return 0;
  37. }
  38. /// <summary>
  39. /// Gets the name.
  40. /// </summary>
  41. /// <value>The name.</value>
  42. public string Name => ItemSortBy.ProductionYear;
  43. }
  44. }