StartDateComparer.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.LiveTv;
  6. using MediaBrowser.Controller.Sorting;
  7. using MediaBrowser.Model.Querying;
  8. namespace Emby.Server.Implementations.Sorting
  9. {
  10. public class StartDateComparer : IBaseItemComparer
  11. {
  12. /// <summary>
  13. /// Gets the name.
  14. /// </summary>
  15. /// <value>The name.</value>
  16. public string Name => ItemSortBy.StartDate;
  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 GetDate(x).CompareTo(GetDate(y));
  26. }
  27. /// <summary>
  28. /// Gets the date.
  29. /// </summary>
  30. /// <param name="x">The x.</param>
  31. /// <returns>DateTime.</returns>
  32. private static DateTime GetDate(BaseItem x)
  33. {
  34. if (x is LiveTvProgram hasStartDate)
  35. {
  36. return hasStartDate.StartDate;
  37. }
  38. return DateTime.MinValue;
  39. }
  40. }
  41. }