Repository: microsoft/PowerToys
File: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.TimeDate/FallbackTimeDateItem.cs (C#)

Code before:
using System.Drawing;
using System.Globalization;
using Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;

namespace Microsoft.CmdPal.Ext.TimeDate;

internal sealed partial class FallbackTimeDateItem : FallbackCommandItem
{
    private readonly HashSet<string> _validOptions;
    private SettingsManager _settingsManager;

    public FallbackTimeDateItem(SettingsManager settings)
         : base(new NoOpCommand(), Resources.Microsoft_plugin_timedate_fallback_display_title)
    {
        Title = string.Empty;
        Subtitle = string.Empty;
        _settingsManager = settings;
        _validOptions = new(StringComparer.OrdinalIgnoreCase)
        {
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagWeek", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagDate", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_Year", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_Now", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_Time", CultureInfo.CurrentCulture),
        };
    }

    public override void UpdateQuery(string query)
    {
        if (!_settingsManager.EnableFallbackItems || string.IsNullOrWhiteSpace(query) || !_validOptions.Contains(query))
        {
            Title = string.Empty;
            Subtitle = string.Empty;
            Command = new NoOpCommand();
            return;
        }

        var availableResults = AvailableResultsList.GetList(false, _settingsManager);
        ListItem result = null;
        var maxScore = 0;

        foreach (var f in availableResults)
        {
            var score = f.Score(query, f.Label, f.AlternativeSearchTag);
            if (score > maxScore)
            {
                maxScore = score;
                result = f.ToListItem();
            }

Review comment (refactor):
attention: there is a difference in the strings between converting input results and the strings for current time/date. As I think we don't support conversation in fallback results we should use the steing ending with "now" in the name. (This was what the helper method switches.)

Code after:
using System.Drawing;
using System.Globalization;
using System.Linq;
using Microsoft.CmdPal.Ext.TimeDate.Helpers;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;

namespace Microsoft.CmdPal.Ext.TimeDate;

internal sealed partial class FallbackTimeDateItem : FallbackCommandItem
{
    private readonly HashSet<string> _validOptions;
    private SettingsManager _settingsManager;

    public FallbackTimeDateItem(SettingsManager settings)
         : base(new NoOpCommand(), Resources.Microsoft_plugin_timedate_fallback_display_title)
    {
        Title = string.Empty;
        Subtitle = string.Empty;
        _settingsManager = settings;
        _validOptions = new(StringComparer.OrdinalIgnoreCase)
        {
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagDate", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagDateNow", CultureInfo.CurrentCulture),

            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagTime", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagTimeNow", CultureInfo.CurrentCulture),

            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagFormat", CultureInfo.CurrentCulture),
            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagFormatNow", CultureInfo.CurrentCulture),

            Resources.ResourceManager.GetString("Microsoft_plugin_timedate_SearchTagWeek", CultureInfo.CurrentCulture),
        };
    }

    public override void UpdateQuery(string query)
    {
        if (!_settingsManager.EnableFallbackItems || string.IsNullOrWhiteSpace(query) || !IsValidQuery(query))
        {
            Title = string.Empty;
            Subtitle = string.Empty;
            Command = new NoOpCommand();
            return;
        }

        var availableResults = AvailableResultsList.GetList(false, _settingsManager);
        ListItem result = null;
        var maxScore = 0;

        foreach (var f in availableResults)
        {