github.com/metacubex/mihomo@v1.18.5/transport/tuic/congestion/minmax.go (about) 1 package congestion 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 // AbsDuration returns the absolute value of a time duration 23 func AbsDuration(d time.Duration) time.Duration { 24 if d >= 0 { 25 return d 26 } 27 return -d 28 } 29 30 // MinTime returns the earlier time 31 func MinTime(a, b time.Time) time.Time { 32 if a.After(b) { 33 return b 34 } 35 return a 36 } 37 38 // MinNonZeroTime returns the earlist time that is not time.Time{} 39 // If both a and b are time.Time{}, it returns time.Time{} 40 func MinNonZeroTime(a, b time.Time) time.Time { 41 if a.IsZero() { 42 return b 43 } 44 if b.IsZero() { 45 return a 46 } 47 return MinTime(a, b) 48 } 49 50 // MaxTime returns the later time 51 func MaxTime(a, b time.Time) time.Time { 52 if a.After(b) { 53 return a 54 } 55 return b 56 }