aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs
blob: 8a434655636c37dd77c187dfe7b057168007417c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Ryujinx.Ui.App.Common;
using System;
using System.Collections.Generic;

namespace Ryujinx.Ava.UI.Models.Generic
{
    internal class LastPlayedSortComparer : IComparer<ApplicationData>
    {
        public LastPlayedSortComparer() { }
        public LastPlayedSortComparer(bool isAscending) { IsAscending = isAscending; }

        public bool IsAscending { get; }

        public int Compare(ApplicationData x, ApplicationData y)
        {
            var aValue = x.LastPlayed;
            var bValue = y.LastPlayed;

            if (!aValue.HasValue)
            {
                aValue = DateTime.UnixEpoch;
            }

            if (!bValue.HasValue)
            {
                bValue = DateTime.UnixEpoch;
            }

            return (IsAscending ? 1 : -1) * DateTime.Compare(bValue.Value, aValue.Value);
        }
    }
}