FromHour() public static method

Create a new time based on the given hour.
public static FromHour ( Byte Hour ) : Time
Hour Byte The hour.
return Time
Example #1
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);
        }
Example #2
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, Byte EndTime)
 {
     return(new TimeRange(TimeRange.StartTime, Time.FromHour(EndTime)));
 }
Example #3
0
 /// <summary>
 /// Create a new time range having the given starting time.
 /// </summary>
 /// <param name="StartTime">The starting time.</param>
 public static TimeRange From(Byte StartTime)
 {
     return(new TimeRange(Time.FromHour(StartTime), null));
 }
Example #4
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;
        }