From 90ad72ca30ca7e99e3e84c4cac4e507f91b47a4c Mon Sep 17 00:00:00 2001 From: 01Dri Date: Fri, 23 May 2025 16:33:47 -0300 Subject: [PATCH 1/2] Diff Time in Created At and LastModifiedAt --- .../Views/PreviewPanel.xaml.cs | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs index aaf1efdc1fd..1981a8b0e08 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.Globalization; using System.IO; using System.Runtime.CompilerServices; @@ -65,22 +66,22 @@ public PreviewPanel(Settings settings, string filePath) if (Settings.ShowCreatedDateInPreviewPanel) { - CreatedAt = File - .GetCreationTime(filePath) - .ToString( - $"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}", - CultureInfo.CurrentCulture - ); + DateTime createdDate = File.GetCreationTime(filePath); + string formattedDate = createdDate.ToString( + $"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}", + CultureInfo.CurrentCulture + ); + CreatedAt = $"{GetDiffTimeString(createdDate)} - {formattedDate}"; } if (Settings.ShowModifiedDateInPreviewPanel) { - LastModifiedAt = File - .GetLastWriteTime(filePath) - .ToString( - $"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}", - CultureInfo.CurrentCulture - ); + DateTime lastModifiedDate = File.GetLastWriteTime(filePath); + string formattedDate = lastModifiedDate.ToString( + $"{Settings.PreviewPanelDateFormat} {Settings.PreviewPanelTimeFormat}", + CultureInfo.CurrentCulture + ); + LastModifiedAt = $"{GetDiffTimeString(lastModifiedDate)} - {formattedDate}"; } _ = LoadImageAsync(); @@ -90,7 +91,27 @@ private async Task LoadImageAsync() { PreviewImage = await Main.Context.API.LoadImageAsync(FilePath, true).ConfigureAwait(false); } + + private string GetDiffTimeString(DateTime fileDateTime) + { + DateTime now = DateTime.Now; + TimeSpan difference = now - fileDateTime; + + if (difference.TotalDays < 1) + return "Today"; + if (difference.TotalDays < 30) + return $"{(int)difference.TotalDays} days ago"; + + int monthsDiff = (now.Year - fileDateTime.Year) * 12 + now.Month - fileDateTime.Month; + if (monthsDiff < 12) + return monthsDiff == 1 ? "1 month ago" : $"{monthsDiff} months ago"; + int yearsDiff = now.Year - fileDateTime.Year; + if (now.Month < fileDateTime.Month || (now.Month == fileDateTime.Month && now.Day < fileDateTime.Day)) + yearsDiff--; + + return yearsDiff == 1 ? "1 year ago" : $"{yearsDiff} years ago"; + } public event PropertyChangedEventHandler? PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) From 52355b941fef1bb22505bb48acffc7b1522cfb38 Mon Sep 17 00:00:00 2001 From: 01Dri Date: Fri, 23 May 2025 16:47:07 -0300 Subject: [PATCH 2/2] Future case --- .../Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs index 1981a8b0e08..fa28ea915c8 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs @@ -96,6 +96,9 @@ private string GetDiffTimeString(DateTime fileDateTime) { DateTime now = DateTime.Now; TimeSpan difference = now - fileDateTime; + + if (fileDateTime > now) + return "In the future"; if (difference.TotalDays < 1) return "Today";