From 8f0f3e6ace98cf8812473b1569fc2f0b8204e437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Sun, 15 Oct 2023 19:43:51 -0300 Subject: [PATCH] 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.) --- bookwyrm/models/import_job.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 8929e9037..8329ee955 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -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):