cron icon indicating copy to clipboard operation
cron copied to clipboard

Seems some bad case

Open WUST-mengqinyu opened this issue 1 year ago • 3 comments

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

WUST-mengqinyu avatar Aug 16 '24 10:08 WUST-mengqinyu

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.

norman-abramovitz avatar Sep 06 '24 02:09 norman-abramovitz

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?

WUST-mengqinyu avatar Sep 08 '24 06:09 WUST-mengqinyu

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.

norman-abramovitz avatar Sep 08 '24 20:09 norman-abramovitz