1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add convert_to_int function

This commit is contained in:
Kelly Brazil
2021-04-17 17:22:59 -07:00
parent f7b9fbefdd
commit b5d8968144

View File

@ -83,6 +83,25 @@ def has_data(data):
return True if data and not data.isspace() else False return True if data and not data.isspace() else False
def convert_to_int(value):
"""
Converts string input to integer by stripping all non-numeric characters
Parameters:
value: (string) Input value
Returns:
integer/None Integer if successful conversion, otherwise None
"""
try:
value = int(re.sub('[^0-9]', '', value))
except (ValueError, TypeError):
return None
return value
class timestamp: class timestamp:
""" """
Input a date-time text string of several formats and convert to a naive or timezone-aware epoch timestamp in UTC Input a date-time text string of several formats and convert to a naive or timezone-aware epoch timestamp in UTC