forked from manythumbed/checkers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
33 lines (24 loc) · 834 Bytes
/
time_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package checkers
import (
"time"
. "gopkg.in/check.v1"
)
type Time struct{}
func (ts *Time) TestWithinDuration(c *C) {
t1 := time.Now()
maxDiff := time.Minute
c.Check(t1, WithinDuration, t1.Add(time.Second), maxDiff)
c.Check(t1, WithinDuration, t1.Add(-time.Second), maxDiff)
c.Check(t1, WithinDuration, t1.Add(time.Minute), maxDiff)
c.Check(t1, WithinDuration, t1.Add(-time.Minute), maxDiff)
c.Check(t1, Not(WithinDuration), t1.Add(2*time.Minute), maxDiff)
c.Check(t1, Not(WithinDuration), t1.Add(-2*time.Minute), maxDiff)
}
func (ts *Time) TestTimeEquals(c *C) {
t1 := time.Now()
c.Check(t1, TimeEquals, t1)
c.Check(t1, TimeEquals, t1.UTC())
c.Check(t1, TimeEquals, t1.Add(time.Nanosecond*10))
c.Check(t1, TimeEquals, t1.Add(-time.Nanosecond*120))
c.Check(t1, Not(TimeEquals), t1.Add(time.Microsecond+1))
}