bree
bree copied to clipboard
[fix] Cron last day of the month incorrect behaviour
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
- [X] I have searched through GitHub issues for similar issues.
- [X] I have completely read through the README and documentation.
- [X] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.