github.com/apernet/quic-go@v0.43.1-0.20240515053213-5e9e635fd9f0/internal/utils/minmax.go (about)

     1  package utils
     2  
     3  import (
     4  	"math"
     5  	"time"
     6  )
     7  
     8  // InfDuration is a duration of infinite length
     9  const InfDuration = time.Duration(math.MaxInt64)
    10  
    11  // MinNonZeroDuration return the minimum duration that's not zero.
    12  func MinNonZeroDuration(a, b time.Duration) time.Duration {
    13  	if a == 0 {
    14  		return b
    15  	}
    16  	if b == 0 {
    17  		return a
    18  	}
    19  	return min(a, b)
    20  }
    21  
    22  // MinTime returns the earlier time
    23  func MinTime(a, b time.Time) time.Time {
    24  	if a.After(b) {
    25  		return b
    26  	}
    27  	return a
    28  }
    29  
    30  // MaxTime returns the later time
    31  func MaxTime(a, b time.Time) time.Time {
    32  	if a.After(b) {
    33  		return a
    34  	}
    35  	return b
    36  }