Skip to content

Commit

Permalink
Switch to backports for iso8601 for python3.10
Browse files Browse the repository at this point in the history
Switch to backports for iso8601 for python3.10 instead of ciso8601
  • Loading branch information
chillymosh committed Mar 18, 2024
1 parent 0718249 commit 39ec8ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aiohttp>=3.9.1,<4
typing_extensions>=4.1.0
ciso8601; python_version < '3.11'
backports.datetime_fromisoformat>=2.0.1
20 changes: 6 additions & 14 deletions twitchio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from datetime import datetime
from typing import Any

from backports.datetime_fromisoformat import MonkeyPatch # type: ignore


MonkeyPatch.patch_fromisoformat() # type: ignore

try:
import orjson # type: ignore
Expand All @@ -14,17 +18,6 @@
except ImportError:
_from_json = json.loads

try:
from ciso8601 import parse_datetime as parse_iso
except ImportError:
from datetime import timezone

def parse_iso(datetime_string: str) -> datetime:
dt = datetime.fromisoformat(datetime_string)
dt = dt.replace(tzinfo=timezone.utc) if dt.tzinfo is None else dt.astimezone(timezone.utc)
return dt


__all__ = ("_from_json", "setup_logging", "ColourFormatter", "ColorFormatter", "parse_timestamp")


Expand Down Expand Up @@ -64,8 +57,7 @@ def stream_supports_rgb(stream: Any) -> bool:

def parse_timestamp(timestamp: str) -> datetime:
"""
Parses a timestamp in ISO8601 format to a datetime object using either
ciso8601.parse_datetime or datetime.fromisoformat based on availability.
Parses a timestamp in ISO8601 format to a datetime object.
Parameters
----------
Expand All @@ -77,7 +69,7 @@ def parse_timestamp(timestamp: str) -> datetime:
datetime.datetime
The parsed datetime object.
"""
return parse_iso(timestamp)
return datetime.fromisoformat(timestamp)


class ColourFormatter(logging.Formatter):
Expand Down

0 comments on commit 39ec8ed

Please sign in to comment.