Use ciso8601 library to parse datetime faster (#32128)
parent
d996a4a9a9
commit
15b4975681
|
@ -7,6 +7,7 @@ async_timeout==3.0.1
|
|||
attrs==19.3.0
|
||||
bcrypt==3.1.7
|
||||
certifi>=2019.11.28
|
||||
ciso8601==2.1.3
|
||||
cryptography==2.8
|
||||
defusedxml==0.6.0
|
||||
distro==1.4.0
|
||||
|
|
|
@ -3,6 +3,7 @@ import datetime as dt
|
|||
import re
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
||||
|
||||
import ciso8601
|
||||
import pytz
|
||||
import pytz.exceptions as pytzexceptions
|
||||
import pytz.tzinfo as pytzinfo
|
||||
|
@ -122,6 +123,10 @@ def parse_datetime(dt_str: str) -> Optional[dt.datetime]:
|
|||
Raises ValueError if the input is well formatted but not a valid datetime.
|
||||
Returns None if the input isn't well formatted.
|
||||
"""
|
||||
try:
|
||||
return ciso8601.parse_datetime(dt_str)
|
||||
except (ValueError, IndexError):
|
||||
pass
|
||||
match = DATETIME_RE.match(dt_str)
|
||||
if not match:
|
||||
return None
|
||||
|
|
1
pylintrc
1
pylintrc
|
@ -5,6 +5,7 @@ ignore=tests
|
|||
jobs=2
|
||||
load-plugins=pylint_strict_informational
|
||||
persistent=no
|
||||
extension-pkg-whitelist=ciso8601
|
||||
|
||||
[BASIC]
|
||||
good-names=id,i,j,k,ex,Run,_,fp
|
||||
|
|
|
@ -5,6 +5,7 @@ async_timeout==3.0.1
|
|||
attrs==19.3.0
|
||||
bcrypt==3.1.7
|
||||
certifi>=2019.11.28
|
||||
ciso8601==2.1.3
|
||||
importlib-metadata==1.5.0
|
||||
jinja2>=2.10.3
|
||||
PyJWT==1.7.1
|
||||
|
|
1
setup.py
1
setup.py
|
@ -38,6 +38,7 @@ REQUIRES = [
|
|||
"attrs==19.3.0",
|
||||
"bcrypt==3.1.7",
|
||||
"certifi>=2019.11.28",
|
||||
"ciso8601==2.1.3",
|
||||
"importlib-metadata==1.5.0",
|
||||
"jinja2>=2.10.3",
|
||||
"PyJWT==1.7.1",
|
||||
|
|
|
@ -464,7 +464,7 @@ def test_time():
|
|||
def test_datetime():
|
||||
"""Test date time validation."""
|
||||
schema = vol.Schema(cv.datetime)
|
||||
for value in [date.today(), "Wrong DateTime", "2016-11-23"]:
|
||||
for value in [date.today(), "Wrong DateTime"]:
|
||||
with pytest.raises(vol.MultipleInvalid):
|
||||
schema(value)
|
||||
|
||||
|
|
Loading…
Reference in New Issue