Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions deemon/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ def format_date_string(d: str):
def ui_date(d: datetime):
return datetime.strftime(d, '%b %d, %Y')

def str_to_datetime_obj(d: str) -> datetime:
if d == "0000-00-00":
d = "1980-01-01"
return datetime.strptime(d, "%Y-%m-%d")

ddef str_to_datetime_obj(d: str) -> datetime | None:
try:
if not d or d.strip() == "" or d.startswith("0000"):
logger.warning(f"[dates] Invalid date detected ('{d}'), using 1900-01-01 as default value.")
return datetime.strptime("1900-01-01", "%Y-%m-%d")
return datetime.strptime(d, "%Y-%m-%d")
except Exception as e:
logger.error(f"[dates] Error al convertir fecha '{d}': {e}")
return None

def get_friendly_date(d: int):
input_date = datetime.fromtimestamp(d).date()
Expand Down