-
Notifications
You must be signed in to change notification settings - Fork 2
/
time.go
38 lines (31 loc) · 813 Bytes
/
time.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
34
35
36
37
38
package spectest
import (
"time"
"github.com/tenntenn/testtime"
)
// Interval represents a time interval.
type Interval struct {
// Started is the Started time of the interval.
Started time.Time
// Finished is the Finished time of the interval.
Finished time.Time
}
// NewInterval creates a new interval.
// This method is not set the start and end time of the interval.
func NewInterval() *Interval {
return &Interval{}
}
// Start sets the start time of the interval.
func (i *Interval) Start() *Interval {
i.Started = testtime.Now()
return i
}
// End sets the end time of the interval.
func (i *Interval) End() *Interval {
i.Finished = testtime.Now()
return i
}
// Duration returns the duration of the interval.
func (i Interval) Duration() time.Duration {
return i.Finished.Sub(i.Started)
}