// NumberToDuration converts number to Duration.
514945
func NumberToDuration(number int64, fsp int) (Duration, error) {
	if number > TimeMaxValue {
		// Try to parse DATETIME.
		if number >= 10000000000 { // '2001-00-00 00-00-00'
			if t, err := ParseDatetimeFromNum(nil, number); err == nil {
				dur, err1 := t.ConvertToDuration()
				return dur, errors.Trace(err1)
			}
		}
		dur, err1 := MaxMySQLTime(fsp).ConvertToDuration()
		terror.Log(err1)
		return dur, ErrOverflow.GenWithStackByArgs("Duration", strconv.Itoa(int(number)))
	} else if number < -TimeMaxValue {
		dur, err1 := MaxMySQLTime(fsp).ConvertToDuration()
		terror.Log(err1)
		dur.Duration = -dur.Duration
		return dur, ErrOverflow.GenWithStackByArgs("Duration", strconv.Itoa(int(number)))
	}
	var neg bool
	if neg = number < 0; neg {
		number = -number
	}

	if number/10000 > TimeMaxHour || number%100 >= 60 || (number/100)%100 >= 60 {
		return ZeroDuration, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(number))
	}
	t := Time{Time: FromDate(0, 0, 0, int(number/10000), int((number/100)%100), int(number%100), 0), Type: mysql.TypeDuration, Fsp: fsp}
	dur, err := t.ConvertToDuration()
	if err != nil {
		return ZeroDuration, errors.Trace(err)
	}
	if neg {
		dur.Duration = -dur.Duration
	}
	return dur, nil
}
292082
func (s *GetMaintenanceWindowOutput) SetDuration(v int64) *GetMaintenanceWindowOutput {
	s.Duration = &v
	return s
}
254245
func roundDuration(in int64) int64 {
	abs := in
	if abs < 0 {
		abs = -abs
	}
	if abs <= 10 { // 10s -> don't round
		return in
	} else if abs <= 60 { // 1min -> round to 10s
		return round(in, 10)
	} else if abs <= 600 { // 10min -> round to 1min
		return round(in, 60)
	} else if abs <= 3600 { // 1h -> round to 10min
		return round(in, 600)
	} else if abs <= 3600*24 { // 24h -> round to 1h
		return round(in, 3600)
	} else if abs <= 3600*24*7 { // 7d -> round to 1d
		return round(in, 3600*24)
	} else if abs <= 3600*24*30 { // 30d -> round to 7d
		return round(in, 3600*24*7)
	}
	// default to rounding to months
	return round(in, 3600*24*30)
}
1247668
func (d *defaulter) AsDuration(v Valuer, dv time.Duration) time.Duration {
	value, err := v.Value()
	if err != nil {
		d.logValuerError(err)
		return dv
	}
	dvalue, err := time.ParseDuration(value)
	if err != nil {
		d.logFormatError("duration", err)
		return dv
	}
	return dvalue
}
867490
func (c *Context) GlobalDuration(name string) time.Duration {
	return lookupDuration(name, c.globalSet)
}
351829
func (s *MaintenanceWindowIdentity) SetDuration(v int64) *MaintenanceWindowIdentity {
	s.Duration = &v
	return s
}
126144
func gifDuration(g *gif.GIF) int {
	var total int
	for _, d := range g.Delay {
		total += d
	}

	// total is in 100ths of a second, multiply by 10 to get milliseconds
	return total * 10
}
565002
func (d *Decoder) Duration() (time.Duration, error) {
	if d == nil {
		return 0, errors.New("can't calculate the duration of a nil pointer")
	}
	d.ReadInfo()
	if err := d.Err(); err != nil {
		return 0, err
	}
	duration := time.Duration(float64(d.NumSampleFrames) / float64(d.SampleRate) * float64(time.Second))
	return duration, nil
}
426398
func (s *TimeSpan) SetDuration(v string) *TimeSpan {
	s.Duration = &v
	return s
}
293273
func randDuration(n time.Duration) time.Duration {
	return time.Duration(random.Math.Int63n(int64(n)))
}
295928
func ToNormalizedDuration(d time.Duration, u time.Duration) int64 {
	return int64(d / u)
}
301217
func timeDurationToHumanizedDuration(duration time.Duration) humanizedDuration {
	r := humanizedDuration{}
	if duration.Seconds() < 60.0 {
		r.Seconds = int64(duration.Seconds())
		return r
	}
	if duration.Minutes() < 60.0 {
		remainingSeconds := math.Mod(duration.Seconds(), 60)
		r.Seconds = int64(remainingSeconds)
		r.Minutes = int64(duration.Minutes())
		return r
	}
	if duration.Hours() < 24.0 {
		remainingMinutes := math.Mod(duration.Minutes(), 60)
		remainingSeconds := math.Mod(duration.Seconds(), 60)
		r.Seconds = int64(remainingSeconds)
		r.Minutes = int64(remainingMinutes)
		r.Hours = int64(duration.Hours())
		return r
	}
	remainingHours := math.Mod(duration.Hours(), 24)
	remainingMinutes := math.Mod(duration.Minutes(), 60)
	remainingSeconds := math.Mod(duration.Seconds(), 60)
	r.Hours = int64(remainingHours)
	r.Minutes = int64(remainingMinutes)
	r.Seconds = int64(remainingSeconds)
	r.Days = int64(duration.Hours() / 24)
	return r
}
499149
func (s *RecencyDimension) SetDuration(v string) *RecencyDimension {
	s.Duration = &v
	return s
}
958355
func (c *Client) Duration(stat string, duration time.Duration, rate float64) error {
	return c.send(stat, rate, "%d|ms", millisecond(duration))
}
410036
func RandomDuration(max time.Duration) time.Duration {
	randomVal, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
	if err != nil {
		return max / 2
	}
	return time.Duration(randomVal.Int64())
}
384528
func (s *DescribeEventsInput) SetDuration(v int64) *DescribeEventsInput {
	s.Duration = &v
	return s
}
1212143
func (c *Config) GetDuration(s string) time.Duration {
	return c.config.GetDuration(s)
}