WithinDuration asserts that the two times are within duration delta of each other. assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{})
| 1318 | // |
| 1319 | // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second) |
| 1320 | func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool { |
| 1321 | if h, ok := t.(tHelper); ok { |
| 1322 | h.Helper() |
| 1323 | } |
| 1324 | |
| 1325 | dt := expected.Sub(actual) |
| 1326 | if dt < -delta || dt > delta { |
| 1327 | return Fail(t, fmt.Sprintf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt), msgAndArgs...) |
| 1328 | } |
| 1329 | |
| 1330 | return true |
| 1331 | } |
| 1332 | |
| 1333 | // WithinRange asserts that a time is within a time range (inclusive). |
| 1334 | // |