AirTimeComparer.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Entities.TV;
  3. using MediaBrowser.Controller.Sorting;
  4. using MediaBrowser.Model.Querying;
  5. using System;
  6. namespace MediaBrowser.Server.Implementations.Sorting
  7. {
  8. public class AirTimeComparer : 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 DateTime.Compare(GetValue(x), GetValue(y));
  19. }
  20. /// <summary>
  21. /// Gets the value.
  22. /// </summary>
  23. /// <param name="x">The x.</param>
  24. /// <returns>System.String.</returns>
  25. private DateTime GetValue(BaseItem x)
  26. {
  27. var series = (x as Series) ?? x.FindParent<Series>();
  28. DateTime result;
  29. if (series != null && DateTime.TryParse(series.AirTime, out result))
  30. {
  31. return result;
  32. }
  33. return DateTime.MinValue;
  34. }
  35. /// <summary>
  36. /// Gets the name.
  37. /// </summary>
  38. /// <value>The name.</value>
  39. public string Name
  40. {
  41. get { return ItemSortBy.AirTime; }
  42. }
  43. }
  44. }