robfig / cron

a cron library for go
MIT License
13.14k stars 1.63k forks source link

How to start job from the past time? #512

Open BugKillerPro opened 9 months ago

BugKillerPro commented 9 months ago
       parser := cron.NewParser(
        cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
    )
    c := cron.New(cron.WithParser(parser))

    // 0 0 */5 * *
    c.AddFunc("0 0 0 */5 * ?", func() {
        fmt.Println("Every 5 day")
    })

If this program run at 2024-01-01,then fmt.Println("Every 5 day") will run at 2024-01-06、2024-01-11 ......, but if I restart this program at 2024-01-02,then fmt.Println("Every 5 day") will run at 2024-01-07、2024-01-12 ......., So ,How to avoid restart influence?or How to start job from the past time? or How to set a specific past time as original cron start time ?