add dateutil as a dependency, use it in utils.datetime.iso8601_parse
This commit is contained in:
parent
ae7c6d8572
commit
e4d71f6c0c
2 changed files with 5 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
||||||
beautifulsoup4==4.8.0
|
beautifulsoup4==4.8.0
|
||||||
cryptography==2.7
|
cryptography==2.7
|
||||||
dataclasses==0.6
|
dataclasses==0.6
|
||||||
|
dateutil==2.8.1
|
||||||
dnspython==1.16.0
|
dnspython==1.16.0
|
||||||
feedparser==5.2.1
|
feedparser==5.2.1
|
||||||
lxml==4.4.1
|
lxml==4.4.1
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import re, typing
|
import re, typing
|
||||||
import datetime as _datetime
|
import datetime as _datetime
|
||||||
|
import dateutil.parser
|
||||||
ISO8601_PARSE = "%Y-%m-%dT%H:%M:%S%z"
|
|
||||||
ISO8601_PARSE_MICROSECONDS = "%Y-%m-%dT%H:%M:%S.%f%z"
|
|
||||||
|
|
||||||
ISO8601_FORMAT_DT = "%Y-%m-%dT%H:%M:%S"
|
ISO8601_FORMAT_DT = "%Y-%m-%dT%H:%M:%S"
|
||||||
ISO8601_FORMAT_TZ = "%z"
|
ISO8601_FORMAT_TZ = "%z"
|
||||||
|
@ -27,9 +25,9 @@ def iso8601_format(dt: _datetime.datetime, milliseconds: bool=False) -> str:
|
||||||
return "%s%s%s" % (dt_format, ms_format, tz_format)
|
return "%s%s%s" % (dt_format, ms_format, tz_format)
|
||||||
def iso8601_format_now(milliseconds: bool=False) -> str:
|
def iso8601_format_now(milliseconds: bool=False) -> str:
|
||||||
return iso8601_format(utcnow(), milliseconds=milliseconds)
|
return iso8601_format(utcnow(), milliseconds=milliseconds)
|
||||||
def iso8601_parse(s: str, microseconds: bool=False) -> _datetime.datetime:
|
|
||||||
fmt = ISO8601_PARSE_MICROSECONDS if microseconds else ISO8601_PARSE
|
def iso8601_parse(s: str) -> _datetime.datetime:
|
||||||
return _datetime.datetime.strptime(s, fmt)
|
return dateutil.parser.isoparse(s)
|
||||||
|
|
||||||
def datetime_human(dt: _datetime.datetime):
|
def datetime_human(dt: _datetime.datetime):
|
||||||
return _datetime.datetime.strftime(dt, DATETIME_HUMAN)
|
return _datetime.datetime.strftime(dt, DATETIME_HUMAN)
|
||||||
|
|
Loading…
Reference in a new issue