kiorky / croniter

MIT License
382 stars 37 forks source link

Last Thursday of the month pattern doesn't work... #60

Closed Fyphon closed 6 months ago

Fyphon commented 6 months ago
def test():
    datetime_str = '23/02/24 00:00:00'
    base = datetime.strptime(datetime_str, '%d/%m/%y %H:%M:%S')
    end_date = base + timedelta(days=31)
    print(
        f'Start time {base.strftime("%d/%m/%Y, %A")}, end time {end_date.strftime("%d/%m/%Y, %A")}')
    testdata = '0 0 24-31 * 4'  # pattern for last Thursday of the month
    for dt in croniter_range(base, end_date, testdata):
        print(dt.strftime("%d/%m/%Y, %A"))

Output: Start time 23/02/2024, Friday, end time 25/03/2024, Monday 24/02/2024, Saturday 25/02/2024, Sunday 26/02/2024, Monday 27/02/2024, Tuesday 28/02/2024, Wednesday 29/02/2024, Thursday 07/03/2024, Thursday 14/03/2024, Thursday 21/03/2024, Thursday 24/03/2024, Sunday 25/03/2024, Monday

The iterator is return every date that is in the day-of-moth range OR a Thursday. I want every date that is in the day-of-moth range AND a Thursday.

Fyphon commented 6 months ago

This is not an error, it is expected behaviour (unfortunatly) so the issue can be closed. From the cron documentation: https://man7.org/linux/man-pages/man5/crontab.5.html

"Note: The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the current time."