More Improvement to unix timestamp performance

This commit is contained in:
Qstick
2023-02-23 20:04:45 -06:00
parent 495f61f412
commit 2e9f6cd94b
2 changed files with 15 additions and 1 deletions

View File

@@ -257,5 +257,18 @@ namespace NzbDrone.Common.Extensions
{
return input.Contains(':') ? $"[{input}]" : input;
}
public static bool IsAllDigits(this string input)
{
foreach (var c in input)
{
if (c < '0' || c > '9')
{
return false;
}
}
return true;
}
}
}

View File

@@ -2,6 +2,7 @@ using System;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Parser
{
@@ -123,7 +124,7 @@ namespace NzbDrone.Core.Parser
str = str.Trim();
// try parsing the str as an unix timestamp
if (str.All(char.IsDigit) && long.TryParse(str, out var unixTimeStamp))
if (str.IsAllDigits() && long.TryParse(str, out var unixTimeStamp))
{
return UnixTimestampToDateTime(unixTimeStamp);
}