Skip to content

Commit 0862126

Browse files
committed
fix: 修复GetStartTime的bug和补充GetNextStartTime的单元测试
1 parent 9def273 commit 0862126

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

datetime_expression_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,12 @@ func TestDateTimeExpression_GetStartTime_Hour(t *testing.T) {
629629
err: ErrOutOfDate,
630630
result: time.Time{},
631631
},
632+
{
633+
exp: "[2000][02-04][05-07][8:00:00-10:00:00,11:00:00-12:30:30]",
634+
input: time.Date(2000, time.April, 7, 12, 30, 30, 0, time.Local),
635+
err: ErrOutOfDate,
636+
result: time.Time{},
637+
},
632638
}
633639
for i, data := range testDatas {
634640
fmt.Printf("[%d] exp:%s\n", i, data.exp)
@@ -1133,3 +1139,49 @@ func TestDateTimeExpression_GetEndTime_Hour(t *testing.T) {
11331139
assert.Equal(t, data.result, endTime)
11341140
}
11351141
}
1142+
1143+
func TestDateTimeExpression_GetNextStartTime(t *testing.T) {
1144+
testDatas := []struct {
1145+
exp string
1146+
input time.Time
1147+
err error
1148+
result time.Time
1149+
}{
1150+
{
1151+
exp: "[*][*][*][*]",
1152+
input: time.Date(2000, time.January, 8, 0, 0, 00, 0, time.Local),
1153+
err: ErrAlwaysActiveNoStartTime,
1154+
result: time.Time{},
1155+
},
1156+
{
1157+
exp: "[2000][02-04][05-07][8:00:00-10:00:00,11:00:00-12:30:30]",
1158+
input: time.Date(2000, time.January, 8, 0, 0, 00, 0, time.Local),
1159+
err: nil,
1160+
result: time.Date(2000, time.February, 5, 8, 00, 00, 0, time.Local),
1161+
},
1162+
{
1163+
exp: "[2000][02-04][05-07][8:00:00-10:00:00,11:00:00-12:30:30]",
1164+
input: time.Date(2000, time.February, 5, 9, 0, 00, 0, time.Local),
1165+
err: nil,
1166+
result: time.Date(2000, time.February, 5, 11, 00, 00, 0, time.Local),
1167+
},
1168+
{
1169+
exp: "[2000][02-04][05-07][8:00:00-10:00:00,11:00:00-12:30:30]",
1170+
input: time.Date(2000, time.April, 8, 0, 0, 00, 0, time.Local),
1171+
err: ErrOutOfDate,
1172+
result: time.Time{},
1173+
},
1174+
}
1175+
1176+
for i, data := range testDatas {
1177+
fmt.Printf("[%d] exp:%s\n", i, data.exp)
1178+
expr, err := NewDateTimeExpression(data.exp)
1179+
if err != nil {
1180+
panic(err)
1181+
}
1182+
1183+
nextStartTime, err := expr.GetNextStartTime(data.input)
1184+
assert.Equal(t, data.err, err)
1185+
assert.Equal(t, data.result, nextStartTime)
1186+
}
1187+
}

hour_expression.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (expression *hourExpression) getStart(hour, min, sec int) (hourUint hourUni
7676
minUnit = &unit.start
7777
}
7878

79-
if paramSec > unit.end.toSec() {
79+
if paramSec >= unit.end.toSec() {
8080
continue
8181
}
8282
if targetUnit == nil || targetUnit.toSec() > unit.start.toSec() {

0 commit comments

Comments
 (0)