Skip to content

Commit

Permalink
Merge branch 'jlane9-use_conditionals' into python3_only
Browse files Browse the repository at this point in the history
  • Loading branch information
kipe committed Dec 5, 2019
2 parents 25319f5 + 9aaec2f commit 25966b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pycron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@


def _to_int(value, allow_daynames=False):
try:
"""
Converts a value to an integer. If allow_daynames is True, it will convert day of week to an integer 0 through 6.
@input:
value = value to convert to integer
allow_daynames = True, to allow values like Mon or Monday
@output: value as an integer
"""

if isinstance(value, int) or (isinstance(value, str) and value.isnumeric()):
return int(value)
except ValueError:
if not allow_daynames:
raise

for i, day_name in enumerate(DAY_NAMES):
if day_name == value:
return i
for i, day_abbr in enumerate(DAY_ABBRS):
if day_abbr == value:
return i

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

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

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

Expand Down
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@
description='Simple cron-like parser, which determines if current datetime matches conditions.',
author='Kimmo Huoman',
author_email='[email protected]',
license='MIT',
keywords='cron parser',
url='https://github.com/kipe/pycron',
packages=[
'pycron',
],
setup_requires=['nose>=1.0'],
tests_require=[
"arrow>=0.12.0",
"coverage>=4.4.2",
"coveralls>=1.2.0",
"Delorean>=0.6.0",
"nose>=1.0",
"pendulum>=1.3.2",
"pytz>=2017.3",
"udatetime>=0.0.14"
]
)
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ arrow>=0.12.0
coverage>=4.4.2
coveralls>=1.2.0
Delorean>=0.6.0
nose>=1.0
pendulum>=1.3.2
pytz>=2017.3
udatetime>=0.0.14

0 comments on commit 25966b5

Please sign in to comment.