Skip to content

Commit

Permalink
style: [lint] add docs for public symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Apr 21, 2021
1 parent 3955e88 commit 3fa84a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ import (
"time"
)

// Checker is interface for cron segment due check.
type Checker interface {
GetRef() time.Time
SetRef(ref time.Time)
CheckDue(segment string, pos int) (bool, error)
}

// SegmentChecker is factory implementation of Checker.
type SegmentChecker struct {
ref time.Time
}

// GetRef returns the current reference time
func (c *SegmentChecker) GetRef() time.Time {
return c.ref
}

// SetRef sets the reference time for which to check if a cron expression is due.
func (c *SegmentChecker) SetRef(ref time.Time) {
c.ref = ref
}

// CheckDue checks if the cron segment at given position is due.
// It returns bool or error if any.
func (c *SegmentChecker) CheckDue(segment string, pos int) (bool, error) {
ref := c.GetRef()
val, loc := valueByPos(ref, pos), ref.Location()
Expand Down
4 changes: 4 additions & 0 deletions gronx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ func normalize(expr string) []string {
return strings.Split(strings.ReplaceAll(expr, " ", " "), " ")
}

// Gronx is the main program.
type Gronx struct {
C Checker
}

// New initializes Gronx with factory defaults.
func New() Gronx {
return Gronx{&SegmentChecker{}}
}

// IsDue checks if cron expression is due for given reference time (or now).
// It returns bool or error if any.
func (g *Gronx) IsDue(expr string, ref ...time.Time) (bool, error) {
segs := normalize(expr)
if len(segs) < 5 || len(segs) > 6 {
Expand Down

0 comments on commit 3fa84a4

Please sign in to comment.