kiorky / croniter

MIT License
410 stars 40 forks source link

I found 3 test cases that seem to fail on #92

Closed pmsteil closed 3 months ago

pmsteil commented 3 months ago

If you run this code:

from datetime import datetime
from croniter import croniter

# Helper function to print results and check if they match the expectations
def test_cron(cron_expr, base_time, expected):
    actual = croniter(cron_expr, base_time).get_next(datetime)
    result = "PASS" if actual == expected else "FAIL"
    print(f"[{result}] Cron: {cron_expr}, Base time: {base_time}")
    print(f"  Expected: {expected}, Got: {actual}\n")
    return result == "PASS"

# Test cases and results
tests = [
    # "*/15 6-18 * * *" means every 15 minutes from 6 AM to 6 PM
    ("*/15 6-18 * * *", datetime(2023, 10, 10, 17, 45), datetime(2023, 10, 10, 18, 0)),

    # "0 9 * * 1-5" means 9:00 AM Monday to Friday
    ("0 9 * * 1-5", datetime(2023, 10, 13, 9, 0), datetime(2023, 10, 16, 9, 0)),

    # "0 0 * * *" means midnight (00:00) every day
    ("0 0 * * *", datetime(2023, 12, 31, 23, 59), datetime(2024, 1, 1, 0, 0)),

    # "* * * * *" means every minute
    ("* * * * *", datetime(2023, 10, 10, 23, 59), datetime(2023, 10, 11, 0, 0)),

    # "30 1 * * 1" means 1:30 AM every Monday
    ("30 1 * * 1", datetime(2023, 10, 10, 1, 30), datetime(2023, 10, 16, 1, 30)),

    # "0 22 * * 6,0" means 10:00 PM every Saturday and Sunday
    ("0 22 * * 6,0", datetime(2023, 10, 13, 22, 0), datetime(2023, 10, 14, 22, 0)),

    # "*/30 9-17 * * *" means every 30 minutes from 9 AM to 5 PM
    ("*/30 9-17 * * *", datetime(2023, 10, 10, 17, 30), datetime(2023, 10, 11, 9, 0)),

    # "*/15 6-18 * * *" means every 15 minutes from 6 AM to 6 PM
    ("*/15 6-18 * * *", datetime(2023, 10, 10, 18, 30), datetime(2023, 10, 11, 6, 0)),

    # "*/5 0-3,20-23 * * *" means every 5 minutes from midnight to 3 AM and from 8 PM to 11 PM
    ("*/5 0-3,20-23 * * *", datetime(2023, 10, 10, 3, 0), datetime(2023, 10, 10, 20, 0)),

    # "15 14 1 * *" means 2:15 PM on the 1st of every month
    ("15 14 1 * *", datetime(2023, 9, 30, 14, 15), datetime(2023, 11, 1, 14, 15)),
]

# Run test cases
for cron_expr, base_time, expected in tests:
    test_cron(cron_expr, base_time, expected)

You will get this output, note the last three that fail, the last one is the one that got me started testing this and is most important to me.

[PASS] Cron: */15 6-18 * * *, Base time: 2023-10-10 17:45:00
  Expected: 2023-10-10 18:00:00, Got: 2023-10-10 18:00:00

[PASS] Cron: 0 9 * * 1-5, Base time: 2023-10-13 09:00:00
  Expected: 2023-10-16 09:00:00, Got: 2023-10-16 09:00:00

[PASS] Cron: 0 0 * * *, Base time: 2023-12-31 23:59:00
  Expected: 2024-01-01 00:00:00, Got: 2024-01-01 00:00:00

[PASS] Cron: * * * * *, Base time: 2023-10-10 23:59:00
  Expected: 2023-10-11 00:00:00, Got: 2023-10-11 00:00:00

[PASS] Cron: 30 1 * * 1, Base time: 2023-10-10 01:30:00
  Expected: 2023-10-16 01:30:00, Got: 2023-10-16 01:30:00

[PASS] Cron: 0 22 * * 6,0, Base time: 2023-10-13 22:00:00
  Expected: 2023-10-14 22:00:00, Got: 2023-10-14 22:00:00

[PASS] Cron: */30 9-17 * * *, Base time: 2023-10-10 17:30:00
  Expected: 2023-10-11 09:00:00, Got: 2023-10-11 09:00:00

[FAIL] Cron: */5 0-3,20-23 * * *, Base time: 2023-10-10 03:00:00
  Expected: 2023-10-10 20:00:00, Got: 2023-10-10 03:05:00

[FAIL] Cron: 15 14 1 * *, Base time: 2023-09-30 14:15:00
  Expected: 2023-11-01 14:15:00, Got: 2023-10-01 14:15:00

MOST IMPORTANT ONE... >>
[FAIL] Cron: */15 6-18 * * *, Base time: 2023-10-10 18:30:00
  Expected: 2023-10-11 06:00:00, Got: 2023-10-10 18:45:00

thanks for any help! Other than this, great library!

pmsteil commented 3 months ago

I figured it out... at least on my most important one...

[FAIL] Cron: /15 6-18 , Base time: 2023-10-10 18:30:00 Expected: 2023-10-11 06:00:00, Got: 2023-10-10 18:45:00

[PASS] Cron: /15 6-18 , Base time: 2023-10-10 18:45:00 Expected: 2023-10-11 06:00:00, Got: 2023-10-11 06:00:00

6-18 means to go ALL the way through the 6pm hour... got it...

closing this for now