2012-01-30 21:34:15 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2012-01-31 06:55:57 +00:00
|
|
|
|
var ts = (TimeSpan)value;
|
|
|
|
|
writer.WriteValue(ts.ToString());
|
2012-01-30 21:34:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
var split = reader.Value.ToString().Split(':');
|
|
|
|
|
|
2012-01-31 06:55:57 +00:00
|
|
|
|
if (split.Count() != 3)
|
2012-01-30 21:34:15 +00:00
|
|
|
|
{
|
2012-01-31 20:18:03 +00:00
|
|
|
|
throw new ArgumentException("Expected 0:0:0 format, but received: " + reader.Value);
|
2012-01-31 06:55:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new TimeSpan(int.Parse(split[0]), // hours
|
2012-01-30 21:34:15 +00:00
|
|
|
|
int.Parse(split[1]), // minutes
|
|
|
|
|
int.Parse(split[2]) // seconds
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool CanConvert(Type objectType)
|
|
|
|
|
{
|
2012-01-31 06:55:57 +00:00
|
|
|
|
return objectType == typeof(TimeSpan);
|
2012-01-30 21:34:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|