diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 9c8793649..85ee654e3 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -569,15 +569,17 @@ class PartialDateField(ActivitypubFieldMixin, SealedDateField): except (ValueError, ParserError): return None - # FIXME #1: add timezone if missing (SealedDate only accepts tz-aware). - # - # FIXME #2: decide whether to fix timestamps like "2023-09-30T21:00:00-03": + if timezone.is_aware(parsed): + return SealedDate.from_datetime(parsed) + else: + # Should not happen on the wire, but truncate down to date parts. + return SealedDate.from_date_parts(parsed.year, parsed.month, parsed.day) + + # FIXME: decide whether to fix timestamps like "2023-09-30T21:00:00-03": # clearly Oct 1st, not Sep 30th (an unwanted side-effect of USE_TZ). It's # basically the remnants of #3028; there is a data migration pending (see …) # but over the wire we might get these for an indeterminate amount of time. - return SealedDate.from_datetime(parsed) - class HtmlField(ActivitypubFieldMixin, models.TextField): """a text field for storing html""" diff --git a/bookwyrm/tests/models/test_fields.py b/bookwyrm/tests/models/test_fields.py index e9afcdef6..d04178d4a 100644 --- a/bookwyrm/tests/models/test_fields.py +++ b/bookwyrm/tests/models/test_fields.py @@ -601,9 +601,8 @@ class ModelFields(TestCase): instance = fields.PartialDateField() expected = datetime.date(2023, 10, 20) test_cases = [ - # XXX: must fix before merging. - # ("no_tz", "2023-10-20T00:00:00"), - # ("no_tz_eod", "2023-10-20T23:59:59.999999"), + ("no_tz", "2023-10-20T00:00:00"), + ("no_tz_eod", "2023-10-20T23:59:59.999999"), ("utc_offset_midday", "2023-10-20T12:00:00+0000"), ("utc_offset_midnight", "2023-10-20T00:00:00+00"), ("eastern_tz_parsed", "2023-10-20T15:20:30+04:30"),