AK.F1.Timing.Live.LiveData.ParseTime C# (CSharp) Method

ParseTime() public static method

Parses a System.TimeSpan from the specified string.
This method is capabable of parsing all known grid time formats, including: lap, sector interval gap, elapsed session and remaining session times. It will not parse interval or gaps times in the ##L format.
/// Thrown when is incorrectly formatted. ///
public static ParseTime ( string s ) : System.TimeSpan
s string The string to parse.
return System.TimeSpan
        public static TimeSpan ParseTime(string s)
        {
            DateTime date;

            if(DateTime.TryParseExact(s, TimeFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
            {
                return date.TimeOfDay;
            }

            double seconds;
            // Sector times may be greater than 60 seconds in which case they are formatted as 73.7
            // This format cannot be expressed as a time format so revert to parsing it as a double.
            if(Double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out seconds))
            {
                return TimeSpan.FromSeconds(seconds);
            }

            throw Guard.LiveData_UnableToParseTime(s);
        }