// TimeRangeAsEpochNano extracs the min and max epoch times from the expression
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
}
536547
func DurationProto(d time.Duration) *durpb.Duration {
	nanos := d.Nanoseconds()
	secs := nanos / 1e9
	nanos -= secs * 1e9
	return &durpb.Duration{
		Seconds: secs,
		Nanos:   int32(nanos),
	}
}
1255588
func OptDialerTimeout(d time.Duration) Option {
	return func(h *HCI) error {
		h.dialerTmo = d
		return nil
	}
}
251778
func (t TimeRange) IsZero() bool {
	return t.Min.IsZero() && t.Max.IsZero()
}
493830
func DurationFromProto(duration *google_duration.Duration) time.Duration {
	if duration == nil {
		return 0
	}
	return time.Duration((duration.Seconds * int64(time.Second)) + int64(duration.Nanos))
}
925734
func TimestampAgo(ts *gogotypes.Timestamp) string {
	if ts == nil {
		return ""
	}
	t, err := gogotypes.TimestampFromProto(ts)
	if err != nil {
		panic(err)
	}
	return humanize.Time(t)
}
1372785
func (s *stateTransitions) timer(address string) *clock.Timer {
	s.Lock()
	t, ok := s.timers[address]
	s.Unlock()
	if !ok {
		return nil
	}
	return t.Timer
}
1009069
func addtimerLocked(t *Timer) {
	// when must never be negative; otherwise timerproc will overflow
	// during its delta calculation and never expire other runtime·timers.
	if t.when < 0 {
		t.when = 1<<63 - 1
	}
	t.i = len(timers.t)
	timers.t = append(timers.t, t)
	siftupTimer(t.i)
	if t.i == 0 {
		// siftup moved to top: new earliest deadline.
		if timers.sleeping {
			timers.sleeping = false
			select {
			case timers.sleep <- timers.sleeping:
			default:
			}
		}
		/*
			if timers.rescheduling {
				timers.rescheduling = false
				select {
				case timers.reschedule <- timers.rescheduling:
				default:
				}
			}
		*/
	}
	if !timers.created {
		timers.created = true
		timers.sleep = make(chan bool, 1)
		timers.reschedule = make(chan bool, 1)
		timers.T = time.NewTimer(time.Duration(t.when - Nanotime()))
		go timerproc()
	}
}
69572
func clearTimer(tp **time.Timer) {
	if t := *tp; t != nil {
		t.Stop()
		*tp = nil
	}
}
612393
func EventRemoveTimeout(timer int) error {
	var err C.virError
	ret := C.virEventRemoveTimeoutWrapper((C.int)(timer), &err)
	if ret < 0 {
		return makeError(&err)
	}

	return nil
}
501855
func (f *Factory) Timer(options metrics.TimerOptions) metrics.Timer {
	timer := &timer{
		timers: make([]metrics.Timer, len(f.factories)),
	}
	for i, factory := range f.factories {
		timer.timers[i] = factory.Timer(options)
	}
	return timer
}
619618
func (f *FakeClock) NewTimer(d time.Duration) Timer {
	f.lock.Lock()
	defer f.lock.Unlock()
	stopTime := f.time.Add(d)
	ch := make(chan time.Time, 1) // Don't block!
	timer := &fakeTimer{
		fakeClock: f,
		waiter: fakeClockWaiter{
			targetTime: stopTime,
			destChan:   ch,
		},
	}
	f.waiters = append(f.waiters, timer.waiter)
	return timer
}
771179
func (a *Astilectron) watchNoAccept(timeout time.Duration, chanAccepted chan bool) {
	//check timeout
	if timeout == 0 {
		timeout = DefaultAcceptTCPTimeout
	}
	var t = time.NewTimer(timeout)
	defer t.Stop()
	for {
		select {
		case <-chanAccepted:
			return
		case <-t.C:
			astilog.Errorf("No TCP connection has been accepted in the past %s", timeout)
			a.dispatcher.dispatch(Event{Name: EventNameAppNoAccept, TargetID: targetIDApp})
			a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
			return
		}
	}
}
17123
func (c *crontime) DurationUntilNextEvent() time.Duration {
	return c.nextEvent().Sub(time.Now())
}
1054535
func ParseOrZero(layout, value string) time.Time {
	t, err := time.Parse(layout, value)
	if err != nil {
		return TimeRFC3339Zero()
	}
	return t
}
855796
func (m *Time) ProtoTime() *ProtoTime {
	if m == nil {
		return &ProtoTime{}
	}
	return &ProtoTime{
		Timestamp: Timestamp{
			Seconds: m.Time.Unix(),
			Nanos:   int32(m.Time.Nanosecond()),
		},
	}
}
537826
func NewTimeDecider(timesource timesrc.TimeSource, remainingTimeThreshold time.Duration) oracle.OracleSource {
	return &timedecider{timesource, remainingTimeThreshold}
}