-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrange.go
35 lines (28 loc) · 823 Bytes
/
range.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
package anytime
import (
"time"
)
// RangeFunc is a function that can make a Range, given a reference time
// and a default direction.
type RangeFunc func(ref time.Time, dir Direction) Range
// Range is a time range as a half-open interval.
type Range struct {
start time.Time
Duration time.Duration
}
// Start is when the range begins, inclusive.
func (r Range) Start() time.Time {
return r.start
}
// End is when the range ends, exclusive.
func (r Range) End() time.Time {
return r.start.Add(r.Duration)
}
// Equal returns true if the two ranges are equal.
func (r Range) Equal(other Range) bool {
return r.start.Equal(other.start) && r.Duration == other.Duration
}
// RangeFromTimes returns a Range from two times.
func RangeFromTimes(start, end time.Time) Range {
return Range{start, end.Sub(start)}
}