Skip to content

Commit

Permalink
add decoder module with function to decode datatimes as string
Browse files Browse the repository at this point in the history
  • Loading branch information
m-p-esser committed Oct 3, 2023
1 parent 65954f1 commit 2f3cdc6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/decoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
""" Decoding functions """

from datetime import datetime


def datetime_decoder(dct: dict):
"""Convert all datetime values in a dict to a string"""
for key, value in dct.items():
if isinstance(value, str):
try:
dct[key] = datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ").strftime(
"%Y-%m-%d %H:%M:%S"
)
except ValueError:
pass
return dct

0 comments on commit 2f3cdc6

Please sign in to comment.