mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-10 08:12:47 +00:00
PartialDateField: allow incoming dates without timezone
This commit is contained in:
parent
1952bb6ddc
commit
dccac11527
2 changed files with 9 additions and 8 deletions
|
@ -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"""
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in a new issue