TryParseTimeSpanInt() публичный статический Метод

Convert a raw time string to a standard integer accepted by CourseTimeSpan constructor
public static TryParseTimeSpanInt ( string rawTime, byte &result ) : bool
rawTime string Raw time string in the form 11:30 or 11
result byte
Результат bool
Пример #1
0
        public static bool TryParseTimeString(string time, out CourseSectionTime result)
        {
            MatchCollection collection = timeStringRegex.Matches(time);

            result = new CourseSectionTime();
            List <CourseSectionTimeSpan> meetTimes = new List <CourseSectionTimeSpan>();

            if (collection.Count > 0)
            {
                foreach (Match match in collection)
                {
                    CourseSectionTimeSpan span;
                    DayOfWeek             day;
                    switch (match.Groups["day"].ToString().ToLowerInvariant())
                    {
                    case "monday":
                        day = DayOfWeek.Monday;
                        break;

                    case "tuesday":
                        day = DayOfWeek.Tuesday;
                        break;

                    case "wednesday":
                        day = DayOfWeek.Wednesday;
                        break;

                    case "thursday":
                        day = DayOfWeek.Thursday;
                        break;

                    case "friday":
                        day = DayOfWeek.Friday;
                        break;

                    default:
                        return(false);
                    }
                    span.Day = day;

                    byte start, end;
                    if (!UTCourseSectionTimeSpan.TryParseTimeSpanInt(match.Groups["start"].ToString(), out start))
                    {
                        return(false);
                    }
                    if (!UTCourseSectionTimeSpan.TryParseTimeSpanInt(match.Groups["end"].ToString(), out end))
                    {
                        return(false);
                    }

                    meetTimes.Add(new CourseSectionTimeSpan(day, start, end));
                }
                result.MeetTimes = meetTimes;
                return(true);
            }
            return(false);
        }
Пример #2
0
        public static bool TryParseRawTime(string time, out CourseSectionTime result)
        {
            if (time == "TBA")
            {
                result = new CourseSectionTime()
                {
                    TBA = true
                };
                return(true);
            }
            Regex           regex      = new Regex("((?<day>(mo)|(tu)|(we)|(th)|(fr)) (?<start>[0-9][0-9]?:[0-9]{2}) (?<end>[0-9][0-9]?:[0-9]{2}))+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            MatchCollection collection = regex.Matches(time);

            result = new CourseSectionTime();
            List <CourseSectionTimeSpan> meetTimes = new List <CourseSectionTimeSpan>();

            if (collection.Count > 0)
            {
                foreach (Match match in collection)
                {
                    CourseSectionTimeSpan span;
                    DayOfWeek             day;
                    switch (match.Groups["day"].ToString().ToLowerInvariant())
                    {
                    case "mo":
                        day = DayOfWeek.Monday;
                        break;

                    case "tu":
                        day = DayOfWeek.Tuesday;
                        break;

                    case "we":
                        day = DayOfWeek.Wednesday;
                        break;

                    case "th":
                        day = DayOfWeek.Thursday;
                        break;

                    case "fr":
                        day = DayOfWeek.Friday;
                        break;

                    default:
                        return(false);
                    }
                    span.Day = day;

                    byte start, end;
                    if (!UTCourseSectionTimeSpan.TryParseTimeSpanInt(match.Groups["start"].ToString(), out start))
                    {
                        return(false);
                    }
                    if (!UTCourseSectionTimeSpan.TryParseTimeSpanInt(match.Groups["end"].ToString(), out end))
                    {
                        return(false);
                    }

                    meetTimes.Add(new CourseSectionTimeSpan(day, start, end));
                }
                result.MeetTimes = meetTimes;
                return(true);
            }
            return(false);
        }