You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
38 lines
1.2 KiB
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)
|
|
{
|
|
var ts = (TimeSpan)value;
|
|
writer.WriteValue(ts.ToString());
|
|
}
|
|
|
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
|
{
|
|
var split = reader.Value.ToString().Split(':');
|
|
|
|
if (split.Count() != 3)
|
|
{
|
|
throw new ArgumentException("Expected 0:0:0 format, but received: " + reader.Value);
|
|
}
|
|
|
|
return new TimeSpan(int.Parse(split[0]), // hours
|
|
int.Parse(split[1]), // minutes
|
|
int.Parse(split[2]) // seconds
|
|
);
|
|
}
|
|
|
|
public override bool CanConvert(Type objectType)
|
|
{
|
|
return objectType == typeof(TimeSpan);
|
|
}
|
|
}
|
|
}
|