Skip to content

Commit 7173507

Browse files
committed
Add back is_date
1 parent 3769ce2 commit 7173507

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

schema_automator/generalizers/csv_data_generalizer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,22 @@ def get_db(db_id: str) -> Optional[str]:
680680
return parts[0]
681681

682682

683+
def is_date(string, fuzzy=False):
684+
"""
685+
Return whether the string can be interpreted as a date.
686+
687+
:param string: str, string to check for date
688+
:param fuzzy: bool, ignore unknown tokens in string if True
689+
"""
690+
try:
691+
parse(string, fuzzy=fuzzy)
692+
return True
693+
except Exception:
694+
# https://stackoverflow.com/questions/4990718/how-can-i-write-a-try-except-block-that-catches-all-exceptions
695+
# we don't know all the different parse exceptions, we assume any error means this is a date
696+
return False
697+
698+
683699
def is_date_or_datetime(string, fuzzy=False):
684700
"""
685701
Return whether the string can be interpreted as a date or datetime.

0 commit comments

Comments
 (0)