mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Bring history back
1. bring history back, disabled in 56d08663410916df0a4e408da6e4af3d2a2722c0 2. fix #632 #722 3. hotkey: ctrl+H
This commit is contained in:
45
Wox/Storage/HistoryItem.cs
Normal file
45
Wox/Storage/HistoryItem.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user