Handle parsed dates that already have a timezone on import.

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
This commit is contained in:
André Jaenisch 2022-05-23 20:52:57 +02:00
parent 12541d5f1c
commit b564e514fd
No known key found for this signature in database
GPG key ID: 5A668E771F1ED854

View file

@ -175,9 +175,12 @@ class ImportItem(models.Model):
def date_added(self):
"""when the book was added to this dataset"""
if self.normalized_data.get("date_added"):
return timezone.make_aware(
dateutil.parser.parse(self.normalized_data.get("date_added"))
)
parsed_date_added = dateutil.parser.parse(self.normalized_data.get("date_added"))
if timezone.is_aware(parsed_date_added):
# Keep timezone if import already had one
return parsed_date_added
return timezone.make_aware(parsed_date_added)
return None
@property