MCPcopy
hub / github.com/stretchr/testify / WithinDuration

Function WithinDuration

assert/assertions.go:1372–1383  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

1370//
1371// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
1372func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool {
1373 if h, ok := t.(tHelper); ok {
1374 h.Helper()
1375 }
1376
1377 dt := expected.Sub(actual)
1378 if dt < -delta || dt > delta {
1379 return Fail(t, fmt.Sprintf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt), msgAndArgs...)
1380 }
1381
1382 return true
1383}
1384
1385// WithinRange asserts that a time is within a time range (inclusive).
1386//

Callers 4

WithinDurationFunction · 0.92
WithinDurationfFunction · 0.70
TestWithinDurationFunction · 0.70
WithinDurationMethod · 0.70

Calls 2

FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestWithinDurationFunction · 0.56