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)
| 97 | // If both times have a monotonic clock reading, then the monotonic time |
| 98 | // difference will be used. The margin must be non-negative. |
| 99 | func 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 | |
| 107 | func areNonZeroTimes(x, y time.Time) bool { |
| 108 | return !x.IsZero() && !y.IsZero() |