Skip to content

Commit

Permalink
Merge pull request #10 from elinventor/main
Browse files Browse the repository at this point in the history
Fix: new method to format TZ type time (@elinventor)
  • Loading branch information
fcoagz authored Sep 13, 2024
2 parents 1b85d72 + 9f372f4 commit ebc1d88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pyDolarVenezuela/providers/criptodolar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion pyDolarVenezuela/utils/time.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ebc1d88

Please sign in to comment.