StartDateComparer.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.LiveTv;
  4. using MediaBrowser.Controller.Sorting;
  5. using MediaBrowser.Model.Querying;
  6. namespace Emby.Server.Implementations.Sorting
  7. {
  8. public class StartDateComparer : IBaseItemComparer
  9. {
  10. /// <summary>
  11. /// Compares the specified x.
  12. /// </summary>
  13. /// <param name="x">The x.</param>
  14. /// <param name="y">The y.</param>
  15. /// <returns>System.Int32.</returns>
  16. public int Compare(BaseItem x, BaseItem y)
  17. {
  18. return GetDate(x).CompareTo(GetDate(y));
  19. }
  20. /// <summary>
  21. /// Gets the date.
  22. /// </summary>
  23. /// <param name="x">The x.</param>
  24. /// <returns>DateTime.</returns>
  25. private static DateTime GetDate(BaseItem x)
  26. {
  27. var hasStartDate = x as LiveTvProgram;
  28. if (hasStartDate != null)
  29. {
  30. return hasStartDate.StartDate;
  31. }
  32. return DateTime.MinValue;
  33. }
  34. /// <summary>
  35. /// Gets the name.
  36. /// </summary>
  37. /// <value>The name.</value>
  38. public string Name => ItemSortBy.StartDate;
  39. }
  40. }