// MaxTimeSignature sets the maximum time signature
// The time signature (meter) is a notational convention to
// specify how many beats are in each bar (or measure).
168555
func (ta *TrackAttributes) MaxTimeSignature(timeSignature int) *TrackAttributes {
	ta.intAttributes["max_time_signature"] = timeSignature
	return ta
}
30751
func OutputSignatureSuccessNonKeybase(m libkb.MetaContext, keyID uint64, signatureTime time.Time) error {
	arg := keybase1.OutputSignatureSuccessNonKeybaseArg{
		KeyID:    fmt.Sprintf("%X", keyID),
		SignedAt: keybase1.TimeFromSeconds(signatureTime.Unix()),
	}
	return m.UIs().PgpUI.OutputSignatureSuccessNonKeybase(m.Ctx(), arg)
}
444673
func translateTimestampUntil(timestamp metav1.Time) string {
	if timestamp.IsZero() {
		return "<unknown>"
	}

	return duration.HumanDuration(time.Until(timestamp.Time))
}
1203857
func TimestampFromSigned(s *Signed) (*SignedTimestamp, error) {
	ts := Timestamp{}
	if err := defaultSerializer.Unmarshal(*s.Signed, &ts); err != nil {
		return nil, err
	}
	if err := IsValidTimestampStructure(ts); err != nil {
		return nil, err
	}
	sigs := make([]Signature, len(s.Signatures))
	copy(sigs, s.Signatures)
	return &SignedTimestamp{
		Signatures: sigs,
		Signed:     ts,
	}, nil
}
494525
func MaxTime(a, b time.Time) time.Time {
	if a.After(b) {
		return a
	}
	return b
}
792931
func (mSig *Multisignature) AddSignature(sig []byte, index int) {
	newSigIndex := mSig.BitArray.NumTrueBitsBefore(index)
	// Signature already exists, just replace the value there
	if mSig.BitArray.GetIndex(index) {
		mSig.Sigs[newSigIndex] = sig
		return
	}
	mSig.BitArray.SetIndex(index, true)
	// Optimization if the index is the greatest index
	if newSigIndex == len(mSig.Sigs) {
		mSig.Sigs = append(mSig.Sigs, sig)
		return
	}
	// Expand slice by one with a dummy element, move all elements after i
	// over by one, then place the new signature in that gap.
	mSig.Sigs = append(mSig.Sigs, make([]byte, 0))
	copy(mSig.Sigs[newSigIndex+1:], mSig.Sigs[newSigIndex:])
	mSig.Sigs[newSigIndex] = sig
}
1311107
func MaxTime(t1, t2 time.Time) time.Time {
	if t1.After(t2) {
		return t1
	}
	return t2
}
1371724
func ParseSignatureMust(s string) Signature {
	sig, err := ParseSignature(s)
	if err != nil {
		panic(err)
	}
	return sig
}
875342
func Time(from time.Time, maxDelta time.Duration) time.Time {
	globalLk.Lock()
	defer globalLk.Unlock()
	return globalGen.Time(from, maxDelta)
}
317112
func ParsePrettySignature(content []byte, signatureKey string) (*JSONSignature, error) {
	var contentMap map[string]json.RawMessage
	err := json.Unmarshal(content, &contentMap)
	if err != nil {
		return nil, fmt.Errorf("error unmarshalling content: %s", err)
	}
	sigMessage, ok := contentMap[signatureKey]
	if !ok {
		return nil, ErrMissingSignatureKey
	}

	var signatureBlocks []jsParsedSignature
	err = json.Unmarshal([]byte(sigMessage), &signatureBlocks)
	if err != nil {
		return nil, fmt.Errorf("error unmarshalling signatures: %s", err)
	}

	js := newJSONSignature()
	js.signatures = make([]jsSignature, len(signatureBlocks))

	for i, signatureBlock := range signatureBlocks {
		protectedBytes, err := joseBase64UrlDecode(signatureBlock.Protected)
		if err != nil {
			return nil, fmt.Errorf("base64 decode error: %s", err)
		}
		var protectedHeader map[string]interface{}
		err = json.Unmarshal(protectedBytes, &protectedHeader)
		if err != nil {
			return nil, fmt.Errorf("error unmarshalling protected header: %s", err)
		}

		formatLength, ok := readIntFromMap("formatLength", protectedHeader)
		if !ok {
			return nil, errors.New("missing formatted length")
		}
		encodedTail, ok := readStringFromMap("formatTail", protectedHeader)
		if !ok {
			return nil, errors.New("missing formatted tail")
		}
		formatTail, err := joseBase64UrlDecode(encodedTail)
		if err != nil {
			return nil, fmt.Errorf("base64 decode error on tail: %s", err)
		}
		if js.formatLength == 0 {
			js.formatLength = formatLength
		} else if js.formatLength != formatLength {
			return nil, errors.New("conflicting format length")
		}
		if len(js.formatTail) == 0 {
			js.formatTail = formatTail
		} else if bytes.Compare(js.formatTail, formatTail) != 0 {
			return nil, errors.New("conflicting format tail")
		}

		header := jsHeader{
			Algorithm: signatureBlock.Header.Algorithm,
			Chain:     signatureBlock.Header.Chain,
		}
		if signatureBlock.Header.JWK != nil {
			publicKey, err := UnmarshalPublicKeyJWK([]byte(signatureBlock.Header.JWK))
			if err != nil {
				return nil, fmt.Errorf("error unmarshalling public key: %s", err)
			}
			header.JWK = publicKey
		}
		js.signatures[i] = jsSignature{
			Header:    header,
			Signature: signatureBlock.Signature,
			Protected: signatureBlock.Protected,
		}
	}
	if js.formatLength > len(content) {
		return nil, errors.New("invalid format length")
	}
	formatted := make([]byte, js.formatLength+len(js.formatTail))
	copy(formatted, content[:js.formatLength])
	copy(formatted[js.formatLength:], js.formatTail)
	js.indent = detectJSONIndent(formatted)
	js.payload = joseBase64UrlEncode(formatted)

	return js, nil
}
869729
func MaxUnitForDuration(d time.Duration) (int64, Unit) {
	var (
		currMultiple int64
		currUnit     = Nanosecond
		dUnixNanos   = d.Nanoseconds()
		isNegative   bool
	)
	if dUnixNanos < 0 {
		dUnixNanos = -dUnixNanos
		isNegative = true
	}
	for _, u := range unitsByDurationDesc {
		// The unit is guaranteed to be valid so it's safe to ignore error here.
		duration, _ := u.Value()
		if dUnixNanos < duration.Nanoseconds() {
			continue
		}
		durationUnixNanos := int64(duration)
		quotient := dUnixNanos / durationUnixNanos
		remainder := dUnixNanos - quotient*durationUnixNanos
		if remainder != 0 {
			continue
		}
		currMultiple = quotient
		currUnit = u
		break
	}
	if isNegative {
		currMultiple = -currMultiple
	}
	return currMultiple, currUnit
}
735475
func (r *DateRule) Max(max time.Time) *DateRule {
	r.max = max
	return r
}
596372
func (f *FreqDist) max() (string, error) {
	if len(f.Samples) == 0 {
		return "", fmt.Errorf("No Samples loaded, please add samples before getting max")
	}

	max := maxFreq{}
	for key, val := range f.Samples {
		if val > max.Val {
			max.Key = key
			max.Val = val
		}
	}
	return max.Key, nil
}
795857
func (e PrecisionTiming) durationToMs(x time.Duration) float64 {
	return float64(x) / float64(time.Millisecond)
}
1345276
func MaxWaitTime(value time.Duration) Option {
	return func(o *Options) {
		o.maxWaitTime = value
	}
}
811376
func setEmitTimeMetrics() {
	Set("goroutines", runtime.NumGoroutine())

	var mem runtime.MemStats
	runtime.ReadMemStats(&mem)
	SetNested("memory", "heap_alloc", mem.HeapAlloc)
	SetNested("memory", "sys", mem.Sys)
}
711356
func translateTimestampSince(timestamp metav1.Time) string {
	if timestamp.IsZero() {
		return "<unknown>"
	}

	return duration.HumanDuration(time.Since(timestamp.Time))
}