WithinRange asserts that a time is within a time range (inclusive). assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
(t TestingT, actual, start, end time.Time, msgAndArgs ...interface{})
| 1334 | // |
| 1335 | // assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second)) |
| 1336 | func WithinRange(t TestingT, actual, start, end time.Time, msgAndArgs ...interface{}) bool { |
| 1337 | if h, ok := t.(tHelper); ok { |
| 1338 | h.Helper() |
| 1339 | } |
| 1340 | |
| 1341 | if end.Before(start) { |
| 1342 | return Fail(t, "Start should be before end", msgAndArgs...) |
| 1343 | } |
| 1344 | |
| 1345 | if actual.Before(start) { |
| 1346 | return Fail(t, fmt.Sprintf("Time %v expected to be in time range %v to %v, but is before the range", actual, start, end), msgAndArgs...) |
| 1347 | } else if actual.After(end) { |
| 1348 | return Fail(t, fmt.Sprintf("Time %v expected to be in time range %v to %v, but is after the range", actual, start, end), msgAndArgs...) |
| 1349 | } |
| 1350 | |
| 1351 | return true |
| 1352 | } |
| 1353 | |
| 1354 | func toFloat(x interface{}) (float64, bool) { |
| 1355 | var xf float64 |