From 279b64c78b8c397e7ffee232391fbf18d14e38cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20G=C3=B3recki?= Date: Mon, 23 Jul 2018 20:37:45 +0200 Subject: [PATCH] Possibility to input start time in formats HH:MM:SS, H:MM:SS, MM:SS, M:SS, SS, S instead of only HH:MM:SS. --- Helper.cs | 17 +++++++++++++++++ formMain.cs | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Helper.cs b/Helper.cs index 495b590..5424ecc 100644 --- a/Helper.cs +++ b/Helper.cs @@ -178,6 +178,23 @@ public static bool checkFFmpegFontConfig() } } + /// + /// Converts input to HH:MM:SS format. + /// 1 -> 00:00:01 + /// 11 -> 00:00:11 + /// 1:11 -> 00:01:11 + /// 11:11 -> 00:11:11 + /// 1:11:11 -> 01:11:11 + /// 11:11:11 -> 11:11:11 + /// + /// input text + /// + public static string fillMissingZeroes(string timeInput) + { + string zeroes = "00:00:00"; + return zeroes.Substring(0, zeroes.Length - timeInput.Length) + timeInput; + } + /// /// Verifies the version of the program. /// It will prompt the user if the program is diff --git a/formMain.cs b/formMain.cs index e64c54c..ff45b32 100644 --- a/formMain.cs +++ b/formMain.cs @@ -17,7 +17,7 @@ public partial class formMain : Form private String runningDirectory = AppDomain.CurrentDomain.BaseDirectory; // Obtains the root directory Regex verifyLength = new Regex(@"^\d{1,3}"); // Regex to verify if txtLength is properly typed in - Regex verifyTimeStart = new Regex(@"^[0-6]\d:[0-6]\d:[0-6]\d"); // Regex to verify if txtStartTime is properly typed in + Regex verifyTimeStart = new Regex(@"^(([0-6]?\d\D+)?[0-6]?\d\D+)?[0-6]?\d");// Regex to verify if txtStartTime is properly typed in Regex verifyWidth = new Regex(@"^\d{1,4}"); // Regex to verify if txtWidth is properly typed in Regex verifyMaxSize = new Regex(@"^\d{1,4}"); // Regex to verify if txtMaxSize is properly typed in Regex verifyCrop = new Regex(@"^\d{1,4}:\d{1,4}:\d{1,4}:\d{1,4}"); // Regex to verify if txtCrop is properly typed in @@ -95,6 +95,13 @@ private void btnConvert_Click(object sender, EventArgs e) } else { + if (txtTimeStart.Text.Length < 8) + { + // Input is valid against regex, but maybe we have to add missing zeroes + string correctedTimeInput = Helper.fillMissingZeroes(txtTimeStart.Text); + txtTimeStart.Text = correctedTimeInput; + } + // Calculates the seconds from the time-code double seconds = Helper.convertToSeconds(txtTimeStart.Text);