summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2022-07-12 12:46:50 +0200
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2022-07-12 12:51:22 +0200
commitfc63768cfc5bdd98c6e57a027b7006b6cbcb1366 (patch)
tree2f79f77cb623f52ed4edb2000132291902230b61
parent5e5a7419941910fd616baf18321703c6204d7d07 (diff)
downloadslixmpp-fc63768cfc5bdd98c6e57a027b7006b6cbcb1366.tar.gz
slixmpp-fc63768cfc5bdd98c6e57a027b7006b6cbcb1366.tar.bz2
slixmpp-fc63768cfc5bdd98c6e57a027b7006b6cbcb1366.tar.xz
slixmpp-fc63768cfc5bdd98c6e57a027b7006b6cbcb1366.zip
XEP-0082: Move from mini_dateutil to datetime
Since datetime got merged into Python (probably around py3k), it’s now usable for all of our needs and so we can do away with the old fallback.
-rw-r--r--slixmpp/plugins/xep_0082.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/slixmpp/plugins/xep_0082.py b/slixmpp/plugins/xep_0082.py
index e8050286..0cdee465 100644
--- a/slixmpp/plugins/xep_0082.py
+++ b/slixmpp/plugins/xep_0082.py
@@ -6,7 +6,6 @@
import datetime as dt
from slixmpp.plugins import BasePlugin, register_plugin
-from slixmpp.thirdparty import tzutc, tzoffset, parse_iso
# =====================================================================
@@ -21,7 +20,10 @@ def parse(time_str):
Arguments:
time_str -- A formatted timestamp string.
"""
- return parse_iso(time_str)
+ try:
+ return dt.datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S.%f%z')
+ except ValueError:
+ return dt.datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S%z')
def format_date(time_obj):
@@ -52,7 +54,7 @@ def format_time(time_obj):
if isinstance(time_obj, dt.datetime):
time_obj = time_obj.timetz()
timestamp = time_obj.isoformat()
- if time_obj.tzinfo == tzutc():
+ if time_obj.tzinfo == dt.timezone.utc:
timestamp = timestamp[:-6]
return '%sZ' % timestamp
return timestamp
@@ -69,7 +71,7 @@ def format_datetime(time_obj):
time_obj -- A datetime object.
"""
timestamp = time_obj.isoformat('T')
- if time_obj.tzinfo == tzutc():
+ if time_obj.tzinfo == dt.timezone.utc:
timestamp = timestamp[:-6]
return '%sZ' % timestamp
return timestamp
@@ -128,9 +130,9 @@ def time(hour=None, min=None, sec=None, micro=None, offset=None, obj=False):
if micro is None:
micro = now.microsecond
if offset in (None, 0):
- offset = tzutc()
+ offset = dt.timezone.utc
elif not isinstance(offset, dt.tzinfo):
- offset = tzoffset(None, offset)
+ offset = dt.timezone(dt.timedelta(seconds=offset))
value = dt.time(hour, min, sec, micro, offset)
if obj:
return value
@@ -175,9 +177,9 @@ def datetime(year=None, month=None, day=None, hour=None,
if micro is None:
micro = now.microsecond
if offset in (None, 0):
- offset = tzutc()
+ offset = dt.timezone.utc
elif not isinstance(offset, dt.tzinfo):
- offset = tzoffset(None, offset)
+ offset = dt.timezone(dt.timedelta(seconds=offset))
value = dt.datetime(year, month, day, hour,
min, sec, micro, offset)