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

[FEATURE] - Support scheduling months based count of days since last day of the month (-2, -3, etc.) #523

Closed
SrijaSingu opened this issue Jul 4, 2023 · 5 comments · Fixed by #542
Labels
enhancement New feature or request

Comments

@SrijaSingu
Copy link

Describe the bug

Go cron monthly schedule is not scheduling job on the day specified in the month if the day exists for the month.This behaviour is seen only in last days of the months i.e, 29th, 30th , 31st.It is throwing validation error if any day is choosen among them.

In the library, it is mentioned that -1 is special value that can be used to create schedule on last day for all the months. But if user wants to schedule a job on every 29th of the month, he cannot even though the day exists for the month.

To Reproduce

Steps to reproduce the behavior:

  1. Schedule a monthly job to run on every 29th day of month

Version
v1.30.1

Actual behavior

Validation Error thrown - "only days 1 through 28 are allowed for monthly schedules"

Expected behavior

It should schedule job on 29th day for the months if the day exists.
Expected to schedule for all months except February.For February, it can schedule job on last day of the month since day does not exists (considering it's not leap year).

@SrijaSingu SrijaSingu added the bug Something isn't working label Jul 4, 2023
@JohnRoesler
Copy link
Contributor

Hi @SrijaSingu

The functionality you're describing doesn't currently exist in gocron. I'm going to change this issue into a feature request tag.

@JohnRoesler JohnRoesler added enhancement New feature or request and removed bug Something isn't working labels Jul 10, 2023
@JohnRoesler JohnRoesler changed the title [BUG] - Go Cron Schedule Issue for last days of the month [Feature Request] - Go Cron Schedule Issue for last days of the month Jul 10, 2023
@JohnRoesler JohnRoesler changed the title [Feature Request] - Go Cron Schedule Issue for last days of the month [FEATURE] - Go Cron Schedule Issue for last days of the month Jul 10, 2023
@JohnRoesler JohnRoesler changed the title [FEATURE] - Go Cron Schedule Issue for last days of the month [FEATURE] - Support scheduling months based count of days since last day of the month (-2, -3, etc.) Jul 12, 2023
@gabrielcipriano
Copy link

how is the expected interface?

now in the method Months(daysOfTheMonth ...int) we would be able to pass a list of negative numbers too?

being -1 the last day, -2 the penultimate day of the month, etc?

@gabrielcipriano
Copy link

what about the MonthLastDay() method? an another approach would be to be able to pass a 'optional' parameter to this method, maybe it would be more readable:

.MonthLastDay(-1) = last day minus one = penultimate day of the month

@pavakj
Copy link

pavakj commented Jan 3, 2024

I think this will still not support all the months correctly. For example if I say -2 for 31 days months it will be 29, For 30 days months it will be 28 and for February it will be 27 or 26.

@JohnRoesler
Copy link
Contributor

I think this will still not support all the months correctly

I guess that depends on expected behavior. The design here is to support X days prior to the last day of the month. If you wanted to run on the 29th of the month, then you could, for all months except Feb (except leap years).

Handling which day it should run each month is interesting and all depends on what each user wants. If you wanted exact control, you could schedule several copies of the job. For example, a job that runs every 12 months on Feb 28th, and then jobs that run April, June, September, and November on the 29th, and then on the 30th of the other months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants