Skip to content

Commit a163ada

Browse files
author
King Long Tse
committed
refactor
1 parent 189850b commit a163ada

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

labelbox/schema/project.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,22 +311,15 @@ def _string_from_dict(dictionary: dict, value_with_quotes=False) -> str:
311311

312312
def _validate_datetime(string_date: str) -> bool:
313313
"""helper function validate that datetime is as follows: YYYY-MM-DD for the export"""
314-
succeed = False
315314
if string_date:
316-
try:
317-
datetime.strptime(string_date, "%Y-%m-%d")
318-
succeed = True
319-
except ValueError:
320-
pass
321-
try:
322-
datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S")
323-
succeed = True
324-
except ValueError:
325-
pass
326-
if not succeed:
327-
raise ValueError(f"""Incorrect format for: {string_date}.
328-
Format must be \"YYYY-MM-DD\" or \"YYYY-MM-DD hh:mm:ss\"""")
329-
return True
315+
for fmt in ("%Y-%m-%d", "%Y-%m-%d %H:%M:%S"):
316+
try:
317+
datetime.strptime(string_date, fmt)
318+
return
319+
except ValueError:
320+
pass
321+
raise ValueError(f"""Incorrect format for: {string_date}.
322+
Format must be \"YYYY-MM-DD\" or \"YYYY-MM-DD hh:mm:ss\"""")
330323

331324
sleep_time = 2
332325
id_param = "projectId"

0 commit comments

Comments
 (0)