Skip to content

Commit 578554d

Browse files
niels9001Copilot
andauthored
[Settings] Format last update check date with friendly relative dates (#46923)
## Summary Formats the Last checked date on the General and Dashboard pages with friendly relative strings instead of raw date/time output. **Before:** Last checked: 4/12/2026 1:22:00 PM **After:** Last checked: Today at 1:22 PM / Yesterday at 3:45 PM ### Changes - Add LastCheckedDateTime property to UpdatingSettings exposing the parsed DateTime - Create FriendlyDateHelper in Settings.UI that formats Today/Yesterday with localized resource strings, falling back to the full culture-specific format for older dates - Update GeneralViewModel and CheckUpdateControl to use the friendly format - Add localized resource strings General_LastCheckedDate_TodayAt and General_LastCheckedDate_YesterdayAt Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e4f9889 commit 578554d

File tree

6 files changed

+77
-7
lines changed

6 files changed

+77
-7
lines changed

src/settings-ui/Settings.UI.Library/UpdatingSettings.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,35 @@ public string NewVersion
6565
}
6666

6767
public string LastCheckedDateLocalized
68+
{
69+
get
70+
{
71+
var dt = LastCheckedDateTime;
72+
return dt?.ToString(CultureInfo.CurrentCulture) ?? string.Empty;
73+
}
74+
}
75+
76+
[JsonIgnore]
77+
public DateTime? LastCheckedDateTime
6878
{
6979
get
7080
{
7181
try
7282
{
7383
if (LastCheckedDate == null)
7484
{
75-
return string.Empty;
85+
return null;
7686
}
7787

7888
long seconds = long.Parse(LastCheckedDate, CultureInfo.CurrentCulture);
7989
var date = DateTimeOffset.FromUnixTimeSeconds(seconds).UtcDateTime;
80-
return date.ToLocalTime().ToString(CultureInfo.CurrentCulture);
90+
return date.ToLocalTime();
8191
}
8292
catch (Exception)
8393
{
8494
}
8595

86-
return string.Empty;
96+
return null;
8797
}
8898
}
8999

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft Corporation
2+
// The Microsoft Corporation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Globalization;
7+
8+
namespace Microsoft.PowerToys.Settings.UI.Helpers;
9+
10+
public static class FriendlyDateHelper
11+
{
12+
/// <summary>
13+
/// Formats a <see cref="DateTime"/> as a friendly relative string.
14+
/// Today → "Today at 1:22 PM", Yesterday → "Yesterday at 3:45 PM",
15+
/// older dates fall back to the full culture-specific date/time format.
16+
/// </summary>
17+
public static string Format(DateTime? dateTime)
18+
{
19+
if (dateTime is not DateTime dt)
20+
{
21+
return string.Empty;
22+
}
23+
24+
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
25+
var today = DateTime.Now.Date;
26+
var time = dt.ToString("t", CultureInfo.CurrentCulture);
27+
28+
if (dt.Date == today)
29+
{
30+
var fmt = resourceLoader.GetString("General_LastCheckedDate_TodayAt");
31+
if (!string.IsNullOrEmpty(fmt))
32+
{
33+
return string.Format(CultureInfo.CurrentCulture, fmt, time);
34+
}
35+
}
36+
37+
if (dt.Date == today.AddDays(-1))
38+
{
39+
var fmt = resourceLoader.GetString("General_LastCheckedDate_YesterdayAt");
40+
if (!string.IsNullOrEmpty(fmt))
41+
{
42+
return string.Format(CultureInfo.CurrentCulture, fmt, time);
43+
}
44+
}
45+
46+
return dt.ToString(CultureInfo.CurrentCulture);
47+
}
48+
}

src/settings-ui/Settings.UI/SettingsXAML/Controls/Dashboard/CheckUpdateControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<TextBlock x:Uid="YoureUpToDate" FontWeight="SemiBold" />
7373
<TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}" Style="{StaticResource CaptionTextBlockStyle}">
7474
<Run x:Uid="General_VersionLastChecked" />
75-
<Run Text="{x:Bind UpdateSettingsConfig.LastCheckedDateLocalized, Mode=OneTime}" />
75+
<Run Text="{x:Bind LastCheckedDateFriendly, Mode=OneTime}" />
7676
</TextBlock>
7777
</StackPanel>
7878
</Grid>

