@@ -160,21 +160,73 @@ public bool IsImage()
160
160
return false ;
161
161
}
162
162
163
- public ListedItem ( string folderRelativeId )
163
+ /// <summary>
164
+ /// Create an item object, optionally with an explicitly-specified dateReturnFormat.
165
+ /// </summary>
166
+ /// <param name="folderRelativeId"></param>
167
+ /// <param name="dateReturnFormat">Specify a date return format to reduce redundant checks of this setting.</param>
168
+ public ListedItem ( string folderRelativeId , string dateReturnFormat = null )
164
169
{
165
170
FolderRelativeId = folderRelativeId ;
171
+ if ( dateReturnFormat != null )
172
+ {
173
+ DateReturnFormat = dateReturnFormat ;
174
+ }
175
+ else
176
+ {
177
+ ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
178
+ string returnformat = Enum . Parse < TimeStyle > ( localSettings . Values [ LocalSettings . DateTimeFormat ] . ToString ( ) ) == TimeStyle . Application ? "D" : "g" ;
179
+ DateReturnFormat = returnformat ;
180
+ }
166
181
}
167
182
168
- public static string GetFriendlyDate ( DateTimeOffset d )
183
+ private string DateReturnFormat { get ; }
184
+
185
+ private string GetFriendlyDate ( DateTimeOffset d )
169
186
{
170
- ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
171
187
var elapsed = DateTimeOffset . Now - d ;
172
188
173
- string returnformat = Enum . Parse < TimeStyle > ( localSettings . Values [ LocalSettings . DateTimeFormat ] . ToString ( ) ) == TimeStyle . Application ? "D" : "g" ;
189
+ if ( elapsed . TotalDays > 7 )
190
+ {
191
+ return d . ToString ( DateReturnFormat ) ;
192
+ }
193
+ else if ( elapsed . TotalDays > 2 )
194
+ {
195
+ return string . Format ( ResourceController . GetTranslation ( "DaysAgo" ) , elapsed . Days ) ;
196
+ }
197
+ else if ( elapsed . TotalDays > 1 )
198
+ {
199
+ return string . Format ( ResourceController . GetTranslation ( "DayAgo" ) , elapsed . Days ) ;
200
+ }
201
+ else if ( elapsed . TotalHours > 2 )
202
+ {
203
+ return string . Format ( ResourceController . GetTranslation ( "HoursAgo" ) , elapsed . Hours ) ;
204
+ }
205
+ else if ( elapsed . TotalHours > 1 )
206
+ {
207
+ return string . Format ( ResourceController . GetTranslation ( "HourAgo" ) , elapsed . Hours ) ;
208
+ }
209
+ else if ( elapsed . TotalMinutes > 2 )
210
+ {
211
+ return string . Format ( ResourceController . GetTranslation ( "MinutesAgo" ) , elapsed . Minutes ) ;
212
+ }
213
+ else if ( elapsed . TotalMinutes > 1 )
214
+ {
215
+ return string . Format ( ResourceController . GetTranslation ( "MinuteAgo" ) , elapsed . Minutes ) ;
216
+ }
217
+ else
218
+ {
219
+ return string . Format ( ResourceController . GetTranslation ( "SecondsAgo" ) , elapsed . Seconds ) ;
220
+ }
221
+ }
222
+
223
+ public static string GetFriendlyDateFromFormat ( DateTimeOffset d , string returnFormat )
224
+ {
225
+ var elapsed = DateTimeOffset . Now - d ;
174
226
175
227
if ( elapsed . TotalDays > 7 )
176
228
{
177
- return d . ToString ( returnformat ) ;
229
+ return d . ToString ( returnFormat ) ;
178
230
}
179
231
else if ( elapsed . TotalDays > 2 )
180
232
{
@@ -213,7 +265,7 @@ public static string GetFriendlyDate(DateTimeOffset d)
213
265
214
266
public class RecycleBinItem : ListedItem
215
267
{
216
- public RecycleBinItem ( string folderRelativeId ) : base ( folderRelativeId )
268
+ public RecycleBinItem ( string folderRelativeId , string returnFormat ) : base ( folderRelativeId , returnFormat )
217
269
{
218
270
}
219
271
@@ -223,7 +275,7 @@ public RecycleBinItem(string folderRelativeId) : base(folderRelativeId)
223
275
224
276
public class ShortcutItem : ListedItem
225
277
{
226
- public ShortcutItem ( string folderRelativeId ) : base ( folderRelativeId )
278
+ public ShortcutItem ( string folderRelativeId , string returnFormat ) : base ( folderRelativeId , returnFormat )
227
279
{
228
280
}
229
281
0 commit comments