From c599498993f873c77f1ca3ef51c1f088cf1c3269 Mon Sep 17 00:00:00 2001 From: Viraat Das Date: Thu, 4 Jun 2026 22:25:16 -0700 Subject: [PATCH] Parse the numeric day-of-week token 'd' arrow can format a date with the single 'd' token (ISO day of week as a number) but cannot parse it back: arrow.get("3", "d") raises because 'd' is not handled in the parser. Add 'd' to the parseable tokens and map it to day_of_week so a 'd'-formatted value round-trips. Fixes #1072. --- arrow/parser.py | 4 ++++ tests/test_parser.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/arrow/parser.py b/arrow/parser.py index fc3774b0..769019ce 100644 --- a/arrow/parser.py +++ b/arrow/parser.py @@ -550,6 +550,7 @@ def _parse_token( "m", "ss", "s", + "d", "x", ], value: Union[str, bytes, SupportsInt, bytearray], @@ -645,6 +646,9 @@ def _parse_token( ) parts["day_of_week"] = day_of_week - 1 + elif token == "d": + parts["day_of_week"] = int(value) - 1 + elif token.upper() in ["HH", "H"]: parts["hour"] = int(value) diff --git a/tests/test_parser.py b/tests/test_parser.py index 7038d880..9838f89c 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -586,6 +586,9 @@ def test_parse_ddd_and_dddd(self): assert self.parser.parse("Tuesday", "dddd") == expected assert fr_parser.parse("mardi", "dddd") == expected + # Get first Wednesday after epoch by ISO day of week + assert arrow.get("3", "d") == arrow.get(1970, 1, 7) + # Get first Tuesday in 2020 expected = datetime(2020, 1, 7) assert self.parser.parse("Tue 2020", "ddd YYYY") == expected