8000 two cron expression all run on 2017-10-18, i think it's a bug · Issue #118 · robfig/cron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

two cron expression all run on 2017-10-18, i think it's a bug 8000 #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jindongyi011039 opened this issue Oct 18, 2017 · 3 comments
Closed

Comments

@jindongyi011039
Copy link
jindongyi011039 commented Oct 18, 2017

two cron expression all run on 2017-10-18, i think it's a bug
[/10 * * 1-29 10 1-5],[/10 * * 30,31 10 1-5]
test code:
cronTask.AddFunc("/10 * * 1-29 10 1-5", func() {
fmt.Println("run:" + "
/10 * * 1-29 10 1-5")
})
cronTask.AddFunc("/10 * * 30,31 10 1-5", func() {
fmt.Println("run:" + "
/10 * * 30,31 10 1-5")
})
the code in spec.go line149
func dayMatches return true on domMatch || dowMatch, but, this expression "*/10 * * 30,31 10 1-5" should return false.

@antsbean
Copy link

It's not a bug,
because

  • author definition day-of-week and day-of-month use "or" semantic not "and" semantic when two field doesn't "*" or "?"
  • author definition day-of-week and day-of-month use "and" semantic not "or" semantic when two field anyone use "*" or "?"

Why see below code

parse.go files

func getRange(expr string, r bounds) (uint64, error) {
	var (
		start, end, step uint
		rangeAndStep     = strings.Split(expr, "/")
		lowAndHigh       = strings.Split(rangeAndStep[0], "-")
		singleDigit      = len(lowAndHigh) == 1
		err              error
	)

	var extra uint64
	if lowAndHigh[0] == "*" || lowAndHigh[0] == "?" {
		start = r.min
		end = r.max
		extra = starBit

when day-of-week or day-of-month any one is "*" or "?" lead to

func dayMatches(s *SpecSchedule, t time.Time) bool {
	var (
		domMatch bool = 1<<uint(t.Day())&s.Dom > 0
		dowMatch bool = 1<<uint(t.Weekday())&s.Dow > 0
	)
	if s.Dom&starBit > 0 || s.Dow&starBit > 0 {
		return domMatch && dowMatch
	}
	return domMatch || dowMatch
}

if s.Dom&starBit > 0 || s.Dow&starBit > 0 is true
when day-of-week or day-of-month any one is other lead to
return domMatch || dowMatch is true

@jindongyi011039
Copy link
Author

hqy, thank you for quickly answer.
I want to write two cron expression, Daylight saving time and standard time change-over.
the first: do some things at 15:00 during working days between 2017/10/1 and 2017/10/29
the second: do some things at 16:00 during working days between 2017/10/30 and 2017/10/31
It looks like it's a little difficult.

@robfig
Copy link
Owner
robfig commented Jan 19, 2019

You are correct, sorry for the long silence. This is a dupe of issue #70

@robfig robfig closed this as completed Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0