MCPcopy
hub / github.com/google/go-cmp / EquateApproxTime

Function EquateApproxTime

cmp/cmpopts/equate.go:99–105  ·  view source on GitHub ↗

EquateApproxTime returns a [cmp.Comparer] option that determines two non-zero [time.Time] values to be equal if they are within some margin of one another. If both times have a monotonic clock reading, then the monotonic time difference will be used. The margin must be non-negative.

(margin time.Duration)

Source from the content-addressed store, hash-verified

97// If both times have a monotonic clock reading, then the monotonic time
98// difference will be used. The margin must be non-negative.
99func EquateApproxTime(margin time.Duration) cmp.Option {
100 if margin < 0 {
101 panic("margin must be a non-negative number")
102 }
103 a := timeApproximator{margin}
104 return cmp.FilterValues(areNonZeroTimes, cmp.Comparer(a.compare))
105}
106
107func areNonZeroTimes(x, y time.Time) bool {
108 return !x.IsZero() && !y.IsZero()

Callers 1

TestOptionsFunction · 0.85

Calls 2

FilterValuesFunction · 0.92
ComparerFunction · 0.92

Tested by 1

TestOptionsFunction · 0.68