mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-15 03:59:15 +08:00
15c5e9833a
1. bring history back, disabled in 56d08663410916df0a4e408da6e4af3d2a2722c0 2. fix #632 #722 3. hotkey: ctrl+H
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
|
|
namespace Wox.Storage
|
|
{
|
|
public class HistoryItem
|
|
{
|
|
public string Query { get; set; }
|
|
public DateTime ExecutedDateTime { get; set; }
|
|
|
|
public string GetTimeAgo()
|
|
{
|
|
return DateTimeAgo(ExecutedDateTime);
|
|
}
|
|
|
|
private string DateTimeAgo(DateTime dt)
|
|
{
|
|
var span = DateTime.Now - dt;
|
|
if (span.Days > 365)
|
|
{
|
|
int years = (span.Days / 365);
|
|
if (span.Days % 365 != 0)
|
|
years += 1;
|
|
return $"about {years} {(years == 1 ? "year" : "years")} ago";
|
|
}
|
|
if (span.Days > 30)
|
|
{
|
|
int months = (span.Days / 30);
|
|
if (span.Days % 31 != 0)
|
|
months += 1;
|
|
return $"about {months} {(months == 1 ? "month" : "months")} ago";
|
|
}
|
|
if (span.Days > 0)
|
|
return $"about {span.Days} {(span.Days == 1 ? "day" : "days")} ago";
|
|
if (span.Hours > 0)
|
|
return $"about {span.Hours} {(span.Hours == 1 ? "hour" : "hours")} ago";
|
|
if (span.Minutes > 0)
|
|
return $"about {span.Minutes} {(span.Minutes == 1 ? "minute" : "minutes")} ago";
|
|
if (span.Seconds > 5)
|
|
return $"about {span.Seconds} seconds ago";
|
|
if (span.Seconds <= 5)
|
|
return "just now";
|
|
return string.Empty;
|
|
}
|
|
}
|
|
} |