A structure to store a simple time.
Example #1
0
 /// <summary>
 /// Return a new time range having the end time set to the given value.
 /// </summary>
 /// <param name="TimeRange">A time range object.</param>
 /// <param name="EndTime">The new ending time.</param>
 public static TimeRange To(this TimeRange TimeRange, Time EndTime)
 {
     return new TimeRange(TimeRange.StartTime, EndTime);
 }
Example #2
0
        /// <summary>
        /// Try to parse the given text as time.
        /// </summary>
        /// <param name="Text">A text representation of the time.</param>
        /// <param name="Time">The parsed time.</param>
        public static Boolean TryParse(String Text, out Time Time)
        {
            var Fragments = Text.Trim().Split(':');

            Byte Hour    = 0;
            Byte Minute  = 0;
            Byte Second  = 0;

            Time = Time.FromHour(0);

            if (Fragments.Length == 1)
            {

                if (!Byte.TryParse(Fragments[0], out Hour))
                    return false;

                Time = Time.FromHour(Hour);
                return true;

            }

            else if (Fragments.Length == 2)
            {

                if (!Byte.TryParse(Fragments[0], out Hour))
                    return false;

                if (!Byte.TryParse(Fragments[1], out Minute))
                    return false;

                Time = Time.FromHourMin(Hour, Minute);
                return true;

            }

            else if (Fragments.Length == 3)
            {

                if (!Byte.TryParse(Fragments[0], out Hour))
                    return false;

                if (!Byte.TryParse(Fragments[1], out Minute))
                    return false;

                if (!Byte.TryParse(Fragments[2], out Second))
                    return false;

                Time = Time.FromHourMinSec(Hour, Minute, Second);
                return true;

            }

            return false;
        }