[Quantproject-developers] QuantProject/b1_ADT/Timing Time.cs, 1.2, 1.3
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2008-11-18 22:31:35
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Timing In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7856/b1_ADT/Timing Modified Files: Time.cs Log Message: Static method IsValidTimeFormat has been simplified (my previous code was totally insane ...) Index: Time.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Timing/Time.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Time.cs 14 Nov 2008 15:57:46 -0000 1.2 --- Time.cs 18 Nov 2008 22:31:29 -0000 1.3 *************** *** 30,75 **** public struct Time : IEquatable<Time> , IComparable<Time> { - #region IsValidTimeFormat public static bool IsValidTimeFormat ( string stringRepresentingTime ) { ! bool returnValue = false; ! char[] chars = stringRepresentingTime.ToCharArray(); ! if( ! //first - hour ! (chars[0]=='0' || chars[0]=='1' || chars[0]=='2') && ! //second - hour ! ( (chars[0]=='0' || chars[0]=='1') && ! (chars[1]=='0' || chars[1]=='1' || chars[1]=='2' || ! chars[1]=='3' || chars[1]=='4' || chars[1]=='5' || ! chars[1]=='6' || chars[1]=='7' || chars[1]=='8' || chars[1]=='9') || ! chars[0] == '2' && ! (chars[1]=='0' || chars[1]=='1' || chars[1]=='2' || ! chars[1]=='3' || chars[1]=='4') ) && ! //third - separator ! (chars[2]==':') && ! //fourth - minute ! (chars[3]=='0' || chars[3]=='1' || chars[3]=='2' || ! chars[3]=='3' || chars[3]=='4' || chars[3]=='5') && ! //fifth - minute ! (chars[4]=='0' || chars[4]=='1' || chars[4]=='2' || ! chars[4]=='3' || chars[4]=='4' || chars[4]=='5' || ! chars[4]=='6' || chars[4]=='7' || chars[4]=='8' || chars[4]=='9') && ! //sixth - separator ! (chars[5]==':') && ! //seventh - second ! (chars[6]=='0' || chars[6]=='1' || chars[6]=='2' || ! chars[6]=='3' || chars[6]=='4' || chars[6]=='5') && ! //eighth - second ! (chars[7]=='0' || chars[7]=='1' || chars[7]=='2' || ! chars[7]=='3' || chars[7]=='4' || chars[7]=='5' || ! chars[7]=='6' || chars[7]=='7' || chars[7]=='8' || chars[7]=='9') ! ) ! returnValue = true; ! return returnValue; } ! #endregion isValidTimeFormat ! ! /// <summary> /// Returns a new DateTime, having the date as the given dateTime --- 30,49 ---- public struct Time : IEquatable<Time> , IComparable<Time> { public static bool IsValidTimeFormat ( string stringRepresentingTime ) { ! int hour = Convert.ToInt32(stringRepresentingTime.Substring(0,2)); ! int minute = Convert.ToInt32(stringRepresentingTime.Substring(3,2)); ! int second = Convert.ToInt32(stringRepresentingTime.Substring(6,2)); ! string firstSeparator = stringRepresentingTime.Substring(2,1); ! string secondSeparator = stringRepresentingTime.Substring(5,1); ! return (stringRepresentingTime.Length == 8) && ! (hour >= 0 && hour <= 24) && ! (firstSeparator == ":") && ! (minute >= 0 && minute <= 59) && ! (secondSeparator == ":") && ! (second >= 0 && second <= 59); } ! /// <summary> /// Returns a new DateTime, having the date as the given dateTime *************** *** 84,89 **** time.Hour , time.Minute , time.Second ); } ! ! private DateTime standardDateTime; --- 58,62 ---- time.Hour , time.Minute , time.Second ); } ! private DateTime standardDateTime; *************** *** 121,124 **** --- 94,98 ---- int minute = Convert.ToInt32(stringRepresentingTime.Substring(3,2)); int second = Convert.ToInt32(stringRepresentingTime.Substring(6,2)); + return new DateTime(1900, 1, 1, hour, minute, second); } *************** *** 126,131 **** private void time_checkParameter ( string stringRepresentingTime ) { ! if( stringRepresentingTime.Length != 8 || ! !Time.IsValidTimeFormat( stringRepresentingTime ) ) throw new Exception("string is not in the requested time-format hh:mm:ss"); } --- 100,104 ---- private void time_checkParameter ( string stringRepresentingTime ) { ! if( !Time.IsValidTimeFormat( stringRepresentingTime ) ) throw new Exception("string is not in the requested time-format hh:mm:ss"); } |