// SafeTimingDuration submits a statsd timing type, logging errors
13897
func (s *LoggingStatter) SafeTimingDuration(stat string, delta time.Duration, rate float32) {
	if err := s.TimingDuration(stat, delta, rate); err != nil {
		logger.WithError(err).Errorf("Error sending stat %s TimingDuration to statsd", stat)
	}
}
558993
func AlignDuration(tm time.Time, interval time.Duration) time.Duration {
	return AlignTime(tm, interval).Sub(tm)
}
1252575
func (c *StatsdClient) TimingWithSampling(stat string, delta int64, sampleRate float32) error {
	if err := checkSampleRate(sampleRate); err != nil {
		return err
	}

	if !shouldFire(sampleRate) {
		return nil // ignore this call
	}

	return c.send(stat, "%d|ms", delta, sampleRate)
}
1273856
func (cfg Config) FormatRelativeDuration(d time.Duration) string {

	isPast := d >= 0

	if d < 0 {
		d = -d
	}

	s, _ := cfg.getTimeText(d, true)

	if isPast {
		return strings.Join([]string{cfg.PastPrefix, s, cfg.PastSuffix}, "")
	} else {
		return strings.Join([]string{cfg.FuturePrefix, s, cfg.FutureSuffix}, "")
	}
}
1203223
func ConvertStringToTimeDuration(input string) (time.Duration, error) {
	output, err := strconv.Atoi(input)
	return time.Duration(output), err
}
87192
func (t Time) ConvertToDuration() (Duration, error) {
	if t.IsZero() {
		return ZeroDuration, nil
	}

	hour, minute, second := t.Clock()
	frac := t.Time.Microsecond() * 1000

	d := gotime.Duration(hour*3600+minute*60+second)*gotime.Second + gotime.Duration(frac)
	// TODO: check convert validation
	return Duration{Duration: d, Fsp: t.Fsp}, nil
}
712077
func (c *Config) ReadDuration(id string) (time.Duration, error) {
	val, ok := c.Options[id]
	if !ok {
		return time.Duration(0), fmt.Errorf("Specified config is missing from options")
	}
	dval, err := time.ParseDuration(val)
	if err != nil {
		return time.Duration(0), fmt.Errorf("Failed to parse %s as time duration: %s", val, err)
	}
	return dval, nil
}
786637
func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}
	if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
		return
	}
	t.FailNow()
}
107521
func RandomDuration(max time.Duration) time.Duration {
	if max == 0 {
		return 0
	}

	var sleepns int64
	maxSleep := big.NewInt(max.Nanoseconds())
	if j, err := rand.Int(rand.Reader, maxSleep); err == nil {
		sleepns = j.Int64()
	}

	return time.Duration(sleepns)
}
143373
func NewTimedRotatingFileHandler(
	filepath string,
	mode int,
	bufferSize int,
	when string,
	interval uint32,
	backupCount uint32,
	utc bool) (*TimedRotatingFileHandler, error) {

	var timeInterval time.Duration
	var suffix, extMatch string
	var weekday int
	// Calculate the real rollover interval, which is just the number seconds
	// between rollovers. Also set the filename suffix used when a rollover
	// occurs. Current 'when' events supported:
	// S - Seconds
	// M - Minutes
	// H - Hours
	// D - Days
	// midnight - roll over at midnight
	// W{0-6} - roll over on a certain weekday; 0 - Monday
	// Case of the 'when' specifier is not important; lower or upper case
	// will work.
	when = strings.ToUpper(when)
	switch {
	case when == "S":
		timeInterval = time.Second
		suffix = "%Y-%m-%d_%H-%M-%S"
		extMatch = `^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$`
	case when == "M":
		timeInterval = time.Minute
		suffix = "%Y-%m-%d_%H-%M"
		extMatch = `^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$`
	case when == "H":
		timeInterval = time.Hour
		suffix = "%Y-%m-%d_%H"
		extMatch = `^\d{4}-\d{2}-\d{2}_\d{2}$`
	case (when == "D") || (when == "MIDNIGHT"):
		timeInterval = Day
		suffix = "%Y-%m-%d"
		extMatch = `^\d{4}-\d{2}-\d{2}$`
	case strings.HasPrefix(when, "W"):
		timeInterval = Week
		if len(when) != 2 {
			return nil, ErrorInvalidFormat
		}
		dayChar := when[1]
		if (dayChar < '0') || (dayChar > '6') {
			return nil, ErrorInvalidFormat
		}
		// cast Python style index value to Golang style index value
		weekday = (int(dayChar-'0') + 1) % 7
		suffix = "%Y-%m-%d"
		extMatch = `^\d{4}-\d{2}-\d{2}$`
	default:
		return nil, ErrorInvalidFormat
	}
	timeInterval = time.Duration(int64(timeInterval) * int64(interval))
	baseHandler, err := NewBaseRotatingHandler(filepath, mode, bufferSize)
	if err != nil {
		return nil, err
	}
	fileInfo, err := os.Stat(baseHandler.GetFilePath())
	if err != nil {
		baseHandler.Close()
		return nil, err
	}
	object := &TimedRotatingFileHandler{
		BaseRotatingHandler: baseHandler,
		when:                when,
		weekday:             weekday,
		interval:            timeInterval,
		backupCount:         backupCount,
		suffix:              suffix,
		extMatch:            extMatch,
		utc:                 utc,
	}
	object.rolloverTime = object.computeRolloverTime(fileInfo.ModTime())
	return object, nil
}
360171
func TryToDuration(i interface{}) (d time.Duration, err error) {
	switch v := i.(type) {
	case time.Duration:
		d = v
	case *time.Duration:
		d = *v
	case int64:
		d = time.Duration(v)
	case *int64:
		d = time.Duration(*v)
	case string:
		d, err = time.ParseDuration(v)
	case *string:
		d, err = time.ParseDuration(*v)
	default:
		err = castError(i, "time.Duration")
	}
	return
}
1087115
func NewDuration(d time.Duration) *Duration {
	return &Duration{v: *NewInt64(int64(d))}
}
220061
func (b *Build) RunDuration() (duration time.Duration, ok bool) {
	if b.StartTime.IsZero() || b.CompletionTime.IsZero() {
		return 0, false
	}
	return b.CompletionTime.Sub(b.StartTime), true
}
543748
func ValidateRunOnceDurationConfig(config *runonceduration.RunOnceDurationConfig) field.ErrorList {
	allErrs := field.ErrorList{}
	if config == nil || config.ActiveDeadlineSecondsLimit == nil {
		return allErrs
	}
	if *config.ActiveDeadlineSecondsLimit <= 0 {
		allErrs = append(allErrs, field.Invalid(field.NewPath("activeDeadlineSecondsOverride"), config.ActiveDeadlineSecondsLimit, "must be greater than 0"))
	}
	return allErrs
}
607144
func FriendlyDuration(when *time.Time, now time.Time) string {
	if when == nil {
		return ""
	}
	return UserFriendlyDuration(*when, now)
}
840452
func (self *Commands) IsDuration(value interface{}) error {
	if _, err := timeutil.ParseDuration(fmt.Sprintf("%v", value)); err == nil {
		return nil
	} else {
		return fmt.Errorf("Expected duration value")
	}
}
752315
func GroupCheckDuration(duration time.Duration) func(*Group) {
	return func(g *Group) {
		g.groupCheckDuration = duration
	}
}