mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-06-13 18:59:24 +00:00
PartialDateField: allow incoming dates without timezone
This commit is contained in:
parent
1952bb6ddc
commit
dccac11527
|
@ -569,15 +569,17 @@ class PartialDateField(ActivitypubFieldMixin, SealedDateField):
|
||||||
except (ValueError, ParserError):
|
except (ValueError, ParserError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# FIXME #1: add timezone if missing (SealedDate only accepts tz-aware).
|
if timezone.is_aware(parsed):
|
||||||
#
|
return SealedDate.from_datetime(parsed)
|
||||||
# FIXME #2: decide whether to fix timestamps like "2023-09-30T21:00:00-03":
|
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
|
# 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 …)
|
# 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.
|
# but over the wire we might get these for an indeterminate amount of time.
|
||||||
|
|
||||||
return SealedDate.from_datetime(parsed)
|
|
||||||
|
|
||||||
|
|
||||||
class HtmlField(ActivitypubFieldMixin, models.TextField):
|
class HtmlField(ActivitypubFieldMixin, models.TextField):
|
||||||
"""a text field for storing html"""
|
"""a text field for storing html"""
|
||||||
|
|
|
@ -601,9 +601,8 @@ class ModelFields(TestCase):
|
||||||
instance = fields.PartialDateField()
|
instance = fields.PartialDateField()
|
||||||
expected = datetime.date(2023, 10, 20)
|
expected = datetime.date(2023, 10, 20)
|
||||||
test_cases = [
|
test_cases = [
|
||||||
# XXX: must fix before merging.
|
("no_tz", "2023-10-20T00:00:00"),
|
||||||
# ("no_tz", "2023-10-20T00:00:00"),
|
("no_tz_eod", "2023-10-20T23:59:59.999999"),
|
||||||
# ("no_tz_eod", "2023-10-20T23:59:59.999999"),
|
|
||||||
("utc_offset_midday", "2023-10-20T12:00:00+0000"),
|
("utc_offset_midday", "2023-10-20T12:00:00+0000"),
|
||||||
("utc_offset_midnight", "2023-10-20T00:00:00+00"),
|
("utc_offset_midnight", "2023-10-20T00:00:00+00"),
|
||||||
("eastern_tz_parsed", "2023-10-20T15:20:30+04:30"),
|
("eastern_tz_parsed", "2023-10-20T15:20:30+04:30"),
|
||||||
|
|
Loading…
Reference in a new issue