// DurationForNowSubDt8 returns a duartion struct between a Dt8 value and the current time.
328198
func DurationForNowSubDt8(dt8 int32) (time.Duration, error) {
	t, err := TimeForDt8(dt8)
	if err != nil {
		var d time.Duration
		return d, err
	}
	now := time.Now()
	return now.Sub(t), nil
}
1358624
func TimeSinceNowAsString(t time.Time) string {
	return DurationToString(time.Now().Sub(t))
}
742207
func Duration(key string, fallback time.Duration) time.Duration {
	return DefaultClient.Duration(key, fallback)
}
1087115
func NewDuration(d time.Duration) *Duration {
	return &Duration{v: *NewInt64(int64(d))}
}
513838
func (b *backoff) Duration() (dur time.Duration) {
	// Zero-values are nonsensical, so we use
	// them to apply defaults
	if b.Max == 0 {
		b.Max = 10 * time.Second
	}

	if b.Initial == 0 {
		b.Initial = 100 * time.Millisecond
	}

	// calculate this duration
	if dur = time.Duration(1 << uint(b.attempts)); dur > 0 {
		dur = dur * b.Initial
	} else {
		dur = b.Max
	}

	if b.Jitter > 0 {
		dur = dur + time.Duration(rand.Intn(int(b.Jitter)))
	}

	// bump attempts count
	b.attempts++

	return dur
}
544805
func (d *TimePeriod_Duration) ToSeconds() (int64, error) {
	// Decompose the duration into a slice of [duration, <int64>, <unit>].
	m := regexp.MustCompile(durationRegex).FindStringSubmatch(d.Duration)
	if len(m) != 3 {
		return 0, errors.Reason("duration must match regex %q", durationRegex).Err()
	}
	n, err := strconv.ParseInt(m[1], 10, 64)
	if err != nil {
		return 0, errors.Reason("duration must not exceed %q", int64(math.MaxInt64)).Err()
	}
	var mul int64
	switch m[2] {
	case "s":
		// 1 second.
		mul = 1
	case "m":
		// 60 seconds.
		mul = 60
	case "h":
		// 60 minutes.
		mul = 3600
	case "d":
		// 24 hours.
		mul = 86400
	case "mo":
		// 30 days.
		mul = 2592000
	}
	if n > math.MaxInt64/mul {
		n = math.MaxInt64
	} else {
		n *= mul
	}
	return n, nil
}
1297126
func (ta *TrackAttributes) TargetDuration(duration int) *TrackAttributes {
	ta.intAttributes["target_duration_ms"] = duration
	return ta
}
1278635
func (c *client) Duration(key string, fallback time.Duration) time.Duration {
	if d, err := time.ParseDuration(c.Getenv(key)); err == nil {
		return d
	}

	return fallback
}
175574
func (s *promScope) TimingDuration(stat string, delta time.Duration) {
	s.autoSummary(s.statName(stat) + "_seconds").Observe(delta.Seconds())
}
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),
	}
}
1228832
func NewDuration(duration string) (d *Duration, err error) {
	dur, err := readDuration(duration)
	tmp := Duration(dur)
	return &tmp, err
}
50313
func (t ntpTimeShort) Duration() time.Duration {
	t64 := uint64(t)
	sec := (t64 >> 16) * nanoPerSec
	frac := (t64 & 0xffff) * nanoPerSec >> 16
	return time.Duration(sec + frac)
}
582532
func (t *Time) Sub(t1 *Time) Duration {
	var duration gotime.Duration
	if t.Type == mysql.TypeTimestamp && t1.Type == mysql.TypeTimestamp {
		// TODO: Consider time_zone variable.
		a, _ := t.Time.GoTime(gotime.Local)
		b, _ := t1.Time.GoTime(gotime.Local)
		duration = a.Sub(b)
	} else {
		seconds, microseconds, neg := calcTimeDiff(t.Time, t1.Time, 1)
		duration = gotime.Duration(seconds*1e9 + microseconds*1e3)
		if neg {
			duration = -duration
		}
	}

	fsp := t.Fsp
	if fsp < t1.Fsp {
		fsp = t1.Fsp
	}
	return Duration{
		Duration: duration,
		Fsp:      fsp,
	}
}
23004
func Duration(val string) (*duration.Duration, error) {
	var r *duration.Duration
	err := jsonpb.UnmarshalString(val, r)
	return r, err
}
104743
func (r Row) GetDuration(colIdx int, fillFsp int) types.Duration {
	col := r.c.columns[colIdx]
	dur := *(*int64)(unsafe.Pointer(&col.data[r.idx*8]))
	return types.Duration{Duration: time.Duration(dur), Fsp: fillFsp}
}
1197236
func Duration(max time.Duration) time.Duration {
	nbNanoseconds := 1 + int(rand.Int63n(max.Nanoseconds()))
	return time.Duration(nbNanoseconds) * time.Nanosecond
}
597023
func truncateDuration(d time.Duration) time.Duration {
	for _, t := range durTransactions {
		if d > t.threshold {
			return d.Round(t.round)
		}
	}
	return d
}