-
Notifications
You must be signed in to change notification settings - Fork 345
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
Hey, how do I set the last day of the month to be executed on time? #106
Comments
Did you find any way to do it? |
It doesn't look like there is a way to do that currently. Seems like a feature would need to be added. Perhaps a |
Yes, currently he needs FirstDay(), LastDay(), DayOfMonth(15) |
I'm not certain this is the purview of gocron. For example, I've needed to create a report on the 12th of each month - EXCEPT if the 12th was on the weekend and then it was either the 11th if the 12th was a Saturday or the 13th if the 12th was a Sunday. That would be an interesting set of options to describe in a single line of gocron scheduling. So, maybe something like this for the question at hand func coreTask() {
fmt.Println("Must be last day of month - time to make the donuts")
}
func task() {
now := time.Now()
currentYear, currentMonth, currentDay := now.Date()
currentLocation := now.Location()
firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
if lastOfMonth.Day() == currentDay {
coreTask()
}
}
gocron.Every(1).Day().At("10:30").Do(task) Last day of month code from here |
I like your solution @wishdev! Seems very reasonable to handle outside of gocron as to your point - the options could be highly involved getting exactly the right cron schedule unless it was a simple, I want this date of the month always, or the first day or last day. |
Nice solution @wishdev. Was also looking for something similar and this does the job. Good enough for me 👍 |
@003random come check out our active fork https://github.com/go-co-op/gocron we’ve added support for Monthly schedules 👍 |
Oh awesome! Thanks @JohnRoesler |
Hey, how do I set the last day of the month to be executed on time?
The text was updated successfully, but these errors were encountered: