product_calendar_break_time_period_test.go
1.2 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package domain
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestCheckOverDay(t *testing.T) {
var input = []struct {
name string
begin string
end string
overDay bool
}{
{
"normal",
"11:00",
"12:00",
false,
},
{
"over day",
"23:45",
"00:45",
true,
},
}
for _, v := range input {
p := NewProductCalendarBreakTimePeriod(v.begin, v.end, 0)
t.Run(v.name, func(t *testing.T) {
ok, err := p.CheckOverDay()
assert.Equal(t, v.overDay, ok)
assert.Nil(t, err)
})
}
}
func TestGetCheckTime(t *testing.T) {
var input = []struct {
name string
begin string
end string
overDay bool
in time.Time
}{
{
"normal",
"11:00",
"12:00",
false,
time.Date(2022, 5, 5, 9, 0, 0, 0, time.Local),
},
{
"over day",
"23:45",
"00:45",
true,
time.Date(2022, 5, 5, 23, 0, 0, 0, time.Local),
},
}
for _, v := range input {
p := NewProductCalendarBreakTimePeriod(v.begin, v.end, 0)
t.Run(v.name, func(t *testing.T) {
begin := p.GetCheckBeginTime(time.Now())
end := p.GetCheckEndTime(time.Now())
overDay := begin.Day() != end.Day()
assert.Equal(t, v.overDay, overDay, fmt.Sprintf("begin:%v end:%v", begin, end))
})
}
}