fCraft.DateTimeUtil.ToTimeSpan C# (CSharp) Method

ToTimeSpan() public static method

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero
public static ToTimeSpan ( [ str, System.TimeSpan &result ) : bool
str [
result System.TimeSpan
return bool
        public static bool ToTimeSpan( [NotNull] this string str, out TimeSpan result ) {
            if( str == null ) throw new ArgumentNullException( "str" );
            if( str.Length == 0 ) {
                result = TimeSpan.Zero;
                return true;
            }
            long ticks;
            if( Int64.TryParse( str, out ticks ) ) {
                result = new TimeSpan( ticks * TimeSpan.TicksPerSecond );
                return true;
            } else {
                result = TimeSpan.Zero;
                return false;
            }
        }