Skip to content
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

Seems some bad case #527

Open
WUST-mengqinyu opened this issue Aug 16, 2024 · 3 comments
Open

Seems some bad case #527

WUST-mengqinyu opened this issue Aug 16, 2024 · 3 comments

Comments

@WUST-mengqinyu
Copy link

Expr: 0 0 */2 * 3
in https://crontab.guru/ expected:

at 2024-08-21 00:00:00
then at 2024-08-28 00:00:00
then at 2024-09-04 00:00:00
then at 2024-09-11 00:00:00
then at 2024-09-18 00:00:00

for this lib

import (
	"fmt"
	"testing"
	"time"

	"github.com/robfig/cron/v3"
)

func TestCronJob(t *testing.T) {
	expr, err := cron.ParseStandard("0 0 */2 * 3")
	fmt.Println(err)
	now := time.Now()
	for i := range 10 {
		nxt := expr.Next(now)
		fmt.Println("next", i, ":", nxt.String())
		now = nxt
	}
}

res:

next 0 : 2024-08-17 00:00:00 +0800 CST
next 1 : 2024-08-19 00:00:00 +0800 CST
next 2 : 2024-08-21 00:00:00 +0800 CST
next 3 : 2024-08-23 00:00:00 +0800 CST
next 4 : 2024-08-25 00:00:00 +0800 CST
next 5 : 2024-08-27 00:00:00 +0800 CST
next 6 : 2024-08-28 00:00:00 +0800 CST
next 7 : 2024-08-29 00:00:00 +0800 CST
next 8 : 2024-08-31 00:00:00 +0800 CST
next 9 : 2024-09-01 00:00:00 +0800 CST

@norman-abramovitz
Copy link

norman-abramovitz commented Sep 6, 2024

I would claim both might be broken. */2 maps to 1-31/2 which means all old days. The day of week means Wednesday. so do you OR the resulting sets or AND the resulting sets or do you ignore one of the resulting sets. The GURU case is ignoring the day of the month and chose to use the day of the week only.

I would have said robfig ignored the day of the week, but I do not know where the 8-28 came from since I do not know which crontab specification was used.

Using https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html specification,

The opensgroup specification state it should be an OR, So guru is definitely broken and robfig is correct since 8-28 is an actual wednesday for the date range being shown.

There is a reason why the ? operator exists.

@WUST-mengqinyu
Copy link
Author

I would claim both might be broken. */2 maps to 1-31/2 which means all old days. The day of week means Wednesday. so do you OR the resulting sets or AND the resulting sets or do you ignore one of the resulting sets. The GURU case is ignoring the day of the month and chose to use the day of the week only.

I would have said robfig ignored the day of the week, but I do not know where the 8-28 came from since I do not know which crontab specification was used.

Using https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html specification,

The opensgroup specification state it should be an OR, So guru is definitely broken and robfig is correct since 8-28 is an actual wednesday for the date range being shown.

There is a reason why the ? operator exists.

If so, I think this lib should return a error rather than a not correct result?

@norman-abramovitz
Copy link

I would agree with you if we knew which specification this repo code was written to. Since I did find a specification supporting this cron's implementation, there is no error in this repo. There is a very strong possibility that the guru repo has the error and should be generating an error.

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

2 participants