From d75ce52bd464d14f32ea87d16317756823d3d6cb Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Fri, 10 Jan 2025 20:23:47 -0600 Subject: [PATCH] UI: Show play time in one time unit, maxing out at hours. --- .../UI/Controls/ApplicationListView.axaml | 5 +-- .../UI/Windows/SettingsWindow.axaml.cs | 7 ++++ .../Utilities/AppLibrary/ApplicationData.cs | 2 ++ src/Ryujinx/Utilities/ValueFormatUtils.cs | 36 ++++++++++--------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/Ryujinx/UI/Controls/ApplicationListView.axaml b/src/Ryujinx/UI/Controls/ApplicationListView.axaml index 41a8af0e0..764a33cc0 100644 --- a/src/Ryujinx/UI/Controls/ApplicationListView.axaml +++ b/src/Ryujinx/UI/Controls/ApplicationListView.axaml @@ -133,12 +133,13 @@ Spacing="5"> ValueFormatUtils.FormatTimeSpan(TimePlayed); + public bool HasPlayedPreviously => TimePlayedString != string.Empty; + public string LastPlayedString => ValueFormatUtils.FormatDateTime(LastPlayed)?.Replace(" ", "\n"); public string FileSizeString => ValueFormatUtils.FormatFileSize(FileSize); diff --git a/src/Ryujinx/Utilities/ValueFormatUtils.cs b/src/Ryujinx/Utilities/ValueFormatUtils.cs index 944cfbf8a..f5cdb4125 100644 --- a/src/Ryujinx/Utilities/ValueFormatUtils.cs +++ b/src/Ryujinx/Utilities/ValueFormatUtils.cs @@ -1,3 +1,5 @@ +using Humanizer; +using Humanizer.Localisation; using Ryujinx.Ava.Common.Locale; using System; using System.Globalization; @@ -31,7 +33,7 @@ namespace Ryujinx.Ava.Utilities Gigabytes = 9, Terabytes = 10, Petabytes = 11, - Exabytes = 12, + Exabytes = 12 } private const double SizeBase10 = 1000; @@ -48,22 +50,24 @@ namespace Ryujinx.Ava.Utilities public static string FormatTimeSpan(TimeSpan? timeSpan) { if (!timeSpan.HasValue || timeSpan.Value.TotalSeconds < 1) - { - // Game was never played - return TimeSpan.Zero.ToString("c", CultureInfo.InvariantCulture); - } + return string.Empty; + + if (timeSpan.Value.TotalSeconds < 60) + return timeSpan.Value.Humanize(1, + countEmptyUnits: false, + maxUnit: TimeUnit.Second, + minUnit: TimeUnit.Second); - if (timeSpan.Value.TotalDays < 1) - { - // Game was played for less than a day - return timeSpan.Value.ToString("c", CultureInfo.InvariantCulture); - } - - // Game was played for more than a day - TimeSpan onlyTime = timeSpan.Value.Subtract(TimeSpan.FromDays(timeSpan.Value.Days)); - string onlyTimeString = onlyTime.ToString("c", CultureInfo.InvariantCulture); - - return $"{timeSpan.Value.Days}d, {onlyTimeString}"; + if (timeSpan.Value.TotalMinutes < 60) + return timeSpan.Value.Humanize(1, + countEmptyUnits: false, + maxUnit: TimeUnit.Minute, + minUnit: TimeUnit.Minute); + + return timeSpan.Value.Humanize(1, + countEmptyUnits: false, + maxUnit: TimeUnit.Hour, + minUnit: TimeUnit.Hour); } ///