Example #1
0
        public static IntervalRange ParseInterval(string interval)
        {
            Match match = IntervalRegex.Match(interval);

            if (!match.Success)
            {
                return(null);
            }

            // Create the time objects
            Time startingTime, endingTime;

            try
            {
                startingTime = new Time
                {
                    Hour = byte.Parse(match.Groups[1].Value), Minute = byte.Parse(match.Groups[2].Value)
                };
                endingTime = new Time
                {
                    Hour = byte.Parse(match.Groups[3].Value), Minute = byte.Parse(match.Groups[4].Value)
                };
            }
            catch (ArgumentOutOfRangeException)
            {
                return(null);
            }

            // Get the timeout and interval type (which don't require additional validation)
            long timeout = long.Parse(match.Groups[5].Value);
            IntervalRangeType intervalRangeType = IntervalRangeTypeUtil.GetFromChar(match.Groups[6].Value[0]);

            return(new IntervalRange(startingTime, endingTime, timeout, intervalRangeType));
        }
Example #2
0
        public IntervalRange(Time startingTime, Time endingTime, long timeout,
                             IntervalRangeType intervalRangeType = IntervalRangeType.Minutes)
        {
            _startingTime = startingTime;
            _endingTime   = endingTime;
            // Validate that the ending time is actually bigger than the startingTime
            if (endingTime <= startingTime)
            {
                throw new InvalidOperationException("Ending time is not larger the starting time");
            }

            // Raise an error when we overflow
            checked
            {
                _timeout = timeout * (int)intervalRangeType;
            }
        }