Merge pull request #212 from mcarlton00/bad-dates-are-bad

Validate date is not the default as it's invalid and throws errors when trying to parse it
This commit is contained in:
Abby 2020-02-26 18:42:24 +00:00 committed by GitHub
commit 589a1896db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -480,10 +480,13 @@ def convert_to_local(date):
date = parser.parse(date) if isinstance(date, string_types) else date date = parser.parse(date) if isinstance(date, string_types) else date
date = date.replace(tzinfo=tz.tzutc()) date = date.replace(tzinfo=tz.tzutc())
date = date.astimezone(tz.tzlocal()) date = date.astimezone(tz.tzlocal())
# Bad metadata defaults to date 1-1-1. Catch it and don't throw errors
if date.year == 1:
return str(date)
else:
return date.strftime('%Y-%m-%dT%H:%M:%S') return date.strftime('%Y-%m-%dT%H:%M:%S')
except Exception as error: except Exception as error:
LOG.exception(error) LOG.exception('Item date: {} --- {}'.format(str(date), error))
return str(date) return str(date)