From e77a6d70078bf865b25c367ad4db4d980673f5f5 Mon Sep 17 00:00:00 2001 From: vera-rubin <322284620+vera-rubin@users.noreply.github.com> Date: Wed, 14 Oct 2026 19:46:44 +0000 Subject: [PATCH] Fix parsing of the Y year token in from_format() --- src/pendulum/formatting/formatter.py | 1 + tests/datetime/test_from_format.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/pendulum/formatting/formatter.py b/src/pendulum/formatting/formatter.py index b09977d0d..3c87af64a 100644 --- a/src/pendulum/formatting/formatter.py +++ b/src/pendulum/formatting/formatter.py @@ -206,6 +206,7 @@ class Formatter: _PARSE_TOKENS: ClassVar[dict[str, Callable[[str], Any]]] = { "YYYY": lambda year: int(year), "YY": lambda year: int(year), + "Y": lambda year: int(year), "Q": lambda quarter: int(quarter), "MMMM": lambda month: month, "MMM": lambda month: month, diff --git a/tests/datetime/test_from_format.py b/tests/datetime/test_from_format.py index ecf59632a..bba644d46 100644 --- a/tests/datetime/test_from_format.py +++ b/tests/datetime/test_from_format.py @@ -95,6 +95,7 @@ def test_from_format_with_invalid_padded_day(): ("1234567890", "X", "2009-02-13T23:31:30+00:00", None), ("1234567890123", "x", "2009-02-13T23:31:30.123000+00:00", None), ("2016-10-06", "YYYY-MM-DD", "2016-10-06T00:00:00+00:00", None), + ("2024-02-29", "Y-MM-DD", "2024-02-29T00:00:00+00:00", None), ("Tuesday", "dddd", "2015-11-10T00:00:00+00:00", None), ("Monday", "dddd", "2018-01-29T00:00:00+00:00", "2018-02-02"), ("Mon", "ddd", "2018-01-29T00:00:00+00:00", "2018-02-02"),