mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
* Moved all files from Wox to Powerlauncher * Removed Wox project * Changed namespace for imported files * Resolved errors for VM * Added build dependency order * Fixed errors in helper class * Remove Wox files * Fixed errors in SingleInstance class * Fixed wox.tests * Fixed MSI * Removed obsolete methods from PublicAPI * nit fixes * Throw null exception * Fix merge conflict
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
|
|
namespace PowerLauncher.Storage
|
|
{
|
|
public class HistoryItem
|
|
{
|
|
public string Query { get; set; }
|
|
public DateTime ExecutedDateTime { get; set; }
|
|
|
|
public string GetTimeAgo()
|
|
{
|
|
return DateTimeAgo(ExecutedDateTime);
|
|
}
|
|
|
|
private static 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;
|
|
}
|
|
}
|
|
} |