| | 1 | | using Jellyfin.Data.Enums; |
| | 2 | | using MediaBrowser.Controller.Entities; |
| | 3 | | using MediaBrowser.Controller.Sorting; |
| | 4 | | using MediaBrowser.Model.Querying; |
| | 5 | |
|
| | 6 | | namespace Emby.Server.Implementations.Sorting |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Class ProductionYearComparer. |
| | 10 | | /// </summary> |
| | 11 | | public class ProductionYearComparer : IBaseItemComparer |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Gets the name. |
| | 15 | | /// </summary> |
| | 16 | | /// <value>The name.</value> |
| 1 | 17 | | public ItemSortBy Type => ItemSortBy.ProductionYear; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Compares the specified x. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="x">The x.</param> |
| | 23 | | /// <param name="y">The y.</param> |
| | 24 | | /// <returns>System.Int32.</returns> |
| | 25 | | public int Compare(BaseItem? x, BaseItem? y) |
| | 26 | | { |
| 0 | 27 | | return GetValue(x).CompareTo(GetValue(y)); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets the date. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name="x">The x.</param> |
| | 34 | | /// <returns>DateTime.</returns> |
| | 35 | | private static int GetValue(BaseItem? x) |
| | 36 | | { |
| 0 | 37 | | if (x is null) |
| | 38 | | { |
| 0 | 39 | | return 0; |
| | 40 | | } |
| | 41 | |
|
| 0 | 42 | | if (x.ProductionYear.HasValue) |
| | 43 | | { |
| 0 | 44 | | return x.ProductionYear.Value; |
| | 45 | | } |
| | 46 | |
|
| 0 | 47 | | if (x.PremiereDate.HasValue) |
| | 48 | | { |
| 0 | 49 | | return x.PremiereDate.Value.Year; |
| | 50 | | } |
| | 51 | |
|
| 0 | 52 | | return 0; |
| | 53 | | } |
| | 54 | | } |
| | 55 | | } |