ImportItem: preserve parsed timezones in date_started, date_read

This is a follow-up to b564e514f ("Handle parsed dates that already
have a timezone on import"), which was applied to `date_added` only.

(Appart from consistency, this will allow to apply future parsing fixes
more easily.)
This commit is contained in:
Adeodato Simó 2023-10-15 19:43:51 -03:00
parent 6667178703
commit 8f0f3e6ace
No known key found for this signature in database
GPG key ID: CDF447845F1A986F

View file

@ -259,12 +259,10 @@ class ImportItem(models.Model):
except ValueError:
return None
@property
def date_added(self):
"""when the book was added to this dataset"""
if self.normalized_data.get("date_added"):
def _parse_datefield(self, field, /):
if self.normalized_data.get(field):
parsed_date_added = dateutil.parser.parse(
self.normalized_data.get("date_added")
self.normalized_data.get(field)
)
if timezone.is_aware(parsed_date_added):
@ -274,23 +272,20 @@ class ImportItem(models.Model):
return timezone.make_aware(parsed_date_added)
return None
@property
def date_added(self):
"""when the book was added to this dataset"""
return self._parse_datefield("date_added")
@property
def date_started(self):
"""when the book was started"""
if self.normalized_data.get("date_started"):
return timezone.make_aware(
dateutil.parser.parse(self.normalized_data.get("date_started"))
)
return None
return self._parse_datefield("date_started")
@property
def date_read(self):
"""the date a book was completed"""
if self.normalized_data.get("date_finished"):
return timezone.make_aware(
dateutil.parser.parse(self.normalized_data.get("date_finished"))
)
return None
return self._parse_datefield("date_finished")
@property
def reads(self):