Skip to content

Fix: Fixed showing a negative elapsed time in case of a future timestamp #11125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public override string ToShortLabel(DateTimeOffset offset)
{ TotalHours: >= 1 } => string.Format("HourAgo".GetLocalizedResource(), elapsed.Hours),
{ TotalMinutes: >= 2 } => string.Format("MinutesAgo".GetLocalizedResource(), elapsed.Minutes),
{ TotalMinutes: >= 1 } => string.Format("MinuteAgo".GetLocalizedResource(), elapsed.Minutes),
_ => string.Format("SecondsAgo".GetLocalizedResource(), elapsed.Seconds),
{ TotalSeconds: >= 2 } => string.Format("SecondsAgo".GetLocalizedResource(), elapsed.Seconds),
{ TotalSeconds: >= 1 } => "OneSecondAgo".GetLocalizedResource(),
{ TotalSeconds: >= 0 } => "Now".GetLocalizedResource(),
_ => ToString(offset, "D"),
};
}

Expand All @@ -38,7 +41,7 @@ public override string ToLongLabel(DateTimeOffset offset)
return " ";
}
var localTime = offset.ToLocalTime();
if (elapsed.TotalDays < 7)
if (elapsed.TotalDays < 7 && elapsed.TotalSeconds >= 0)
{
return $"{localTime:D} {localTime:t} ({ToShortLabel(offset)})";
}
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@
<data name="SecondsAgo" xml:space="preserve">
<value>{0} seconds ago</value>
</data>
<data name="OneSecondAgo" xml:space="preserve">
<value>1 second ago</value>
</data>
<data name="Now" xml:space="preserve">
<value>Now</value>
</data>
<data name="SettingsOnStartupOpenASpecificPagePath.PlaceholderText" xml:space="preserve">
<value>New Tab</value>
</data>
Expand Down Expand Up @@ -2886,4 +2892,4 @@
<data name="BundlesBeingRemovedTitle" xml:space="preserve">
<value>Bundles will be retiring in a future update 📎</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public PreferencesViewModel()

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