ProductionYearComparer.cs 1.3 KB

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