1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Core/Helpers/SabnzbdQueueTimeConverter.cs
Mark McDowall 26adbf2602 Code cleanup per commit comments. More Work?!
EpisodeParseResult will use Season ## when it is a full season instead of writing out each episode number.
2012-01-30 22:55:57 -08:00

38 lines
1.1 KiB
C#

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("TimeSpan is invalid");
}
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);
}
}
}