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{})
| 1386 | // |
| 1387 | // assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second)) |
| 1388 | func WithinRange(t TestingT, actual, start, end time.Time, msgAndArgs ...interface{}) bool { |
| 1389 | if h, ok := t.(tHelper); ok { |
| 1390 | h.Helper() |
| 1391 | } |
| 1392 | |
| 1393 | if end.Before(start) { |
| 1394 | return Fail(t, "Start should be before end", msgAndArgs...) |
| 1395 | } |
| 1396 | |
| 1397 | if actual.Before(start) { |
| 1398 | 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...) |
| 1399 | } else if actual.After(end) { |
| 1400 | 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...) |
| 1401 | } |
| 1402 | |
| 1403 | return true |
| 1404 | } |
| 1405 | |
| 1406 | func toFloat(x interface{}) (float64, bool) { |
| 1407 | var xf float64 |