1
- using System . ComponentModel ;
1
+ using System ;
2
+ using System . ComponentModel ;
2
3
using System . Globalization ;
3
4
using System . IO ;
4
5
using System . Runtime . CompilerServices ;
@@ -65,22 +66,22 @@ public PreviewPanel(Settings settings, string filePath)
65
66
66
67
if ( Settings . ShowCreatedDateInPreviewPanel )
67
68
{
68
- CreatedAt = File
69
- . GetCreationTime ( filePath )
70
- . ToString (
71
- $ " { Settings . PreviewPanelDateFormat } { Settings . PreviewPanelTimeFormat } " ,
72
- CultureInfo . CurrentCulture
73
- ) ;
69
+ DateTime createdDate = File . GetCreationTime ( filePath ) ;
70
+ string formattedDate = createdDate . ToString (
71
+ $ " { Settings . PreviewPanelDateFormat } { Settings . PreviewPanelTimeFormat } " ,
72
+ CultureInfo . CurrentCulture
73
+ ) ;
74
+ CreatedAt = $ " { GetDiffTimeString ( createdDate ) } - { formattedDate } " ;
74
75
}
75
76
76
77
if ( Settings . ShowModifiedDateInPreviewPanel )
77
78
{
78
- LastModifiedAt = File
79
- . GetLastWriteTime ( filePath )
80
- . ToString (
81
- $ " { Settings . PreviewPanelDateFormat } { Settings . PreviewPanelTimeFormat } " ,
82
- CultureInfo . CurrentCulture
83
- ) ;
79
+ DateTime lastModifiedDate = File . GetLastWriteTime ( filePath ) ;
80
+ string formattedDate = lastModifiedDate . ToString (
81
+ $ " { Settings . PreviewPanelDateFormat } { Settings . PreviewPanelTimeFormat } " ,
82
+ CultureInfo . CurrentCulture
83
+ ) ;
84
+ LastModifiedAt = $ " { GetDiffTimeString ( lastModifiedDate ) } - { formattedDate } " ;
84
85
}
85
86
86
87
_ = LoadImageAsync ( ) ;
@@ -90,7 +91,27 @@ private async Task LoadImageAsync()
90
91
{
91
92
PreviewImage = await Main . Context . API . LoadImageAsync ( FilePath , true ) . ConfigureAwait ( false ) ;
92
93
}
94
+
95
+ private string GetDiffTimeString ( DateTime fileDateTime )
96
+ {
97
+ DateTime now = DateTime . Now ;
98
+ TimeSpan difference = now - fileDateTime ;
99
+
100
+ if ( difference . TotalDays < 1 )
101
+ return "Today" ;
102
+ if ( difference . TotalDays < 30 )
103
+ return $ "{ ( int ) difference . TotalDays } days ago";
104
+
105
+ int monthsDiff = ( now . Year - fileDateTime . Year ) * 12 + now . Month - fileDateTime . Month ;
106
+ if ( monthsDiff < 12 )
107
+ return monthsDiff == 1 ? "1 month ago" : $ "{ monthsDiff } months ago";
93
108
109
+ int yearsDiff = now . Year - fileDateTime . Year ;
110
+ if ( now . Month < fileDateTime . Month || ( now . Month == fileDateTime . Month && now . Day < fileDateTime . Day ) )
111
+ yearsDiff -- ;
112
+
113
+ return yearsDiff == 1 ? "1 year ago" : $ "{ yearsDiff } years ago";
114
+ }
94
115
public event PropertyChangedEventHandler ? PropertyChanged ;
95
116
96
117
protected virtual void OnPropertyChanged ( [ CallerMemberName ] string ? propertyName = null )
0 commit comments