Skip to content

Commit 39a9cd5

Browse files
committed
refactor(checker): preserve error, for pos 2 & 4 bail only on due or err
1 parent 3b0f444 commit 39a9cd5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

checker.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func (c *SegmentChecker) SetRef(ref time.Time) {
3333
func (c *SegmentChecker) CheckDue(segment string, pos int) (bool, error) {
3434
ref := c.GetRef()
3535
val, loc := valueByPos(ref, pos), ref.Location()
36+
last := time.Date(ref.Year(), ref.Month(), 1, 0, 0, 0, 0, loc).AddDate(0, 1, 0).Add(-time.Nanosecond).Day()
3637

3738
for _, offset := range strings.Split(segment, ",") {
3839
mod := pos == 2 || pos == 4
@@ -45,25 +46,25 @@ func (c *SegmentChecker) CheckDue(segment string, pos int) (bool, error) {
4546
continue
4647
}
4748

48-
last := time.Date(ref.Year(), ref.Month(), 1, 0, 0, 0, 0, loc).AddDate(0, 1, 0).Add(-time.Nanosecond).Day()
4949
if pos == 2 {
50-
return isValidMonthDay(offset, last, ref)
50+
due, err = isValidMonthDay(offset, last, ref)
51+
} else if pos == 4 {
52+
due, err = isValidWeekDay(offset, last, ref)
5153
}
52-
if pos == 4 {
53-
return isValidWeekDay(offset, last, ref)
54+
if due || err != nil {
55+
return due, err
5456
}
5557
}
5658

5759
return false, nil
5860
}
5961

6062
func (c *SegmentChecker) isOffsetDue(offset string, val int) (bool, error) {
61-
if strings.Contains(offset, "/") && inStep(val, offset) {
62-
return true, nil
63+
if strings.Contains(offset, "/") {
64+
return inStep(val, offset)
6365
}
64-
65-
if strings.Contains(offset, "-") && inRange(val, offset) {
66-
return true, nil
66+
if strings.Contains(offset, "-") {
67+
return inRange(val, offset)
6768
}
6869

6970
if val == 0 || offset == "0" {

0 commit comments

Comments
 (0)