Fixed: (Cardigann) Switch to DateTime standard

pull/1473/head
Bogdan 2 years ago
parent caab337379
commit 888b514dd8

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
@ -613,14 +614,22 @@ namespace NzbDrone.Core.Indexers.Cardigann
case "timeparse": case "timeparse":
case "dateparse": case "dateparse":
var layout = (string)filter.Args; var layout = (string)filter.Args;
try
if (layout.Contains("yy") && DateTime.TryParseExact(data, layout, CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate))
{ {
var date = DateTimeUtil.ParseDateTimeGoLang(data, layout); data = parsedDate.ToString(DateTimeUtil.Rfc1123ZPattern);
data = date.ToString(DateTimeUtil.Rfc1123ZPattern);
} }
catch (InvalidDateException ex) else
{ {
_logger.Debug(ex.Message); try
{
var date = DateTimeUtil.ParseDateTimeGoLang(data, layout);
data = date.ToString(DateTimeUtil.Rfc1123ZPattern);
}
catch (InvalidDateException ex)
{
_logger.Debug(ex.Message);
}
} }
break; break;
@ -657,15 +666,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
break; break;
case "trim": case "trim":
var cutset = (string)filter.Args; var cutset = (string)filter.Args;
if (cutset != null) data = cutset != null ? data.Trim(cutset[0]) : data.Trim();
{
data = data.Trim(cutset[0]);
}
else
{
data = data.Trim();
}
break; break;
case "prepend": case "prepend":
var prependstr = (string)filter.Args; var prependstr = (string)filter.Args;

@ -72,6 +72,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
} }
var parsedJson = JToken.Parse(results); var parsedJson = JToken.Parse(results);
if (parsedJson == null) if (parsedJson == null)
{ {
throw new IndexerException(indexerResponse, "Error Parsing Json Response"); throw new IndexerException(indexerResponse, "Error Parsing Json Response");
@ -80,12 +81,10 @@ namespace NzbDrone.Core.Indexers.Cardigann
if (search.Rows.Count != null) if (search.Rows.Count != null)
{ {
var countVal = HandleJsonSelector(search.Rows.Count, parsedJson, variables); var countVal = HandleJsonSelector(search.Rows.Count, parsedJson, variables);
if (int.TryParse(countVal, out var count))
if (int.TryParse(countVal, out var count) && count < 1)
{ {
if (count < 1) return releases;
{
return releases;
}
} }
} }

@ -1,5 +1,6 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace NzbDrone.Core.Parser namespace NzbDrone.Core.Parser
@ -120,6 +121,13 @@ namespace NzbDrone.Core.Parser
try try
{ {
str = str.Trim(); str = str.Trim();
// try parsing the str as an unix timestamp
if (str.All(char.IsDigit) && long.TryParse(str, out var unixTimeStamp))
{
return UnixTimestampToDateTime(unixTimeStamp);
}
if (str.ToLower().Contains("now")) if (str.ToLower().Contains("now"))
{ {
return DateTime.UtcNow; return DateTime.UtcNow;
@ -212,14 +220,6 @@ namespace NzbDrone.Core.Parser
return dt; return dt;
} }
// try parsing the str as an unix timestamp
if (long.TryParse(str, out var unixTimeStamp))
{
return UnixTimestampToDateTime(unixTimeStamp);
}
// it wasn't a timestamp, continue....
// add missing year // add missing year
match = _MissingYearRegexp.Match(str); match = _MissingYearRegexp.Match(str);
if (match.Success) if (match.Success)
@ -312,7 +312,7 @@ namespace NzbDrone.Core.Parser
} }
catch (FormatException ex) catch (FormatException ex)
{ {
throw new InvalidDateException($"Error while parsing DateTime \"{date}\", using layout \"{layout}\" ({pattern}): {ex.Message}"); throw new InvalidDateException($"Error while parsing DateTime \"{date}\", using layout \"{layout}\" ({pattern}): {ex.Message}", ex);
} }
} }

Loading…
Cancel
Save