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

Last day of month, or 28th day #2

Open
rootedsoftware opened this issue Sep 22, 2014 · 2 comments
Open

Last day of month, or 28th day #2

rootedsoftware opened this issue Sep 22, 2014 · 2 comments

Comments

@rootedsoftware
Copy link

What happens if a task is scheduled for the last day of one month and that day doesn't exist in the next month?

I'm trying to run tasks every month regardless of the number of days in the month. So if I schedule a task to run every day: 31 in January then this task won't run in February.

How do you handle this?

@chfritz
Copy link
Owner

chfritz commented Sep 22, 2014

Good question. I don't think the package supports this use case. If you specify day: 31 then I think in months that have fewer days than 31 the function will get executed in the early days of the next month (30 days -> execute on 1st, 28 days -> execute on 3rd). I haven't validated this, but I'm using the setDate of Date objects to set the day, and that's the way that function handles cases like that.

Example:

> x = new Date()
Sun Sep 21 2014 17:33:11 GMT-0700 (PDT)
> x.setDate(32)
1412296391273
> x
Thu Oct 02 2014 17:33:11 GMT-0700 (PDT)

@chfritz
Copy link
Owner

chfritz commented Nov 19, 2015

It occurred to me that setDate(-1) will give you the last day of the previous month. This might be all you need. Have you tried entering a -1 for the month entry of the cron schedule? That might work out of the box.

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