Ejemplo n.º 1
0
        public TkInterval ElementAt(int index)
        {
            if (index >= Count())
            {
                return(TkInterval.Null());
            }

            return(_tkIntervals[index]);
        }
Ejemplo n.º 2
0
        public TkInterval ExtractInterval(TimeSpan timeSpan)
        {
            var orderedIntervals      = GetOrderedIntervals();
            var intervalToExtractFrom = orderedIntervals.FirstOrDefault(o => o.Length() > timeSpan);

            if (intervalToExtractFrom.isNull)
            {
                return(TkInterval.Null());
            }

            var index             = indexOf(intervalToExtractFrom);
            var extractedInterval = new TkInterval();

            if (index != -1)
            {
                extractedInterval = intervalToExtractFrom.ExtractInterval(timeSpan);

                intervalToExtractFrom.SubtractTimeSpan(timeSpan);

                var updatedInterval = new TkInterval()
                {
                    id    = intervalToExtractFrom.id,
                    start = intervalToExtractFrom.start,
                    end   = intervalToExtractFrom.end
                };

                // If we have less than 5 minutes left, remove it
                if (updatedInterval.Length() < TimeSpan.FromMinutes(5))
                {
                    Remove(updatedInterval);
                }
                else
                {
                    _tkIntervals[index] = updatedInterval;
                    _tkIntervals        = GetOrderedIntervals();
                }
            }

            return(extractedInterval);
        }