api_entreprise: ignore null timestamps (#36546)

This commit is contained in:
Benjamin Dauvergne 2019-10-05 13:42:42 +02:00
parent 8aedbe41b1
commit 7b82aae51c
1 changed files with 13 additions and 8 deletions

View File

@ -54,14 +54,19 @@ def normalize_dates(data):
pass
if key.endswith('timestamp'):
# timestamps can be integers or strings
# convert only if positive values
if int(data[key]) > 0:
try:
aware_date = make_aware(datetime.fromtimestamp(int(data[key])))
timestamp_to_datetime[key[:-len('timestamp')] + 'datetime'] = aware_date
except (ValueError, TypeError):
pass
# timestamps can be integers or strings or null
# convert only if it's a positive integer
try:
tstamp = int(data[key])
except (ValueError, TypeError):
pass
else:
if tstamp > 0:
try:
aware_date = make_aware(datetime.fromtimestamp(int(data[key])))
timestamp_to_datetime[key[:-len('timestamp')] + 'datetime'] = aware_date
except (ValueError, TypeError):
pass
# add converted timestamps to initial data
data.update(timestamp_to_datetime)