Beispiel #1
0
        public static TimeParseResult ParseStartEndTimes(string starts, string ends, bool checkEndTime)
        {
            if (string.IsNullOrEmpty(starts))
            {
                return(new TimeParseResult(false, "Start time not provided", TimeSpan.MinValue, TimeSpan.MaxValue));
            }
            if (checkEndTime && string.IsNullOrEmpty(ends))
            {
                return(new TimeParseResult(false, "End time not provided", TimeSpan.MinValue, TimeSpan.MaxValue));
            }
            BoolMessageItem <TimeSpan> boolMessageItem = TimeHelper.Parse(starts);
            TimeSpan timeSpan  = TimeSpan.MinValue;
            TimeSpan timeSpan2 = TimeSpan.MaxValue;

            if (!boolMessageItem.Success)
            {
                return(new TimeParseResult(false, boolMessageItem.Message, TimeSpan.MinValue, TimeSpan.MaxValue));
            }
            timeSpan = boolMessageItem.Item;
            if (checkEndTime)
            {
                BoolMessageItem <TimeSpan> boolMessageItem2 = TimeHelper.Parse(ends);
                if (!boolMessageItem2.Success)
                {
                    return(new TimeParseResult(false, boolMessageItem2.Message, TimeSpan.MinValue, TimeSpan.MaxValue));
                }
                timeSpan2 = boolMessageItem2.Item;
                if (timeSpan2 < timeSpan)
                {
                    return(new TimeParseResult(false, "End time must be greater than or equal to start time.", timeSpan, timeSpan2));
                }
            }
            return(new TimeParseResult(true, string.Empty, timeSpan, timeSpan2));
        }
Beispiel #2
0
        public static TimeParseResult ParseStartEndTimes(string startAndEndTimeRange)
        {
            string text = "-";
            int    num  = startAndEndTimeRange.IndexOf(text);

            if (num < 0)
            {
                text = "to";
                num  = startAndEndTimeRange.IndexOf(text);
                if (num < 0)
                {
                    BoolMessageItem <TimeSpan> boolMessageItem = TimeHelper.Parse(startAndEndTimeRange);
                    TimeSpan start = TimeSpan.MinValue;
                    if (!boolMessageItem.Success)
                    {
                        return(new TimeParseResult(false, boolMessageItem.Message, start, TimeSpan.MaxValue));
                    }
                    start = boolMessageItem.Item;
                    return(new TimeParseResult(true, string.Empty, start, TimeSpan.MaxValue));
                }
            }
            string starts = startAndEndTimeRange.Substring(0, num);
            string ends   = startAndEndTimeRange.Substring(num + text.Length);

            return(TimeHelper.ParseStartEndTimes(starts, ends, true));
        }
Beispiel #3
0
        public static TimeSpan ToTime(this string txt)
        {
            if (string.IsNullOrEmpty(txt))
            {
                return(TimeSpan.MinValue);
            }
            string strTime = txt.Trim().ToLower();

            return(TimeHelper.Parse(strTime).Item);
        }