// NewDateRangeQuery creates a new Query for ranges
// of date values.
// Date strings are parsed using the DateTimeParser configured in the
//  top-level config.QueryDateTimeParser
// Either, but not both endpoints can be nil.
767894
func NewDateRangeQuery(start, end time.Time) *DateRangeQuery {
	return NewDateRangeInclusiveQuery(start, end, nil, nil)
}
1338725
func FormatQueryParameters(queries []Query) url.Values {
	params := url.Values{}
	for _, query := range queries {
		params.Add(string(query.Key), strings.Join(query.Values, ","))
	}

	return params
}
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
}
676070
func DateRange(start, end time.Time) time.Time {
	return time.Unix(0, int64(Number(int(start.UnixNano()), int(end.UnixNano())))).UTC()
}
152535
func NewDate(s string) Date {
	t, err := time.Parse("2006-01-02", s)

	if err != nil {
		panic(`NewDate(string) requires format "2006-01-02"`)
	}

	return Date(t)
}
1051291
func NewFromRawQuery(rawQuery string) *QueryString {
	qs := new(QueryString)
	qs.fields = make(map[string]string)

	for {
		i := strings.IndexRune(rawQuery, '=')
		if i == -1 {
			break
		}
		name := rawQuery[:i]
		rawQuery = rawQuery[i+1:]

		i = strings.IndexFunc(rawQuery, charClassDetector(1, 1))
		var value string
		if i == -1 {
			value = rawQuery
		} else {
			value = rawQuery[:i]
			rawQuery = rawQuery[i+1:]
		}

		qs.fields[name] = value

		if i == -1 {
			break
		}
	}

	return qs
}
936146
func NewRegexpQuery(regexp string) *RegexpQuery {
	q := &RegexpQuery{newFtsQueryBase()}
	q.options["regexp"] = regexp
	return q
}
1021126
func QueryAll(db DB, dst interface{}, query string, args ...interface{}) error {
	return Default.QueryAll(db, dst, query, args...)
}
1361465
func NewDateFacet(field string, size int) *DateFacet {
	mq := &DateFacet{}
	mq.data.Field = field
	mq.data.Size = size
	return mq
}
1061426
func (q *DateRangeQuery) Field(field string) *DateRangeQuery {
	q.options["field"] = field
	return q
}
696509
func (q *Query) RawQuery(stmt string, args ...interface{}) *Query {
	q.RawSQL = &clause{stmt, args}
	return q
}
67996
func (tx *Tx) FormatQuery(dst []byte, query string, params ...interface{}) []byte {
	return tx.db.FormatQuery(dst, query, params...)
}
736657
func NewMockQuery(ctrl *gomock.Controller) *MockQuery {
	mock := &MockQuery{ctrl: ctrl}
	mock.recorder = &MockQueryMockRecorder{mock}
	return mock
}
1097468
func NewQueryHandler(handler QueryHandler) http.Handler {
	return handlerFunc(func(ctx context.Context, enc *objconv.StreamEncoder, dec *objconv.Decoder) error {
		req := queryRequest{}
		res := queryResponse{enc: enc}

		if err := dec.Decode(&req); err != nil {
			return err
		}

		if err := handler.ServeQuery(ctx, &res, &QueryRequest{
			From:          req.Range.From,
			To:            req.Range.To,
			Interval:      req.Interval,
			Targets:       req.Targets,
			MaxDataPoints: req.MaxDataPoints,
		}); err != nil {
			return err
		}

		return res.close()
	})
}
364175
func QueryEvents(c context.Context, q *datastore.Query) ([]*api.Event, error) {
	var ev []Event
	if err := datastore.GetAll(c, q.Order("-When"), &ev); err != nil {
		return nil, transient.Tag.Apply(err)
	}
	out := make([]*api.Event, len(ev))
	for i, e := range ev {
		out[i] = &api.Event{}
		if err := proto.Unmarshal(e.Event, out[i]); err != nil {
			return nil, errors.Annotate(err, "failed to unmarshal Event with ID %d", e.ID).Err()
		}
	}
	return out, nil
}
868656
func NewRange(start, end Date) (term Range) {
	term.Start = start
	term.End = end
	return
}
184757
func (v *Validator) validateRangeQueries(ns string, rangeQueriesInfo []*kvrwset.RangeQueryInfo, updates *privacyenabledstate.PubUpdateBatch) (bool, error) {
	for _, rqi := range rangeQueriesInfo {
		if valid, err := v.validateRangeQuery(ns, rqi, updates); !valid || err != nil {
			return valid, err
		}
	}
	return true, nil
}