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

Update day names handling in _to_int function #33

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Test

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
test:
Expand Down
8 changes: 4 additions & 4 deletions pycron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def _to_int(value, allow_daynames=False):
if isinstance(value, int) or (isinstance(value, str) and value.isnumeric()):
return int(value)

if isinstance(value, str) and allow_daynames and value in DAY_NAMES:
return DAY_NAMES.index(value)
if isinstance(value, str) and allow_daynames and value.lower() in DAY_NAMES:
return DAY_NAMES.index(value.lower())

if isinstance(value, str) and allow_daynames and value in DAY_ABBRS:
return DAY_ABBRS.index(value)
if isinstance(value, str) and allow_daynames and value.lower() in DAY_ABBRS:
return DAY_ABBRS.index(value.lower())

raise ValueError("Failed to parse string to integer")

Expand Down
13 changes: 13 additions & 0 deletions tests/test_day_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ def run(now):
assert pycron.is_now("* * * * tuesday-sunday/2", now) is False
assert pycron.is_now("* * * * tue-sun/2", now) is False

# Test capitalised names
assert pycron.is_now("* * * * THU", now)
assert pycron.is_now("* * * * THURSDAY", now)
assert pycron.is_now("* * * * */THU", now)
assert pycron.is_now("* * * * */THURSDAY", now)
assert pycron.is_now("* * * * SUN,WED,THU", now)
assert pycron.is_now("* * * * SUNDAY,WEDNESDAY,THURSDAY", now)
assert pycron.is_now("* * * * WED", now) is False
assert pycron.is_now("* * * * WEDNESDAY", now) is False
assert pycron.is_now("* * * * */WED", now) is False
assert pycron.is_now("* * * * */WEDNESDAY", now) is False
assert pycron.is_now("* * * * SUN,WED,SAT", now) is False

now = datetime(2015, 6, 18, 16, 7)
run(now)
run(now.replace(tzinfo=utc))
Expand Down
Loading