-
Notifications
You must be signed in to change notification settings - Fork 1
/
date_range_test.go
57 lines (50 loc) · 1.52 KB
/
date_range_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package enu_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/yuemori/enu"
)
func TestDateRange(t *testing.T) {
t.Parallel()
is := assert.New(t)
r1 := enu.FromDateRange(
time.Date(2023, 5, 20, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 20, 23, 59, 59, 0, time.UTC),
time.Hour,
).ToSlice()
is.Equal([]time.Time{
time.Date(2023, 5, 20, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 20, 22, 59, 59, 0, time.UTC),
time.Date(2023, 5, 20, 23, 59, 59, 0, time.UTC),
}, r1)
r2 := enu.FromDateRange(
time.Date(2023, 5, 20, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 23, 21, 59, 59, 0, time.UTC),
time.Hour*24,
).ToSlice()
is.Equal([]time.Time{
time.Date(2023, 5, 20, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 21, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 22, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 23, 21, 59, 59, 0, time.UTC),
}, r2)
r3 := enu.FromDateRange(
time.Date(2023, 5, 20, 21, 59, 59, 0, time.UTC),
time.Date(2099, 5, 23, 21, 59, 59, 0, time.UTC),
time.Hour*24,
).Take(5).ToSlice()
is.Equal([]time.Time{
time.Date(2023, 5, 20, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 21, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 22, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 23, 21, 59, 59, 0, time.UTC),
time.Date(2023, 5, 24, 21, 59, 59, 0, time.UTC),
}, r3)
r4 := enu.FromDateRange(
time.Date(2023, 5, 20, 23, 59, 59, 0, time.UTC),
time.Date(2023, 5, 20, 21, 59, 59, 0, time.UTC),
time.Hour,
).ToSlice()
is.Equal([]time.Time{}, r4)
}