33 lines
614 B
Python
33 lines
614 B
Python
from datetime import datetime
|
|
|
|
|
|
def is_empty(_str: str) -> bool:
|
|
return len(_str.strip(" ")) == 0
|
|
|
|
|
|
def toDateTime(dt: str) -> datetime | int:
|
|
if len(dt) == 0:
|
|
return -1
|
|
try:
|
|
return datetime.strptime(dt, "%Y-%m-%d")
|
|
except ValueError:
|
|
return -1
|
|
|
|
|
|
def toFloat(v: str) -> float:
|
|
if len(v) == 0:
|
|
return -1.0
|
|
try:
|
|
return float(v)
|
|
except ValueError:
|
|
return -1.0
|
|
|
|
|
|
def toInt(v: str) -> int | None:
|
|
if len(v) == 0:
|
|
return None
|
|
try:
|
|
return int(v)
|
|
except ValueError:
|
|
return None
|