src/settings-ui/Settings.UI/SettingsXAML/Controls/Dashboard/CheckUpdateControl.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The Microsoft Corporation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Microsoft.PowerToys.Settings.UI.Helpers;
56
using Microsoft.PowerToys.Settings.UI.Library;
67
using Microsoft.PowerToys.Settings.UI.Services;
78
using Microsoft.PowerToys.Settings.UI.Views;
@@ -15,11 +16,14 @@ public sealed partial class CheckUpdateControl : UserControl
1516

1617
public UpdatingSettings UpdateSettingsConfig { get; set; }
1718

19+
public string LastCheckedDateFriendly { get; set; }
20+
1821
public CheckUpdateControl()
1922
{
2023
InitializeComponent();
2124
UpdateSettingsConfig = UpdatingSettings.LoadSettings();
2225
UpdateAvailable = UpdateSettingsConfig != null && (UpdateSettingsConfig.State == UpdatingSettings.UpdatingState.ReadyToInstall || UpdateSettingsConfig.State == UpdatingSettings.UpdatingState.ReadyToDownload);
26+
LastCheckedDateFriendly = FriendlyDateHelper.Format(UpdateSettingsConfig?.LastCheckedDateTime);
2327
}
2428

2529
private void SWVersionButtonClicked(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)

src/settings-ui/Settings.UI/Strings/en-us/Resources.resw

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,14 @@ opera.exe</value>
13771377
<data name="General_VersionLastChecked.Text" xml:space="preserve">
13781378
<value>Last checked: </value>
13791379
</data>
1380+
<data name="General_LastCheckedDate_TodayAt" xml:space="preserve">
1381+
<value>Today at {0}</value>
1382+
<comment>Friendly date format when the last update check was today. {0} is the localized short time, e.g. "Today at 1:22 PM".</comment>
1383+
</data>
1384+
<data name="General_LastCheckedDate_YesterdayAt" xml:space="preserve">
1385+
<value>Yesterday at {0}</value>
1386+
<comment>Friendly date format when the last update check was yesterday. {0} is the localized short time, e.g. "Yesterday at 3:45 PM".</comment>
1387+
</data>
13801388
<data name="General_SettingsBackupInfo_DateHeader.Text" xml:space="preserve">
13811389
<value>Created at:</value>
13821390
</data>

src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public GeneralViewModel(ISettingsRepository<GeneralSettings> settingsRepository,
188188
_updatingState = UpdatingSettingsConfig.State;
189189
_newAvailableVersion = UpdatingSettingsConfig.NewVersion;
190190
_newAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
191-
_updateCheckedDate = UpdatingSettingsConfig.LastCheckedDateLocalized;
191+
_updateCheckedDate = FriendlyDateHelper.Format(UpdatingSettingsConfig.LastCheckedDateTime);
192192

193193
_newUpdatesToastIsGpoDisabled = GPOWrapper.GetDisableNewUpdateToastValue() == GpoRuleConfigured.Enabled;
194194
_autoDownloadUpdatesIsGpoDisabled = GPOWrapper.GetDisableAutomaticUpdateDownloadValue() == GpoRuleConfigured.Enabled;
@@ -1383,15 +1383,15 @@ public void RefreshUpdatingState()
13831383
}
13841384
else
13851385
{
1386-
bool dateChanged = UpdateCheckedDate == UpdatingSettingsConfig.LastCheckedDateLocalized;
1386+
bool dateChanged = UpdateCheckedDate == FriendlyDateHelper.Format(UpdatingSettingsConfig.LastCheckedDateTime);
13871387
bool fileDownloaded = string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
13881388
IsNewVersionDownloading = !(dateChanged || fileDownloaded);
13891389
}
13901390

13911391
PowerToysUpdatingState = UpdatingSettingsConfig.State;
13921392
PowerToysNewAvailableVersion = UpdatingSettingsConfig.NewVersion;
13931393
PowerToysNewAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
1394-
UpdateCheckedDate = UpdatingSettingsConfig.LastCheckedDateLocalized;
1394+
UpdateCheckedDate = FriendlyDateHelper.Format(UpdatingSettingsConfig.LastCheckedDateTime);
13951395

13961396
_isNoNetwork = PowerToysUpdatingState == UpdatingSettings.UpdatingState.NetworkError;
13971397
NotifyPropertyChanged(nameof(IsNoNetwork));

0 commit comments

Comments
 (0)