Fix: Resolved a parsing issue when timeleft for an SabQueueItem was greater than 24 hours.

pull/4/head
Mark McDowall 13 years ago
parent 2635ff9bee
commit 1f983094ac

@ -67,7 +67,7 @@
"size":"267 MB",
"sizeleft":"239 MB",
"status":"Downloading",
"timeleft":"31:12:34",
"timeleft":"57:27:45",
"unpackopts":"3",
"verbosity":""
},

@ -188,8 +188,6 @@ namespace NzbDrone.Core.Test.ProviderTests.SabProviderTests
result.Should().BeTrue();
}
[Test]
public void IsInQueue_should_return_false_if_queue_is_empty()
{
@ -209,6 +207,21 @@ namespace NzbDrone.Core.Test.ProviderTests.SabProviderTests
result.Should().BeFalse();
}
[Test]
public void GetQueue_should_parse_timeleft_with_hours_greater_than_24_hours()
{
WithFullQueue();
var result = Mocker.Resolve<SabProvider>().GetQueue();
result.Should().NotBeEmpty();
var timeleft = result.First(q => q.Id == "SABnzbd_nzo_qv6ilb").Timeleft;
timeleft.Days.Should().Be(2);
timeleft.Hours.Should().Be(9);
timeleft.Minutes.Should().Be(27);
timeleft.Seconds.Should().Be(45);
}
[TearDown]
public void TearDown()
{

@ -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;
}
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using NzbDrone.Core.Helpers;
namespace NzbDrone.Core.Model.Sabnzbd
{
@ -10,6 +11,8 @@ namespace NzbDrone.Core.Model.Sabnzbd
{
public string Status { get; set; }
public int Index { get; set; }
[JsonConverter(typeof(SabnzbdQueueTimeConverter))]
public TimeSpan Timeleft { get; set; }
[JsonProperty(PropertyName = "mb")]

@ -226,6 +226,7 @@
<Compile Include="Helpers\EpisodeSortingHelper.cs" />
<Compile Include="Helpers\FileSizeFormatHelper.cs" />
<Compile Include="Helpers\SortHelper.cs" />
<Compile Include="Helpers\SabnzbdQueueTimeConverter.cs" />
<Compile Include="Jobs\CheckpointJob.cs" />
<Compile Include="Providers\AnalyticsProvider.cs" />
<Compile Include="Instrumentation\LogDbContext.cs" />

Loading…
Cancel
Save