INNER CODE UNIT · Python
force_int_validator
DogsTailFarmer/martin-binance · martin_binance/backup.py:252
def force_int_validator(v: Any) -> Any:
"""Safely converts float/string timestamps to integer by dropping fractions."""
if v is None or v == "None":
return None
try:
return int(float(v))
except (ValueError, TypeError):
return 0
def force_datetime_validator(v: Any) -> Any:
"""Guarantees conversion of ISO strings from JSON back into datetime objects."""
if v is None or isinstance(v, datetime):
return v
try:
# Clean up any extraneous escaped quotes and parse the ISO string.
return datetime.fromisoformat(str(v).replace('"', '').replace("'", ""))
except (ValueError, TypeError):