// ToSeconds returns this duration in seconds. Clamps to math.MaxInt64.
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
}
1021563
func (t *Timedelta) Duration() time.Duration {
	return t.Days*24*time.Hour +
		t.Seconds*time.Second +
		t.Microseconds*time.Microsecond +
		t.Milliseconds*time.Millisecond +
		t.Minutes*time.Minute +
		t.Hours*time.Hour +
		t.Weeks*7*24*time.Hour
}
369774
func (c *Parser) Duration() (time.Duration, error) {
	if c == nil {
		return 0, errors.New("can't calculate the duration of a nil pointer")
	}
	if c.ID == [4]byte{} || c.AvgBytesPerSec == 0 {
		err := c.Parse()
		if err != nil {
			return 0, nil
		}
	}
	switch c.Format {
	case WavFormatID:
		return c.wavDuration()
	default:
		return 0, ErrFmtNotSupported
	}
}
800624
func (c *Client) Duration(name string, duration time.Duration) error {
	return c.send(name, 1, "%d|ms", millisecond(duration))
}
2882
func newTimeval(timeout time.Duration) (*unix.Timeval, error) {
	if timeout < time.Microsecond {
		return nil, &timeoutError{}
	}
	return &unix.Timeval{
		Sec:  int64(timeout / time.Second),
		Usec: int64(timeout % time.Second / time.Microsecond),
	}, nil
}
98358
func timeToEpochMilliseconds(t time.Time) int64 {
	return t.UnixNano() / int64(time.Millisecond)
}
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
}
1159915
func (d Duration) Time(unit Duration, bpm int) time.Duration {
	val := (60.0 / float64(bpm)) / (float64(d.Value) / 4.0) / (float64(unit.Value) / 4.0)

	for i := 0; i < d.Dots; i++ {
		val += val / 2.0
	}

	if d.Triplet {
		val = val / 3.0
	}

	return time.Duration(val * ns)
}
253786
func FormattedSecondsToMax8Chars(t time.Duration) (string, error) {
	sec := t.Seconds()
	min := t.Minutes()
	hour := t.Hours()

	if sec < 1.0 {
		// 0.999999 sec -> 0.99 sec
		return fmt.Sprintf("%.2f sec", sec), nil // 8
	} else if sec < 10.0 {
		// 9.99999 sec -> 9.99 sec
		return fmt.Sprintf("%.2f sec", sec), nil // 8
	} else if sec < 600 {
		// 599,999 sec -> 599 sec
		return fmt.Sprintf("%.f sec", sec), nil // 7
	} else if min < 60 {
		// 59,999 min -> 59.9 min
		return fmt.Sprintf("%.1f min", min), nil // 8
	} else if hour < 10 {
		// 9.999 hour -> 9.9 hour
		return fmt.Sprintf("%.1f hour", hour), nil // 8
	} else if hour < 1000 {
		// 999,999 hour -> 999 hour
		return fmt.Sprintf("%.f hour", hour), nil // 8
	}

	return "", fmt.Errorf("time (%f hour) greater than max allowed (999 hour)", hour)
}
869718
func (s *Stopwatch) ElapsedSeconds() float64 {
	s.RLock()
	defer s.RUnlock()

	return s.Elapsed().Seconds()
}
892596
func DurationToTS(d time.Duration) uint64 {
	return oracle.ComposeTS(d.Nanoseconds()/int64(time.Millisecond), 0)
}
973940
func fromDuration(t time.Duration) microseconds {
	return microseconds(float64(t) / float64(time.Microsecond))
}
7406
func (dt DateTime) Add(duration time.Duration) DateTime {
	t := dt.t.Add(toSeconds(duration))
	return DateTime{t: t}
}
1242155
func toTime(ts *timestamp.Timestamp) (result time.Time) {
	// We want a zero-ed out time.Time, not one set to the epoch.
	if t, err := ptypes.Timestamp(ts); err == nil {
		result = t
	}
	return
}
1197236
func Duration(max time.Duration) time.Duration {
	nbNanoseconds := 1 + int(rand.Int63n(max.Nanoseconds()))
	return time.Duration(nbNanoseconds) * time.Nanosecond
}
465949
func NewUnixTimeFromSeconds(seconds float64) UnixTime {
	return NewUnixTimeFromDuration(time.Duration(seconds * float64(time.Second)))
}
377912
func (p *parserMixin) Duration() (target *time.Duration) {
	target = new(time.Duration)
	p.DurationVar(target)
	return
}