Skip to content

Commit 7157cee

Browse files
authored
Fix: Fixed issue where app would show a negative elapsed time in case of a future timestamp (#11125)
1 parent e5d2bb2 commit 7157cee

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/Files.App/ServicesImplementation/DateTimeFormatter/ApplicationDateTimeFormatter.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public override string ToShortLabel(DateTimeOffset offset)
2525
{ TotalHours: >= 1 } => string.Format("HourAgo".GetLocalizedResource(), elapsed.Hours),
2626
{ TotalMinutes: >= 2 } => string.Format("MinutesAgo".GetLocalizedResource(), elapsed.Minutes),
2727
{ TotalMinutes: >= 1 } => string.Format("MinuteAgo".GetLocalizedResource(), elapsed.Minutes),
28-
_ => string.Format("SecondsAgo".GetLocalizedResource(), elapsed.Seconds),
28+
{ TotalSeconds: >= 2 } => string.Format("SecondsAgo".GetLocalizedResource(), elapsed.Seconds),
29+
{ TotalSeconds: >= 1 } => "OneSecondAgo".GetLocalizedResource(),
30+
{ TotalSeconds: >= 0 } => "Now".GetLocalizedResource(),
31+
_ => ToString(offset, "D"),
2932
};
3033
}
3134

@@ -38,7 +41,7 @@ public override string ToLongLabel(DateTimeOffset offset)
3841
return " ";
3942
}
4043
var localTime = offset.ToLocalTime();
41-
if (elapsed.TotalDays < 7)
44+
if (elapsed.TotalDays < 7 && elapsed.TotalSeconds >= 0)
4245
{
4346
return $"{localTime:D} {localTime:t} ({ToShortLabel(offset)})";
4447
}

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,12 @@
495495
<data name="SecondsAgo" xml:space="preserve">
496496
<value>{0} seconds ago</value>
497497
</data>
498+
<data name="OneSecondAgo" xml:space="preserve">
499+
<value>1 second ago</value>
500+
</data>
501+
<data name="Now" xml:space="preserve">
502+
<value>Now</value>
503+
</data>
498504
<data name="SettingsOnStartupOpenASpecificPagePath.PlaceholderText" xml:space="preserve">
499505
<value>New Tab</value>
500506
</data>
@@ -2886,4 +2892,4 @@
28862892
<data name="BundlesBeingRemovedTitle" xml:space="preserve">
28872893
<value>Bundles will be retiring in a future update 📎</value>
28882894
</data>
2889-
</root>
2895+
</root>

src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public PreferencesViewModel()
128128

129129
private void AddDateTimeOptions()
130130
{
131-
DateTimeOffset sampleDate1 = DateTime.Now;
131+
DateTimeOffset sampleDate1 = DateTime.Now.AddSeconds(-5);
132132
DateTimeOffset sampleDate2 = new DateTime(sampleDate1.Year - 5, 12, 31, 14, 30, 0);
133133
var styles = new DateTimeFormats[] { DateTimeFormats.Application, DateTimeFormats.System, DateTimeFormats.Universal };
134134
DateFormats = styles.Select(style => new DateTimeFormatItem(style, sampleDate1, sampleDate2)).ToList();

0 commit comments

Comments
 (0)