kiorky / croniter

MIT License
410 stars 40 forks source link

Incorrect calculation of the next execution date when processing certain day, month, and day of the week constraints #72

Closed VladLide closed 4 months ago

VladLide commented 6 months ago

The library appears to incorrectly calculate the next execution date when processing cron expressions that include certain day, month, and day of week constraints. If the specified month is current and a specific day of the week is specified.

Example problem:

from croniter import croniter
from datetime import datetime

if __name__ == '__main__':
     print(f"Current time: {datetime.now()}")
     print(f"Next execution date: {croniter('* * 1 5 1-4').get_next(datetime)}")

Result:

Current time: 2024-05-20 09:57:48.044267
Next execution date: 2024-05-20 09:58:00

The expected output should contain a time of May 1, 2025, given the constraints, but the library returns today's date instead.

zachary-povey commented 6 months ago

Think this is actually correct based on the crontab spec:

""" Finally, if either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month, or the day of week, shall be matched """

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html