Skip to content
Snippets Groups Projects
Commit 15a2a81d authored by Alessandro Cerioni's avatar Alessandro Cerioni
Browse files

Removing .%f in the datetime (de)serializer

parent b1abe301
Branches
Tags
No related merge requests found
...@@ -4,7 +4,7 @@ import pytz ...@@ -4,7 +4,7 @@ import pytz
# cf. https://stackoverflow.com/questions/30313243/messagepack-and-datetime # cf. https://stackoverflow.com/questions/30313243/messagepack-and-datetime
def decode_datetime(obj): def decode_datetime(obj):
if '__datetime__' in obj.keys(): if '__datetime__' in obj.keys():
tmp = datetime.datetime.strptime(obj["as_str"], "%Y-%m-%dT%H:%M:%S.%fZ") tmp = datetime.datetime.strptime(obj["as_str"], "%Y-%m-%dT%H:%M:%SZ")
output = pytz.timezone('UTC').localize(tmp) output = pytz.timezone('UTC').localize(tmp)
elif '__date__' in obj.keys(): elif '__date__' in obj.keys():
output = datetime.datetime.strptime(obj["as_str"], "%Y-%m-%d") output = datetime.datetime.strptime(obj["as_str"], "%Y-%m-%d")
...@@ -24,7 +24,7 @@ def encode_datetime(obj): ...@@ -24,7 +24,7 @@ def encode_datetime(obj):
tmp2 = tmp1.astimezone(pytz.UTC) tmp2 = tmp1.astimezone(pytz.UTC)
return {'__datetime__': True, 'as_str': tmp2.strftime("%Y-%m-%dT%H:%M:%S.%fZ")} return {'__datetime__': True, 'as_str': tmp2.strftime("%Y-%m-%dT%H:%M:%SZ")}
if isinstance(obj, datetime.date): if isinstance(obj, datetime.date):
return {'__date__': True, 'as_str': obj.strftime("%Y-%m-%d")} return {'__date__': True, 'as_str': obj.strftime("%Y-%m-%d")}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment