mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
Fix: Resolved a parsing issue when timeleft for an SabQueueItem was greater than 24 hours.
This commit is contained in:
parent
2635ff9bee
commit
1f983094ac
5 changed files with 63 additions and 3 deletions
43
NzbDrone.Core/Helpers/SabnzbdQueueTimeConverter.cs
Normal file
43
NzbDrone.Core/Helpers/SabnzbdQueueTimeConverter.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NzbDrone.Core.Helpers
|
||||
{
|
||||
public class SabnzbdQueueTimeConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
if (value is TimeSpan)
|
||||
writer.WriteValue(value.ToString());
|
||||
|
||||
else
|
||||
throw new Exception("Expected TimeSpan object value.");
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var split = reader.Value.ToString().Split(':');
|
||||
|
||||
if (split.Count() == 3)
|
||||
{
|
||||
return new TimeSpan(int.Parse(split[0]), // hours
|
||||
int.Parse(split[1]), // minutes
|
||||
int.Parse(split[2]) // seconds
|
||||
);
|
||||
}
|
||||
|
||||
throw new ArgumentException("TimeSpan is invalid");
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
if (objectType == typeof(TimeSpan))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue