Skip to content

[PT Run][Time and Date] Add friendly date/time result (#16809)#46803

Open
RealPratham21 wants to merge 1 commit intomicrosoft:mainfrom
RealPratham21:feature/friendly-date-time
Open

[PT Run][Time and Date] Add friendly date/time result (#16809)#46803
RealPratham21 wants to merge 1 commit intomicrosoft:mainfrom
RealPratham21:feature/friendly-date-time

Conversation

@RealPratham21
Copy link
Copy Markdown

Summary of the Pull Request

This PR adds a Friendly date/time result to the Time and Date PT Run plugin.
The plugin now shows a human-readable representation (e.g. “Today”, “Yesterday”, “in 3 hours”, “4 hours ago”) alongside the existing formats when the user queries the current system time or a specific timestamp. The change is localized, documented, and covered by unit tests in the TimeDate plugin test project.

PR Checklist

  • Communication: I've added a comment for this on the issue and the contributors issue as well.
  • Tests: Added unit testing and other test cases to verify correct functionality.
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

  • New Friendly result

    • Added a predefined Friendly result in AvailableResultsList.GetList that is shown together with the existing formats (Time, Date, Now, Unix, ISO 8601, etc.) when returning the full result list.
    • The result value is computed via a new helper TimeAndDateHelper.GetFriendlyDateTime(DateTime target, DateTime referenceNow), which:
      • Uses local date boundaries to return Today, Yesterday, or Tomorrow when appropriate.
      • Otherwise returns relative phrases such as “just now”, “1 minute ago / in 1 minute”, “{N} minutes/hours ago / in {N} minutes/hours”, or “{N} days ago / in {N} days”.
      • Supports both past and future timestamps and respects DateTimeKind (UTC values are converted to local for comparison).
    • The result uses the existing DateTime icon and a new search-tag resource so it can be discovered with terms like “friendly”, “relative”, “yesterday”, “today”, “tomorrow”, or “ago”.
  • Integration and localization

    • AvailableResultsList.GetList gained an optional now parameter so tests can inject a stable reference time; callers in production continue to use current system time when now is not specified.
    • All new user-facing text (Friendly label, Today/Yesterday/Tomorrow, relative phrases and tags) is stored in Resources.resx with corresponding properties in Resources.Designer.cs.
  • Tests and docs

    • Unit tests
      • TimeAndDateHelperTests: added a data-driven test that verifies typical Friendly outputs (e.g. “4 hours ago”, “in 3 hours”, “Today”, “Yesterday”, “Tomorrow”) for a fixed now and different targets.
      • TimeDateResultTests: updated to call the new GetList signature and to ensure existing format values remain unchanged.
      • ImageTests: extended to assert that the Friendly result uses the expected DateTime icon in both dark and light themes.
      • QueryTests: adjusted expected counts for keyword queries that now include the Friendly result, and confirmed that Friendly participates in the same matching logic as other formats.
    • Dev docs
      • doc/devdocs/modules/launcher/plugins/timedate.md: added the Friendly format to the “List of available formats” table with an example like “Yesterday”.

Note on tests: due to tooling constraints on my current machine (Visual Studio workloads / Windows SDK installation blocked by disk space), I was not able to run the TimeDate test project end-to-end locally. The changes are intentionally scoped to the TimeDate plugin and its tests, and I would appreciate CI and at least one local maintainer run of Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests before merge.

Validation Steps Performed

Automated (intended):

  • dotnet test src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests.csproj -c Release
    (I could not complete this locally due to missing VS workloads / SDK; please run in CI or on a fully provisioned dev machine.)

Suggested manual validation:

  1. System time query
    • Invoke PT Run and the Time and Date plugin.
    • Type the plugin keyword + now (or just the keyword, depending on configuration).
    • Confirm that:
      • A Friendly result appears alongside existing formats.
      • Its value is a reasonable description of the current time (e.g. “Today”, “just now”).
  2. Relative past/future
    • Query a timestamp a few hours in the past and future (e.g. 10:00 vs an assumed 13:00 now, or specific dates).
    • Confirm Friendly shows “N hours ago” or “in N hours” as expected.
  3. Date boundaries
    • Query dates of “yesterday”, “today”, and “tomorrow” relative to the current date.
    • Confirm the Friendly result reads exactly “Yesterday”, “Today”, or “Tomorrow”.
  4. Search and icons
    • With the plugin keyword, type partial terms like friendly, relative, yesterday.
    • Confirm the Friendly result is returned and uses the same DateTime icon as the existing Date+Time results for both dark and light themes.

@RealPratham21
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PT Run] [Time and Date plugin] Add friendly date/time format

1 participant