fix: usar regex en _fmt_datetime para eliminar espacios en horas de Firebird
re.sub('\s*:\s*', ':') captura cualquier tipo de espacio alrededor
de los dos puntos, incluyendo tipos no-ASCII que .replace() no atrapa.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
4aa30c74c1
commit
9d87c3fa1c
@@ -1,3 +1,4 @@
|
|||||||
|
import re as _re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
@@ -5,6 +6,11 @@ from typing import Optional
|
|||||||
|
|
||||||
# ── helpers de formato de fecha ──────────────────────────────────────────────
|
# ── helpers de formato de fecha ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
def _clean_dt(s: str) -> str:
|
||||||
|
"""Elimina cualquier espacio alrededor de los dos puntos en horas."""
|
||||||
|
return _re.sub(r'\s*:\s*', ':', s)
|
||||||
|
|
||||||
|
|
||||||
def _fmt_fecha(val) -> str:
|
def _fmt_fecha(val) -> str:
|
||||||
if not val:
|
if not val:
|
||||||
return ""
|
return ""
|
||||||
@@ -17,16 +23,15 @@ def _fmt_fecha(val) -> str:
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def _clean_time(s: str) -> str:
|
|
||||||
return s.replace(": ", ":").replace(" :", ":")
|
|
||||||
|
|
||||||
|
|
||||||
def _fmt_datetime(val) -> str:
|
def _fmt_datetime(val) -> str:
|
||||||
if not val:
|
if not val:
|
||||||
return ""
|
return ""
|
||||||
|
# Convertir a string primero para poder limpiar espacios
|
||||||
if hasattr(val, "strftime"):
|
if hasattr(val, "strftime"):
|
||||||
return _clean_time(val.strftime("%d/%m/%Y %H:%M:%S"))
|
s = val.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
s = _clean_time(str(val))
|
else:
|
||||||
|
s = str(val)
|
||||||
|
s = _clean_dt(s)
|
||||||
s = s[:19].replace("T", " ")
|
s = s[:19].replace("T", " ")
|
||||||
parts = s.split(" ")
|
parts = s.split(" ")
|
||||||
if len(parts) == 2:
|
if len(parts) == 2:
|
||||||
|
|||||||
Reference in New Issue
Block a user