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. /// Gets the name.
  13. /// </summary>
  14. /// <value>The name.</value>
  15. public string Name => ItemSortBy.ProductionYear;
  16. /// <summary>
  17. /// Compares the specified x.
  18. /// </summary>
  19. /// <param name="x">The x.</param>
  20. /// <param name="y">The y.</param>
  21. /// <returns>System.Int32.</returns>
  22. public int Compare(BaseItem? x, BaseItem? y)
  23. {
  24. return GetValue(x).CompareTo(GetValue(y));
  25. }
  26. /// <summary>
  27. /// Gets the date.
  28. /// </summary>
  29. /// <param name="x">The x.</param>
  30. /// <returns>DateTime.</returns>
  31. private static int GetValue(BaseItem? x)
  32. {
  33. if (x == null)
  34. {
  35. return 0;
  36. }
  37. if (x.ProductionYear.HasValue)
  38. {
  39. return x.ProductionYear.Value;
  40. }
  41. if (x.PremiereDate.HasValue)
  42. {
  43. return x.PremiereDate.Value.Year;
  44. }
  45. return 0;
  46. }
  47. }
  48. }