StartDateComparer.cs 1.2 KB

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