// durToMsec converts a duration to a millisecond specified string. If the
// user selected a positive value that rounds to 0 ms, then we will use 1 ms
// so they get a short delay, otherwise Consul will translate the 0 ms into
// a huge default delay.
343900
func durToMsec(dur time.Duration) string {
	ms := dur / time.Millisecond
	if dur > 0 && ms == 0 {
		ms = 1
	}
	return fmt.Sprintf("%dms", ms)
}
446253
func (c *Config) ReadDurationDefault(id string, defaultValue time.Duration) time.Duration {
	val, err := c.ReadDuration(id)
	if err != nil {
		return defaultValue
	}
	return val
}
8057
func DurationFunc(v string) (interface{}, error) {
	s, err := time.ParseDuration(v)
	if err != nil {
		return nil, fmt.Errorf("unable to parser duration: %v", err)
	}
	return s, err
}
1106401
func (*StdClock) NowNanoseconds() int64 {
	sec, nsec, _ := now()
	return sec*1e9 + int64(nsec)
}
1138998
func (p *parserMixin) DurationVar(target *time.Duration) {
	p.SetValue(newDurationValue(target))
}
892596
func DurationToTS(d time.Duration) uint64 {
	return oracle.ComposeTS(d.Nanoseconds()/int64(time.Millisecond), 0)
}
578142
func Dur(max time.Duration) time.Duration {
	return time.Duration(Int63n(int64(max)))
}
736339
func (t *SimpleTrack) TimeDuration() time.Duration {
	return time.Duration(t.Duration) * time.Millisecond
}
998503
func (d Duration) Compare(o Duration) int {
	if d.Duration > o.Duration {
		return 1
	} else if d.Duration == o.Duration {
		return 0
	} else {
		return -1
	}
}
446913
func GetDurationOrDefault(key string, defVal time.Duration) time.Duration {
	viperLock.RLock()
	defer viperLock.RUnlock()

	if val := viper.GetDuration(key); val != 0 {
		return val
	}

	return defVal
}
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
}
831014
func Duration(input interface{}) (output time.Duration, err error) {
	switch castValue := input.(type) {
	case string:
		output, err = time.ParseDuration(castValue)
		if err != nil {
			outputInt, errCast := Int(castValue)
			if errCast != nil {
				err = NewCastError("Could not convert to time.Duration")
				return
			}
			output = time.Duration(int(outputInt))
		}
		return
	case time.Duration:
		output = castValue
		return
	default:
		outputInt, errCast := Int(castValue)
		if errCast == nil {
			output = time.Duration(int(outputInt))
			return
		}
		err = NewCastError("Could not convert to time.Duration")
	}
	return
}
800624
func (c *Client) Duration(name string, duration time.Duration) error {
	return c.send(name, 1, "%d|ms", millisecond(duration))
}
1335390
func CheckDelay(d time.Duration) Option {
	return func(c *Client) error {
		c.checkDelay = d
		return nil
	}
}
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),
	}
}
50313
func (t ntpTimeShort) Duration() time.Duration {
	t64 := uint64(t)
	sec := (t64 >> 16) * nanoPerSec
	frac := (t64 & 0xffff) * nanoPerSec >> 16
	return time.Duration(sec + frac)
}
1139675
func (c *Client) TimeInMilliseconds(name string, value float64, tags []string, rate float64) error {
	return c.send(name, value, timingSuffix, tags, rate)
}