Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plus sign in timezone designator #1787

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@ Contributors (chronological)
- Stephen Eaton `@madeinoz67 <https://github.com/madeinoz67>`_
- Antonio Lassandro `@lassandroan <https://github.com/lassandroan>`_
- Javier Fernández `@jfernandz <https://github.com/jfernandz>`_
- Felix Claessen `@flix6x <https://github.com/flix6x>`_
2 changes: 1 addition & 1 deletion src/marshmallow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def rfcformat(datetime: dt.datetime) -> str:
r"(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})"
r"[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})"
r"(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?"
r"(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$"
r"(?P<tzinfo>Z|[ +-]\d{2}(?::?\d{2})?)?$"
)

_iso8601_date_re = re.compile(r"(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$")
Expand Down
1 change: 1 addition & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from marshmallow.exceptions import ValidationError

central = pytz.timezone("US/Central")
adam = pytz.timezone("Europe/Amsterdam")


ALL_FIELDS = [
Expand Down
25 changes: 23 additions & 2 deletions tests/test_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import ipaddress
import decimal
import math
from urllib import parse

import pytest

from marshmallow import EXCLUDE, INCLUDE, RAISE, fields, Schema, validate
from marshmallow.exceptions import ValidationError
from marshmallow.validate import Equal

from tests.base import assert_date_equal, assert_time_equal, central, ALL_FIELDS
from tests.base import assert_date_equal, assert_time_equal, adam, central, ALL_FIELDS


class TestDeserializingNone:
Expand Down Expand Up @@ -456,6 +457,11 @@ def test_custom_date_format_datetime_field_deserialization(self):
central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
True,
),
(
"Sun, 10 Nov 2013 01:23:45 +0100",
adam.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
True,
),
],
)
def test_rfc_datetime_field_deserialization(self, fmt, value, expected, aware):
Expand Down Expand Up @@ -500,6 +506,21 @@ def test_rfc_datetime_field_deserialization(self, fmt, value, expected, aware):
central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
True,
),
(
parse.unquote_plus("2013-11-10T01:23:45-06:00"),
central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
True,
),
(
"2013-11-10T01:23:45+01:00",
adam.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
True,
),
(
parse.unquote_plus("2013-11-10T01:23:45+01:00"),
adam.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
True,
),
],
)
def test_iso_datetime_field_deserialization(self, fmt, value, expected, aware):
Expand Down Expand Up @@ -558,7 +579,7 @@ def test_naive_datetime_with_timezone(self, fmt, timezone, value, expected):
field = fields.NaiveDateTime(format=fmt, timezone=timezone)
assert field.deserialize(value) == expected

@pytest.mark.parametrize("timezone", (dt.timezone.utc, central))
@pytest.mark.parametrize("timezone", (dt.timezone.utc, central, adam))
@pytest.mark.parametrize(
("fmt", "value"),
[("iso", "2013-11-10T01:23:45"), ("rfc", "Sun, 10 Nov 2013 01:23:45")],
Expand Down