// TimeRange generates an arbitrary time.Time with a range
// from defines the start of the time range
// duration defines the overall duration of the time range
480746
func TimeRange(from time.Time, duration time.Duration) gopter.Gen {
	return func(genParams *gopter.GenParameters) *gopter.GenResult {
		v := from.Add(time.Duration(genParams.Rng.Int63n(int64(duration))))
		return gopter.NewGenResult(v, TimeShrinker)
	}
}
1316227
func (d Duration) ConvertToTime(tp uint8) (Time, error) {
	year, month, day := gotime.Now().Date()
	// just use current year, month and day.
	n := gotime.Date(year, month, day, 0, 0, 0, 0, gotime.Local)
	n = n.Add(d.Duration)

	t := Time{
		Time: FromGoTime(n),
		Type: mysql.TypeDatetime,
		Fsp:  d.Fsp,
	}

	return t.Convert(tp)
}
1100373
func (s *Sample) Duration() time.Duration {
	return s.End.Sub(s.Start)
}
369225
func Duration(r io.Reader) (time.Duration, error) {
	c := New(r)
	if err := c.ParseHeaders(); err != nil {
		return 0, err
	}
	return c.Duration()
}
144676
func (RealClock) Timer(d time.Duration) Timer {
	return &realTimer{t: time.NewTimer(d)}
}
736339
func (t *SimpleTrack) TimeDuration() time.Duration {
	return time.Duration(t.Duration) * time.Millisecond
}
402501
func (t *Timer) Time(f func()) {
	s := time.Now()
	f()
	t.UpdateSince(s)
}
377256
func (gc *GenericChannelAspect) StartTimer(d time.Duration) {
	timer := time.Tick(d)
	go func() {
		for {
			<-timer
			gc.calculate()
		}
	}()
}
776639
func TimeRangeAsEpochNano(expr influxql.Expr, now time.Time) (min, max int64, err error) {
	// TODO(desa): is this OK?
	_, trange, err := influxql.ConditionExpr(expr, nil)
	if err != nil {
		return 0, 0, err
	}
	tmin, tmax := trange.Min, trange.Max
	if tmin.IsZero() {
		min = time.Unix(0, influxql.MinTime).UnixNano()
	} else {
		min = tmin.UnixNano()
	}
	if tmax.IsZero() {
		max = now.UnixNano()
	} else {
		max = tmax.UnixNano()
	}
	return
}
123189
func (c *Distconf) Duration(key string, defaultVal time.Duration) *Duration {
	c.grabInfo(key)
	s := &durationConf{
		defaultVal: defaultVal,
		Duration: Duration{
			currentVal: defaultVal.Nanoseconds(),
		},
		logger: log.NewContext(c.Logger).With(logkey.DistconfKey, key),
	}
	// Note: in race conditions 's' may not be the thing actually returned
	ret, okCast := c.createOrGet(key, s).(*durationConf)
	if !okCast {
		c.Logger.Log(logkey.DistconfKey, key, "Registering key with multiple types!  FIX ME!!!!")
		return nil
	}
	return &ret.Duration
}
158325
func (g *Generator) Duration(lo, hi time.Duration) time.Duration {
	if lo == hi {
		return lo
	}
	if lo > hi {
		lo, hi = hi, lo
	}
	n := g.rand.Int63n(int64(hi) - int64(lo) + 1)
	return lo + time.Duration(n)
}
17123
func (c *crontime) DurationUntilNextEvent() time.Duration {
	return c.nextEvent().Sub(time.Now())
}
165366
func NewTimeRange(start, end string) TimeRange {
	tStart, err := time.Parse("2006-01-02", start)
	if err != nil {
		panic(`NewDate(string) requires format "2006-01-02"`)
	}

	tEnd, err := time.Parse("2006-01-02", end)
	if err != nil {
		panic(`NewDate(string) requires format "2006-01-02"`)
	}

	return TimeRange{tStart, tEnd}
}
7406
func (dt DateTime) Add(duration time.Duration) DateTime {
	t := dt.t.Add(toSeconds(duration))
	return DateTime{t: t}
}
417574
func NewTimer(fn Func, interval time.Duration, counter int) *Timer {
	id := atomic.AddInt64(&Manager.incrementID, 1)
	t := &Timer{
		ID:       id,
		fn:       fn,
		createAt: time.Now().UnixNano(),
		interval: interval,
		elapse:   int64(interval), // first execution will be after interval
		counter:  counter,
	}

	// add to manager
	Manager.ChCreatedTimer <- t
	return t
}
742207
func Duration(key string, fallback time.Duration) time.Duration {
	return DefaultClient.Duration(key, fallback)
}
512789
func timerReset(t *time.Timer, d time.Duration) {
	if !t.Stop() {
		<-t.C
	}
	t.Reset(d)
}