Skip to content

Commit

Permalink
refactor(checker): preserve error, for pos 2 & 4 bail only on due or err
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Apr 22, 2021
1 parent 3b0f444 commit 39a9cd5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (c *SegmentChecker) SetRef(ref time.Time) {
func (c *SegmentChecker) CheckDue(segment string, pos int) (bool, error) {
ref := c.GetRef()
val, loc := valueByPos(ref, pos), ref.Location()
last := time.Date(ref.Year(), ref.Month(), 1, 0, 0, 0, 0, loc).AddDate(0, 1, 0).Add(-time.Nanosecond).Day()

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

last := time.Date(ref.Year(), ref.Month(), 1, 0, 0, 0, 0, loc).AddDate(0, 1, 0).Add(-time.Nanosecond).Day()
if pos == 2 {
return isValidMonthDay(offset, last, ref)
due, err = isValidMonthDay(offset, last, ref)
} else if pos == 4 {
due, err = isValidWeekDay(offset, last, ref)
}
if pos == 4 {
return isValidWeekDay(offset, last, ref)
if due || err != nil {
return due, err
}
}

return false, nil
}

func (c *SegmentChecker) isOffsetDue(offset string, val int) (bool, error) {
if strings.Contains(offset, "/") && inStep(val, offset) {
return true, nil
if strings.Contains(offset, "/") {
return inStep(val, offset)
}

if strings.Contains(offset, "-") && inRange(val, offset) {
return true, nil
if strings.Contains(offset, "-") {
return inRange(val, offset)
}

if val == 0 || offset == "0" {
Expand Down

0 comments on commit 39a9cd5

Please sign in to comment.