Skip to content

Commit

Permalink
Make lap times nullable
Browse files Browse the repository at this point in the history
Fixes issue with Q1 some times being an empty string
  • Loading branch information
Krusen committed Sep 11, 2017
1 parent 4c63de7 commit 4521c17
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ErgastApi/Responses/Models/RaceInfo/FastestLap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FastestLap

[JsonPathProperty("Time.time")]
[JsonConverter(typeof(StringTimeSpanConverter))]
public TimeSpan LapTime { get; private set; }
public TimeSpan? LapTime { get; private set; }

[JsonProperty("AverageSpeed")]
public AverageSpeed AverageSpeed { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion src/ErgastApi/Responses/Models/RaceInfo/LapTiming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class LapTiming

[JsonProperty("time")]
[JsonConverter(typeof(StringTimeSpanConverter))]
public TimeSpan Time { get; private set; }
public TimeSpan? Time { get; private set; }
}
}
6 changes: 3 additions & 3 deletions src/ErgastApi/Responses/Models/RaceInfo/QualifyingResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public class QualifyingResult : ResultBase
{
[JsonProperty("Q1")]
[JsonConverter(typeof(StringTimeSpanConverter))]
public TimeSpan Q1 { get; private set; }
public TimeSpan? Q1 { get; private set; }

[JsonProperty("Q2")]
[JsonConverter(typeof(StringTimeSpanConverter))]
public TimeSpan Q2 { get; private set; }
public TimeSpan? Q2 { get; private set; }

[JsonProperty("Q3")]
[JsonConverter(typeof(StringTimeSpanConverter))]
public TimeSpan Q3 { get; private set; }
public TimeSpan? Q3 { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

var value = (string) reader.Value;

TimeSpan result;
if (TimeSpan.TryParseExact(value, Formats, null, out result))
if (value == null)
return null;

if (TimeSpan.TryParseExact(value, Formats, null, out var result))
return result;

return null;
Expand Down

0 comments on commit 4521c17

Please sign in to comment.