Skip to content
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
3 changes: 3 additions & 0 deletions src/pendulum/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ def _get_parsed_value(
elif token in ["X", "x"]:
parsed["timestamp"] = parsed_token
elif token in ["ZZ", "Z"]:
if value in ["Z", "z"]:
value = "+00:00"

negative = bool(value.startswith("-"))
tz = value[1:]
if ":" not in tz:
Expand Down
14 changes: 14 additions & 0 deletions tests/datetime/test_from_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ def test_from_format_with_timezone():
assert d.timezone_name == "Europe/London"


@pytest.mark.parametrize("token", ["Z", "ZZ"])
@pytest.mark.parametrize("offset", ["Z", "z", "+00:00", "+0000"])
@pytest.mark.parametrize("default_tz", ["UTC", "Europe/Paris"])
def test_from_format_with_utc_designator(token, offset, default_tz):
d = pendulum.from_format(
f"1975-05-21T22:32:11{offset}",
f"YYYY-MM-DD[T]HH:mm:ss{token}",
tz=default_tz,
)

assert_datetime(d, 1975, 5, 21, 22, 32, 11)
assert d.offset == 0


def test_from_format_with_square_bracket_in_timezone():
with pytest.raises(ValueError, match=r"^String does not match format"):
pendulum.from_format(
Expand Down