ProductionYearComparer.cs 1.4 KB

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