using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying;
namespace MediaBrowser.Server.Implementations.Sorting
{
///
/// Class ProductionYearComparer
///
public class ProductionYearComparer : IBaseItemComparer
{
///
/// Compares the specified x.
///
/// The x.
/// The y.
/// System.Int32.
public int Compare(BaseItem x, BaseItem y)
{
return GetValue(x).CompareTo(GetValue(y));
}
///
/// Gets the date.
///
/// The x.
/// DateTime.
private int GetValue(BaseItem x)
{
if (x.ProductionYear.HasValue)
{
return x.ProductionYear.Value;
}
if (x.PremiereDate.HasValue)
{
return x.PremiereDate.Value.Year;
}
return 0;
}
///
/// Gets the name.
///
/// The name.
public string Name
{
get { return ItemSortBy.ProductionYear; }
}
}
}