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

[fix] Cron last day of the month incorrect behaviour #210

Open
3 tasks done
Giacomo-R opened this issue Jan 20, 2023 · 0 comments
Open
3 tasks done

[fix] Cron last day of the month incorrect behaviour #210

Giacomo-R opened this issue Jan 20, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Giacomo-R
Copy link

Describe the bug

Node.js version: 18.12.1

OS version: Windows 11

Description: I am trying to create a job that runs every month 8 days before the last day of the month, however the L-N° returned is wrong, I have tested using the late.parse.cron() function imported from "@breejs/later" and it returns in fact a wrong date.

Actual behavior

Yesterday, when I actually wrote it, it seemed to be working just fine, however today when I started the code below and it began starting in loop the process, even changing any other value of the cron doesn't make the difference and any value above 8 cause the same issue, anything below doesn't begin the loop but still gives incorrect date

I have tried printing the next 12 sheduled running times from "@breejs/later", code and output below, considering that the current date/time is "2023-01-20T10:44:30.086Z", so it simply prints the current time and date:

Code:

var cronSched = later.parse.cron('* * L-8 * *')
let next = later.schedule(cronSched).next(12)
console.log(next)

Result:

[
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z,
  2023-01-20T10:44:30.086Z
]

I have tried also to run a cron using "L-1" in the month field, it caused the following behaviour, which is still wrong because L alone is 31:

Code:

var cronSched = later.parse.cron('* * L-1 * *')
let next = later.schedule(cronSched).next(12)
console.log(next)

Result:

[
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z,
  2023-01-27T00:00:00.000Z
]

Code to reproduce

import Bree from "bree"
import Cabin from "cabin"

const bree = new Bree({
    logger: new Cabin(),
    jobs: [
        {
            name: "dailyImport",
            cron: "* * L-8 * *", 

            cronValidate: {
                override: {
                    useLastDayOfMonth: true
                }
            }
        },
    ]
})

await bree.start()

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
@Giacomo-R Giacomo-R added the bug Something isn't working label Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant