From f13ca0d3b570d01af2fb6626574fbf6460cd9347 Mon Sep 17 00:00:00 2001 From: amnesiaof Date: Sun, 11 Oct 2026 10:56:34 +0300 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFTruncate=20the=20date=20properties=20t?= =?UTF-8?q?o=20the=20day=20so=20the=20columns=20sort=20as=20they=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Date and Install Date columns format with Language.Date_Format, which is {0:d}, and grouping already used InstallDate?.Date, but both properties kept the full timestamp that DEVPKEY_DriverPackage_DriverDate and _ImportDate report. ObjectListView sorts the raw value, so two entries sharing a day never compared equal and Shift-clicking a second column did nothing for them. Closes #460 --- Rapr/Utils/DriverStoreEntry.cs | 18 ++++++++- RaprTests/DriverStoreEntryTests.cs | 62 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 RaprTests/DriverStoreEntryTests.cs diff --git a/Rapr/Utils/DriverStoreEntry.cs b/Rapr/Utils/DriverStoreEntry.cs index 5b43258..91f80d2 100644 --- a/Rapr/Utils/DriverStoreEntry.cs +++ b/Rapr/Utils/DriverStoreEntry.cs @@ -39,10 +39,18 @@ public class DriverStoreEntry /// public Guid DriverExtensionId { get; set; } + // The date columns format with {0:d} and ObjectListView sorts the raw value, so a time part + // makes the sort disagree with the text on screen and starves the secondary sort column. + private DateTime driverDate; + /// /// Sys file date /// - public DateTime DriverDate { get; set; } + public DateTime DriverDate + { + get => this.driverDate; + set => this.driverDate = value.Date; + } /// /// Sys file version @@ -174,10 +182,16 @@ private static string SanitizeFolderName(string name, int maxLength) /// public bool? DevicePresent { get; set; } + private DateTime? installDate; + /// /// Driver install date - when the driver package was imported/added to the driver store /// - public DateTime? InstallDate { get; set; } + public DateTime? InstallDate + { + get => this.installDate; + set => this.installDate = value?.Date; + } /// /// List of driver files (sys, DLLs) in the driver package diff --git a/RaprTests/DriverStoreEntryTests.cs b/RaprTests/DriverStoreEntryTests.cs new file mode 100644 index 0000000..8586a48 --- /dev/null +++ b/RaprTests/DriverStoreEntryTests.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using Rapr.Utils; + +namespace Rapr.Tests +{ + [TestClass] + public class DriverStoreEntryTests + { + [TestMethod] + public void InstallDateIsTruncatedToTheDayItDisplays() + { + var morning = new DriverStoreEntry { DriverInfName = "morning", InstallDate = new DateTime(2026, 10, 6, 8, 15, 1) }; + var evening = new DriverStoreEntry { DriverInfName = "evening", InstallDate = new DateTime(2026, 10, 6, 23, 45, 59) }; + var nextDay = new DriverStoreEntry { DriverInfName = "nextDay", InstallDate = new DateTime(2026, 10, 7, 0, 0, 0) }; + + Assert.AreEqual(new DateTime(2026, 10, 6), morning.InstallDate); + Assert.AreEqual(new DateTime(2026, 10, 6), evening.InstallDate); + Assert.AreEqual(new DateTime(2026, 10, 7), nextDay.InstallDate); + + // ObjectListView falls through to the secondary column only when this compare returns + // 0, and OrderBy keeps ties in input order, so "evening" staying ahead of "morning" + // is the order a reader now gets instead of the raw 23:45 sorting after 08:15. + CollectionAssert.AreEqual( + new[] { "evening", "morning", "nextDay" }, + new List { evening, nextDay, morning } + .OrderBy(e => e.InstallDate) + .Select(e => e.DriverInfName) + .ToArray()); + } + + [TestMethod] + public void InstallDateKeepsNull() + { + var entry = new DriverStoreEntry { InstallDate = null }; + Assert.IsNull(entry.InstallDate); + + entry.InstallDate = new DateTime(2026, 10, 6, 8, 15, 1); + Assert.AreEqual(new DateTime(2026, 10, 6), entry.InstallDate); + + entry.InstallDate = null; + Assert.IsNull(entry.InstallDate); + } + + [TestMethod] + public void DriverDateIsTruncatedToTheDayItDisplays() + { + var entry = new DriverStoreEntry { DriverDate = new DateTime(2026, 10, 6, 23, 45, 59) }; + Assert.AreEqual(new DateTime(2026, 10, 6), entry.DriverDate); + + entry.DriverDate = default(DateTime); + Assert.AreEqual(default(DateTime), entry.DriverDate); + + entry.SetDriverDateAndVersion("2026-10-06 31.0.15.3623"); + Assert.AreEqual(new DateTime(2026, 10, 6), entry.DriverDate); + } + } +}