Catch error for dateutil

In the event the server has some weird date that can't be converted
This commit is contained in:
angelblue05 2019-01-10 20:36:20 -06:00
parent 67377922a4
commit 1942f05559
1 changed files with 9 additions and 4 deletions

View File

@ -450,11 +450,16 @@ def convert_to_local(date):
''' Convert the local datetime to local. ''' Convert the local datetime to local.
''' '''
date = convert_str_to_date(date) if type(date) in (unicode, str) else date try:
date = date.replace(tzinfo=tz.tzutc()) date = convert_str_to_date(date) if type(date) in (unicode, str) else date
date = date.astimezone(tz.tzlocal()) date = date.replace(tzinfo=tz.tzutc())
date = date.astimezone(tz.tzlocal())
return date.strftime('%Y-%m-%dT%H:%M:%S') return date.strftime('%Y-%m-%dT%H:%M:%S')
except Exception as error:
LOG.error(error)
return str(date)
def convert_str_to_date(date): def convert_str_to_date(date):