[PTRun][DateTime]Fix and improvements for Windows File Time and Unix Epoch Time (#29900)

* improvements and fixes for unix time and windows file time

* spell fix
This commit is contained in:
Heiko
2023-11-20 19:04:23 +01:00
committed by GitHub
parent 99b014516d
commit 42564e6c10
3 changed files with 30 additions and 13 deletions

View File

@@ -260,7 +260,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
}
[TestMethod]
public void UnixTimestampFormat()
public void UnixTimestampSecondsFormat()
{
// Setup
string formatLabel = "Unix epoch time";
@@ -275,6 +275,22 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
Assert.AreEqual(expectedResult.ToString(CultureInfo.CurrentCulture), result?.Value);
}
[TestMethod]
public void UnixTimestampMillisecondsFormat()
{
// Setup
string formatLabel = "Unix epoch time in milliseconds";
DateTime timeValue = DateTime.Now.ToUniversalTime();
var helperResults = AvailableResultsList.GetList(true, false, false, timeValue);
var expectedResult = (long)timeValue.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));
// Assert
Assert.AreEqual(expectedResult.ToString(CultureInfo.CurrentCulture), result?.Value);
}
[TestMethod]
public void WindowsFileTimeFormat()
{
@@ -282,7 +298,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
string formatLabel = "Windows file time (Int64 number)";
DateTime timeValue = DateTime.Now;
var helperResults = AvailableResultsList.GetList(true, false, false, timeValue);
var expectedResult = timeValue.Ticks.ToString(CultureInfo.CurrentCulture);
var expectedResult = timeValue.ToFileTime().ToString(CultureInfo.CurrentCulture);
// Act
var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase));