// timeRangesCoverEntries returns true if the time ranges fully cover the entries.
5743
func timeRangesCoverEntries(merger timeRangeMerger, entries []IndexEntry) (covers bool) {
	if len(entries) == 0 {
		return true
	}

	mustCover := entries[0].MinTime
	ts, ok := merger.Pop()

	for len(entries) > 0 && ok {
		switch {
		// If the tombstone does not include mustCover, we
		// know we do not fully cover every entry.
		case ts.Min > mustCover:
			return false

		// Otherwise, if the tombstone covers the rest of
		// the entry, consume it and bump mustCover to the
		// start of the next entry.
		case ts.Max >= entries[0].MaxTime:
			entries = entries[1:]
			if len(entries) > 0 {
				mustCover = entries[0].MinTime
			}

		// Otherwise, we're still inside of an entry, and
		// so the tombstone must adjoin the current tombstone.
		default:
			if ts.Max >= mustCover {
				mustCover = ts.Max + 1
			}
			ts, ok = merger.Pop()
		}
	}

	return len(entries) == 0
}
529453
func NewTimer() *Timer {
	return &Timer{t: time.NewTimer(time.Duration(math.MaxInt64))}
}
759863
func excludeEntries(e []IndexEntry, tr TimeRange) []IndexEntry {
	for i := range e {
		if e[i].OverlapsTimeRange(tr.Min, tr.Max) {
			e = e[i:]
			break
		}
	}

	for i := range e {
		if !e[i].OverlapsTimeRange(tr.Min, tr.Max) {
			e = e[:i]
			break
		}
	}

	return e
}
575290
func (c *Call) MaxTimes(n int) *Call {
	c.maxCalls = n
	if c.minCalls == 1 {
		c.minCalls = 0
	}
	return c
}
765382
func (ad *Attempt_Data) PurgeTimestamps() {
	if ad == nil {
		return
	}
	ad.Created = nil
	ad.Modified = nil
	if p, _ := ad.AttemptType.(TimestampPurger); p != nil {
		p.PurgeTimestamps()
	}
}
207683
func (m *LocalDatasetShardsManagerInMemory) purgeExpiredEntries() {
	for {
		func() {
			m.Lock()
			cutoverLimit := time.Now().Add(-24 * time.Hour)
			var oldShardNames []string
			for name, tc := range m.name2Channel {
				if tc.lastWriteAt.Before(cutoverLimit) {
					oldShardNames = append(oldShardNames, name)
				}
			}
			for _, name := range oldShardNames {
				m.doDelete(name)
			}
			m.Unlock()
			time.Sleep(1 * time.Hour)
		}()
	}
}
987937
func (s *DataTransferProgress) SetEstimatedTimeToCompletionInSeconds(v int64) *DataTransferProgress {
	s.EstimatedTimeToCompletionInSeconds = &v
	return s
}
372104
func (s *UpdateOriginEndpointInput) SetTimeDelaySeconds(v int64) *UpdateOriginEndpointInput {
	s.TimeDelaySeconds = &v
	return s
}
537826
func NewTimeDecider(timesource timesrc.TimeSource, remainingTimeThreshold time.Duration) oracle.OracleSource {
	return &timedecider{timesource, remainingTimeThreshold}
}
1095210
func TimeAtOrIn(from, at time.Time, in time.Duration) time.Time {
	if in == 0 {
		return at
	}
	return from.Add(in)
}
926444
func (c *config) GetTimeErr(key string, args ...interface{}) (time.Time, error) {
	val, err := c.Get(key, args...)
	if err != nil {
		return time.Time{}, err
	}
	tval, err := cfg.ToTime(val)
	c.log(TOTIME, err, toVarArgs(args, val, tval)...)
	return tval, err
}
1204136
func NewRegisteredTimer(name string, r Registry) Timer {
	c := NewTimer()
	if nil == r {
		r = DefaultRegistry
	}
	r.Register(name, c)
	return c
}
53998
func (pgb *ChainDB) NumAddressIntervals(addr string, grouping dbtypes.TimeBasedGrouping) (int64, error) {
	ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
	defer cancel()
	return retrieveAddressTxsCount(ctx, pgb.db, addr, grouping.String())
}
214313
func IsExpiredAtOrIn(from time.Time, until time.Duration, at time.Time, in time.Duration) (time.Time, bool) {
	expiration := TimeAtOrIn(from, at, in)
	if expiration.IsZero() {
		return expiration, false
	}

	return expiration, expiration.Before(time.Now().Add(until))
}
478101
func (kva *KvAlert) EnumerateWithinTimeRange(
	timeStart time.Time,
	timeEnd time.Time,
	resourceType api.ResourceType,
) ([]*api.Alert, error) {
	allAlerts := []*api.Alert{}
	resourceAlerts := []*api.Alert{}
	var err error

	kv := kva.GetKvdbInstance()
	if resourceType != 0 {
		resourceAlerts, err = kva.getResourceSpecificAlerts(resourceType, kv)
		if err != nil {
			return nil, err
		}
	} else {
		resourceAlerts, err = kva.getAllAlerts(kv)
		if err != nil {
			return nil, err
		}
	}
	for _, v := range resourceAlerts {
		alertTime := prototime.TimestampToTime(v.Timestamp)
		if alertTime.Before(timeEnd) && alertTime.After(timeStart) {
			allAlerts = append(allAlerts, v)
		}
	}
	return allAlerts, nil
}
319248
func (e *DockerRegistryServiceController) watchForDockerURLChanges() {
	workFn := func() bool {
		key, quit := e.registryLocationQueue.Get()
		if quit {
			return true
		}
		defer e.registryLocationQueue.Done(key)

		if err := e.syncRegistryLocationHandler(); err == nil {
			// this means the request was successfully handled.  We should "forget" the item so that any retry
			// later on is reset
			e.registryLocationQueue.Forget(key)

		} else {
			// if we had an error it means that we didn't handle it, which means that we want to requeue the work
			utilruntime.HandleError(fmt.Errorf("error syncing service, it will be retried: %v", err))
			e.registryLocationQueue.AddRateLimited(key)
		}

		return false
	}

	for {
		if workFn() {
			return
		}
	}
}
699118
func (c *DNSCache) cleanupExpiredEntries(expires time.Time) ([]string, time.Time) {
	timediff := int(expires.Sub(c.lastCleanup).Seconds())
	startTime := c.lastCleanup
	expiredEntries := []string{}
	for i := 0; i < int(timediff); i++ {
		expiredTime := c.lastCleanup.Add(time.Second)
		key := expiredTime.Unix()
		c.lastCleanup = expiredTime
		entries, exists := c.cleanup[key]
		if !exists {
			continue
		}
		expiredEntries = append(expiredEntries, entries...)
		delete(c.cleanup, key)
	}

	result := []string{}
	for _, name := range KeepUniqueNames(expiredEntries) {
		if entries, exists := c.forward[name]; exists {
			if !c.removeExpired(entries, c.lastCleanup, time.Time{}) {
				continue
			}
			result = append(result, name)
		}
	}
	return result, startTime
}