mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 11:01:12 +00:00
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:
parent
6667178703
commit
8f0f3e6ace
1 changed files with 10 additions and 15 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue