Update conversion
SuccessfulCode/BritishHorseRacingApi/master This commit looks good

This commit is contained in:
2020-02-27 23:37:51 +00:00
parent 644e3e2fdb
commit d0adf48787
2 changed files with 19 additions and 3 deletions
@@ -36,7 +36,20 @@ namespace BritishHorseRacingApi.Tests
}
[Theory()]
[InlineData("1m 1f 104y", 2084)]
[InlineData("1m 15.39s(+0.34s)", 340)]
[InlineData(null, null)]
[InlineData(" ", null)]
public void TestStopwatchStringDifferenceToMilliseconds(string time, double? expectedValue)
{
//Arrange
//Act
var totalMilliseconds = DataConverterHelper.StopwatchStringDifferenceToMilliseconds(time);
//Assert
Assert.Equal(totalMilliseconds, expectedValue);
}
[Theory()]
[InlineData("1m 1f 104y ", 2084)]
[InlineData("1f 104y", 324)]
[InlineData("104y", 104)]
[InlineData("", null)]
@@ -58,10 +58,13 @@ namespace BritishHorseRacingApi.Helpers
return (T)Convert.ChangeType(group.Value, typeof(T));
}
public static int StopwatchStringDifferenceToMilliseconds(string timeDifferenceString)
public static int? StopwatchStringDifferenceToMilliseconds(string timeDifferenceString)
{
if (String.IsNullOrWhiteSpace(timeDifferenceString))
return null;
var match = _stopwatchTimeRegex.Match(timeDifferenceString);
var lossDifference = GetComponent(match, "lossDifference", 0);
var lossDifference = GetComponent(match, "lossDifference", 0d);
return (int)TimeSpan.FromSeconds(lossDifference).TotalMilliseconds;
}
}