]> granicus.if.org Git - handbrake/commitdiff
WinGui: More robust Timespan parsing.
authorsr55 <sr55.hb@outlook.com>
Sat, 23 Mar 2019 14:19:05 +0000 (14:19 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 23 Mar 2019 14:21:23 +0000 (14:21 +0000)
win/CS/HandBrakeWPF/Helpers/TimeSpanHelper.cs

index e3f4dfb59fd1c4eb796b6cd4de4be8e7df5a24b7..73f3f491f399264bb8efb5d23575ae1e95c8c1a2 100644 (file)
@@ -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;
         }
     }
 }