// deadlineTimer returns a time.Timer that fires at the
// provided deadline. If the deadline is 0, it returns nil.
974323
func deadlineTimer(t time.Time) *time.Timer {
	if t.IsZero() {
		return nil
	}
	return time.NewTimer(t.Sub(time.Now()))
}
384717
func (ms *MetricSystem) StartTimer(name string) TimerToken {
	return TimerToken{
		Name:         name,
		Start:        time.Now(),
		MetricSystem: ms,
	}
}
139278
func (c *client) setExpirationTimer(d time.Duration) {
	c.mu.Lock()
	c.atmr = time.AfterFunc(d, c.authExpired)
	c.mu.Unlock()
}
435532
func (ctn *Connection) SetTimeout(deadline time.Time, socketTimeout time.Duration) error {
	ctn.deadline = deadline
	ctn.socketTimeout = socketTimeout

	return nil
}
265389
func resetTimer(t *time.Timer, d time.Duration) {
	t.Stop()
	// Very likely this doesn't actually work if we are already
	// selecting on t.C.  However we've stopped the original timer
	// so won't break transfers but may not time them out :-(
	*t = *time.NewTimer(d)
}
276173
func (b *B) resetTimer() {
	if b.timerOn {
		runtime.ReadMemStats(&memStats)
		b.startAllocs = memStats.Mallocs
		b.startBytes = memStats.TotalAlloc
		b.start = time.Now()
	}
	b.duration = 0
	b.netAllocs = 0
	b.netBytes = 0
}
123105
func Deadline(err error) error {
	if err == nil || IsDeadline(err) {
		return err
	}
	return errDeadline{err}
}
69572
func clearTimer(tp **time.Timer) {
	if t := *tp; t != nil {
		t.Stop()
		*tp = nil
	}
}
972215
func GetDateTimer() DateTimer {
	mu.Lock()
	defer mu.Unlock()

	if date == nil {
		date = &DateTime{}
	}
	return date
}
572012
func NewTimer(h Histogram) *Timer {
	return &Timer{
		h: h,
		t: time.Now(),
		u: time.Second,
	}
}
977848
func (c *C) StartTimer() {
	if !c.timerOn {
		c.start = time.Now()
		c.timerOn = true

		runtime.ReadMemStats(&memStats)
		c.startAllocs = memStats.Mallocs
		c.startBytes = memStats.TotalAlloc
	}
}
726083
func (tr Row) TimeErr(nn int, loc *time.Location) (t time.Time, err error) {
	switch data := tr[nn].(type) {
	case nil:
		// nop
	case time.Time:
		if loc == time.Local {
			t = data
		} else {
			y, mon, d := data.Date()
			h, m, s := data.Clock()
			t = time.Date(y, mon, d, h, m, s, t.Nanosecond(), loc)
		}
	case Date:
		t = data.Time(loc)
	case []byte:
		t, err = ParseTime(string(data), loc)
	case *[]byte:
		t, err = ParseTime(string(*data), loc)
	}
	return
}
642730
func (n *drainingNode) DeadlineTime() (bool, time.Time) {
	n.l.RLock()
	defer n.l.RUnlock()

	// Should never happen
	if n.node == nil || n.node.DrainStrategy == nil {
		return false, time.Time{}
	}

	return n.node.DrainStrategy.DeadlineTime()
}
846169
func NewTimer(sec time.Duration, worker *worker.Worker) (*Timer, error) {
	return &Timer{
		ticker: time.NewTicker(sec * time.Second),
		worker: worker,
	}, nil
}
1043594
func (ctl *taskController) AddTimer(ctx context.Context, delay time.Duration, title string, payload []byte) {
	// ID for the new timer. It is guaranteed to be unique when we land the
	// transaction because all ctl.saved modifications are serialized in time (see
	// MutationsCount checks in Save), and we include serial number of such
	// modification into the timer id (and suffix it with the index of the timer
	// emitted by this particular modification). If two modification happen
	// concurrently, they may temporary get same timer ID, but only one will
	// actually land.
	timerID := fmt.Sprintf("%s:%d:%d:%d",
		ctl.JobID(), ctl.InvocationID(),
		ctl.saved.MutationsCount, len(ctl.timers))

	ctl.DebugLog("Scheduling timer %q (%s) after %s", title, timerID, delay)

	now := clock.Now(ctx)
	ctl.timers = append(ctl.timers, &internal.Timer{
		Id:      timerID,
		Created: google.NewTimestamp(now),
		Eta:     google.NewTimestamp(now.Add(delay)),
		Title:   title,
		Payload: payload,
	})
}
117056
func (rt *RequestTimeAspect) StartTimer(d time.Duration) {
	timer := time.Tick(d)
	go func() {
		for {
			<-timer
			rt.calculate()
		}
	}()
}
1236960
func NewTimeLimiter(window, limit time.Duration, now time.Time) *TimeLimiter {
	l := TimeLimiter{
		since:  now,
		next:   now.Add(window),
		window: window,
		limit:  limit,
		factor: float64(window) / float64(limit),
	}
	return &l
}