using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace DateTimeUtils {
publicstaticclass Conversion {
publicstatic TimeSpan ConvertToTimeSpan( string time ) {
TimeSpan result = TimeSpan.Zero;
if ( string.IsNullOrEmpty( time ) ) thrownew ArgumentNullException( "No time given." );
Regex regex = new Regex( "^([0-1][0-9]|[2][0-3]):([0-5][0-9])$" );
if ( !regex.IsMatch( time ) ) thrownew FormatException( "Invalid time format" );
TimeSpan.TryParse( time, out result );
return result;
}
}
}