diff options
author | sr55 <[email protected]> | 2019-03-23 14:19:05 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2019-03-23 14:21:23 +0000 |
commit | 9a0a337de714c33400f8093e0dbb50c5d6f66242 (patch) | |
tree | 7eb36575459482bd4c2047bd210e32dab9adf04e /win | |
parent | d305c97317393af7d3404a8c4525579e9fe83d29 (diff) |
WinGui: More robust Timespan parsing.
Diffstat (limited to 'win')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/TimeSpanHelper.cs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/TimeSpanHelper.cs b/win/CS/HandBrakeWPF/Helpers/TimeSpanHelper.cs index e3f4dfb59..73f3f491f 100644 --- a/win/CS/HandBrakeWPF/Helpers/TimeSpanHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/TimeSpanHelper.cs @@ -12,6 +12,8 @@ namespace HandBrakeWPF.Helpers using System; using System.Globalization; + using HandBrakeWPF.Services.Encode.Model.Models; + /// <summary> /// Helper functions for handling <see cref="TimeSpan"/> structures /// </summary> @@ -28,10 +30,20 @@ namespace HandBrakeWPF.Helpers /// </returns> internal static TimeSpan ParseChapterTimeStart(string chapterStartRaw) { + if (string.IsNullOrEmpty(chapterStartRaw)) + { + return TimeSpan.MinValue; + } + // Format: 02:35:05 and 02:35:05.2957333 - return TimeSpan.ParseExact( - chapterStartRaw, - new[] { @"hh\:mm\:ss", @"hh\:mm\:ss\.FFFFFFF" }, CultureInfo.InvariantCulture); // Handle whole seconds then Handle fraction seconds + TimeSpan converted; + string fromTime = chapterStartRaw.Trim().TrimEnd('0'); + if (TimeSpan.TryParseExact(fromTime, new[] { @"HH\:mm\:ss", @"hh\:mm\:ss\.FFFFFFF", }, CultureInfo.InvariantCulture, out converted)) + { + return converted; + } + + return TimeSpan.Zero; } } } |