Пример #1
0
        private TimeOffsets(List <Entry> entries)
        {
            this.entries = entries;

            var baseOffset = entries[entries.Count - 1].offset;

            // generate optimized offset getters for typical cases
            // fallback to generic getter for other cases
            if (entries.Count == 1)             // base offset only
            {
                offsetGetter = dateTime => baseOffset;
            }
            else if (entries.Count == 2)             // one offset
            {
                var offset1 = entries[0];
                offsetGetter = dateTime => dateTime < offset1.at ? baseOffset : offset1.offset;
            }
            else
            {
                // generic getter
                offsetGetter = dateTime =>
                               entries[ListUtils.BinarySearch(entries, 0, entries.Count, e => e.at > dateTime)].offset;
            }
        }
Пример #2
0
 int ITimeGaps.BinarySearch(int begin, int end, Predicate <TimeGap> lessThanValueBeingSearched)
 {
     return(ListUtils.BinarySearch(items, begin, end, lessThanValueBeingSearched));
 }