// tApplyRangeMode is the same as applyRangeMode for date/time axis/ranges.
770378
func tApplyRangeMode(mode RangeMode, val time.Time, step TimeDelta, upper bool) (bound time.Time, tic time.Time) {
	if mode.Fixed {
		bound = mode.TValue
		if upper {
			tic = RoundDown(val, step)
		} else {
			tic = RoundUp(val, step)
		}
		return
	}
	if mode.Constrained { // TODO(vodo) use T...
		sval := val.Unix()
		if sval < int64(mode.Lower) {
			sval = int64(mode.Lower)
		} else if sval > int64(mode.Upper) {
			sval = int64(mode.Upper)
		}
		val = time.Unix(sval, 0).In(val.Location())
	}

	switch mode.Expand {
	case ExpandToTic:
		if upper {
			val = RoundUp(val, step)
		} else {
			val = RoundDown(val, step)
		}
		return val, val
	case ExpandNextTic:
		if upper {
			tic = RoundUp(val, step)
		} else {
			tic = RoundDown(val, step)
		}
		s := tic.Unix()
		if math.Abs(float64(s-val.Unix())/float64(step.Seconds())) < 0.15 {
			if upper {
				val = RoundUp(time.Unix(s+step.Seconds()/2, 0).In(val.Location()), step)
			} else {
				val = RoundDown(time.Unix(s-step.Seconds()/2, 0).In(val.Location()), step)
			}
		} else {
			val = tic
		}
		return val, val
	case ExpandABit:
		if upper {
			tic = RoundDown(val, step)
			val = time.Unix(tic.Unix()+step.Seconds()/2, 0).In(val.Location())
		} else {
			tic = RoundUp(val, step)
			val = time.Unix(tic.Unix()-step.Seconds()/2, 0).In(val.Location())
		}
		return

	}

	return val, val
}
706436
func (_m *API) ExecExitCode(ctx context.Context, execID string) (int, error) {
	ret := _m.Called(ctx, execID)

	var r0 int
	if rf, ok := ret.Get(0).(func(context.Context, string) int); ok {
		r0 = rf(ctx, execID)
	} else {
		r0 = ret.Get(0).(int)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
		r1 = rf(ctx, execID)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
53623
func (r *Range) TFixed(min, max time.Time, delta TimeDelta) {
	r.MinMode.Fixed, r.MaxMode.Fixed = true, true
	r.MinMode.TValue, r.MaxMode.TValue = min, max
	r.TicSetting.TDelta = delta
}
20684
func (s *Server) InvalidateNodeDataRange(node Node, off int64, size int64) error {
	return s.invalidateNode(node, off, size)
}
1081762
func ConvertGoLayoutToUnicode(layout string) string {
	// Year
	layout = strings.Replace(layout, "20", "yy", -1)
	layout = strings.Replace(layout, "06", "yy", -1)

	// Month
	layout = strings.Replace(layout, "January", "MMMM", -1)
	layout = strings.Replace(layout, "Jan", "MMM", -1)
	layout = strings.Replace(layout, "01", "MM", -1)
	layout = strings.Replace(layout, "1", "M", -1)

	// Day
	layout = strings.Replace(layout, "02", "dd", -1)
	layout = strings.Replace(layout, "_2", "d", -1)

	// Weekday
	layout = strings.Replace(layout, "Mon", "EEE", -1)
	layout = strings.Replace(layout, "Monday", "EEEE", -1)

	// Hour
	layout = strings.Replace(layout, "03", "hh", -1)
	layout = strings.Replace(layout, "3", "h", -1)
	layout = strings.Replace(layout, "15", "HH", -1)
	layout = strings.Replace(layout, "PM", "a", -1)

	// Minute
	layout = strings.Replace(layout, "04", "mm", -1)

	// Second
	layout = strings.Replace(layout, "05", "ss", -1)

	// Timezone
	layout = strings.Replace(layout, "MST", "zzz", -1)
	layout = strings.Replace(layout, "-0700", "ZZZ", -1)
	layout = strings.Replace(layout, "GMT-07:00", "ZZZZ", -1)

	return layout
}
429575
func (tr Ranges) addRangeInPlace(r Range) {
	if r.IsEmpty() {
		return
	}

	e := tr.findFirstNotBefore(r)
	for e != nil {
		lr := e.Value.(Range)
		ne := e.Next()
		if !lr.Overlaps(r) {
			break
		}
		r = r.Merge(lr)
		tr.sortedRanges.Remove(e)
		e = ne
	}
	if e == nil {
		tr.sortedRanges.PushBack(r)
		return
	}
	tr.sortedRanges.InsertBefore(r, e)
}
716635
func (r Range) Merge(other Range) Range {
	start := MinTime(r.Start, other.Start)
	end := MaxTime(r.End, other.End)
	return Range{Start: start, End: end}
}
192044
func (f *fragment) rangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) {
	b := f.row(uint64(bitDepth))
	keep1 := NewRow() // GTE
	keep2 := NewRow() // LTE

	// Filter any bits that don't match the current bit value.
	for i := int(bitDepth - 1); i >= 0; i-- {
		row := f.row(uint64(i))
		bit1 := (predicateMin >> uint(i)) & 1
		bit2 := (predicateMax >> uint(i)) & 1

		// GTE predicateMin
		// If bit is set then remove all unset columns not already kept.
		if bit1 == 1 {
			b = b.Difference(b.Difference(row).Difference(keep1))
		} else {
			// If bit is unset then add columns with set bit to keep.
			// Don't bother to compute this on the final iteration.
			if i > 0 {
				keep1 = keep1.Union(b.Intersect(row))
			}
		}

		// LTE predicateMin
		// If bit is zero then remove all set bits not in excluded bitmap.
		if bit2 == 0 {
			b = b.Difference(row.Difference(keep2))
		} else {
			// If bit is set then add columns for set bits to exclude.
			// Don't bother to compute this on the final iteration.
			if i > 0 {
				keep2 = keep2.Union(b.Difference(row))
			}
		}
	}

	return b, nil
}
1373292
func splitRange(value string) (string, string, error) {
	p := strings.SplitN(value, ",", 2)
	if len(p) != 2 || p[0] == "" || p[1] == "" {
		return "", "", fmt.Errorf("date: failed to parse date range '%s'", value)
	}
	return strings.ToLower(p[0][1:]), strings.ToLower(p[1][:len(p[1])-1]), nil
}
1186394
func (dd *xlsxCellDataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValidationOperator) error {
	formula1 := fmt.Sprintf("%d", f1)
	formula2 := fmt.Sprintf("%d", f2)

	switch o {
	case DataValidationOperatorBetween:
		if f1 > f2 {
			tmp := formula1
			formula1 = formula2
			formula2 = tmp
		}
	case DataValidationOperatorNotBetween:
		if f1 > f2 {
			tmp := formula1
			formula1 = formula2
			formula2 = tmp
		}
	}

	dd.Formula1 = formula1
	dd.Formula2 = formula2
	dd.Type = convDataValidationType(t)
	dd.Operator = convDataValidationOperatior(o)
	return nil
}
594572
func (g *GossipTimestampRange) Encode(w io.Writer, pver uint32) error {
	return WriteElements(w,
		g.ChainHash[:],
		g.FirstTimestamp,
		g.TimestampRange,
	)
}
860850
func range_(thread *Thread, fn *Builtin, args Tuple, kwargs []Tuple) (Value, error) {
	var start, stop, step int
	step = 1
	if err := UnpackPositionalArgs("range", args, kwargs, 1, &start, &stop, &step); err != nil {
		return nil, err
	}

	// TODO(adonovan): analyze overflow/underflows cases for 32-bit implementations.

	var n int
	switch len(args) {
	case 1:
		// range(stop)
		start, stop = 0, start
		fallthrough
	case 2:
		// range(start, stop)
		if stop > start {
			n = stop - start
		}
	case 3:
		// range(start, stop, step)
		switch {
		case step > 0:
			if stop > start {
				n = (stop-1-start)/step + 1
			}
		case step < 0:
			if start > stop {
				n = (start-1-stop)/-step + 1
			}
		default:
			return nil, fmt.Errorf("range: step argument must not be zero")
		}
	}

	return rangeValue{start: start, stop: stop, step: step, len: n}, nil
}
132920
func (v *Vector) ApplyRange(from, to int, m Mutator) error {
	if to < from {
		return ErrInvertedRange
	}
	if from == to {
		return nil
	}
	var (
		la   Equaler
		old  position
		min  = v.min.pos
		max  = v.max.pos
		delQ []query
	)
	if !v.Relaxed && (to <= min || from >= max) {
		return ErrOutOfRange
	}
	if v.Relaxed {
		if from < min {
			v.SetRange(from, min, v.Zero)
		}
		if max < to {
			v.SetRange(max, to, v.Zero)
		}
	}

	var end int
	old.pos, end, old.val, _ = v.StepAt(from)
	la = old.val
	la = m(la)
	if to <= end {
		v.SetRange(from, to, la)
		return nil
	}
	if !la.Equal(old.val) {
		switch {
		case from > min:
			if !la.Equal(v.t.Floor(lower(from)).(*position).val) {
				v.t.Insert(&position{from, la})
			} else {
				v.t.Delete(query(from))
			}
		case from < min:
			v.SetRange(from, min, la)
		default:
			*v.min = position{from, la}
		}
	}

	var tail *position
	v.t.DoRange(func(c llrb.Comparable) (done bool) {
		p := c.(*position)
		if p.pos == max {
			// We should be at v.t.Max(), but don't stop
			// just in case there is more. We want to fail
			// noisily if max < v.t.Max().
			return
		}
		if p.pos == to {
			tail = p
			return
		}
		old = *p // Needed for fix-up of last step if to is not at a step boundary.
		p.val = m(p.val)
		if p.pos != min && p.val.Equal(la) {
			delQ = append(delQ, query(p.pos))
		}
		la = p.val
		return
	}, query(end), upper(to))
	for _, d := range delQ {
		v.t.Delete(d)
	}
	if to < max {
		if tail == nil {
			prev := v.t.Floor(lower(to)).(*position)
			if old.pos != from && !old.val.Equal(prev.val) {
				v.t.Insert(&position{to, old.val})
			}
		} else {
			prev := v.t.Floor(lower(tail.pos)).(*position)
			if tail.val != nil && tail.val.Equal(prev.val) {
				v.t.Delete(query(tail.pos))
			}
		}
		return nil
	}

	if v.Relaxed && to > max {
		v.SetRange(max, to, m(v.Zero))
	}

	return nil
}
1123078
func (s *FragmentSelector) SetTimestampRange(v *TimestampRange) *FragmentSelector {
	s.TimestampRange = v
	return s
}
1124027
func (dt *DateTime) InRange(min, max time.Time) *DateTime {
	if !((dt.value.After(min) || dt.value.Equal(min)) &&
		(dt.value.Before(max) || dt.value.Equal(max))) {
		dt.chain.fail(
			"\nexpected datetime in range:\n min: %s\n max: %s\n\nbut got: %s",
			min, max, dt.value)
	}
	return dt
}
642020
func (g GridType) XRange() (min, max float64) {
	min = g.xTicks[0]
	max = g.xTicks[len(g.xTicks)-1]
	return
}
555419
func DayInRange(t time.Time, minDay, maxDay int) bool {
	return (minDay <= t.Day()) && (t.Day() <= maxDay)
}