From 9f372f4b10d827e7cd8cd1e8399f01b254cfdf93 Mon Sep 17 00:00:00 2001 From: Jesus Galindez Date: Fri, 13 Sep 2024 00:04:27 -0500 Subject: [PATCH] Fix: Corregido error de formato de fecha ValueError: Invalid isoformat string: 20XX-XX-12T05:15:02.801Z para prorider cripto_dolar --- pyDolarVenezuela/providers/criptodolar.py | 4 ++-- pyDolarVenezuela/utils/time.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pyDolarVenezuela/providers/criptodolar.py b/pyDolarVenezuela/providers/criptodolar.py index 85fbcfa..87bf1cb 100644 --- a/pyDolarVenezuela/providers/criptodolar.py +++ b/pyDolarVenezuela/providers/criptodolar.py @@ -2,7 +2,7 @@ import json from .. import network -from ..utils.time import get_formatted_date +from ..utils.time import get_formatted_date, get_formatted_date_tz from ..utils.common import _convert_specific_format, _convert_dollar_name_to_monitor_name from ..utils.extras import list_monitors_images from ._base import Base @@ -25,7 +25,7 @@ def _load(cls, **kwargs) -> List[Dict[str, Any]]: title = _convert_dollar_name_to_monitor_name(monitor['name']) price = round(monitor['price'], 2) price_old = monitor['priceOld'] - last_update = get_formatted_date(monitor['updatedAt']) + last_update = get_formatted_date_tz(monitor['updatedAt']) data.append({ 'key': key, diff --git a/pyDolarVenezuela/utils/time.py b/pyDolarVenezuela/utils/time.py index 3a1cf44..3498268 100644 --- a/pyDolarVenezuela/utils/time.py +++ b/pyDolarVenezuela/utils/time.py @@ -1,6 +1,6 @@ from babel.dates import format_date, format_time from datetime import datetime, timedelta -from pytz import timezone +from pytz import timezone,utc from .extras import time_units @@ -35,6 +35,19 @@ def get_formatted_date(date_string: str): """ return datetime.fromisoformat(date_string).astimezone(standard_time_zone) + +def get_formatted_date_tz(date_string: str): + """ + Formatear datetime desde TZ. + """ + # Parsear la fecha y hora usando strptime + dt = datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%S.%fZ") + # Asignar la zona horaria UTC utilizando pytz + dt = dt.replace(tzinfo=utc) + + return dt.astimezone(standard_time_zone) + + def get_time(date_string: str): """ Formatear datetime.