// TimeRange is used as a parameter for request creation. Adds TimeRange constraint to a request.
// It will get values in range [from, to[ ('to' is exclusive).
186975
func TimeRange(from, to time.Time) func(Call) error {
	return TimeRangeUint64(uint64(from.UnixNano()/1e6), uint64(to.UnixNano()/1e6))
}
1249501
func (c *Context) Timer(data Data) *Timer {
	context := c.New(data)
	context.Log(Data{"at": "start"})
	return &Timer{
		Started:  time.Now(),
		TimeUnit: context.TimeUnit,
		context:  context,
		_statter: c._statter.dup(),
	}
}
1308685
func DurationStrToSecondsInt(s string) *int {
	if s == "" {
		return nil
	}
	duration, err := time.ParseDuration(s)
	if err != nil {
		logrus.Errorf("Failed to parse duration:%v", s)
		return nil
	}
	r := (int)(duration.Seconds())
	return &r

}
1193802
func (e *IndexEntry) OverlapsTimeRange(min, max int64) bool {
	return e.MinTime <= max && e.MaxTime >= min
}
554789
func (t TimeRange) MaxTimeNano() int64 {
	if t.Max.IsZero() {
		return MaxTime
	}
	return t.Max.UnixNano()
}
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}
}
659793
func (r *Run) RequestedAtTime() (time.Time, error) {
	return time.Parse(time.RFC3339, r.RequestedAt)
}
343492
func (tr *TimeRange) InsertMax(t time.Time) {
	if !tr.HaveMax {
		tr.Max = t
		tr.HaveMax = true
	} else if IsGreaterThan(t, tr.Max, false) {
		tr.Max = t
	}
}
1000135
func (r *RateLimiter) Try() (ok bool, remaining time.Duration) {
	r.mtx.Lock()
	defer r.mtx.Unlock()
	now := time.Now()
	if l := r.times.Len(); l < r.limit {
		r.times.PushBack(now)
		return true, 0
	}
	frnt := r.times.Front()
	if diff := now.Sub(frnt.Value.(time.Time)); diff < r.interval {
		return false, r.interval - diff
	}
	frnt.Value = now
	r.times.MoveToBack(frnt)
	return true, 0
}
136635
func (m *Mock) Timer(d time.Duration) *Timer {
	ch := make(chan time.Time)
	t := &Timer{
		C:    ch,
		c:    ch,
		mock: m,
		next: m.now.Add(d),
	}
	m.addTimer(t)
	return t
}
1034667
func YearRange(y int) TimeRange {
	return TimeRange{
		time.Date(y, time.January, 1, 0, 0, 0, 0, time.UTC),
		time.Date(y+1, time.January, 0, 0, 0, 0, 0, time.UTC),
	}
}
653071
func Dial(timeout, keepAlive time.Duration) p.Plugin {
	return All(Timeouts{Dial: timeout, KeepAlive: keepAlive})
}
1072914
func parseRange(rangeStr string) ([]uint, error) {
	var values []uint
	if rangeStr == "" {
		return []uint{}, nil
	}

	// split ranges based on "," char
	rangeList := strings.Split(rangeStr, ",")

	for _, subrange := range rangeList {
		minMax := strings.Split(strings.TrimSpace(subrange), "-")
		if len(minMax) == 2 {
			min, err := strconv.Atoi(minMax[0])
			if err != nil {
				log.Errorf("Invalid range: %v", subrange)
				return nil, err
			}
			max, err := strconv.Atoi(minMax[1])
			if err != nil {
				log.Errorf("Invalid range: %v", subrange)
				return nil, err
			}

			// some error checking
			if min > max || min < 0 || max < 0 {
				log.Errorf("Invalid range values: %v", subrange)
				return nil, fmt.Errorf("invalid range values")
			}

			for i := min; i <= max; i++ {
				values = append(values, uint(i))
			}
		} else if len(minMax) == 1 {
			val, err := strconv.Atoi(minMax[0])
			if err != nil {
				log.Errorf("Invalid range: %v", subrange)
				return nil, err
			}

			values = append(values, uint(val))
		} else {
			log.Errorf("Invalid range: %v", subrange)
			return nil, fmt.Errorf("invalid range format")
		}
	}

	return values, nil
}
498755
func RequestTimeout(d time.Duration) Option {
	return func(o *Options) {
		o.CallOptions.RequestTimeout = d
	}
}
901347
func (b *DynamoDBBackend) DeleteRange(ctx context.Context, startKey, endKey []byte) error {
	if len(startKey) == 0 {
		return trace.BadParameter("missing parameter startKey")
	}
	if len(endKey) == 0 {
		return trace.BadParameter("missing parameter endKey")
	}
	// keep fetching and deleting until no records left,
	// keep the very large limit, just in case if someone else
	// keeps adding records
	for i := 0; i < backend.DefaultLargeLimit/100; i++ {
		result, err := b.getRecords(ctx, prependPrefix(startKey), prependPrefix(endKey), 100, nil)
		if err != nil {
			return trace.Wrap(err)
		}
		if len(result.records) == 0 {
			return nil
		}
		requests := make([]*dynamodb.WriteRequest, 0, len(result.records))
		for _, record := range result.records {
			requests = append(requests, &dynamodb.WriteRequest{
				DeleteRequest: &dynamodb.DeleteRequest{
					Key: map[string]*dynamodb.AttributeValue{
						hashKeyKey: {
							S: aws.String(hashKey),
						},
						fullPathKey: {
							S: aws.String(record.FullPath),
						},
					},
				},
			})
		}
		input := dynamodb.BatchWriteItemInput{
			RequestItems: map[string][]*dynamodb.WriteRequest{
				b.Tablename: requests,
			},
		}

		if _, err = b.svc.BatchWriteItemWithContext(ctx, &input); err != nil {
			return trace.Wrap(err)
		}
	}
	return trace.ConnectionProblem(nil, "not all items deleted, too many requests")
}
1158287
func AddTimer(d time.Duration, callback CallbackFunc) *Timer {
	if d < MIN_TIMER_INTERVAL {
		d = MIN_TIMER_INTERVAL
	}

	t := &Timer{
		fireTime: time.Now().Add(d),
		interval: d,
		callback: callback,
		repeat:   true,
	}
	timerHeapLock.Lock()
	t.addseq = nextAddSeq // set addseq when locked
	nextAddSeq += 1

	heap.Push(&timerHeap, t)
	timerHeapLock.Unlock()
	return t
}
665469
func MustParseRange(s string) Range {
	r, err := ParseRange(s)
	if err != nil {
		panic(`semver: ParseRange(` + s + `): ` + err.Error())
	}
	return r
}