ProductionYearComparer.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 == null)
  29. {
  30. return 0;
  31. }
  32. if (x.ProductionYear.HasValue)
  33. {
  34. return x.ProductionYear.Value;
  35. }
  36. if (x.PremiereDate.HasValue)
  37. {
  38. return x.PremiereDate.Value.Year;
  39. }
  40. return 0;
  41. }
  42. /// <summary>
  43. /// Gets the name.
  44. /// </summary>
  45. /// <value>The name.</value>
  46. public string Name => ItemSortBy.ProductionYear;
  47. }
  48. }