33from email .utils import parsedate
44from typing import Optional , Union
55
6- import pytz
7-
86ISO8601_DATE_FORMAT = "%Y-%m-%d"
97ISO8601_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
108
119
12- def iso8601_date (s : str ) -> Optional [ Union [datetime .date , str ] ]:
10+ def iso8601_date (s : str ) -> Union [datetime .date , str ]:
1311 """
1412 Parses an ISO 8601 date string and returns a UTC date object or the string
1513 if the parsing failed.
@@ -19,7 +17,7 @@ def iso8601_date(s: str) -> Optional[Union[datetime.date, str]]:
1917 try :
2018 return (
2119 datetime .datetime .strptime (s , ISO8601_DATE_FORMAT )
22- .replace (tzinfo = pytz .utc )
20+ .replace (tzinfo = datetime . timezone .utc )
2321 .date ()
2422 )
2523 except (TypeError , ValueError ):
@@ -28,15 +26,15 @@ def iso8601_date(s: str) -> Optional[Union[datetime.date, str]]:
2826
2927def iso8601_datetime (
3028 s : str ,
31- ) -> Optional [ Union [datetime .datetime , str ] ]:
29+ ) -> Union [datetime .datetime , str ]:
3230 """
3331 Parses an ISO 8601 datetime string and returns a UTC datetime object,
3432 or the string if parsing failed.
3533 :param s: ISO 8601-formatted datetime string (2015-01-25T12:34:56Z)
3634 """
3735 try :
3836 return datetime .datetime .strptime (s , ISO8601_DATETIME_FORMAT ).replace (
39- tzinfo = pytz .utc
37+ tzinfo = datetime . timezone .utc
4038 )
4139 except (TypeError , ValueError ):
4240 return s
@@ -52,10 +50,10 @@ def rfc2822_datetime(s: str) -> Optional[datetime.datetime]:
5250 date_tuple = parsedate (s )
5351 if date_tuple is None :
5452 return None
55- return datetime .datetime (* date_tuple [:6 ]).replace (tzinfo = pytz .utc )
53+ return datetime .datetime (* date_tuple [:6 ]).replace (tzinfo = datetime . timezone .utc )
5654
5755
58- def decimal (d : Optional [str ]) -> Optional [ Union [Decimal , str ] ]:
56+ def decimal (d : Optional [str ]) -> Union [Decimal , str ]:
5957 """
6058 Parses a decimal string into a Decimal
6159 :param d: decimal string
@@ -65,7 +63,7 @@ def decimal(d: Optional[str]) -> Optional[Union[Decimal, str]]:
6563 return Decimal (d , BasicContext )
6664
6765
68- def integer (i : str ) -> Optional [ Union [int , str ] ]:
66+ def integer (i : str ) -> Union [int , str ]:
6967 """
7068 Parses an integer string into an int
7169 :param i: integer string
0 commit comments