From 5bb433222263568651f69de4a6f968205c1ec137 Mon Sep 17 00:00:00 2001 From: AbhisumatK Date: Wed, 10 Jun 2026 16:22:35 +0530 Subject: [PATCH] Fixed the Timezone Parsing Regression --- arrow/parser.py | 2 +- test_arrow_get.py | 12 ++++++++++++ test_reproduce.py | 10 ++++++++++ tests/test_parser.py | 8 ++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test_arrow_get.py create mode 100644 test_reproduce.py diff --git a/arrow/parser.py b/arrow/parser.py index fc3774b09..fca8749b6 100644 --- a/arrow/parser.py +++ b/arrow/parser.py @@ -888,7 +888,7 @@ class TzinfoParser: """ _TZINFO_RE: ClassVar[Pattern[str]] = re.compile( - r"^(?:\(UTC)*([\+\-])?(\d{2})(?:\:?(\d{2}))?" + r"^(?:\(UTC)*([\+\-])?(\d{2})(?:\:?(\d{2}))?(?![0-9.:])" ) @classmethod diff --git a/test_arrow_get.py b/test_arrow_get.py new file mode 100644 index 000000000..7ff083f56 --- /dev/null +++ b/test_arrow_get.py @@ -0,0 +1,12 @@ +import arrow +try: + a = arrow.get("+03:00.34") + print(f"Parsed '+03:00.34' as: {a}") +except Exception as e: + print(f"Failed to parse '+03:00.34': {e}") + +try: + a = arrow.get("2023-10-10T10:00:00+03:00.34") + print(f"Parsed '2023-10-10T10:00:00+03:00.34' as: {a}") +except Exception as e: + print(f"Failed to parse '2023-10-10T10:00:00+03:00.34': {e}") diff --git a/test_reproduce.py b/test_reproduce.py new file mode 100644 index 000000000..2cef4769b --- /dev/null +++ b/test_reproduce.py @@ -0,0 +1,10 @@ +import arrow +from datetime import datetime + +try: + # Passing a string that contains a timezone but isn't a full datetime + # arrow.get('2023-10-10 10:00:00', tzinfo='+03:00.34') + a = arrow.get(datetime(2023, 10, 10), tzinfo='+03:00.34') + print(f"Parsed with tzinfo='+03:00.34' as: {a}") +except Exception as e: + print(f"Failed with tzinfo='+03:00.34': {e}") diff --git a/tests/test_parser.py b/tests/test_parser.py index 7038d880f..9e7401ee3 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1330,6 +1330,14 @@ def test_parse_utc_withoffset(self): "(UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien" ) == timezone(timedelta(seconds=3600)) + def test_parse_partial_offset_fail(self): + # Regression tests for issue where partial offsets were matched + with pytest.raises(parser.ParserError): + self.parser.parse("+03:00.34") + + with pytest.raises(parser.ParserError): + self.parser.parse("+03005") + def test_parse_iso(self): assert self.parser.parse("01:00") == timezone(timedelta(seconds=3600)) assert self.parser.parse("11:35") == timezone(