Exemple #1
0
        public static int GetTime(string timeString)
        {
            Match m = null;

            timeString = timeString.Trim();
            // h:mm (\d\d?):(\d\d?)?
            // # m (\d+) ?m?
            // # h (\d+) ?h
            // #h #m (\d+) ?h? ?(\d+) ?m?
            m = Regex.Match(timeString, @"^(\d\d?):(\d\d?)?$");
            if (m.Success)
            {
                return(Integers.Parse(m.Groups[1].Value, 0) * 60 + Integers.Parse(m.Groups[2].Value, 0));
            }

            m = Regex.Match(timeString, @"^(\d+) ?m?$", RegexOptions.IgnoreCase);
            if (m.Success)
            {
                return(Integers.Parse(m.Groups[1].Value, 0));
            }

            m = Regex.Match(timeString, @"^(\d+) ?h$", RegexOptions.IgnoreCase);
            if (m.Success)
            {
                return(Integers.Parse(m.Groups[1].Value, 0) * 60);
            }

            m = Regex.Match(timeString, @"^(\d+) ?h? ?(\d+) ?m?$", RegexOptions.IgnoreCase);
            if (m.Success)
            {
                return(Integers.Parse(m.Groups[1].Value, 0) * 60 + Integers.Parse(m.Groups[2].Value, 0));
            }

            return(0);
        }
 public void Test_Parse_ShouldReturnCorrectValue(string xStr, int x)
 {
     Assert.Equal(Integers.Parse(xStr), x);
 }